增加群聊置顶、免打扰和应用内提醒
This commit is contained in:
1 parent
ced6e9030d
commit
f54077ce46
17 files changed
+228
-42
No files matched your search
@@ -5,7 +5,7 @@ import { useSession } from '../session'
|
||||
import { APIError } from '../api'
|
||||
import type { Contact } from '../contacts'
|
||||
import GroupChat from '../chat/GroupChat.vue'
|
||||
import type { GroupSummary } from '../chat/group-chat'
|
||||
import type { GroupPreferences, GroupSummary } from '../chat/group-chat'
|
||||
|
||||
type Group = GroupSummary
|
||||
type Detail = Group & { members: { id: string; username: string; state: Group['state']; role: Group['role'] }[] }
|
||||
@@ -111,6 +111,15 @@ function change(action: string, target?: string, value?: string) {
|
||||
})
|
||||
}
|
||||
|
||||
function setPreference(key: keyof GroupPreferences) {
|
||||
const current = detail.value
|
||||
if (current?.state !== 'active') return
|
||||
void run(async () => {
|
||||
await session.authorized('/groups/' + current.id + '/preferences', 'POST', { [key]: !current[key] })
|
||||
await refresh()
|
||||
})
|
||||
}
|
||||
|
||||
watch(id, () => {
|
||||
detail.value = undefined
|
||||
confirmation.value = undefined
|
||||
@@ -144,7 +153,10 @@ onBeforeUnmount(() => {
|
||||
</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><strong>{{ group.name }}</strong><small>{{ group.state === 'invited' ? '待接受邀请' : roles[group.role] }}</small></span>
|
||||
<span>
|
||||
<strong>{{ group.name }}</strong>
|
||||
<small>{{ group.state === 'invited' ? '待接受邀请' : roles[group.role] }}<template v-if="group.pinned"> · 已置顶</template><template v-if="group.muted"> · 免打扰</template></small>
|
||||
</span>
|
||||
</RouterLink>
|
||||
</aside>
|
||||
<div class="device-content chat-page">
|
||||
@@ -159,6 +171,10 @@ onBeforeUnmount(() => {
|
||||
</div>
|
||||
</template>
|
||||
<template v-else>
|
||||
<div class="message-actions" aria-label="群聊设置">
|
||||
<button type="button" class="plain" :aria-pressed="detail.pinned" :disabled="busy" @click="setPreference('pinned')">置顶群聊</button>
|
||||
<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" />
|
||||
<form v-if="manage" class="contact-preferences" @submit.prevent="change('rename', undefined, nextName)">
|
||||
<label>修改群名称<input v-model="nextName" required maxlength="64"></label>
|
||||
|
||||
@@ -1,11 +1,29 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue'
|
||||
import { onBeforeUnmount, ref, watch } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
import { useSession } from '../session'
|
||||
|
||||
const session = useSession()
|
||||
const route = useRoute()
|
||||
const error = ref('')
|
||||
const busy = ref(false)
|
||||
const browser = window.xhchat?.openBrowser
|
||||
const notice = ref<string>()
|
||||
let noticeTimer: ReturnType<typeof setTimeout> | undefined
|
||||
|
||||
function dismissNotice() {
|
||||
clearTimeout(noticeTimer)
|
||||
notice.value = undefined
|
||||
}
|
||||
|
||||
watch(() => session.groupChange, (event) => {
|
||||
if (!event?.notify || route.params.id === event.groupId) return
|
||||
dismissNotice()
|
||||
notice.value = event.groupId
|
||||
noticeTimer = setTimeout(dismissNotice, 8000)
|
||||
})
|
||||
watch(() => route.params.id, (id) => { if (id === notice.value) dismissNotice() })
|
||||
onBeforeUnmount(dismissNotice)
|
||||
|
||||
async function act(action: () => Promise<void>) {
|
||||
busy.value = true
|
||||
@@ -48,5 +66,17 @@ async function act(action: () => Promise<void>) {
|
||||
</div>
|
||||
</aside>
|
||||
<RouterView />
|
||||
<div v-if="notice" class="group-notice" role="status">
|
||||
<RouterLink :to="'/groups/' + notice" @click="dismissNotice">有新的群消息</RouterLink>
|
||||
<button type="button" class="plain" aria-label="关闭群消息提醒" @click="dismissNotice">关闭</button>
|
||||
</div>
|
||||
</main>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.group-notice {
|
||||
position: fixed; inset-inline-end: 1rem; inset-block-end: 1rem; z-index: 6;
|
||||
display: flex; align-items: center; gap: .7rem; padding: .6rem .85rem;
|
||||
background: var(--surface); border: 1px solid var(--line); border-radius: .5rem;
|
||||
}
|
||||
</style>
|
||||
Reference in new issue
Block a user