feat(chat): delete a chat, disband a group, Seen — and purge what everyone deleted
Delete chat is the caller's alone: the history so far vanishes for them (chat_members.cleared_id) and a direct chat leaves their list (hidden) until a new message arrives; the others keep theirs. What EVERY member has deleted is deleted for real (purge): messages up to the lowest cleared_id and their files on disk, and a direct chat both people deleted, whole. Purge also runs when a member leaves or is removed. A group's creator disbands it for everyone (DELETE /api/chat/rooms/:id). Seen: rooms carry every member's read mark (reads); a mark that moves is told to the members (chat_read, exactAudience) and never passes the newest message. Under your newest message: Seen / Seen by … / Seen by everyone. A room open on a tab you come back to is marked read then.
This commit is contained in:
+24
-1
@@ -118,6 +118,24 @@ router.post(
|
||||
})
|
||||
);
|
||||
|
||||
// Delete the chat for the caller only (their history; a direct chat leaves their list).
|
||||
router.post(
|
||||
"/rooms/:id/clear",
|
||||
sameOriginGuard,
|
||||
handle((me, req, res) => res.json(chat.clearChat(me, req.params.id)))
|
||||
);
|
||||
|
||||
// The group's creator deletes it for everyone.
|
||||
router.delete(
|
||||
"/rooms/:id",
|
||||
sameOriginGuard,
|
||||
handle((me, req, res) => {
|
||||
const { notify } = chat.disbandGroup(me, req.params.id);
|
||||
tell("chat_room", { roomId: Number(req.params.id) }, notify);
|
||||
res.json({ ok: true });
|
||||
})
|
||||
);
|
||||
|
||||
router.get(
|
||||
"/rooms/:id/messages",
|
||||
handle((me, req, res) =>
|
||||
@@ -153,7 +171,12 @@ router.delete(
|
||||
router.post(
|
||||
"/rooms/:id/read",
|
||||
sameOriginGuard,
|
||||
handle((me, req, res) => res.json(chat.markRead(me, req.params.id, req.body?.upTo)))
|
||||
handle((me, req, res) => {
|
||||
const { lastReadId, moved, notify } = chat.markRead(me, req.params.id, req.body?.upTo);
|
||||
// "Seen": the other members' views move their read marks.
|
||||
if (moved) tell("chat_read", { roomId: Number(req.params.id), userId: me, lastReadId }, notify);
|
||||
res.json({ lastReadId });
|
||||
})
|
||||
);
|
||||
|
||||
router.get(
|
||||
|
||||
Reference in New Issue
Block a user