diff options
author | George Hazan <ghazan@miranda.im> | 2023-01-27 19:48:42 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2023-01-27 19:48:42 +0300 |
commit | 899221e2d058f5afe30bb2ecdbf168c8ad3c15a6 (patch) | |
tree | ea2346678575a4fc5fdd9575b6a9174bd30c70dc /protocols/Gadu-Gadu/src | |
parent | c736d08681747a9453bd4c266f6dd54d8cbd79eb (diff) |
Group chats: all old APIs with lookup by module+session removed
Diffstat (limited to 'protocols/Gadu-Gadu/src')
-rw-r--r-- | protocols/Gadu-Gadu/src/core.cpp | 29 | ||||
-rw-r--r-- | protocols/Gadu-Gadu/src/gg.h | 2 | ||||
-rw-r--r-- | protocols/Gadu-Gadu/src/gg_proto.h | 2 | ||||
-rw-r--r-- | protocols/Gadu-Gadu/src/groupchat.cpp | 58 |
4 files changed, 44 insertions, 47 deletions
diff --git a/protocols/Gadu-Gadu/src/core.cpp b/protocols/Gadu-Gadu/src/core.cpp index 6a0698e1cf..19735b87e2 100644 --- a/protocols/Gadu-Gadu/src/core.cpp +++ b/protocols/Gadu-Gadu/src/core.cpp @@ -809,21 +809,20 @@ retry: else if (!e->event.msg.recipients_count || gc_enabled) {
// Check if groupchat
if (e->event.msg.recipients_count && gc_enabled && !getByte(GG_KEY_IGNORECONF, GG_KEYDEF_IGNORECONF)) {
- wchar_t *chat = gc_getchat(e->event.msg.sender, e->event.msg.recipients, e->event.msg.recipients_count);
- if (chat) {
+ auto *si = gc_getchat(e->event.msg.sender, e->event.msg.recipients, e->event.msg.recipients_count);
+ if (si) {
wchar_t id[32];
UIN2IDT(e->event.msg.sender, id);
- GCEVENT gce = { m_szModuleName, 0, GC_EVENT_MESSAGE };
+ GCEVENT gce = { si, GC_EVENT_MESSAGE };
time_t t = time(0);
- gce.pszID.w = chat;
gce.pszUID.w = id;
wchar_t* messageT = mir_utf8decodeW(e->event.msg.message);
gce.pszText.w = messageT;
gce.pszNick.w = (wchar_t*)Clist_GetContactDisplayName(getcontact(e->event.msg.sender, 1, 0, nullptr));
gce.time = (!(e->event.msg.msgclass & GG_CLASS_OFFLINE) || e->event.msg.time > (t - timeDeviation)) ? t : e->event.msg.time;
gce.dwFlags = GCEF_ADDTOLOG;
- debugLogW(L"mainthread() (%x): Conference message to room %s & id %s.", this, chat, id);
+ debugLogW(L"mainthread() (%x): Conference message to room %s & id %s.", this, si->ptszID, id);
Chat_Event(&gce);
mir_free(messageT);
}
@@ -870,14 +869,12 @@ retry: case GG_EVENT_MULTILOGON_MSG:
if (e->event.multilogon_msg.recipients_count && gc_enabled && !getByte(GG_KEY_IGNORECONF, GG_KEYDEF_IGNORECONF))
{
- wchar_t *chat = gc_getchat(e->event.multilogon_msg.sender, e->event.multilogon_msg.recipients, e->event.multilogon_msg.recipients_count);
- if (chat)
- {
+ auto *si = gc_getchat(e->event.multilogon_msg.sender, e->event.multilogon_msg.recipients, e->event.multilogon_msg.recipients_count);
+ if (si) {
wchar_t id[32];
UIN2IDT(getDword(GG_KEY_UIN, 0), id);
- GCEVENT gce = { m_szModuleName, 0, GC_EVENT_MESSAGE };
- gce.pszID.w = chat;
+ GCEVENT gce = { si, GC_EVENT_MESSAGE };
gce.pszUID.w = id;
wchar_t* messageT = mir_utf8decodeW(e->event.multilogon_msg.message);
gce.pszText.w = messageT;
@@ -886,14 +883,13 @@ retry: nickT = mir_wstrdup(dbv.pwszVal);
db_free(&dbv);
}
- else
- nickT = mir_wstrdup(TranslateT("Me"));
+ else nickT = mir_wstrdup(TranslateT("Me"));
gce.pszNick.w = nickT;
gce.time = e->event.multilogon_msg.time;
gce.bIsMe = 1;
gce.dwFlags = GCEF_ADDTOLOG;
- debugLogW(L"mainthread() (%x): Sent conference message to room %s.", this, chat);
+ debugLogW(L"mainthread() (%x): Sent conference message to room %s.", this, si->ptszID);
Chat_Event(&gce);
mir_free(messageT);
mir_free(nickT);
@@ -1224,8 +1220,9 @@ void GaduProto::OnContactDeleted(MCONTACT hContact) free(chat->recipients);
list_remove(&chats, chat, 1);
// Terminate chat window / shouldn't cascade entry is deleted
- Chat_Control(m_szModuleName, wszRoomId, SESSION_OFFLINE);
- Chat_Terminate(m_szModuleName, wszRoomId);
+ Chat_Control(chat->si, SESSION_OFFLINE);
+ Chat_Terminate(chat->si, wszRoomId);
+ chat->si = nullptr;
}
return;
}
@@ -1290,7 +1287,7 @@ int GaduProto::dbsettingchanged(WPARAM hContact, LPARAM lParam) debugLogA("dbsettingchanged(): Conference %s was renamed.", wszId.c_str());
// Mark cascading
/* FIXME */ cascade = 1;
- Chat_ChangeSessionName(m_szModuleName, wszId, ptszVal);
+ Chat_ChangeSessionName(Chat_Find(wszId, m_szModuleName), ptszVal);
/* FIXME */ cascade = 0;
}
}
diff --git a/protocols/Gadu-Gadu/src/gg.h b/protocols/Gadu-Gadu/src/gg.h index c4ed8826b4..870af10e41 100644 --- a/protocols/Gadu-Gadu/src/gg.h +++ b/protocols/Gadu-Gadu/src/gg.h @@ -104,7 +104,7 @@ struct GGGC {
uin_t *recipients;
int recipients_count;
- wchar_t id[32];
+ SESSION_INFO *si;
BOOL ignore;
};
diff --git a/protocols/Gadu-Gadu/src/gg_proto.h b/protocols/Gadu-Gadu/src/gg_proto.h index f84691c0b8..6142e92838 100644 --- a/protocols/Gadu-Gadu/src/gg_proto.h +++ b/protocols/Gadu-Gadu/src/gg_proto.h @@ -189,7 +189,7 @@ struct GaduProto : public PROTO<GaduProto> int gc_init();
void gc_menus_init(HGENMENU hRoot);
int gc_destroy();
- wchar_t * gc_getchat(uin_t sender, uin_t *recipients, int recipients_count);
+ SESSION_INFO* gc_getchat(uin_t sender, uin_t *recipients, int recipients_count);
GGGC *gc_lookup(const wchar_t *id);
int gc_changenick(MCONTACT hContact, wchar_t *ptszNick);
diff --git a/protocols/Gadu-Gadu/src/groupchat.cpp b/protocols/Gadu-Gadu/src/groupchat.cpp index 81deec7393..39bd3a0b98 100644 --- a/protocols/Gadu-Gadu/src/groupchat.cpp +++ b/protocols/Gadu-Gadu/src/groupchat.cpp @@ -98,7 +98,7 @@ GGGC* GaduProto::gc_lookup(const wchar_t *id) for (l = chats; l; l = l->next) {
chat = (GGGC *)l->data;
- if (chat && !mir_wstrcmp(chat->id, id))
+ if (chat && !mir_wstrcmp(chat->si->ptszID, id))
return chat;
}
@@ -136,8 +136,7 @@ int GaduProto::gc_event(WPARAM, LPARAM lParam) UIN2IDT(uin, id);
DBVARIANT dbv;
- GCEVENT gce = { m_szModuleName, 0, GC_EVENT_MESSAGE };
- gce.pszID.w = gch->si->ptszID;
+ GCEVENT gce = { gch->si, GC_EVENT_MESSAGE };
gce.pszUID.w = id;
gce.pszText.w = gch->ptszText;
wchar_t* nickT;
@@ -190,8 +189,8 @@ typedef struct _gg_gc_echat ////////////////////////////////////////////////////////////////////////////////
// This is main groupchat initialization routine
-//
-wchar_t* GaduProto::gc_getchat(uin_t sender, uin_t *recipients, int recipients_count)
+
+SESSION_INFO* GaduProto::gc_getchat(uin_t sender, uin_t *recipients, int recipients_count)
{
list_t l;
GGGC *chat;
@@ -226,17 +225,19 @@ wchar_t* GaduProto::gc_getchat(uin_t sender, uin_t *recipients, int recipients_c // Found all recipients
if (found == recipients_count) {
if (chat->ignore)
- debugLogW(L"gc_getchat(): Ignoring existing id %s, size %d.", chat->id, chat->recipients_count);
+ debugLogW(L"gc_getchat(): Ignoring existing id %s, size %d.", chat->si->ptszID, chat->recipients_count);
else
- debugLogW(L"gc_getchat(): Returning existing id %s, size %d.", chat->id, chat->recipients_count);
- return !(chat->ignore) ? chat->id : nullptr;
+ debugLogW(L"gc_getchat(): Returning existing id %s, size %d.", chat->si->ptszID, chat->recipients_count);
+ return !(chat->ignore) ? chat->si : nullptr;
}
}
}
+ wchar_t chatId[32];
+ UIN2IDT(gc_id++, chatId);
+
// Make new uin list to chat mapping
chat = (GGGC *)malloc(sizeof(GGGC));
- UIN2IDT(gc_id++, chat->id);
chat->ignore = FALSE;
// Check groupchat policy (new) / only for incoming
@@ -276,7 +277,7 @@ wchar_t* GaduProto::gc_getchat(uin_t sender, uin_t *recipients, int recipients_c for (; i < recipients_count; i++)
chat->recipients[i] = recipients[i];
if (sender) chat->recipients[i] = sender;
- debugLogW(L"gc_getchat(): Ignoring new chat %s, count %d.", chat->id, chat->recipients_count);
+ debugLogW(L"gc_getchat(): Ignoring new chat %s, count %d.", chatId, chat->recipients_count);
list_add(&chats, chat, 0);
return nullptr;
}
@@ -296,19 +297,19 @@ wchar_t* GaduProto::gc_getchat(uin_t sender, uin_t *recipients, int recipients_c // Create new room
CMStringW wszTitle(L"#"); wszTitle.Append(sender ? senderName : TranslateT("Conference"));
- SESSION_INFO *si = Chat_NewSession(GCW_CHATROOM, m_szModuleName, chat->id, wszTitle, chat);
+ SESSION_INFO *si = Chat_NewSession(GCW_CHATROOM, m_szModuleName, chatId, wszTitle, chat);
if (!si)
return nullptr;
+ chat->si = si;
- Chat_SetStatusbarText(m_szModuleName, chat->id, status);
+ Chat_SetStatusbarText(si, status);
// Add normal group
Chat_AddGroup(si, TranslateT("Participants"));
wchar_t id[32];
- GCEVENT gce = { m_szModuleName, 0, GC_EVENT_JOIN };
- gce.pszID.w = chat->id;
+ GCEVENT gce = { si, GC_EVENT_JOIN };
gce.pszUID.w = id;
gce.dwFlags = GCEF_ADDTOLOG;
@@ -327,8 +328,7 @@ wchar_t* GaduProto::gc_getchat(uin_t sender, uin_t *recipients, int recipients_c mir_free(nickT);
debugLogW(L"gc_getchat(): Myself %s: %s (%s) to the list...", gce.pszUID.w, gce.pszNick.w, gce.pszStatus.w);
}
- else
- debugLogA("gc_getchat(): Myself adding failed with uin %d !!!", uin);
+ else debugLogA("gc_getchat(): Myself adding failed with uin %d !!!", uin);
// Copy recipient list
chat->recipients_count = recipients_count + (sender ? 1 : 0);
@@ -353,13 +353,13 @@ wchar_t* GaduProto::gc_getchat(uin_t sender, uin_t *recipients, int recipients_c Chat_Event(&gce);
}
- Chat_Control(m_szModuleName, chat->id, SESSION_INITDONE);
- Chat_Control(m_szModuleName, chat->id, SESSION_ONLINE);
+ Chat_Control(si, SESSION_INITDONE);
+ Chat_Control(si, SESSION_ONLINE);
- debugLogW(L"gc_getchat(): Returning new chat window %s, count %d.", chat->id, chat->recipients_count);
+ debugLogW(L"gc_getchat(): Returning new chat window %s, count %d.", chatId, chat->recipients_count);
list_add(&chats, chat, 0);
- return chat->id;
+ return si;
}
static MCONTACT gg_getsubcontact(GaduProto* gg, MCONTACT hContact)
@@ -441,9 +441,9 @@ static INT_PTR CALLBACK gg_gc_openconfdlg(HWND hwndDlg, UINT message, WPARAM wPa if (count > i)
i = count;
- wchar_t *chat = gg->gc_getchat(0, participants, count);
- if (chat)
- Chat_Control(gg->m_szModuleName, chat, WINDOW_VISIBLE);
+ auto *si = gg->gc_getchat(0, participants, count);
+ if (si)
+ Chat_Control(si, WINDOW_VISIBLE);
free(participants);
}
@@ -573,23 +573,23 @@ int GaduProto::gc_changenick(MCONTACT hContact, wchar_t *ptszNick) // Lookup for chats having this nick
for (l = chats; l; l = l->next) {
GGGC *chat = (GGGC *)l->data;
- if (chat->recipients && chat->recipients_count)
- for (int i = 0; i < chat->recipients_count; i++)
+ if (chat->recipients && chat->recipients_count) {
+ for (int i = 0; i < chat->recipients_count; i++) {
// Rename this window if it's exising in the chat
if (chat->recipients[i] == uin) {
wchar_t id[32];
UIN2IDT(uin, id);
- GCEVENT gce = { m_szModuleName, 0, GC_EVENT_NICK };
- gce.pszID.w = chat->id;
+ GCEVENT gce = { chat->si, GC_EVENT_NICK };
gce.pszUID.w = id;
gce.pszText.w = ptszNick;
- debugLogW(L"gc_changenick(): Found room %s with uin %d, sending nick change %s.", chat->id, uin, id);
+ debugLogW(L"gc_changenick(): Found room %s with uin %d, sending nick change %s.", chat->si->ptszID, uin, id);
Chat_Event(&gce);
-
break;
}
+ }
+ }
}
return 1;
|