增加按设备统计的群消息未读角标

This commit is contained in:
xhgit committed 2026-11-14 20:11:42 +08:00
1 parent f54077ce46
commit 187923ca3c
16 files changed
+189 -23

No files matched your search

+6 -6
View File
@@ -35,7 +35,7 @@ const recent = ref<Record<string, string>>({})
const conversationQuery = ref('')
const history = ref<HTMLOListElement>()
const shareRead = ref(false)
const pendingVoice = ref<File>()
const pendingFile = ref<File>()
const view = ref<Awaited<ReturnType<typeof synchronize>>>()
const target = computed(() => typeof route.params.user === 'string' ? route.params.user : '')
const peer = computed(() => view.value?.peers.find((item) => item.id === selected.value))
@@ -213,7 +213,7 @@ function attach(event: Event) {
const input = event.target as HTMLInputElement
const file = input.files?.[0]
input.value = ''
if (file) sendFile(file)
if (file) pendingFile.value = file
}
function sendFile(file: File) {
@@ -225,12 +225,12 @@ function sendFile(file: File) {
}
function sendVoice(file: File) {
pendingVoice.value = file
pendingFile.value = file
}
watch([pendingVoice, busy], ([file, inProgress]) => {
watch([pendingFile, busy], ([file, inProgress]) => {
if (!file || inProgress) return
pendingVoice.value = undefined
pendingFile.value = undefined
sendFile(file)
})
@@ -286,7 +286,7 @@ watch(selected, () => {
recalling.value = undefined
forwarding.value = undefined
forwardStatus.value = ''
pendingVoice.value = undefined
pendingFile.value = undefined
draft.value = ''
scheduleReceipt()
})
+24 -4
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 { GroupPreferences, GroupSummary } from '../chat/group-chat'
import type { GroupPreferences, GroupSummary, ListedGroup } from '../chat/group-chat'
type Group = GroupSummary
type Detail = Group & { members: { id: string; username: string; state: Group['state']; role: Group['role'] }[] }
@@ -13,7 +13,7 @@ type Detail = Group & { members: { id: string; username: string; state: Group['s
const session = useSession()
const route = useRoute()
const router = useRouter()
const groups = ref<Group[]>([])
const groups = ref<ListedGroup[]>([])
const contacts = ref<Contact[]>([])
const detail = ref<Detail>()
const term = ref('')
@@ -37,7 +37,7 @@ let revision = 0
async function refresh() {
const version = ++revision
const selected = id.value
let list = await session.authorized<Group[]>('/groups')
let list = await session.authorized<ListedGroup[]>('/groups')
let next: Detail | undefined
if (list.some((group) => group.id === selected)) {
try {
@@ -129,6 +129,7 @@ watch(id, () => {
else reload()
})
watch(() => session.groupListChanges, queueRefresh)
watch(() => session.groupChange, queueRefresh)
watch(() => session.connection, (connection) => { if (connection === '实时连接已建立') queueRefresh() })
onMounted(() => {
reload()
@@ -157,6 +158,10 @@ onBeforeUnmount(() => {
<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>
<span v-if="group.unread" class="group-unread" :class="{ muted: group.muted }">
<span aria-hidden="true">{{ group.unread >= 100 ? '99+' : group.unread }}</span>
<span class="unread-label">{{ group.unread >= 100 ? '99 条以上未读' : group.unread + ' 条未读' }}</span>
</span>
</RouterLink>
</aside>
<div class="device-content chat-page">
@@ -175,7 +180,7 @@ onBeforeUnmount(() => {
<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" />
<GroupChat v-if="session.identity" :key="detail.id" :group="detail" @seen="queueRefresh" />
<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>
@@ -219,3 +224,18 @@ onBeforeUnmount(() => {
</div>
</section>
</template>
<style scoped>
.group-unread {
margin-inline-start: auto;
min-width: 1.5rem;
padding-inline: .35rem;
border-radius: 1rem;
background: var(--green-soft);
color: var(--green);
font-size: .8rem;
text-align: center;
}
.group-unread.muted { background: var(--base); color: var(--muted); }
.unread-label { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
</style>