From 0c6b2e4d280775b4d97dd3ccf8dd3975192504b0 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Tue, 21 Jan 2025 14:03:35 +0300 Subject: Steam: mark read support --- protocols/Steam/src/main.cpp | 1 + protocols/Steam/src/steam_messages.cpp | 19 +++++++++++++++++++ protocols/Steam/src/steam_proto.cpp | 21 +++++++++++++++++++++ protocols/Steam/src/steam_proto.h | 5 +++++ 4 files changed, 46 insertions(+) (limited to 'protocols/Steam/src') diff --git a/protocols/Steam/src/main.cpp b/protocols/Steam/src/main.cpp index 828311e40f..29cb4017a9 100644 --- a/protocols/Steam/src/main.cpp +++ b/protocols/Steam/src/main.cpp @@ -170,6 +170,7 @@ void CMPlugin::InitSteamServices() serviceHandlers[FriendGetActiveSessions] = ServiceResponseHandler(&CSteamProto::OnGotConversations); serviceHandlers[FriendGetRecentMessages] = ServiceResponseHandler(&CSteamProto::OnGotRecentMessages); serviceHandlers[FriendGetIncomingMessage] = ServiceResponseHandler(&CSteamProto::OnGotIncomingMessage); + serviceHandlers[FriendNotifyAckMessage] = ServiceResponseHandler(&CSteamProto::OnGotMarkRead); serviceHandlers[GetMyChatRoomGroups] = ServiceResponseHandler(&CSteamProto::OnGetMyChats); serviceHandlers[GetChatHistory] = ServiceResponseHandler(&CSteamProto::OnGetChatHistory); diff --git a/protocols/Steam/src/steam_messages.cpp b/protocols/Steam/src/steam_messages.cpp index 956b1a07db..28ea4c4b9f 100644 --- a/protocols/Steam/src/steam_messages.cpp +++ b/protocols/Steam/src/steam_messages.cpp @@ -60,6 +60,25 @@ void CSteamProto::OnGotIncomingMessage(const CFriendMessagesIncomingMessageNotif } } +void CSteamProto::OnGotMarkRead(const CFriendMessagesAckMessageNotification &reply, const CMsgProtoBufHeader &) +{ + MCONTACT hContact = GetContact(reply.steamid_partner); + if (!hContact) { + debugLogA("notification from unknown account %lld ignored", reply.steamid_partner); + return; + } + + DB::ECPTR pCursor(DB::Events(hContact, db_event_firstUnread(hContact))); + while (MEVENT hDbEvent = pCursor.FetchNext()) { + DB::EventInfo dbei(hDbEvent, false); + if (reply.timestamp > dbei.iTimestamp) + break; + + if (!dbei.markedRead()) + db_event_markRead(hContact, hDbEvent, true); + } +} + ///////////////////////////////////////////////////////////////////////////////////////// int CSteamProto::UserIsTyping(MCONTACT hContact, int type) diff --git a/protocols/Steam/src/steam_proto.cpp b/protocols/Steam/src/steam_proto.cpp index dcea10e561..1946440bad 100644 --- a/protocols/Steam/src/steam_proto.cpp +++ b/protocols/Steam/src/steam_proto.cpp @@ -298,6 +298,27 @@ bool CSteamProto::OnContactDeleted(MCONTACT hContact, uint32_t) return true; } +void CSteamProto::OnMarkRead(MCONTACT hContact, MEVENT hDbEvent) +{ + if (IsOnline()) { + DB::EventInfo dbei(hDbEvent, false); + + if (Contact::IsGroupChat(hContact)) { + CChatRoomAckChatMessageNotification request; + request.chat_group_id = GetId(hContact, DBKEY_STEAM_ID); request.has_chat_group_id = true; + request.chat_id = getDword(hContact, "ChatId"); request.has_chat_id = true; + request.timestamp = dbei.iTimestamp; request.has_timestamp = true; + WSSendService(AckChatMessage, request); + } + else { + CFriendMessagesAckMessageNotification request; + request.steamid_partner = GetId(hContact, DBKEY_STEAM_ID); request.has_steamid_partner = true; + request.timestamp = dbei.iTimestamp; request.has_timestamp = true; + WSSendService(FriendAckMessage, request); + } + } +} + int CSteamProto::OnPreCreateMessage(WPARAM, LPARAM lParam) { MessageWindowEvent *evt = (MessageWindowEvent *)lParam; diff --git a/protocols/Steam/src/steam_proto.h b/protocols/Steam/src/steam_proto.h index 924563dabb..9d4c822cd6 100644 --- a/protocols/Steam/src/steam_proto.h +++ b/protocols/Steam/src/steam_proto.h @@ -24,15 +24,18 @@ #define GetOwnAuthorizedDevices "DeviceAuth.GetOwnAuthorizedDevices#1" +#define FriendAckMessage "FriendMessages.AckMessage#1" #define FriendSendMessage "FriendMessages.SendMessage#1" #define FriendGetActiveSessions "FriendMessages.GetActiveMessageSessions#1" #define FriendGetRecentMessages "FriendMessages.GetRecentMessages#1" #define FriendGetIncomingMessage "FriendMessagesClient.IncomingMessage#1" +#define FriendNotifyAckMessage "FriendMessagesClient.NotifyAckMessageEcho#1" #define GetMyChatRoomGroups "ChatRoom.GetMyChatRoomGroups#1" #define GetChatHistory "ChatRoom.GetMessageHistory#1" #define SendChatMessage "ChatRoom.SendChatMessage#1" #define LeaveChatGroup "ChatRoom.LeaveChatRoomGroup#1" +#define AckChatMessage "ChatRoom.AckChatMessage#1" #define NotifyIncomingChatMessage "ChatRoomClient.NotifyIncomingChatMessage#1" @@ -298,6 +301,7 @@ class CSteamProto : public PROTO void SendFriendMessage(EChatEntryType, int64_t steamId, const char *pszMessage, void *pInfo = nullptr); void OnGotIncomingMessage(const CFriendMessagesIncomingMessageNotification &reply, const CMsgProtoBufHeader &hdr); + void OnGotMarkRead(const CFriendMessagesAckMessageNotification &reply, const CMsgProtoBufHeader &hdr); void OnMessageSent(const CFriendMessagesSendMessageResponse &reply, const CMsgProtoBufHeader &hdr); int __cdecl OnPreCreateMessage(WPARAM, LPARAM lParam); @@ -367,6 +371,7 @@ public: bool OnContactDeleted(MCONTACT, uint32_t flags) override; MWindow OnCreateAccMgrUI(MWindow) override; + void OnMarkRead(MCONTACT hContact, MEVENT hDbEvent) override; void OnModulesLoaded() override; // menus -- cgit v1.2.3