增加群聊置顶、免打扰和应用内提醒

This commit is contained in:
xhgit committed 2026-11-14 16:00:46 +08:00
1 parent ced6e9030d
commit f54077ce46
17 files changed
+228 -42

No files matched your search

+2 -1
View File
@@ -7,7 +7,8 @@ import type { Attachment, Mutation } from './attachments'
export type GroupMember = { id: string; username: string; state: 'active' | 'invited'; role: 'owner' | 'admin' | 'member' }
export type GroupDetail = { id: string; membershipVersion: string; members: GroupMember[]; role: GroupMember['role'] }
export type GroupSummary = Omit<GroupDetail, 'members'> & { name: string; state: GroupMember['state'] }
export type GroupPreferences = { pinned: boolean; muted: boolean }
export type GroupSummary = Omit<GroupDetail, 'members'> & GroupPreferences & { name: string; state: GroupMember['state'] }
export type GroupDevice = Peer & { user: string }
type Epoch = { id: string; creatorDevice: string; membershipVersion: string; welcome?: string; current: boolean; roster: string[] }
type Publishing = { id: string; membershipVersion: string; devices: { device: string; wire?: string }[] }
+3 -3
View File
@@ -26,7 +26,7 @@ export const useSession = defineStore('session', () => {
const connection = ref('离线')
const contactChanges = ref(0)
const inboxChanges = ref(0)
const groupChange = shallowRef<{ groupId: string }>()
const groupChange = shallowRef<{ groupId: string; notify: boolean }>()
const groupListChanges = ref(0)
let token = ''
let socket: WebSocket | undefined
@@ -54,14 +54,14 @@ export const useSession = defineStore('session', () => {
socket = active
active.onmessage = (event) => {
if (socket !== active) return
const { type, groupId } = JSON.parse(event.data)
const { type, groupId, notify } = JSON.parse(event.data)
if (type === 'ready') {
connection.value = '实时连接已建立'
attempts = 0
}
if (type === 'contacts_changed') contactChanges.value++
if (type === 'inbox_changed') inboxChanges.value++
if (type === 'group_changed' && typeof groupId === 'string') groupChange.value = { groupId }
if (type === 'group_changed' && typeof groupId === 'string') groupChange.value = { groupId, notify: notify === true }
if (type === 'group_list_changed') groupListChanges.value++
}
active.onclose = (event) => {
+18 -2
View File
@@ -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>
+31 -1
View File
@@ -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>