Skip to content
Open
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
1 change: 1 addition & 0 deletions src/stationapi/Node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <memory>
#include <string>
#include <vector>
#include <stdexcept>

template <typename NodeT, typename ClientT>
class Node : public UdpManagerHandler
Expand Down
3 changes: 2 additions & 1 deletion src/stationchat/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ add_executable(
protocol/SetApiVersion.hpp
protocol/SetAvatarAttributes.hpp
protocol/UpdatePersistentMessage.hpp
protocol/UpdatePersistentMessages.hpp
ChatAvatar.cpp
ChatAvatar.hpp
ChatAvatarService.cpp
Expand All @@ -60,7 +61,7 @@ add_executable(
StationChatApp.cpp
StationChatApp.hpp
StationChatConfig.hpp)

# cmake-format: off
target_link_libraries(stationchat
stationapi
Expand Down
1 change: 1 addition & 0 deletions src/stationchat/ChatAvatarService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 4 additions & 0 deletions src/stationchat/GatewayClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "protocol/SetApiVersion.hpp"
#include "protocol/SetAvatarAttributes.hpp"
#include "protocol/UpdatePersistentMessage.hpp"
#include "protocol/UpdatePersistentMessages.hpp"

#include "easylogging++.h"

Expand Down Expand Up @@ -138,6 +139,9 @@ void GatewayClient::OnIncoming(std::istringstream& istream) {
case ChatRequestType::UPDATEPERSISTENTMESSAGE:
HandleIncomingMessage<UpdatePersistentMessage>(istream);
break;
case ChatRequestType::UPDATEPERSISTENTMESSAGES:
HandleIncomingMessage<UpdatePersistentMessages>(istream);
break;
case ChatRequestType::IGNORESTATUS:
HandleIncomingMessage<IgnoreStatus>(istream);
break;
Expand Down
29 changes: 29 additions & 0 deletions src/stationchat/PersistentMessageService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint32_t>(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);
}
3 changes: 3 additions & 0 deletions src/stationchat/PersistentMessageService.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
};
Loading