summaryrefslogtreecommitdiff
path: root/protocols/JabberG/src
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2021-01-24 14:20:00 +0300
committerGeorge Hazan <ghazan@miranda.im>2021-01-24 14:20:00 +0300
commit47a36c81c91640c484eddef1273eb73fb9a40bf8 (patch)
tree0e564c5c2b7240d3c8b93de66488a8837d504632 /protocols/JabberG/src
parent60b39ada2e425a2eb007f4953e110d6385e8491b (diff)
Jabber: fix for a perversive three-state BOOL variable
Diffstat (limited to 'protocols/JabberG/src')
-rw-r--r--protocols/JabberG/src/jabber_chat.cpp69
-rw-r--r--protocols/JabberG/src/jabber_groupchat.cpp15
-rw-r--r--protocols/JabberG/src/jabber_list.h13
3 files changed, 51 insertions, 46 deletions
diff --git a/protocols/JabberG/src/jabber_chat.cpp b/protocols/JabberG/src/jabber_chat.cpp
index 6a723fc0a6..6a90389fb4 100644
--- a/protocols/JabberG/src/jabber_chat.cpp
+++ b/protocols/JabberG/src/jabber_chat.cpp
@@ -111,42 +111,44 @@ int JabberGcGetStatus(JABBER_RESOURCE_STATUS *r)
int CJabberProto::GcInit(JABBER_LIST_ITEM *item)
{
- if (item->bChatActive)
+ if (item->si)
return 1;
Utf2T wszJid(item->jid);
ptrA szNick(JabberNickFromJID(item->jid));
- SESSION_INFO *si = Chat_NewSession(GCW_CHATROOM, m_szModuleName, wszJid, Utf2T(szNick));
- if (si != nullptr) {
- item->hContact = si->hContact;
-
- if (JABBER_LIST_ITEM *bookmark = ListGetItemPtr(LIST_BOOKMARK, item->jid)) {
- if (bookmark->name) {
- ptrW myHandle(db_get_wsa(si->hContact, "CList", "MyHandle"));
- if (myHandle == nullptr)
- db_set_ws(si->hContact, "CList", "MyHandle", bookmark->name);
- }
- }
+ SESSION_INFO *si = item->si = Chat_NewSession(GCW_CHATROOM, m_szModuleName, wszJid, Utf2T(szNick));
+ if (si == nullptr)
+ return 2;
- ptrA tszNick(getUStringA(si->hContact, "MyNick"));
- if (tszNick != nullptr) {
- if (!mir_strcmp(tszNick, szNick))
- delSetting(si->hContact, "MyNick");
- else
- setUString(si->hContact, "MyNick", item->nick);
- }
- else setUString(si->hContact, "MyNick", item->nick);
+ item->hContact = si->hContact;
- ptrA passw(getUStringA(si->hContact, "Password"));
- if (mir_strcmp(passw, item->password)) {
- if (!item->password || !item->password[0])
- delSetting(si->hContact, "Password");
- else
- setUString(si->hContact, "Password", item->password);
+ if (JABBER_LIST_ITEM *bookmark = ListGetItemPtr(LIST_BOOKMARK, item->jid)) {
+ if (bookmark->name) {
+ ptrW myHandle(db_get_wsa(si->hContact, "CList", "MyHandle"));
+ if (myHandle == nullptr)
+ db_set_ws(si->hContact, "CList", "MyHandle", bookmark->name);
}
}
- item->bChatActive = true;
+ ptrA tszNick(getUStringA(si->hContact, "MyNick"));
+ if (tszNick != nullptr) {
+ if (!mir_strcmp(tszNick, szNick))
+ delSetting(si->hContact, "MyNick");
+ else
+ setUString(si->hContact, "MyNick", item->nick);
+ }
+ else setUString(si->hContact, "MyNick", item->nick);
+
+ ptrA passw(getUStringA(si->hContact, "Password"));
+ if (mir_strcmp(passw, item->password)) {
+ if (!item->password || !item->password[0])
+ delSetting(si->hContact, "Password");
+ else
+ setUString(si->hContact, "Password", item->password);
+ }
+
+ item->bChatLogging = false;
+ item->dwChatInitTime = time(0);
for (int i = _countof(sttStatuses) - 1; i >= 0; i--)
Chat_AddGroup(si, TranslateW(Utf2T(sttStatuses[i])));
@@ -158,7 +160,8 @@ int CJabberProto::GcInit(JABBER_LIST_ITEM *item)
void CJabberProto::GcLogShowInformation(JABBER_LIST_ITEM *item, pResourceStatus &user, TJabberGcLogInfoType type)
{
- if (!item || !user || (item->bChatActive != 2)) return;
+ if (!item || !user || !item->bChatLogging)
+ return;
CMStringA buf;
@@ -248,7 +251,7 @@ void CJabberProto::GcLogUpdateMemberStatus(JABBER_LIST_ITEM *item, const char *r
gce.pszUID.a = resource;
gce.pszUserInfo.a = jid;
gce.pszText.a = szReason;
- if (item->bChatActive == 2) {
+ if (item->bChatLogging) {
gce.dwFlags |= GCEF_ADDTOLOG;
gce.time = time(0);
}
@@ -318,8 +321,8 @@ void CJabberProto::GcQuit(JABBER_LIST_ITEM *item, int code, const TiXmlElement *
Chat_Control(m_szModuleName, wszRoomJid, SESSION_OFFLINE);
Contact_Hide(item->hContact, false);
- item->bChatActive = false;
- item->bChatGotSubject = false;
+ item->si = nullptr;
+ item->bChatLogging = false;
if (m_bJabberOnline) {
m_ThreadInfo->send(
@@ -538,7 +541,7 @@ int CJabberProto::JabberGcMenuHook(WPARAM, LPARAM lParam)
idx = IDM_LINK0;
LISTFOREACH_NODEF(i, this, LIST_CHATROOM)
if (item = ListGetItemPtrFromIndex(i)) {
- if (!item->bChatActive)
+ if (!item->si)
continue;
gc_item *pItem = sttFindGcMenuItem(_countof(sttListItems), sttListItems, idx);
@@ -1097,7 +1100,7 @@ static void sttNickListHook(CJabberProto *ppro, JABBER_LIST_ITEM *item, GCHOOK*
LISTFOREACH(i, ppro, LIST_CHATROOM)
{
if (JABBER_LIST_ITEM *pItem = ppro->ListGetItemPtrFromIndex(i)) {
- if (!pItem->bChatActive) continue;
+ if (!pItem->si) continue;
if (!idx--) {
szInviteTo = pItem->jid;
break;
diff --git a/protocols/JabberG/src/jabber_groupchat.cpp b/protocols/JabberG/src/jabber_groupchat.cpp
index 696209eaf5..306af47616 100644
--- a/protocols/JabberG/src/jabber_groupchat.cpp
+++ b/protocols/JabberG/src/jabber_groupchat.cpp
@@ -978,7 +978,7 @@ void CJabberProto::GroupchatProcessPresence(const TiXmlElement *node)
MsgPopup(0, str, TranslateT("Error"));
- if (item != nullptr && !item->bChatActive)
+ if (item != nullptr && !item->si)
ListRemove(LIST_CHATROOM, from);
}
}
@@ -1006,7 +1006,7 @@ void CJabberProto::GroupchatProcessMessage(const TiXmlElement *node)
resource = nullptr;
if ((n = XmlFirstChild(node, "subject")) != nullptr) {
- item->bChatGotSubject = true;
+ item->bChatLogging = true;
msgText = n->GetText();
if (msgText == nullptr || msgText[0] == '\0')
return;
@@ -1062,6 +1062,9 @@ void CJabberProto::GroupchatProcessMessage(const TiXmlElement *node)
if (!msgTime || msgTime > now)
msgTime = now;
+ if (now - item->dwChatInitTime > 2)
+ item->bChatLogging = true;
+
if (resource != nullptr) {
pResourceStatus r(item->findResource(resource));
nick = (r && r->m_szNick) ? r->m_szNick.get() : resource;
@@ -1078,16 +1081,14 @@ void CJabberProto::GroupchatProcessMessage(const TiXmlElement *node)
gce.pszText.a = szText;
gce.bIsMe = nick == nullptr ? FALSE : (mir_strcmp(resource, item->nick) == 0);
- if (item->bChatGotSubject)
+ // if we log chat events, add them to log window
+ if (item->bChatLogging)
gce.dwFlags |= GCEF_ADDTOLOG;
-
- if (m_bGcLogChatHistory && !item->bChatGotSubject)
+ else if (m_bGcLogChatHistory) // else we need to suppress disk logging and sounds/popups
gce.dwFlags |= GCEF_NOTNOTIFY;
Chat_Event(&gce);
- item->bChatActive = 2;
-
if (gce.iType == GC_EVENT_TOPIC)
Chat_SetStatusbarText(m_szModuleName, Utf2T(item->jid), Utf2T(szText));
}
diff --git a/protocols/JabberG/src/jabber_list.h b/protocols/JabberG/src/jabber_list.h
index 4ad59fbdd4..6ad73e6490 100644
--- a/protocols/JabberG/src/jabber_list.h
+++ b/protocols/JabberG/src/jabber_list.h
@@ -180,11 +180,12 @@ struct JABBER_LIST_ITEM : public MZeroedObject
// LIST_CHATROOM
// jid = room JID
- BOOL bChatActive;
- HWND hwndGcListBan;
- HWND hwndGcListAdmin;
- HWND hwndGcListOwner;
- int iChatState;
+ SESSION_INFO *si;
+ HWND hwndGcListBan;
+ HWND hwndGcListAdmin;
+ HWND hwndGcListOwner;
+ int iChatState;
+ DWORD dwChatInitTime;
// LIST_FILE
// jid = string representation of port number
@@ -206,7 +207,7 @@ struct JABBER_LIST_ITEM : public MZeroedObject
char *password; // password for room
bool bAutoJoin;
- bool bChatGotSubject; // MUC received message with subject
+ bool bChatLogging;
bool bUseResource;
bool bHistoryRead;
bool bRealContact;