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:
@@ -59,7 +59,16 @@ const schemas = {
|
||||
members: { type: "array", items: { type: "integer" } },
|
||||
lastMessage: { allOf: [{ $ref: "#/components/schemas/ChatMessage" }], nullable: true },
|
||||
lastReadId: { type: "integer" },
|
||||
clearedId: {
|
||||
type: "integer",
|
||||
description: "Messages up to this id were deleted by the caller for themselves.",
|
||||
},
|
||||
unread: { type: "integer", description: "Messages of others after `lastReadId`." },
|
||||
reads: {
|
||||
type: "object",
|
||||
additionalProperties: { type: "integer" },
|
||||
description: "Every member's read mark by user id — what the room shows as Seen.",
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -145,6 +154,20 @@ const paths = {
|
||||
},
|
||||
},
|
||||
"/api/chat/rooms/{id}": {
|
||||
delete: {
|
||||
tags: ["Chat"],
|
||||
summary: "Disband a group",
|
||||
description:
|
||||
"The group's creator only (`403 EFORBIDDEN`): deletes it for every member, its files included. Broadcasts `chat_room`.",
|
||||
parameters: [idParam],
|
||||
responses: {
|
||||
200: {
|
||||
description: "Disbanded",
|
||||
...json({ type: "object", properties: { ok: { type: "boolean" } } }),
|
||||
},
|
||||
...fail([400, 403, 404]),
|
||||
},
|
||||
},
|
||||
patch: {
|
||||
tags: ["Chat"],
|
||||
summary: "Rename a group, add or remove members",
|
||||
@@ -164,6 +187,31 @@ const paths = {
|
||||
responses: { 200: { description: "Updated", ...roomResp }, ...fail([400, 403, 404]) },
|
||||
},
|
||||
},
|
||||
"/api/chat/rooms/{id}/clear": {
|
||||
post: {
|
||||
tags: ["Chat"],
|
||||
summary: "Delete a chat for yourself",
|
||||
description:
|
||||
"Every message so far is gone for the caller only (`clearedId`); a direct chat also leaves their list until a new message arrives. Nobody else's copy changes — but what EVERY member has deleted is deleted for real (messages, files, and a direct chat both people deleted, whole).",
|
||||
parameters: [idParam],
|
||||
responses: {
|
||||
200: {
|
||||
description: "Cleared",
|
||||
...json({
|
||||
type: "object",
|
||||
properties: {
|
||||
hidden: { type: "boolean" },
|
||||
purged: {
|
||||
type: "boolean",
|
||||
description: "Every member has now deleted it: the chat is gone from the server.",
|
||||
},
|
||||
},
|
||||
}),
|
||||
},
|
||||
...fail([404]),
|
||||
},
|
||||
},
|
||||
},
|
||||
"/api/chat/rooms/{id}/leave": {
|
||||
post: {
|
||||
tags: ["Chat"],
|
||||
@@ -262,6 +310,8 @@ const paths = {
|
||||
post: {
|
||||
tags: ["Chat"],
|
||||
summary: "Mark a room read up to a message",
|
||||
description:
|
||||
"Never moves back, never past the room's newest message. A mark that moved is told to the members as `chat_read` (`{roomId, userId, lastReadId}`).",
|
||||
parameters: [idParam],
|
||||
requestBody: {
|
||||
required: true,
|
||||
|
||||
Reference in New Issue
Block a user