From d5d66b8a85c970595e28a01877844dc0a65e2003 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 9 Mar 2023 13:23:25 +0300 Subject: fixes #3412 (Jabber: If no nick for room in Bookmarks Miranda uses user ID as nick) --- protocols/JabberG/src/jabber_bookmarks.cpp | 2 +- protocols/JabberG/src/jabber_groupchat.cpp | 14 ++------------ protocols/JabberG/src/jabber_iqid.cpp | 17 ++--------------- protocols/JabberG/src/jabber_proto.h | 1 + protocols/JabberG/src/jabber_util.cpp | 12 ++++++++++++ 5 files changed, 18 insertions(+), 28 deletions(-) (limited to 'protocols/JabberG') diff --git a/protocols/JabberG/src/jabber_bookmarks.cpp b/protocols/JabberG/src/jabber_bookmarks.cpp index 396861f691..8fba42a1aa 100644 --- a/protocols/JabberG/src/jabber_bookmarks.cpp +++ b/protocols/JabberG/src/jabber_bookmarks.cpp @@ -393,7 +393,7 @@ public: if (item->nick && *item->nick) m_proto->GroupchatJoinRoom(server, room, item->nick, item->password); else - m_proto->GroupchatJoinRoom(server, room, ptrA(JabberNickFromJID(m_proto->m_szJabberJID)), item->password); + m_proto->GroupchatJoinRoom(server, room, m_proto->MyNick(), item->password); } } else Utils_OpenUrlW(Utf2T(item->jid)); diff --git a/protocols/JabberG/src/jabber_groupchat.cpp b/protocols/JabberG/src/jabber_groupchat.cpp index 51df44cf9a..1dbf0fecac 100644 --- a/protocols/JabberG/src/jabber_groupchat.cpp +++ b/protocols/JabberG/src/jabber_groupchat.cpp @@ -190,18 +190,13 @@ INT_PTR __cdecl CJabberProto::OnJoinChat(WPARAM hContact, LPARAM) if (jid == nullptr) return 0; - ptrA nick(getUStringA(hContact, "MyNick")); - if (nick == nullptr) - if ((nick = getUStringA("Nick")) == nullptr) - return 0; - ptrA password(getUStringA(hContact, "Password")); if (getWord(hContact, "Status", 0) != ID_STATUS_ONLINE) { char *p = strchr(jid, '@'); if (p != nullptr) { *p++ = 0; - GroupchatJoinRoom(p, jid, nick, password); + GroupchatJoinRoom(p, jid, MyNick(hContact), password); } } @@ -1152,12 +1147,7 @@ void CJabberProto::GroupchatProcessInvite(const char *roomJid, const char *from, return; if (m_bAutoAcceptMUC) { - ptrA nick(getUStringA(HContactFromJID(m_szJabberJID), "MyNick")); - if (nick == nullptr) - nick = getUStringA("Nick"); - if (nick == nullptr) - nick = JabberNickFromJID(m_szJabberJID); - AcceptGroupchatInvite(roomJid, nick, password); + AcceptGroupchatInvite(roomJid, MyNick(HContactFromJID(m_szJabberJID)), password); } else CallFunctionAsync(sttShowDialog, new CGroupchatInviteAcceptDlg(this, roomJid, from, reason, password)); } diff --git a/protocols/JabberG/src/jabber_iqid.cpp b/protocols/JabberG/src/jabber_iqid.cpp index 3cd1fb27c1..99375fb286 100644 --- a/protocols/JabberG/src/jabber_iqid.cpp +++ b/protocols/JabberG/src/jabber_iqid.cpp @@ -236,13 +236,7 @@ void CJabberProto::OnProcessLoginRq(ThreadData *info, uint32_t rq) if (item->nick && item->nick[0]) GroupchatJoinRoom(server, p, item->nick, item->password, true); else { - ptrA nick(getUStringA(HContactFromJID(m_szJabberJID), "MyNick")); - if (nick == nullptr) - nick = getUStringA("Nick"); - if (nick == nullptr) - nick = JabberNickFromJID(m_szJabberJID); - - GroupchatJoinRoom(server, p, nick, item->password, true); + GroupchatJoinRoom(server, p, MyNick(HContactFromJID(m_szJabberJID)), item->password, true); } } } @@ -434,14 +428,7 @@ void CJabberProto::GroupchatJoinByHContact(MCONTACT hContact, bool autojoin) server[0] = 0; server++; - ptrA nick(getUStringA(hContact, "MyNick")); - if (nick == nullptr) { - nick = JabberNickFromJID(m_szJabberJID); - if (nick == nullptr) - return; - } - - GroupchatJoinRoom(server, room, nick, ptrA(getUStringA(hContact, "Password")), autojoin); + GroupchatJoinRoom(server, room, MyNick(hContact), ptrA(getUStringA(hContact, "Password")), autojoin); } ///////////////////////////////////////////////////////////////////////////////////////// diff --git a/protocols/JabberG/src/jabber_proto.h b/protocols/JabberG/src/jabber_proto.h index 7d0496040a..309a5c0677 100644 --- a/protocols/JabberG/src/jabber_proto.h +++ b/protocols/JabberG/src/jabber_proto.h @@ -883,6 +883,7 @@ struct CJabberProto : public PROTO, public IJabberInterface bool IsSendAck(MCONTACT hContact); void __cdecl LoadHttpAvatars(void* param); + CMStringA MyNick(MCONTACT hContact = 0); //---- jabber_vcard.c ----------------------------------------------- diff --git a/protocols/JabberG/src/jabber_util.cpp b/protocols/JabberG/src/jabber_util.cpp index 30b0bab275..b23244d3f8 100644 --- a/protocols/JabberG/src/jabber_util.cpp +++ b/protocols/JabberG/src/jabber_util.cpp @@ -118,6 +118,18 @@ char* JabberNickFromJID(const char *jid) return (p != nullptr) ? mir_strndup(jid, p - jid) : mir_strdup(jid); } +CMStringA CJabberProto::MyNick(MCONTACT hContact) +{ + CMStringA sNick; + if (hContact) + sNick = getMStringU(hContact, "MyNick"); + if (sNick.IsEmpty()) + sNick = getMStringU("Nick"); + if (sNick.IsEmpty()) + sNick = ptrA(JabberNickFromJID(m_szJabberJID)); + return sNick; +} + pResourceStatus CJabberProto::ResourceInfoFromJID(const char *jid) { if (jid == nullptr) -- cgit v1.2.3