增加群文件、图片和视频视图
This commit is contained in:
1 parent
d5f4afb485
commit
52c0e52ffd
4 files changed
+102
-13
No files matched your search
@@ -22,6 +22,15 @@ const selected = ref<Record<string, string>>({})
|
||||
const draft = ref('')
|
||||
const search = ref('')
|
||||
const favoritesOnly = ref(false)
|
||||
const historyViews = [
|
||||
{ id: 'messages', label: '消息', empty: '没有匹配的群消息。' },
|
||||
{ id: 'files', label: '群文件', empty: '没有匹配的群文件。' },
|
||||
{ id: 'images', label: '群图片', empty: '没有匹配的群图片。' },
|
||||
{ id: 'videos', label: '群视频', empty: '没有匹配的群视频。' },
|
||||
] as const
|
||||
const historyView = ref<typeof historyViews[number]>(historyViews[0])
|
||||
const mediaPageSize = 24
|
||||
const mediaLimit = ref(mediaPageSize)
|
||||
const replying = ref<GroupLine>()
|
||||
const editing = ref<GroupLine>()
|
||||
const recalling = ref<GroupLine>()
|
||||
@@ -35,10 +44,19 @@ const ready = computed(() => view.value?.ready && view.value.current?.membership
|
||||
const currentEpoch = computed(() => ready.value ? view.value?.current?.id : undefined)
|
||||
const lines = computed(() => {
|
||||
const query = search.value.trim().toLowerCase()
|
||||
return (view.value?.lines ?? []).filter((line) =>
|
||||
(!favoritesOnly.value || line.favorite) &&
|
||||
(!query || [line.text, line.quote, line.attachment?.name].some((part) => part?.toLowerCase().includes(query))))
|
||||
const mode = historyView.value.id
|
||||
const matches = (view.value?.lines ?? []).filter((line) => {
|
||||
if (favoritesOnly.value && !line.favorite) return false
|
||||
if (mode === 'messages') {
|
||||
return !query || [line.text, line.quote, line.attachment?.name].some((part) => part?.toLowerCase().includes(query))
|
||||
}
|
||||
const attachment = line.attachment
|
||||
if (line.recalled || !attachment || attachment.voice || !attachment.name.toLowerCase().includes(query)) return false
|
||||
return mode === 'files' || attachment.media?.startsWith(mode === 'images' ? 'image/' : 'video/')
|
||||
})
|
||||
return mode === 'messages' ? matches : matches.reverse()
|
||||
})
|
||||
const visibleLines = computed(() => historyView.value.id === 'messages' ? lines.value : lines.value.slice(0, mediaLimit.value))
|
||||
const members = computed(() => props.group.members.filter((member) => member.state === 'active' && member.id !== session.identity?.user.id))
|
||||
const canPublish = computed(() => Boolean(view.value && !view.value.current && members.value.every((member) =>
|
||||
view.value?.devices.some((device) => device.user === member.id && device.id === selected.value[member.id] && pinned(device)))))
|
||||
@@ -216,6 +234,7 @@ function discard() {
|
||||
}
|
||||
|
||||
watch(() => props.group.membershipVersion, queueRefresh)
|
||||
watch([historyView, search, favoritesOnly], () => { mediaLimit.value = mediaPageSize })
|
||||
watch(() => session.groupChange, (event) => { if (event?.groupId === props.group.id) queueRefresh() })
|
||||
watch(() => session.connection, (connection) => { if (connection === '实时连接已建立') queueRefresh() })
|
||||
watch(currentEpoch, (epoch, previous) => {
|
||||
@@ -289,13 +308,18 @@ onBeforeUnmount(() => {
|
||||
</div>
|
||||
<button v-if="group.role === 'owner' && !view?.current" class="primary" :disabled="busy || !canPublish" @click="establish">建立群加密会话</button>
|
||||
</details>
|
||||
<div v-if="view?.lines.length || search || favoritesOnly" class="group-chat-search">
|
||||
<div v-if="view" class="group-history-views" role="group" aria-label="群历史视图">
|
||||
<button v-for="mode in historyViews" :key="mode.id" type="button" class="plain"
|
||||
:aria-pressed="historyView.id === mode.id" @click="historyView = mode">{{ mode.label }}</button>
|
||||
</div>
|
||||
<div v-if="view?.lines.length || search || favoritesOnly || historyView.id !== 'messages'" class="group-chat-search">
|
||||
<label>搜索本机群消息<input v-model="search" type="search" maxlength="120"></label>
|
||||
<label class="chat-checkbox"><input v-model="favoritesOnly" type="checkbox">只看收藏</label>
|
||||
</div>
|
||||
<p v-if="!lines.length && (search.trim() || favoritesOnly)" class="muted" role="status">没有匹配的群消息。</p>
|
||||
<ul v-if="lines.length" class="group-chat-lines" aria-label="群消息记录">
|
||||
<li v-for="line in lines" :key="[line.epoch, line.sender, line.id].join('/')">
|
||||
<p v-if="!lines.length && (historyView.id !== 'messages' || search.trim() || favoritesOnly)" class="muted" role="status">{{ historyView.empty }}</p>
|
||||
<ul v-if="visibleLines.length" class="group-chat-lines" :class="{ 'group-media': historyView.id !== 'messages' }"
|
||||
:aria-label="historyView.id === 'messages' ? '群消息记录' : historyView.label">
|
||||
<li v-for="line in visibleLines" :key="[historyView.id, line.epoch, line.sender, line.id].join('/')">
|
||||
<small>{{ line.name }} · {{ new Date(line.time).toLocaleString() }}</small>
|
||||
<blockquote v-if="line.quote">{{ line.quote }}</blockquote>
|
||||
<p v-if="line.recalled" class="muted">消息已撤回</p>
|
||||
@@ -320,6 +344,7 @@ onBeforeUnmount(() => {
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
<button v-if="visibleLines.length < lines.length" type="button" class="plain" @click="mediaLimit += mediaPageSize">加载更多本机附件</button>
|
||||
<ForwardDialog v-if="forwarding && view" :key="[forwarding.epoch, forwarding.sender, forwarding.id].join('/')"
|
||||
:source-group="group.id" :pinned="view.pinned" :busy="busy" @confirm="forward" @cancel="forwarding = undefined" />
|
||||
<div v-if="ready && recalling" class="confirmation">
|
||||
@@ -366,6 +391,10 @@ onBeforeUnmount(() => {
|
||||
.group-chat-lines p { white-space: pre-wrap; overflow-wrap: anywhere; }
|
||||
.group-chat-lines blockquote { margin: .25rem 0; padding-inline-start: .5rem; border-inline-start: 2px solid currentColor; overflow-wrap: anywhere; }
|
||||
.group-chat-search { display: flex; flex-wrap: wrap; align-items: end; gap: .75rem; }
|
||||
.group-history-views { display: flex; flex-wrap: wrap; gap: .4rem; }
|
||||
.group-history-views [aria-pressed='true'] { background: var(--green-soft); color: var(--green); }
|
||||
.group-media { grid-template-columns: repeat(auto-fit, minmax(min(100%, 14rem), 1fr)); align-items: start; }
|
||||
.group-media li { min-width: 0; padding: .7rem; border: 1px solid var(--line); border-radius: .45rem; }
|
||||
.group-chat-composer { display: grid; gap: .55rem; }
|
||||
.group-chat-composer textarea { display: block; width: 100%; resize: vertical; font: inherit; }
|
||||
.group-chat button { justify-self: start; }
|
||||
|
||||
Reference in new issue
Block a user