diff --git a/src/stationapi/Node.hpp b/src/stationapi/Node.hpp index 1ab4703..d781478 100644 --- a/src/stationapi/Node.hpp +++ b/src/stationapi/Node.hpp @@ -8,6 +8,7 @@ #include #include #include +#include template class Node : public UdpManagerHandler diff --git a/src/stationchat/CMakeLists.txt b/src/stationchat/CMakeLists.txt index 3acf72d..e594d09 100644 --- a/src/stationchat/CMakeLists.txt +++ b/src/stationchat/CMakeLists.txt @@ -34,6 +34,7 @@ add_executable( protocol/SetApiVersion.hpp protocol/SetAvatarAttributes.hpp protocol/UpdatePersistentMessage.hpp + protocol/UpdatePersistentMessages.hpp ChatAvatar.cpp ChatAvatar.hpp ChatAvatarService.cpp @@ -60,7 +61,7 @@ add_executable( StationChatApp.cpp StationChatApp.hpp StationChatConfig.hpp) - + # cmake-format: off target_link_libraries(stationchat stationapi diff --git a/src/stationchat/ChatAvatarService.cpp b/src/stationchat/ChatAvatarService.cpp index 0de85a3..746dc32 100644 --- a/src/stationchat/ChatAvatarService.cpp +++ b/src/stationchat/ChatAvatarService.cpp @@ -72,6 +72,7 @@ void ChatAvatarService::LoginAvatar(ChatAvatar* avatar) { } void ChatAvatarService::LogoutAvatar(ChatAvatar* avatar) { + if(!avatar->isOnline_) return; avatar->isOnline_ = false; onlineAvatars_.erase(std::remove_if( diff --git a/src/stationchat/GatewayClient.cpp b/src/stationchat/GatewayClient.cpp index 8a6d521..7ee4723 100644 --- a/src/stationchat/GatewayClient.cpp +++ b/src/stationchat/GatewayClient.cpp @@ -42,6 +42,7 @@ #include "protocol/SetApiVersion.hpp" #include "protocol/SetAvatarAttributes.hpp" #include "protocol/UpdatePersistentMessage.hpp" +#include "protocol/UpdatePersistentMessages.hpp" #include "easylogging++.h" @@ -138,6 +139,9 @@ void GatewayClient::OnIncoming(std::istringstream& istream) { case ChatRequestType::UPDATEPERSISTENTMESSAGE: HandleIncomingMessage(istream); break; + case ChatRequestType::UPDATEPERSISTENTMESSAGES: + HandleIncomingMessage(istream); + break; case ChatRequestType::IGNORESTATUS: HandleIncomingMessage(istream); break; diff --git a/src/stationchat/PersistentMessageService.cpp b/src/stationchat/PersistentMessageService.cpp index 3f22d3d..fe2f34a 100644 --- a/src/stationchat/PersistentMessageService.cpp +++ b/src/stationchat/PersistentMessageService.cpp @@ -208,3 +208,32 @@ void PersistentMessageService::UpdateMessageStatus( sqlite3_finalize(stmt); } + +void PersistentMessageService::BulkUpdateMessageStatus( + uint32_t avatarId, const std::u16string& category, PersistentState newStatus) +{ + sqlite3_stmt* stmt; + + char sql[] = "UPDATE persistent_message SET status = @status WHERE avatar_id = @avatar_id AND " + "category = @category"; + + auto result = sqlite3_prepare_v2(db_, sql, -1, &stmt, 0); + if (result != SQLITE_OK) { + throw SQLite3Exception{result, sqlite3_errmsg(db_)}; + } + + int statusIdx = sqlite3_bind_parameter_index(stmt, "@status"); + int avatarIdIdx = sqlite3_bind_parameter_index(stmt, "@avatar_id"); + int categoryIdx = sqlite3_bind_parameter_index(stmt, "@category"); + + sqlite3_bind_int(stmt, statusIdx, static_cast(newStatus)); + sqlite3_bind_int(stmt, avatarIdIdx, avatarId); + std::string cat = FromWideString(category); + sqlite3_bind_text(stmt, categoryIdx, cat.c_str(), -1, nullptr); + + result = sqlite3_step(stmt); + if (result != SQLITE_DONE) { + throw SQLite3Exception{result, sqlite3_errmsg(db_)}; + } + sqlite3_finalize(stmt); +} diff --git a/src/stationchat/PersistentMessageService.hpp b/src/stationchat/PersistentMessageService.hpp index a61a812..6a8b1bc 100644 --- a/src/stationchat/PersistentMessageService.hpp +++ b/src/stationchat/PersistentMessageService.hpp @@ -25,6 +25,9 @@ class PersistentMessageService { void UpdateMessageStatus( uint32_t avatarId, uint32_t messageId, PersistentState status); + void BulkUpdateMessageStatus( + uint32_t avatarId, const std::u16string& category, PersistentState newStatus); + private: sqlite3* db_; }; diff --git a/src/stationchat/protocol/Protocol.cpp b/src/stationchat/protocol/Protocol.cpp index 8fa6188..35324d4 100644 --- a/src/stationchat/protocol/Protocol.cpp +++ b/src/stationchat/protocol/Protocol.cpp @@ -43,6 +43,7 @@ #include "protocol/SetApiVersion.hpp" #include "protocol/SetAvatarAttributes.hpp" #include "protocol/UpdatePersistentMessage.hpp" +#include "protocol/UpdatePersistentMessages.hpp" #include "easylogging++.h" @@ -56,18 +57,19 @@ AddBan::AddBan(GatewayClient* client, const RequestType& request, ResponseType& auto srcAvatar = avatarService_->GetAvatar(request.srcAvatarId); if (!srcAvatar) { - throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST}; + throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST, std::to_string(request.srcAvatarId).c_str()}; } auto bannedAvatar = avatarService_->GetAvatar(request.destAvatarName, request.destAvatarAddress); if (!bannedAvatar) { - throw ChatResultException{ChatResultCode::DESTAVATARDOESNTEXIST}; + throw ChatResultException{ChatResultCode::DESTAVATARDOESNTEXIST, (FromWideString(request.destAvatarName) + " : " + + FromWideString(request.destAvatarAddress)).c_str()}; } auto room = roomService_->GetRoom(request.destRoomAddress); if (!room) { - throw ChatResultException{ChatResultCode::ADDRESSNOTROOM}; + throw ChatResultException{ChatResultCode::ADDRESSNOTROOM, FromWideString(request.destRoomAddress).c_str()}; } response.destRoomId = room->GetRoomId(); @@ -82,12 +84,12 @@ AddFriend::AddFriend(GatewayClient* client, const RequestType& request, Response << FromWideString(request.srcAddress); auto srcAvatar = avatarService_->GetAvatar(request.srcAvatarId); if (!srcAvatar) { - throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST}; + throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST, std::to_string(request.srcAvatarId).c_str()}; } auto destAvatar = avatarService_->GetAvatar(request.destName, request.destAddress); if (!destAvatar) { - throw ChatResultException{ChatResultCode::DESTAVATARDOESNTEXIST}; + throw ChatResultException{ChatResultCode::DESTAVATARDOESNTEXIST, (FromWideString(request.destName) + " : " + FromWideString(request.destAddress)).c_str()}; } srcAvatar->AddFriend(destAvatar); @@ -104,12 +106,12 @@ AddIgnore::AddIgnore(GatewayClient* client, const RequestType& request, Response << FromWideString(request.srcAddress); auto srcAvatar = avatarService_->GetAvatar(request.srcAvatarId); if (!srcAvatar) { - throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST}; + throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST, std::to_string(request.srcAvatarId).c_str()}; } auto destAvatar = avatarService_->GetAvatar(request.destName, request.destAddress); if (!destAvatar) { - throw ChatResultException{ChatResultCode::DESTAVATARDOESNTEXIST}; + throw ChatResultException{ChatResultCode::DESTAVATARDOESNTEXIST, (FromWideString(request.destName) + " : " + FromWideString(request.destAddress)).c_str()}; } srcAvatar->AddIgnore(destAvatar); @@ -125,18 +127,18 @@ AddInvite::AddInvite(GatewayClient* client, const RequestType& request, Response auto srcAvatar = avatarService_->GetAvatar(request.srcAvatarId); if (!srcAvatar) { - throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST}; + throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST, std::to_string(request.srcAvatarId).c_str()}; } auto invitedAvatar = avatarService_->GetAvatar(request.destAvatarName, request.destAvatarAddress); if (!invitedAvatar) { - throw ChatResultException{ChatResultCode::DESTAVATARDOESNTEXIST}; + throw ChatResultException{ChatResultCode::DESTAVATARDOESNTEXIST, (FromWideString(request.destAvatarName) + " : " + FromWideString(request.destAvatarAddress)).c_str()}; } auto room = roomService_->GetRoom(request.destRoomAddress); if (!room) { - throw ChatResultException{ChatResultCode::ADDRESSNOTROOM}; + throw ChatResultException{ChatResultCode::ADDRESSNOTROOM, FromWideString(request.destRoomAddress).c_str()}; } response.destRoomId = room->GetRoomId(); @@ -155,18 +157,18 @@ AddModerator::AddModerator( auto srcAvatar = avatarService_->GetAvatar(request.srcAvatarId); if (!srcAvatar) { - throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST}; + throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST, std::to_string(request.srcAvatarId).c_str()}; } auto moderatorAvatar = avatarService_->GetAvatar(request.destAvatarName, request.destAvatarAddress); if (!moderatorAvatar) { - throw ChatResultException{ChatResultCode::DESTAVATARDOESNTEXIST}; + throw ChatResultException{ChatResultCode::DESTAVATARDOESNTEXIST, (FromWideString(request.destAvatarName) + " : " + FromWideString(request.destAvatarAddress)).c_str()}; } auto room = roomService_->GetRoom(request.destRoomAddress); if (!room) { - throw ChatResultException{ChatResultCode::ADDRESSNOTROOM}; + throw ChatResultException{ChatResultCode::ADDRESSNOTROOM, FromWideString(request.destRoomAddress).c_str()}; } response.destRoomId = room->GetRoomId(); @@ -192,7 +194,7 @@ DestroyAvatar::DestroyAvatar( , roomService_{client->GetNode()->GetRoomService()} { auto avatar = avatarService_->GetAvatar(request.avatarId); if (!avatar) { - throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST}; + throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST, std::to_string(request.avatarId).c_str()}; } // Remove From All Rooms @@ -216,12 +218,12 @@ DestroyRoom::DestroyRoom(GatewayClient* client, const RequestType& request, Resp auto srcAvatar = avatarService_->GetAvatar(request.srcAvatarId); if (!srcAvatar) { - throw ChatResultException(ChatResultCode::SRCAVATARDOESNTEXIST); + throw ChatResultException(ChatResultCode::SRCAVATARDOESNTEXIST, std::to_string(request.srcAvatarId).c_str()); } auto room = roomService_->GetRoom(request.roomAddress); if (!room) { - throw ChatResultException(ChatResultCode::ADDRESSNOTROOM); + throw ChatResultException(ChatResultCode::ADDRESSNOTROOM, FromWideString(request.roomAddress).c_str()); } auto addresses = room->GetRemoteAddresses(); @@ -243,12 +245,12 @@ EnterRoom::EnterRoom(GatewayClient* client, const RequestType& request, Response auto srcAvatar = avatarService_->GetAvatar(request.srcAvatarId); if (!srcAvatar) { - throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST}; + throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST, std::to_string(request.srcAvatarId).c_str()}; } response.room = roomService_->GetRoom(request.roomAddress); if (!response.room) { - throw ChatResultException{ChatResultCode::ADDRESSNOTROOM}; + throw ChatResultException{ChatResultCode::ADDRESSNOTROOM, FromWideString(request.roomAddress).c_str()}; } response.roomId = response.room->GetRoomId(); @@ -296,7 +298,7 @@ FriendStatus::FriendStatus( auto srcAvatar = avatarService_->GetAvatar(request.srcAvatarId); if (!srcAvatar) { - throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST}; + throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST, std::to_string(request.srcAvatarId).c_str()}; } response.srcAvatar = srcAvatar; @@ -310,7 +312,8 @@ GetAnyAvatar::GetAnyAvatar( auto avatar = avatarService_->GetAvatar(request.name, request.address); if (!avatar) { - throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST}; + throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST, (FromWideString(request.name) + " : " + + FromWideString(request.address)).c_str()}; } response.isOnline = avatar->IsOnline(); @@ -342,7 +345,7 @@ GetRoom::GetRoom(GatewayClient* client, const RequestType& request, ResponseType auto room = roomService_->GetRoom(request.roomAddress); if (!room) { - throw ChatResultException{ChatResultCode::ADDRESSDOESNTEXIST}; + throw ChatResultException{ChatResultCode::ADDRESSDOESNTEXIST, FromWideString(request.roomAddress).c_str()}; } response.room = room; @@ -366,7 +369,7 @@ IgnoreStatus::IgnoreStatus( auto srcAvatar = avatarService_->GetAvatar(request.srcAvatarId); if (!srcAvatar) { - throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST}; + throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST, std::to_string(request.srcAvatarId).c_str()}; } response.srcAvatar = srcAvatar; @@ -381,17 +384,17 @@ KickAvatar::KickAvatar(GatewayClient* client, const RequestType& request, Respon auto srcAvatar = avatarService_->GetAvatar(request.srcAvatarId); if (!srcAvatar) { - throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST}; + throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST, std::to_string(request.srcAvatarId).c_str()}; } auto destAvatar = avatarService_->GetAvatar(request.destAvatarName, request.destAvatarAddress); if (!destAvatar) { - throw ChatResultException{ChatResultCode::DESTAVATARDOESNTEXIST}; + throw ChatResultException{ChatResultCode::DESTAVATARDOESNTEXIST, (FromWideString(request.destAvatarName) + " : " + FromWideString(request.destAvatarAddress)).c_str()}; } auto room = roomService_->GetRoom(request.destRoomAddress); if (!room) { - throw ChatResultException{ChatResultCode::ADDRESSNOTROOM}; + throw ChatResultException{ChatResultCode::ADDRESSNOTROOM, FromWideString(request.destRoomAddress).c_str()}; } response.destRoomId = room->GetRoomId(); @@ -407,12 +410,12 @@ LeaveRoom::LeaveRoom(GatewayClient* client, const RequestType& request, Response , roomService_{client->GetNode()->GetRoomService()} { auto srcAvatar = avatarService_->GetAvatar(request.srcAvatarId); if (!srcAvatar) { - throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST}; + throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST, std::to_string(request.srcAvatarId).c_str()}; } auto room = roomService_->GetRoom(request.roomAddress); if (!room) { - throw ChatResultException{ChatResultCode::ADDRESSNOTROOM}; + throw ChatResultException{ChatResultCode::ADDRESSNOTROOM, FromWideString(request.roomAddress).c_str()}; } response.roomId = room->GetRoomId(); @@ -489,18 +492,18 @@ RemoveBan::RemoveBan(GatewayClient* client, const RequestType& request, Response auto srcAvatar = avatarService_->GetAvatar(request.srcAvatarId); if (!srcAvatar) { - throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST}; + throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST, std::to_string(request.srcAvatarId).c_str()}; } auto bannedAvatar = avatarService_->GetAvatar(request.destAvatarName, request.destAvatarAddress); if (!bannedAvatar) { - throw ChatResultException{ChatResultCode::DESTAVATARDOESNTEXIST}; + throw ChatResultException{ChatResultCode::DESTAVATARDOESNTEXIST, (FromWideString(request.destAvatarName) + " : " + FromWideString(request.destAvatarAddress)).c_str()}; } auto room = roomService_->GetRoom(request.destRoomAddress); if (!room) { - throw ChatResultException{ChatResultCode::ADDRESSNOTROOM}; + throw ChatResultException{ChatResultCode::ADDRESSNOTROOM, FromWideString(request.destRoomAddress).c_str()}; } response.destRoomId = room->GetRoomId(); @@ -517,12 +520,12 @@ RemoveFriend::RemoveFriend( auto srcAvatar = avatarService_->GetAvatar(request.srcAvatarId); if (!srcAvatar) { - throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST}; + throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST, std::to_string(request.srcAvatarId).c_str()}; } auto destAvatar = avatarService_->GetAvatar(request.destName, request.destAddress); if (!destAvatar) { - throw ChatResultException{ChatResultCode::DESTAVATARDOESNTEXIST}; + throw ChatResultException{ChatResultCode::DESTAVATARDOESNTEXIST, (FromWideString(request.destName) + " : " + FromWideString(request.destAddress)).c_str()}; } srcAvatar->RemoveFriend(destAvatar); @@ -536,12 +539,12 @@ RemoveIgnore::RemoveIgnore(GatewayClient* client, const RequestType& request, Re auto srcAvatar = avatarService_->GetAvatar(request.srcAvatarId); if (!srcAvatar) { - throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST}; + throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST, std::to_string(request.srcAvatarId).c_str()}; } auto destAvatar = avatarService_->GetAvatar(request.destName, request.destAddress); if (!srcAvatar) { - throw ChatResultException{ChatResultCode::DESTAVATARDOESNTEXIST}; + throw ChatResultException{ChatResultCode::DESTAVATARDOESNTEXIST, (FromWideString(request.destName) + " : " + FromWideString(request.destAddress)).c_str()}; } srcAvatar->RemoveIgnore(destAvatar); @@ -558,18 +561,18 @@ RemoveInvite::RemoveInvite( auto srcAvatar = avatarService_->GetAvatar(request.srcAvatarId); if (!srcAvatar) { - throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST}; + throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST, std::to_string(request.srcAvatarId).c_str()}; } auto invitedAvatar = avatarService_->GetAvatar(request.destAvatarName, request.destAvatarAddress); if (!invitedAvatar) { - throw ChatResultException{ChatResultCode::DESTAVATARDOESNTEXIST}; + throw ChatResultException{ChatResultCode::DESTAVATARDOESNTEXIST, (FromWideString(request.destAvatarName) + " : " + FromWideString(request.destAvatarAddress)).c_str()}; } auto room = roomService_->GetRoom(request.destRoomAddress); if (!room) { - throw ChatResultException{ChatResultCode::ADDRESSNOTROOM}; + throw ChatResultException{ChatResultCode::ADDRESSNOTROOM, FromWideString(request.destRoomAddress).c_str()}; } response.destRoomId = room->GetRoomId(); @@ -585,17 +588,17 @@ RemoveModerator::RemoveModerator(GatewayClient* client, const RequestType& reque auto srcAvatar = avatarService_->GetAvatar(request.srcAvatarId); if (!srcAvatar) { - throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST}; + throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST, std::to_string(request.srcAvatarId).c_str()}; } auto moderatorAvatar = avatarService_->GetAvatar(request.destAvatarName, request.destAvatarAddress); if (!moderatorAvatar) { - throw ChatResultException{ChatResultCode::DESTAVATARDOESNTEXIST}; + throw ChatResultException{ChatResultCode::DESTAVATARDOESNTEXIST, (FromWideString(request.destAvatarName) + " : " + FromWideString(request.destAvatarAddress)).c_str()}; } auto room = roomService_->GetRoom(request.destRoomAddress); if (!room) { - throw ChatResultException{ChatResultCode::ADDRESSNOTROOM}; + throw ChatResultException{ChatResultCode::ADDRESSNOTROOM, FromWideString(request.destRoomAddress).c_str()}; } response.destRoomId = room->GetRoomId(); @@ -612,12 +615,12 @@ SendInstantMessage::SendInstantMessage( auto srcAvatar = avatarService_->GetAvatar(request.srcAvatarId); if (!srcAvatar) { - throw ChatResultException(ChatResultCode::SRCAVATARDOESNTEXIST); + throw ChatResultException(ChatResultCode::SRCAVATARDOESNTEXIST, std::to_string(request.srcAvatarId).c_str()); } auto destAvatar = avatarService_->GetAvatar(request.destName, request.destAddress); if (!destAvatar) { - throw ChatResultException(ChatResultCode::DESTAVATARDOESNTEXIST); + throw ChatResultException{ChatResultCode::DESTAVATARDOESNTEXIST, (FromWideString(request.destName) + " : " + FromWideString(request.destAddress)).c_str()}; } if (destAvatar->IsIgnored(srcAvatar)) { @@ -634,7 +637,7 @@ SendPersistentMessage::SendPersistentMessage(GatewayClient* client, const Reques auto destAvatar = avatarService_->GetAvatar(request.destName, request.destAddress); if (!destAvatar) { - throw ChatResultException{ChatResultCode::DESTAVATARDOESNTEXIST}; + throw ChatResultException{ChatResultCode::DESTAVATARDOESNTEXIST, (FromWideString(request.destName) + " : " + FromWideString(request.destAddress)).c_str()}; } PersistentMessage message; @@ -642,11 +645,11 @@ SendPersistentMessage::SendPersistentMessage(GatewayClient* client, const Reques if (request.avatarPresence) { auto srcAvatar = avatarService_->GetAvatar(request.srcAvatarId); if (!srcAvatar) { - throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST}; + throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST, std::to_string(request.srcAvatarId).c_str()}; } if (destAvatar->IsIgnored(srcAvatar)) { - throw ChatResultException(ChatResultCode::IGNORING); + throw ChatResultException(ChatResultCode::IGNORING, (std::to_string(destAvatar->GetAvatarId()) + " : " + std::to_string(srcAvatar->GetAvatarId())).c_str()); } message.header.fromName = srcAvatar->GetName(); @@ -680,12 +683,12 @@ SendRoomMessage::SendRoomMessage( auto srcAvatar = avatarService_->GetAvatar(request.srcAvatarId); if (!srcAvatar) { - throw ChatResultException(ChatResultCode::SRCAVATARDOESNTEXIST); + throw ChatResultException(ChatResultCode::SRCAVATARDOESNTEXIST, std::to_string(request.srcAvatarId).c_str()); } auto room = roomService_->GetRoom(request.destRoomAddress); if (!room) { - throw ChatResultException(ChatResultCode::ADDRESSNOTROOM); + throw ChatResultException(ChatResultCode::ADDRESSNOTROOM, FromWideString(request.destRoomAddress).c_str()); } response.roomId = room->GetRoomId(); @@ -709,7 +712,7 @@ SetAvatarAttributes::SetAvatarAttributes(GatewayClient* client, const RequestTyp auto avatar = avatarService_->GetAvatar(request.avatarId); if (!avatar) { - throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST}; + throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST, std::to_string(request.avatarId).c_str()}; } response.avatar = avatar; @@ -729,3 +732,11 @@ UpdatePersistentMessage::UpdatePersistentMessage(GatewayClient* client, const Re messageService_->UpdateMessageStatus( request.srcAvatarId, request.messageId, request.status); } + +UpdatePersistentMessages::UpdatePersistentMessages(GatewayClient *client, const RequestType &request, ResponseType &response) + : messageService_{client->GetNode()->GetMessageService()} +{ + LOG(INFO) << "UPDATEPERSISTENTMESSAGES request received"; + messageService_->BulkUpdateMessageStatus( + request.srcAvatarId, request.category, request.newStatus); +} diff --git a/src/stationchat/protocol/UpdatePersistentMessages.hpp b/src/stationchat/protocol/UpdatePersistentMessages.hpp new file mode 100755 index 0000000..f271086 --- /dev/null +++ b/src/stationchat/protocol/UpdatePersistentMessages.hpp @@ -0,0 +1,67 @@ +/** + * UpdatePersistentMessages.hpp + * Specific handling for bulk-message update requests + * e.g. for use with /emptyMail command + * + * SWG Source Addition - 2021 + * Authors: Aconite + */ + +#pragma once + +#include "ChatEnums.hpp" +#include "PersistentMessage.hpp" + +class PersistentMessageService; +class GatewayClient; + +/** Begin UpdatePersistentMessages Request */ + +struct ReqUpdatePersistentMessages { + const ChatRequestType type = ChatRequestType::UPDATEPERSISTENTMESSAGES; + uint32_t track; + uint32_t srcAvatarId; + PersistentState currentStatus; + PersistentState newStatus; + std::u16string category; +}; + +template +void read(StreamT& ar, ReqUpdatePersistentMessages& data) { + read(ar, data.track); + read(ar, data.srcAvatarId); + read(ar, data.currentStatus); + read(ar, data.newStatus); + read(ar, data.category); +} + +/** Begin UpdatePersistentMessages Response */ + +struct ResUpdatePersistentMessages { + ResUpdatePersistentMessages(uint32_t track_) + : track{track_} + , result{ChatResultCode::SUCCESS} {} + + const ChatResponseType type = ChatResponseType::UPDATEPERSISTENTMESSAGES; + uint32_t track; + ChatResultCode result; +}; + +template +void write(StreamT& ar, const ResUpdatePersistentMessages& data) { + write(ar, data.type); + write(ar, data.track); + write(ar, data.result); +} + +class UpdatePersistentMessages { +public: + using RequestType = ReqUpdatePersistentMessages; + using ResponseType = ResUpdatePersistentMessages; + + UpdatePersistentMessages(GatewayClient* client, const RequestType& request, ResponseType& response); + +private: + PersistentMessageService* messageService_; +}; +