Merge pull request '增加按设备统计的群消息未读角标' (#34) from xhgit/group-unread into xhgit/group-preferences
Reviewed-on: #34
This commit was merged in pull request #34.
This commit is contained in:
commit
9fb2fff3ac
16 files changed
+189
-23
No files matched your search
@@ -19,7 +19,7 @@
|
||||
| 账号与设备 | Windows 和 Web 共用账号,支持用户名注册、登录、查看设备和远程撤销。 |
|
||||
| 联系人 | 按用户名查找、处理好友申请、管理备注与分组,以及拉黑。变更可在双端实时同步。 |
|
||||
| 加密文字聊天 | 在两个已核验设备之间发送 MLS 加密消息,支持离线接收。 |
|
||||
| 加密群聊 | 创建群组、邀请联系人、管理成员,并按账号同步置顶和免打扰。每个账号选一台已核验设备参与 MLS 加密文字聊天。 |
|
||||
| 加密群聊 | 创建群组、邀请联系人和管理成员。群列表显示本机未读,并按账号同步置顶和免打扰。每个账号选一台已核验设备参与 MLS 加密文字聊天。 |
|
||||
| 加密附件 | 两端可在私聊和群聊发送、下载最多 8 MiB 的文件,并在本机预览图片和视频。 |
|
||||
| 加密语音 | 两端可在私聊和群聊录制、取消或发送最长 60 秒的语音消息,接收方在本机解密播放。 |
|
||||
| 消息管理 | 私聊和群聊支持引用回复、编辑文字、撤回、本机搜索和收藏。消息可转发到已建立加密会话的群或已核验的联系人设备。私聊支持可选加密已读回执。 |
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
| GET / POST | /api/v1/groups | 列出当前账号所属群组与邀请,或创建群组 |
|
||||
| GET / POST | /api/v1/groups/{id} | 查看群组详情或执行邀请、接受、拒绝、改名、升降管理员、移除、退出或解散 |
|
||||
| POST | /api/v1/groups/{id}/preferences | 更新当前账号的 `pinned` 和 `muted`,可只传其中一项 |
|
||||
| POST | /api/v1/groups/{id}/seen | 提交当前设备已同步的消息游标 `sequence`,成功返回 204 |
|
||||
| GET | /api/v1/groups/{id}/devices | 获取群成员的有效设备与 MLS 公钥 |
|
||||
| POST | /api/v1/groups/{id}/devices/{device}/claim | 群主一次性领取群成员设备的 KeyPackage |
|
||||
| GET / POST | /api/v1/groups/{id}/epochs | 读取当前设备可访问的会话信息或由群主发布新世代 |
|
||||
@@ -59,6 +60,8 @@ MLS 凭据由标准 Base64 的 publicKey 和 signature 组成,使用 UTF-8 前
|
||||
|
||||
群列表和详情返回当前账号的 `pinned` 和 `muted`。群列表先排序置顶群,随后按创建时间排序。设置修改后,同一账号的在线设备收到刷新提示。离开群组或被移除后,当前成员资格的设置随之清除。
|
||||
|
||||
群列表同时返回当前设备的 `unread`,上限为 100,用于客户端显示 `99+`。统计当前成员资格内、设备获准接收且由其他设备发送的密文投递。`sequence` 是正整数字符串,须指向当前设备在该群有权读取的消息,更新不会回退游标。成员列表和其他账号的 API 响应不包含该设备的查看状态。
|
||||
|
||||
有效成员可通过 `GET /groups/{id}/devices` 获取群内有效设备凭据。群主通过 `POST /groups/{id}/devices/{device}/claim` 一次性领取其他有效成员的设备密钥包。邀请待接受的账号、已离群的账号和撤销设备无法访问群设备目录。
|
||||
|
||||
成员变更后旧世代不能发消息。绑定设备被撤销后需以替代设备发布新世代。重新加入的成员只能补拉本次加入以来的世代。服务端校验外层格式和投递授权,MLS 内容验证由客户端执行。
|
||||
|
||||
@@ -162,3 +162,9 @@ Windows Electron 和 Edge 验证了群组页在兜底轮询前显示邀请、成
|
||||
两端可按账号设置群置顶和免打扰,置顶群排在群列表前面。离开群页面时,未静音的新群投递可显示通用的应用内提醒,点击返回群组。免打扰保留 WebSocket 补拉提示,省略应用内提醒标记。原生系统通知和 Web Push 仍待实现。
|
||||
|
||||
测试覆盖迁移 010、邀请者和外部账号不可修改群设置、不同账号的设置隔离、双端静音收取和提醒入口,以及同一账号的两台设备实时同步偏好。
|
||||
|
||||
## 群聊未读角标
|
||||
|
||||
Windows 和 Web 的群列表按当前设备显示未读投递数量,免打扰群使用低强调角标。打开可见的群聊并同步后,客户端提交本机游标。统计排除本机发送的消息,页面后台时保留角标。游标由服务端按设备保存,其他成员看不到逐条已读状态。编辑和撤回也是群密文投递,会计入尚未同步的数量。
|
||||
|
||||
接口测试覆盖发送设备排除、游标单调递增、越权及重新入群隔离。Windows Electron 与 Edge 验证免打扰时显示未读、启用群安全会话后同步并清除角标,以及群消息和私聊附件回归。私聊文件选择在同步繁忙时也会排队提交。
|
||||
@@ -0,0 +1,9 @@
|
||||
CREATE TABLE group_seen (
|
||||
group_id uuid NOT NULL,
|
||||
user_id uuid NOT NULL,
|
||||
device_id uuid NOT NULL REFERENCES devices(id) ON DELETE CASCADE,
|
||||
sequence bigint NOT NULL CHECK (sequence > 0),
|
||||
PRIMARY KEY (group_id,device_id),
|
||||
FOREIGN KEY (group_id,user_id) REFERENCES group_members(group_id,user_id) ON DELETE CASCADE
|
||||
);
|
||||
CREATE INDEX group_seen_membership ON group_seen(group_id,user_id);
|
||||
@@ -37,6 +37,9 @@ var groupAttachmentsMigration string
|
||||
//go:embed 010_group_preferences.sql
|
||||
var groupPreferencesMigration string
|
||||
|
||||
//go:embed 011_group_seen.sql
|
||||
var groupSeenMigration string
|
||||
|
||||
func Migrate(ctx context.Context, pool *pgxpool.Pool) error {
|
||||
tx, err := pool.Begin(ctx)
|
||||
if err != nil {
|
||||
@@ -52,6 +55,7 @@ func Migrate(ctx context.Context, pool *pgxpool.Pool) error {
|
||||
for index, migration := range []string{
|
||||
identityMigration, contactsMigration, deliveryMigration, keyPackagesMigration, mlsCredentialsMigration,
|
||||
attachmentsMigration, groupsMigration, groupTransportMigration, groupAttachmentsMigration, groupPreferencesMigration,
|
||||
groupSeenMigration,
|
||||
} {
|
||||
version := index + 1
|
||||
var applied bool
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package groups
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
)
|
||||
|
||||
func (s *Store) MarkSeen(ctx context.Context, group, user, device string, sequence int64) error {
|
||||
tx, err := s.db.Begin(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer tx.Rollback(ctx)
|
||||
if _, _, err := lockTransport(ctx, tx, group, user, device); err != nil {
|
||||
return err
|
||||
}
|
||||
var seen int64
|
||||
err = tx.QueryRow(ctx, `
|
||||
INSERT INTO group_seen(group_id,user_id,device_id,sequence)
|
||||
SELECT m.group_id,m.user_id,d.id,x.sequence FROM group_messages x
|
||||
JOIN group_epoch_devices e ON (e.group_id,e.epoch_id)=(x.group_id,x.epoch_id) AND e.device_id=$3
|
||||
JOIN group_epochs epoch ON (epoch.group_id,epoch.id)=(x.group_id,x.epoch_id)
|
||||
JOIN group_members m ON m.group_id=x.group_id AND m.user_id=$2 AND m.state='active'
|
||||
JOIN devices d ON d.id=e.device_id AND d.user_id=m.user_id AND d.revoked_at IS NULL
|
||||
WHERE x.group_id=$1 AND x.sequence=$4 AND epoch.membership_version>=m.joined_version
|
||||
ON CONFLICT (group_id,device_id) DO UPDATE SET sequence=GREATEST(group_seen.sequence,EXCLUDED.sequence)
|
||||
RETURNING sequence
|
||||
`, group, user, device, sequence).Scan(&seen)
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return ErrUnavailable
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return tx.Commit(ctx)
|
||||
}
|
||||
@@ -21,6 +21,11 @@ type Group struct {
|
||||
Preferences
|
||||
}
|
||||
|
||||
type ListedGroup struct {
|
||||
Group
|
||||
Unread int `json:"unread"`
|
||||
}
|
||||
|
||||
type Preferences struct {
|
||||
Pinned bool `json:"pinned"`
|
||||
Muted bool `json:"muted"`
|
||||
@@ -58,21 +63,31 @@ func (s *Store) Create(ctx context.Context, owner, name string) (Group, error) {
|
||||
return result, err
|
||||
}
|
||||
|
||||
const groupColumns = `g.id,g.name,m.state,CASE WHEN g.owner_id=m.user_id THEN 'owner' ELSE m.role END,g.membership_version::text,m.pinned,m.muted`
|
||||
const groupRows = `
|
||||
SELECT g.id,g.name,m.state,CASE WHEN g.owner_id=m.user_id THEN 'owner' ELSE m.role END,g.membership_version::text,m.pinned,m.muted
|
||||
FROM chat_groups g JOIN group_members m ON m.group_id=g.id WHERE m.user_id=$1
|
||||
`
|
||||
|
||||
func (s *Store) List(ctx context.Context, user string) ([]Group, error) {
|
||||
rows, err := s.db.Query(ctx, groupRows+" ORDER BY m.pinned DESC, g.created_at DESC, g.id LIMIT 200", user)
|
||||
func (s *Store) List(ctx context.Context, user, device string) ([]ListedGroup, error) {
|
||||
rows, err := s.db.Query(ctx, "SELECT "+groupColumns+`, (
|
||||
SELECT count(*) FROM (
|
||||
SELECT 1 FROM group_messages x
|
||||
JOIN group_epoch_devices enrolled ON (enrolled.group_id,enrolled.epoch_id)=(x.group_id,x.epoch_id) AND enrolled.device_id=$2
|
||||
JOIN group_epochs epoch ON (epoch.group_id,epoch.id)=(x.group_id,x.epoch_id)
|
||||
JOIN devices d ON d.id=enrolled.device_id AND d.revoked_at IS NULL
|
||||
WHERE x.group_id=g.id AND epoch.membership_version>=m.joined_version AND x.sender_device<>$2
|
||||
AND x.sequence>COALESCE((SELECT seen.sequence FROM group_seen seen WHERE seen.group_id=g.id AND seen.device_id=$2),0)
|
||||
ORDER BY x.sequence LIMIT 100
|
||||
) AS unread
|
||||
)`+groupRows+" ORDER BY m.pinned DESC, g.created_at DESC, g.id LIMIT 200", user, device)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
result := make([]Group, 0)
|
||||
result := make([]ListedGroup, 0)
|
||||
for rows.Next() {
|
||||
var g Group
|
||||
if err := rows.Scan(&g.ID, &g.Name, &g.State, &g.Role, &g.Version, &g.Pinned, &g.Muted); err != nil {
|
||||
var g ListedGroup
|
||||
if err := rows.Scan(&g.ID, &g.Name, &g.State, &g.Role, &g.Version, &g.Pinned, &g.Muted, &g.Unread); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result = append(result, g)
|
||||
@@ -87,7 +102,7 @@ func (s *Store) Detail(ctx context.Context, user, id string) (Detail, error) {
|
||||
return result, err
|
||||
}
|
||||
defer tx.Rollback(ctx)
|
||||
err = tx.QueryRow(ctx, groupRows+" AND g.id=$2", user, id).
|
||||
err = tx.QueryRow(ctx, "SELECT "+groupColumns+" "+groupRows+" AND g.id=$2", user, id).
|
||||
Scan(&result.ID, &result.Name, &result.State, &result.Role, &result.Version, &result.Pinned, &result.Muted)
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return result, ErrUnavailable
|
||||
|
||||
@@ -65,6 +65,7 @@ func New(accounts *account.Store, contactStore *contacts.Store, envelopeStore *d
|
||||
mux.HandleFunc("GET /api/v1/groups/{id}", a.authorized(a.groupDetail))
|
||||
mux.HandleFunc("POST /api/v1/groups/{id}", a.authorized(a.changeGroup))
|
||||
mux.HandleFunc("POST /api/v1/groups/{id}/preferences", a.authorized(a.setGroupPreferences))
|
||||
mux.HandleFunc("POST /api/v1/groups/{id}/seen", a.authorized(a.markGroupSeen))
|
||||
mux.HandleFunc("GET /api/v1/groups/{id}/epochs", a.authorized(a.groupEpochs))
|
||||
mux.HandleFunc("POST /api/v1/groups/{id}/epochs", a.authorized(a.publishGroupEpoch))
|
||||
mux.HandleFunc("GET /api/v1/groups/{id}/messages", a.authorized(a.groupInbox))
|
||||
|
||||
@@ -183,3 +183,30 @@ func (a *API) groupInbox(w http.ResponseWriter, r *http.Request, _ string, actor
|
||||
}
|
||||
respond(w, 200, items)
|
||||
}
|
||||
|
||||
func (a *API) markGroupSeen(w http.ResponseWriter, r *http.Request, _ string, actor account.Identity) {
|
||||
group := r.PathValue("id")
|
||||
if !uuidPattern.MatchString(group) {
|
||||
groupError(w, groups.ErrUnavailable)
|
||||
return
|
||||
}
|
||||
var input struct {
|
||||
Sequence string `json:"sequence"`
|
||||
}
|
||||
if !parse(w, r, &input) {
|
||||
return
|
||||
}
|
||||
sequence, err := strconv.ParseInt(input.Sequence, 10, 64)
|
||||
if err != nil || sequence <= 0 || strconv.FormatInt(sequence, 10) != input.Sequence {
|
||||
problem(w, 400, "invalid_cursor", "无效的已查看游标")
|
||||
return
|
||||
}
|
||||
if !a.limit(w, r, "group-seen:"+actor.Device.ID, 240) {
|
||||
return
|
||||
}
|
||||
if err = a.groups.MarkSeen(r.Context(), group, actor.User.ID, actor.Device.ID, sequence); err != nil {
|
||||
groupError(w, err)
|
||||
return
|
||||
}
|
||||
w.WriteHeader(204)
|
||||
}
|
||||
@@ -59,7 +59,7 @@ func (a *API) createGroup(w http.ResponseWriter, r *http.Request, _ string, id a
|
||||
}
|
||||
|
||||
func (a *API) listGroups(w http.ResponseWriter, r *http.Request, _ string, id account.Identity) {
|
||||
result, err := a.groups.List(r.Context(), id.User.ID)
|
||||
result, err := a.groups.List(r.Context(), id.User.ID, id.Device.ID)
|
||||
if err != nil {
|
||||
groupError(w, err)
|
||||
return
|
||||
|
||||
@@ -220,6 +220,13 @@ test('群密文和实时提示只投递到名单设备,移除或撤销阻断
|
||||
assert.deepEqual(await json(path + '/messages', 'POST', member.token, message), sequence)
|
||||
const received = await json(path + '/messages', 'GET', member.token)
|
||||
assert.deepEqual(received.map((item) => item.wire), [message.wire])
|
||||
const unread = async (actor) => (await json('/groups', 'GET', actor.token)).find((entry) => entry.id === group.id)?.unread
|
||||
const seen = (actor, cursor) => call(path + '/seen', 'POST', actor.token, { sequence: cursor })
|
||||
assert.equal(await unread(owner), 1)
|
||||
assert.equal(await unread(member), 0)
|
||||
assert.equal(await unread(outsider), undefined)
|
||||
assert.equal((await seen(outsider, sequence.sequence)).status, 404)
|
||||
assert.equal((await seen(member, '0')).status, 400)
|
||||
|
||||
await json(path + '/preferences', 'POST', member.token, { muted: true })
|
||||
|
||||
@@ -242,6 +249,11 @@ test('群密文和实时提示只投递到名单设备,移除或撤销阻断
|
||||
await json(attachment, 'GET', member.token, undefined, 404)
|
||||
await json(path + '/messages', 'POST', member.token, linked, 409)
|
||||
const posted = await json(path + '/messages', 'POST', owner.token, linked)
|
||||
assert.equal(await unread(member), 1)
|
||||
assert.equal((await seen(member, posted.sequence)).status, 204)
|
||||
assert.equal((await seen(member, sequence.sequence)).status, 204)
|
||||
assert.equal(await unread(member), 0)
|
||||
assert.equal(await unread(owner), 1)
|
||||
assert.deepEqual(await json(path + '/messages', 'POST', owner.token, linked), posted)
|
||||
await json(path + '/messages', 'POST', owner.token, { ...linked, id: randomUUID() }, 409)
|
||||
await json(path + '/messages', 'POST', owner.token, { ...linked, attachmentId: undefined }, 409)
|
||||
@@ -252,11 +264,14 @@ test('群密文和实时提示只投递到名单设备,移除或撤销阻断
|
||||
assert.deepEqual(Buffer.from(await download.arrayBuffer()), bytes)
|
||||
await json(attachment, 'GET', outsider.token, undefined, 404)
|
||||
await change(owner, 'remove', member.user.id)
|
||||
assert.equal((await seen(member, posted.sequence)).status, 404)
|
||||
await json(path + '/messages', 'GET', member.token, undefined, 404)
|
||||
await json(attachment, 'GET', member.token, undefined, 404)
|
||||
await json(path + '/messages', 'POST', owner.token, { ...message, id: randomUUID() }, 409)
|
||||
await change(owner, 'invite', member.user.id)
|
||||
await change(member, 'accept')
|
||||
assert.equal(await unread(member), 0)
|
||||
assert.equal((await seen(member, posted.sequence)).status, 404)
|
||||
await json(attachment, 'GET', member.token, undefined, 404)
|
||||
assert.equal((await call(attachment, 'GET', owner.token)).status, 200)
|
||||
assert.deepEqual(await json(path + '/messages', 'GET', member.token), [])
|
||||
|
||||
@@ -201,9 +201,13 @@ test('Windows 与 Web 加密群聊支持消息操作、附件、语音和成员
|
||||
await Promise.all([owner, windows].map((page) => chat(page).getByText(first, { exact: true }).waitFor({ timeout: 3500 })))
|
||||
assert.equal(await removed.getByRole('link', { name: '有新的群消息' }).count(), 0)
|
||||
await work(removed).getByRole('link', { name: '群组' }).click()
|
||||
await removed.getByRole('link', { name: new RegExp(group) }).click()
|
||||
const unreadGroup = removed.getByRole('link', { name: new RegExp(group + '.*1 条未读') })
|
||||
await unreadGroup.click()
|
||||
await unreadGroup.waitFor()
|
||||
await chat(removed).getByRole('button', { name: '启用本机群聊' }).click()
|
||||
await chat(removed).getByText(first, { exact: true }).waitFor()
|
||||
await unreadGroup.waitFor({ state: 'detached', timeout: 4500 })
|
||||
assert.equal(await windows.getByRole('link', { name: new RegExp(group + '.*未读') }).count(), 0)
|
||||
|
||||
const original = chat(owner).getByRole('listitem').filter({ hasText: first })
|
||||
assert.equal(await original.getByRole('button', { name: '编辑', exact: true }).count(), 0)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue'
|
||||
import { useSession } from '../session'
|
||||
import { APIError } from '../api'
|
||||
import { downloadAttachment } from './attachments'
|
||||
import type { Attachment } from './attachments'
|
||||
import MediaPreview from './MediaPreview.vue'
|
||||
@@ -12,6 +13,7 @@ import { discardPendingGroupMessage, forwardGroupMessage, groupAttachmentPath, g
|
||||
import type { ForwardDestination, GroupDetail, GroupDevice, GroupLine } from './group-chat'
|
||||
|
||||
const props = defineProps<{ group: GroupDetail }>()
|
||||
const emit = defineEmits<{ seen: [] }>()
|
||||
const session = useSession()
|
||||
const view = ref<Awaited<ReturnType<typeof synchronizeGroup>>>()
|
||||
const code = ref('')
|
||||
@@ -43,6 +45,8 @@ const canPublish = computed(() => Boolean(view.value && !view.value.current && m
|
||||
let timer: ReturnType<typeof setInterval>
|
||||
let refreshTimer: ReturnType<typeof setTimeout> | undefined
|
||||
let refreshPending = false
|
||||
let lastSeen = '0'
|
||||
let active = true
|
||||
|
||||
function pinned(device: GroupDevice) {
|
||||
return view.value?.pinned[device.id] === device.publicKey
|
||||
@@ -52,12 +56,25 @@ async function refresh() {
|
||||
const identity = session.identity
|
||||
if (!code.value || !identity) return
|
||||
view.value = await synchronizeGroup(identity, props.group, session.authorized)
|
||||
if (!active) return
|
||||
for (const member of members.value) {
|
||||
const devices = view.value.devices.filter((device) => device.user === member.id)
|
||||
if (!devices.some((device) => device.id === selected.value[member.id] && pinned(device))) {
|
||||
selected.value[member.id] = devices.find(pinned)?.id ?? ''
|
||||
}
|
||||
}
|
||||
if (view.value.hasMore) queueRefresh()
|
||||
const { cursor } = view.value
|
||||
if (!ready.value || document.visibilityState !== 'visible' || cursor === lastSeen || cursor === '0') return
|
||||
try {
|
||||
await session.authorized('/groups/' + encodeURIComponent(props.group.id) + '/seen', 'POST', { sequence: cursor })
|
||||
} catch (cause) {
|
||||
// Retention or member changes can invalidate an already cached cursor.
|
||||
if (!(cause instanceof APIError) || cause.status !== 404) throw cause
|
||||
}
|
||||
if (!active) return
|
||||
lastSeen = cursor
|
||||
emit('seen')
|
||||
}
|
||||
|
||||
async function run(action: () => Promise<void>, manual = true) {
|
||||
@@ -75,7 +92,7 @@ async function run(action: () => Promise<void>, manual = true) {
|
||||
}
|
||||
|
||||
function queueRefresh() {
|
||||
if (!code.value) return
|
||||
if (!active || !code.value) return
|
||||
refreshPending = true
|
||||
if (busy.value || refreshTimer) return
|
||||
refreshTimer = setTimeout(() => {
|
||||
@@ -223,11 +240,16 @@ watch([pendingVoice, busy, currentEpoch, () => view.value?.hasPending], ([voice,
|
||||
await refresh()
|
||||
})
|
||||
})
|
||||
onMounted(() => { timer = setInterval(queueRefresh, 15_000) })
|
||||
onMounted(() => {
|
||||
timer = setInterval(queueRefresh, 15_000)
|
||||
document.addEventListener('visibilitychange', queueRefresh)
|
||||
})
|
||||
onBeforeUnmount(() => {
|
||||
active = false
|
||||
refreshPending = false
|
||||
clearTimeout(refreshTimer)
|
||||
clearInterval(timer)
|
||||
document.removeEventListener('visibilitychange', queueRefresh)
|
||||
})
|
||||
</script>
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ export type GroupMember = { id: string; username: string; state: 'active' | 'inv
|
||||
export type GroupDetail = { id: string; membershipVersion: string; members: GroupMember[]; role: GroupMember['role'] }
|
||||
export type GroupPreferences = { pinned: boolean; muted: boolean }
|
||||
export type GroupSummary = Omit<GroupDetail, 'members'> & GroupPreferences & { name: string; state: GroupMember['state'] }
|
||||
export type ListedGroup = GroupSummary & { unread: number }
|
||||
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 }[] }
|
||||
@@ -271,7 +272,8 @@ export function synchronizeGroup(identity: ChatIdentity, group: GroupDetail, cal
|
||||
const engine = factory.DeviceMls.restore(decode(state.engine))
|
||||
try { await replenishPackages(identity, call, state, save, engine) } catch { warning ||= '密钥包补充失败' } finally { engine.free() }
|
||||
}
|
||||
return { devices, lines: chat.lines, pinned: state.pinned, ready, current, warning,
|
||||
const hasMore = packets.length === 64 && packets.at(-1)?.sequence === chat.cursor
|
||||
return { devices, lines: chat.lines, pinned: state.pinned, ready, current, warning, cursor: chat.cursor, hasMore,
|
||||
hasPending: Boolean(chat.pendingMessage), stalePending: Boolean(chat.pendingMessage && chat.pendingMessage.epoch !== current?.id) }
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
})
|
||||
|
||||
@@ -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>
|
||||
Reference in new issue
Block a user