mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-11 08:34:52 -07:00
add option to delete a user's messages (#4362)
* add option to delete a user's messages add optional parameter remove_messages to the ban and warn commands add event for clients to redact messages implement server side command and message handling implement server history removal todo: client side implementation add option to remove messages to moderator action dialogs add storage of message beginnings to chatview add redactMessage command handle Event_RemoveMessages on rooms this approach is favored over parsing the chatroom after the fact but will use additional memory to store the block indexes this also leaves a problem in that user messages from the chat backlog are not removed in the same way because they don't have a user associated with them add workaround for old qt versions add action for users to remove messages from users in chats add chat history to userMessagePositions with regex proper const usage for userName allow removing the messages of unregistered users add menus to usernames in chat history this allows you to remove user messages on chat history as well this also allows moderators to take actions on users in chat history Apply suggestions from code review * readd missing call to handler
This commit is contained in:
parent
c25bf491e4
commit
1e995cd97c
22 changed files with 280 additions and 78 deletions
|
|
@ -91,6 +91,7 @@ SET(PROTO_FILES
|
|||
event_reverse_turn.proto
|
||||
event_roll_die.proto
|
||||
event_room_say.proto
|
||||
event_remove_messages.proto
|
||||
event_server_complete_list.proto
|
||||
event_server_identification.proto
|
||||
event_server_message.proto
|
||||
|
|
|
|||
10
common/pb/event_remove_messages.proto
Normal file
10
common/pb/event_remove_messages.proto
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
syntax = "proto2";
|
||||
import "room_event.proto";
|
||||
|
||||
message Event_RemoveMessages {
|
||||
extend RoomEvent {
|
||||
optional Event_RemoveMessages ext = 1004;
|
||||
}
|
||||
optional string name = 1;
|
||||
optional uint32 amount = 2;
|
||||
}
|
||||
|
|
@ -21,6 +21,7 @@ message Command_BanFromServer {
|
|||
optional string reason = 4;
|
||||
optional string visible_reason = 5;
|
||||
optional string clientid = 6;
|
||||
optional uint32 remove_messages = 7;
|
||||
}
|
||||
|
||||
message Command_GetBanHistory {
|
||||
|
|
@ -38,6 +39,7 @@ message Command_WarnUser {
|
|||
optional string user_name = 1;
|
||||
optional string reason = 2;
|
||||
optional string clientid = 3;
|
||||
optional uint32 remove_messages = 4;
|
||||
}
|
||||
|
||||
message Command_GetWarnHistory {
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ message RoomEvent {
|
|||
JOIN_ROOM = 1001;
|
||||
ROOM_SAY = 1002;
|
||||
LIST_GAMES = 1003;
|
||||
REMOVE_MESSAGES = 1004;
|
||||
}
|
||||
optional sint32 room_id = 1;
|
||||
extensions 100 to max;
|
||||
|
|
|
|||
|
|
@ -389,6 +389,19 @@ void Server::externalRoomSay(int roomId, const QString &userName, const QString
|
|||
room->getId(), room->getName());
|
||||
}
|
||||
|
||||
void Server::externalRoomRemoveMessages(int roomId, const QString &userName, int amount)
|
||||
{
|
||||
// This function is always called from the main thread via signal/slot.
|
||||
QReadLocker locker(&roomsLock);
|
||||
|
||||
Server_Room *room = rooms.value(roomId);
|
||||
if (room == nullptr) {
|
||||
qDebug() << "externalRoomRemoveMessages: room id=" << roomId << "not found";
|
||||
return;
|
||||
}
|
||||
room->removeSaidMessages(userName, amount);
|
||||
}
|
||||
|
||||
void Server::externalRoomGameListChanged(int roomId, const ServerInfo_Game &gameInfo)
|
||||
{
|
||||
// This function is always called from the main thread via signal/slot.
|
||||
|
|
|
|||
|
|
@ -223,6 +223,7 @@ protected slots:
|
|||
void externalRoomUserJoined(int roomId, const ServerInfo_User &userInfo);
|
||||
void externalRoomUserLeft(int roomId, const QString &userName);
|
||||
void externalRoomSay(int roomId, const QString &userName, const QString &message);
|
||||
void externalRoomRemoveMessages(int roomId, const QString &userName, int amount);
|
||||
void externalRoomGameListChanged(int roomId, const ServerInfo_Game &gameInfo);
|
||||
void
|
||||
externalJoinGameCommandReceived(const Command_JoinGame &cmd, int cmdId, int roomId, int serverId, qint64 sessionId);
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
#include "pb/event_join_room.pb.h"
|
||||
#include "pb/event_leave_room.pb.h"
|
||||
#include "pb/event_list_games.pb.h"
|
||||
#include "pb/event_remove_messages.pb.h"
|
||||
#include "pb/event_room_say.pb.h"
|
||||
#include "pb/room_commands.pb.h"
|
||||
#include "pb/serverinfo_chat_message.pb.h"
|
||||
|
|
@ -272,11 +273,11 @@ Response::ResponseCode Server_Room::processJoinGameCommand(const Command_JoinGam
|
|||
return result;
|
||||
}
|
||||
|
||||
void Server_Room::say(const QString &userName, const QString &s, bool sendToIsl)
|
||||
void Server_Room::say(const QString &userName, const QString &userMessage, bool sendToIsl)
|
||||
{
|
||||
Event_RoomSay event;
|
||||
event.set_name(userName.toStdString());
|
||||
event.set_message(s.toStdString());
|
||||
event.set_message(userMessage.toStdString());
|
||||
sendRoomEvent(prepareRoomEvent(event), sendToIsl);
|
||||
|
||||
if (chatHistorySize != 0) {
|
||||
|
|
@ -285,13 +286,36 @@ void Server_Room::say(const QString &userName, const QString &s, bool sendToIsl)
|
|||
QString dateTimeString = dateTime.toString();
|
||||
chatMessage.set_time(dateTimeString.toStdString());
|
||||
chatMessage.set_sender_name(userName.toStdString());
|
||||
chatMessage.set_message(s.simplified().toStdString());
|
||||
chatMessage.set_message(userMessage.simplified().toStdString());
|
||||
|
||||
historyLock.lockForWrite();
|
||||
if (chatHistory.size() >= chatHistorySize)
|
||||
if (chatHistory.size() >= chatHistorySize) {
|
||||
chatHistory.removeAt(0);
|
||||
}
|
||||
|
||||
chatHistory << chatMessage;
|
||||
chatHistory.push_back(std::move(chatMessage));
|
||||
historyLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
void Server_Room::removeSaidMessages(const QString &userName, int amount, bool sendToIsl)
|
||||
{
|
||||
Event_RemoveMessages event;
|
||||
auto stdStringUserName = userName.toStdString();
|
||||
event.set_name(stdStringUserName);
|
||||
event.set_amount(amount);
|
||||
sendRoomEvent(prepareRoomEvent(event), sendToIsl);
|
||||
|
||||
if (chatHistorySize != 0) {
|
||||
int removed = 0;
|
||||
historyLock.lockForWrite();
|
||||
// redact [amount] of the most recent messages from this user from history
|
||||
for (auto message = chatHistory.rbegin(); message != chatHistory.rend() && removed != amount; ++message) {
|
||||
if (message->sender_name() == stdStringUserName) {
|
||||
message->clear_message();
|
||||
++removed;
|
||||
}
|
||||
}
|
||||
historyLock.unlock();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -132,6 +132,7 @@ public:
|
|||
Server_AbstractUserInterface *userInterface);
|
||||
|
||||
void say(const QString &userName, const QString &s, bool sendToIsl = true);
|
||||
void removeSaidMessages(const QString &userName, int amount, bool sendToIsl = true);
|
||||
|
||||
void addGame(Server_Game *game);
|
||||
void removeGame(Server_Game *game);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue