diff options
| author | George Hazan <george.hazan@gmail.com> | 2025-01-13 13:05:45 +0300 |
|---|---|---|
| committer | George Hazan <george.hazan@gmail.com> | 2025-01-13 13:05:45 +0300 |
| commit | ff52dc730a047fadc8eb71676b91a9d2ecc654ad (patch) | |
| tree | c392eb7467dc223e00aea2974060b1227c14b7ac | |
| parent | 80a6e614bdb1d571d3eec68c3e508b07542bf06e (diff) | |
Steam: user info request for unknown chat members
| -rw-r--r-- | protocols/Steam/src/steam_chats.cpp | 62 | ||||
| -rw-r--r-- | protocols/Steam/src/steam_contacts.cpp | 21 | ||||
| -rw-r--r-- | protocols/Steam/src/steam_proto.cpp | 2 | ||||
| -rw-r--r-- | protocols/Steam/src/steam_proto.h | 3 |
4 files changed, 62 insertions, 26 deletions
diff --git a/protocols/Steam/src/steam_chats.cpp b/protocols/Steam/src/steam_chats.cpp index 248233166f..704a86e5b1 100644 --- a/protocols/Steam/src/steam_chats.cpp +++ b/protocols/Steam/src/steam_chats.cpp @@ -34,40 +34,51 @@ void CSteamProto::OnGetMyChats(const CChatRoomGetMyChatRoomGroupsResponse &reply SESSION_INFO *pOwner = 0; for (int k = 0; k < pGroup->n_chat_rooms; k++) { + std::vector<uint64_t> ids; + auto *pChat = pGroup->chat_rooms[k]; - CMStringW wszId(FORMAT, L"%lld_%d", pGroup->chat_group_id, pChat->chat_id); + CMStringW wszId(FORMAT, L"%lld_%lld", pGroup->chat_group_id, pChat->chat_id); CMStringW wszTitle(Utf2T(pChat->chat_name)); if (wszTitle.IsEmpty()) wszTitle = Utf2T(pGroup->chat_group_name); auto *si = Chat_NewSession(GCW_CHATROOM, m_szModuleName, wszId, wszTitle); - Chat_AddGroup(si, TranslateT("Owner")); - Chat_AddGroup(si, TranslateT("Participant")); - - if (pOwner == 0) { - for (int j = 0; j < pGroup->n_top_members; j++) { - uint64_t iSteamId = AccountIdToSteamId(pGroup->top_members[j]); - CMStringW wszUserId(FORMAT, L"%lld", iSteamId), wszNick; - - GCEVENT gce = { si, GC_EVENT_JOIN }; - gce.pszUID.w = wszUserId; - - if (iSteamId == m_iSteamId) { - gce.bIsMe = true; - wszNick = getMStringW("Nick"); + if (!si->pStatuses) { + + Chat_AddGroup(si, TranslateT("Owner")); + Chat_AddGroup(si, TranslateT("Participant")); + + if (pOwner == 0) { + for (int j = 0; j < pGroup->n_top_members; j++) { + uint64_t iSteamId = AccountIdToSteamId(pGroup->top_members[j]); + CMStringW wszUserId(FORMAT, L"%lld", iSteamId), wszNick; + + GCEVENT gce = { si, GC_EVENT_JOIN }; + gce.pszUID.w = wszUserId; + + if (iSteamId == m_iSteamId) { + gce.bIsMe = true; + wszNick = getMStringW("Nick"); + } + else if (MCONTACT hContact = GetContact(iSteamId)) + wszNick = Clist_GetContactDisplayName(hContact); + else { + ids.push_back(iSteamId); + { + mir_cslock lck(m_csChats); + m_chatContactInfo[iSteamId] = si; + } + wszNick = L"@" + wszUserId; + } + + gce.pszNick.w = wszNick; + gce.pszStatus.w = (pGroup->top_members[j] == pGroup->accountid_owner) ? TranslateT("Owner") : TranslateT("Participant"); + Chat_Event(&gce); } - else if (MCONTACT hContact = GetContact(iSteamId)) - wszNick = Clist_GetContactDisplayName(hContact); - else - wszNick = L"@" + wszUserId; - - gce.pszNick.w = wszNick; - gce.pszStatus.w = (pGroup->top_members[j] == pGroup->accountid_owner) ? TranslateT("Owner") : TranslateT("Participant"); - Chat_Event(&gce); } + else si->pParent = pOwner; } - else si->pParent = pOwner; setDword(si->hContact, "ChatId", pChat->chat_id); @@ -84,6 +95,9 @@ void CSteamProto::OnGetMyChats(const CChatRoomGetMyChatRoomGroupsResponse &reply Chat_Control(si, WINDOW_HIDDEN); Chat_Control(si, SESSION_ONLINE); + if (!ids.empty()) + SendUserInfoRequest(ids); + uint32_t dwLastMsgId = getDword(si->hContact, DBKEY_LASTMSG); if (pChat->time_last_message > dwLastMsgId) SendGetChatHistory(si->hContact, dwLastMsgId); diff --git a/protocols/Steam/src/steam_contacts.cpp b/protocols/Steam/src/steam_contacts.cpp index 5ce9381f04..7808c1125b 100644 --- a/protocols/Steam/src/steam_contacts.cpp +++ b/protocols/Steam/src/steam_contacts.cpp @@ -75,15 +75,34 @@ void CSteamProto::OnGotFriendInfo(const CMsgClientPersonaState &reply, const CMs { for (int i = 0; i < reply.n_friends; i++) { auto *F = reply.friends[i]; + SESSION_INFO *si = nullptr; + { + mir_cslock lck(m_csChats); + auto it = m_chatContactInfo.find(F->friendid); + if (it != m_chatContactInfo.end()) { + si = it->second; + m_chatContactInfo.erase(it); + } + } auto hContact = GetContact(F->friendid); - if (!hContact && F->friendid != m_iSteamId) + if (!si && !hContact && F->friendid != m_iSteamId) hContact = AddContact(F->friendid); // set name if (F->player_name) { CMStringW realName(Utf2T(F->player_name)); if (!realName.IsEmpty()) { + // set a nickname for group chat user? + if (si) { + CMStringW wszUserId(FORMAT, L"%lld", F->friendid); + GCEVENT gce = { si, GC_EVENT_NICK }; + gce.pszUID.w = wszUserId; + gce.pszText.w = realName; + Chat_Event(&gce); + continue; + } + int pos = realName.Find(L' ', 1); if (pos != -1) { setWString(hContact, "FirstName", realName.Mid(0, pos)); diff --git a/protocols/Steam/src/steam_proto.cpp b/protocols/Steam/src/steam_proto.cpp index 7fd3eb4d92..dcea10e561 100644 --- a/protocols/Steam/src/steam_proto.cpp +++ b/protocols/Steam/src/steam_proto.cpp @@ -48,7 +48,7 @@ CSteamProto::CSteamProto(const char *protoName, const wchar_t *userName) : // groupchat initialization
GCREGISTER gcr = {};
- gcr.dwFlags = GC_TYPNOTIF | GC_DATABASE;
+ gcr.dwFlags = GC_TYPNOTIF | GC_DATABASE | GC_PERSISTENT;
gcr.ptszDispName = m_tszUserName;
gcr.pszModule = m_szModuleName;
Chat_Register(&gcr);
diff --git a/protocols/Steam/src/steam_proto.h b/protocols/Steam/src/steam_proto.h index 3683d19a89..924563dabb 100644 --- a/protocols/Steam/src/steam_proto.h +++ b/protocols/Steam/src/steam_proto.h @@ -208,6 +208,9 @@ class CSteamProto : public PROTO<CSteamProto> INT_PTR __cdecl GetMyAvatar(WPARAM, LPARAM);
// chats
+ mir_cs m_csChats;
+ std::map<uint64_t, SESSION_INFO*> m_chatContactInfo;
+
void SendGetChatsRequest();
void OnGetMyChats(const CChatRoomGetMyChatRoomGroupsResponse &pResponse, const CMsgProtoBufHeader &hdr);
|
