增加一次性群邀请链接和二维码
This commit is contained in:
1 parent
dfeb5bfefa
commit
5ec9c81f90
18 files changed
+727
-14
No files matched your search
@@ -5,6 +5,8 @@ import { useSession } from '../session'
|
||||
import { APIError } from '../api'
|
||||
import type { Contact } from '../contacts'
|
||||
import GroupChat from '../chat/GroupChat.vue'
|
||||
import GroupInviteLink from '../chat/GroupInviteLink.vue'
|
||||
import { incomingGroupInvite, parseGroupInvite } from '../chat/group-invites'
|
||||
import type { GroupPreferences, GroupSummary, ListedGroup } from '../chat/group-chat'
|
||||
|
||||
type Group = GroupSummary
|
||||
@@ -20,6 +22,7 @@ const term = ref('')
|
||||
const name = ref('')
|
||||
const nextName = ref('')
|
||||
const invite = ref('')
|
||||
const inviteCode = ref('')
|
||||
const busy = ref(false)
|
||||
const error = ref('')
|
||||
const confirmation = ref<{ action: string; target?: string; label: string }>()
|
||||
@@ -84,10 +87,10 @@ function reload() {
|
||||
|
||||
function queueRefresh() {
|
||||
refreshPending = true
|
||||
if (busy.value || refreshTimer) return
|
||||
if (busy.value || confirmation.value || refreshTimer) return
|
||||
refreshTimer = setTimeout(() => {
|
||||
refreshTimer = undefined
|
||||
reload()
|
||||
if (!confirmation.value) reload()
|
||||
}, 250)
|
||||
}
|
||||
|
||||
@@ -120,6 +123,17 @@ function setPreference(key: keyof GroupPreferences) {
|
||||
})
|
||||
}
|
||||
|
||||
function redeemInvite() {
|
||||
const code = parseGroupInvite(inviteCode.value)
|
||||
if (!code) { error.value = '请输入当前 XHChat 服务的邀请链接或邀请码'; return }
|
||||
void run(async () => {
|
||||
const { groupId } = await session.authorized<{ groupId: string }>('/group-invites/redeem', 'POST', { code })
|
||||
inviteCode.value = ''
|
||||
await router.push('/groups/' + groupId)
|
||||
await refresh()
|
||||
})
|
||||
}
|
||||
|
||||
watch(id, () => {
|
||||
detail.value = undefined
|
||||
confirmation.value = undefined
|
||||
@@ -129,7 +143,13 @@ watch(id, () => {
|
||||
else reload()
|
||||
})
|
||||
watch(() => session.groupListChanges, queueRefresh)
|
||||
watch(confirmation, (value) => { if (!value && refreshPending) queueRefresh() })
|
||||
watch(() => session.groupChange, queueRefresh)
|
||||
watch(incomingGroupInvite, (code) => {
|
||||
if (!code) return
|
||||
inviteCode.value = code
|
||||
incomingGroupInvite.value = ''
|
||||
}, { immediate: true })
|
||||
watch(() => session.connection, (connection) => { if (connection === '实时连接已建立') queueRefresh() })
|
||||
onMounted(() => {
|
||||
reload()
|
||||
@@ -152,6 +172,10 @@ onBeforeUnmount(() => {
|
||||
<label>群名称<input v-model="name" required maxlength="64"></label>
|
||||
<button class="plain" :disabled="busy || !name.trim()">创建群组</button>
|
||||
</form>
|
||||
<form class="contact-search" @submit.prevent="redeemInvite">
|
||||
<label>群邀请链接或邀请码<input v-model="inviteCode" maxlength="2048" autocomplete="off" spellcheck="false"></label>
|
||||
<button type="submit" class="plain" :disabled="busy || !inviteCode.trim()">领取群邀请</button>
|
||||
</form>
|
||||
<label>查找群组<input v-model="term" type="search" maxlength="64"></label>
|
||||
<RouterLink v-for="group in visible" :key="group.id" class="contact-item" :to="'/groups/' + group.id">
|
||||
<span>
|
||||
@@ -181,6 +205,7 @@ onBeforeUnmount(() => {
|
||||
<button type="button" class="plain" :aria-pressed="detail.muted" :disabled="busy" @click="setPreference('muted')">群聊免打扰</button>
|
||||
</div>
|
||||
<GroupChat v-if="session.identity" :key="detail.id" :group="detail" @seen="queueRefresh" />
|
||||
<GroupInviteLink v-if="detail.role === 'owner'" :key="detail.id" :group-id="detail.id" />
|
||||
<form v-if="manage" class="contact-preferences" @submit.prevent="change('rename', undefined, nextName)">
|
||||
<label>修改群名称<input v-model="nextName" required maxlength="64"></label>
|
||||
<button class="plain" :disabled="busy || !nextName.trim() || nextName.trim() === detail.name">保存群名称</button>
|
||||
|
||||
Reference in new issue
Block a user