mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-10 03:53:26 -08:00
[Server] Let users fetch their own private chat history (#7506)
* [Server] Let users fetch their own private chat history Players lose their private conversations on reconnect or on another device. Servatrice can already log private messages, but only moderators can read the logs. Add Command_GetPrivateChatHistory / Response_PrivateChatHistory so a registered user can page through their own logged conversation with one other user. Operators opt in with logging/allow_user_chat_history (default off, and log_user_msg_chat must be on). The caller is matched by account id so reused guest or deleted-account names can't read older messages; only time, sender name and text are returned. Pages hold 1..200 messages and never split a second, since log_time has 1-second resolution. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * [Server] Harden private chat history identity matching Match both participants by account id and name so a federated user's remote id cannot collide with a local account, and stop storing foreign ids in the local chat log. Extract the paging assembly into a pure helper and cover the whole-second boundary rules with gtests. --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Lukas Brübach <44814898+BruebachL@users.noreply.github.com>
This commit is contained in:
parent
3d8c729517
commit
7709184ecc
17 changed files with 395 additions and 4 deletions
31
servatrice/src/private_chat_paging.cpp
Normal file
31
servatrice/src/private_chat_paging.cpp
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
#include "private_chat_paging.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
PrivateChatPage assemblePrivateChatPage(const QList<ServerInfo_PrivateChatMessage> &newestFirst, int limit)
|
||||
{
|
||||
PrivateChatPage page;
|
||||
page.messages = newestFirst;
|
||||
page.hasMore = newestFirst.size() > limit;
|
||||
if (!page.hasMore) {
|
||||
std::reverse(page.messages.begin(), page.messages.end());
|
||||
return page;
|
||||
}
|
||||
|
||||
// The (limit+1)th message is the first one that does not fit. If its second
|
||||
// appears anywhere in the page, that whole second would be split, so drop
|
||||
// every message in that second and leave it for the next page.
|
||||
const quint64 boundary = newestFirst.at(limit).time();
|
||||
while (!page.messages.isEmpty() && page.messages.last().time() == boundary) {
|
||||
page.messages.removeLast();
|
||||
}
|
||||
|
||||
if (page.messages.isEmpty()) {
|
||||
page.needsWholeSecond = true;
|
||||
page.boundarySecond = boundary;
|
||||
return page;
|
||||
}
|
||||
|
||||
std::reverse(page.messages.begin(), page.messages.end());
|
||||
return page;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue