Browse Source

feat(history): Remove group history on quit when selected

The group itself is a peer, as well as all the members of the group. Members of the group have associated aliases, but the group does not. Chat messages reference the chat_id of the group, with senders referencing the member peer.

Deleting all history belonging to the chat_id already generically cleans up group history. Users who only have history from that group need to have their aliases and peer entries removed.

We don't store what users or aliases where in which group, so just remove any alias that has no associated chat message with it, and and peer that doesn't have an alias (friend with history) and doesn't have a chat message associated with it as a chat_id (group).

The group itself is removed from the peer table directly, and the group never has an alias entry.
reviewable/pr6561/r6
Anthony Bilinski 4 years ago
parent
commit
8086f682a3
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C
  1. 11
      src/persistence/history.cpp

11
src/persistence/history.cpp

@ -822,8 +822,15 @@ void History::removeChatHistory(const ChatId& chatId) @@ -822,8 +822,15 @@ void History::removeChatHistory(const ChatId& chatId)
" SELECT id from history "
" WHERE message_type = 'S' AND chat_id=%1);"
"DELETE FROM history WHERE chat_id=%1; "
"DELETE FROM aliases WHERE owner=%1; "
"DELETE FROM peers WHERE id=%1; "
"DELETE FROM aliases "
"WHERE id NOT IN ( "
" SELECT DISTINCT sender_alias FROM text_messages);"
"DELETE FROM peers "
"WHERE id NOT IN ( "
" SELECT DISTINCT chat_id FROM history "
" UNION SELECT DISTINCT owner from aliases); "
"DELETE FROM aliases WHERE owner=%1;"
"DELETE FROM peers WHERE id=%1;"
"VACUUM;")
.arg(generatePeerIdString(chatId));

Loading…
Cancel
Save