Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make chat host able to delete messages from other people #1862

Merged
merged 1 commit into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/src/os/services/ship/chat/chat.db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ export class ChatDB extends AbstractDataAccess<ChatRow, ChatUpdateTypes> {
const delMessagesRow = dbChange as DelMessagesRow;
// only delete the message if it has a created-at older than dbChange.timestamp (since if the message was created after the delete, the delete is invalid)
const msg = this.getChatMessage(delMessagesRow['msg-id']);
if (msg && msg.created_at < delMessagesRow.timestamp) {
if (msg && msg.createdAt < delMessagesRow.timestamp) {
this._deleteMessagesRow(delMessagesRow['msg-id']);
this.sendUpdate({ type: 'message-deleted', payload: delMessagesRow });
}
Expand Down
10 changes: 7 additions & 3 deletions desks/realm/lib/chat-db.hoon
Original file line number Diff line number Diff line change
Expand Up @@ -406,13 +406,17 @@
|= [=msg-id:sur state=state-2 =bowl:gall]
^- (quip card state-2)

?. ?& =(sender.msg-id src.bowl) :: delete pokes are only valid from the ship which is the original sender
(has:msgon:sur messages-table.state [msg-id 0]) :: delete pokes are only valid if there is a fragment 0 in the table for the msg-id
:: delete pokes are only valid if there is a fragment 0 in the table for the msg-id
=/ msg-part=msg-part:sur (got:msgon:sur messages-table.state `uniq-id:sur`[msg-id 0])
=/ peers=(list peer-row:sur) (~(got by peers-table.state) path.msg-part)
=/ host=peer-row:sur (snag 0 (skim peers |=(p=peer-row:sur =(role.p %host))))
:: delete pokes are only valid either:
?. ?| =(sender.msg-id src.bowl) :: from the ship which is the original sender
=(src.bowl patp.host) :: from the host of the chat
==
~& >>> "an invalid :delete poke was received from {(scow %p src.bowl)}... ignoring."
`state :: we just no-op instead of crashing

=/ msg-part=msg-part:sur (got:msgon:sur messages-table.state `uniq-id:sur`[msg-id 0])
=/ remove-result (remove-message state msg-id now.bowl)
=. state s.remove-result
=/ thechange chat-db-change+!>(ch.remove-result)
Expand Down