diff options
author | George Hazan <ghazan@miranda.im> | 2017-03-09 17:28:47 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2017-03-09 17:28:47 +0300 |
commit | 2d737d50469b965c2787823a94757f4c9f0a7107 (patch) | |
tree | 34d46e0968485a7e9f16cbcbf9f4a18451ba06b1 /src/mir_app | |
parent | 017f8e72ac56a88ecaea40dd1c52b1da0ae46986 (diff) |
chat API:
- SESSION_INFO now addresses an instance of CChatRoomDlg instead of HWND;
- linked list of sessions replaced with the usual LIST<>;
- saveCI removed everywhere
Diffstat (limited to 'src/mir_app')
-rw-r--r-- | src/mir_app/src/chat.h | 8 | ||||
-rw-r--r-- | src/mir_app/src/chat_clist.cpp | 4 | ||||
-rw-r--r-- | src/mir_app/src/chat_manager.cpp | 147 | ||||
-rw-r--r-- | src/mir_app/src/chat_svc.cpp | 45 | ||||
-rw-r--r-- | src/mir_app/src/chat_tools.cpp | 15 | ||||
-rw-r--r-- | src/mir_app/src/netlibsock.cpp | 2 |
6 files changed, 119 insertions, 102 deletions
diff --git a/src/mir_app/src/chat.h b/src/mir_app/src/chat.h index 66c39fa753..fbfc8872f6 100644 --- a/src/mir_app/src/chat.h +++ b/src/mir_app/src/chat.h @@ -27,6 +27,11 @@ struct MODULEINFO : public GCModuleInfoBase {}; struct SESSION_INFO : public GCSessionInfoBase {};
struct LOGSTREAMDATA : public GCLogStreamDataBase {};
+class CChatRoomDlg : public CSrmmBaseDialog
+{
+ CChatRoomDlg(); // just to suppress compiler's warnings, never implemented
+};
+
extern HGENMENU hJoinMenuItem, hLeaveMenuItem;
extern GlobalLogSettingsBase *g_Settings;
extern int g_cbSession, g_cbModuleInfo, g_iFontMode, g_iChatLang;
@@ -34,6 +39,7 @@ extern wchar_t *g_szFontGroup; extern mir_cs csChat;
extern char* pLogIconBmpBits[14];
+extern LIST<SESSION_INFO> g_arSessions;
// log.c
void LoadMsgLogBitmaps(void);
@@ -104,7 +110,7 @@ bool IsHighlighted(SESSION_INFO *si, GCEVENT *pszText); UINT CreateGCMenu(HWND hwndDlg, HMENU *hMenu, int iIndex, POINT pt, SESSION_INFO *si, wchar_t* pszUID, wchar_t* pszWordText);
void DestroyGCMenu(HMENU *hMenu, int iIndex);
BOOL DoEventHookAsync(HWND hwnd, const wchar_t *pszID, const char *pszModule, int iType, const USERINFO *pUser, const wchar_t* pszText, INT_PTR dwItem);
-BOOL DoEventHook(const wchar_t *pszID, const char *pszModule, int iType, const USERINFO *pUser, const wchar_t* pszText, INT_PTR dwItem);
+BOOL DoEventHook(SESSION_INFO *si, int iType, const USERINFO *pUser, const wchar_t* pszText, INT_PTR dwItem);
BOOL IsEventSupported(int eventType);
BOOL LogToFile(SESSION_INFO *si, GCEVENT *gce);
BOOL DoTrayIcon(SESSION_INFO *si, GCEVENT *gce);
diff --git a/src/mir_app/src/chat_clist.cpp b/src/mir_app/src/chat_clist.cpp index 93346dd334..70a126dbe8 100644 --- a/src/mir_app/src/chat_clist.cpp +++ b/src/mir_app/src/chat_clist.cpp @@ -117,8 +117,8 @@ int RoomDoubleclicked(WPARAM hContact, LPARAM) SESSION_INFO *si = SM_FindSession(roomid, szProto);
if (si) {
// is the "toggle visibility option set, so we need to close the window?
- if (si->hWnd != NULL && db_get_b(NULL, CHAT_MODULE, "ToggleVisibility", 0) == 1 && !cli.pfnGetEvent(hContact, 0) && IsWindowVisible(si->hWnd) && !IsIconic(si->hWnd)) {
- PostMessage(si->hWnd, GC_CLOSEWINDOW, 0, 0);
+ if (si->pDlg != NULL && db_get_b(NULL, CHAT_MODULE, "ToggleVisibility", 0) == 1 && !cli.pfnGetEvent(hContact, 0) && IsWindowVisible(si->pDlg->GetHwnd()) && !IsIconic(si->pDlg->GetHwnd())) {
+ PostMessage(si->pDlg->GetHwnd(), GC_CLOSEWINDOW, 0, 0);
return 1;
}
chatApi.ShowRoom(si);
diff --git a/src/mir_app/src/chat_manager.cpp b/src/mir_app/src/chat_manager.cpp index 9c373c376a..1ff2b061e2 100644 --- a/src/mir_app/src/chat_manager.cpp +++ b/src/mir_app/src/chat_manager.cpp @@ -26,6 +26,18 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define WINDOWS_COMMANDS_MAX 30
+static int compareSessions(const SESSION_INFO *p1, const SESSION_INFO *p2)
+{
+ int res = mir_strcmp(p1->pszModule, p2->pszModule);
+ return (res != 0) ? res : mir_wstrcmp(p1->ptszID, p2->ptszID);
+}
+
+LIST<SESSION_INFO> g_arSessions(10, compareSessions);
+
+CHAT_MANAGER::CHAT_MANAGER() :
+ arSessions(g_arSessions)
+{}
+
CHAT_MANAGER chatApi;
MODULEINFO *m_ModList = 0;
@@ -51,7 +63,7 @@ static SESSION_INFO* GetActiveSession(void) if (si)
return si;
- return chatApi.wndList;
+ return g_arSessions[0];
}
//---------------------------------------------------
@@ -99,18 +111,13 @@ int SM_RemoveSession(const wchar_t *pszID, const char *pszModule, BOOL removeCon if (!pszModule)
return FALSE;
- SESSION_INFO *si = chatApi.wndList, *pLast = NULL;
- while (si != NULL) {
+ for (int i = g_arSessions.getCount() - 1; i >= 0; i--) {
+ SESSION_INFO *si = g_arSessions[i];
// match
if ((!pszID && si->iType != GCW_SERVER || !mir_wstrcmpi(si->ptszID, pszID)) && !mir_strcmpi(si->pszModule, pszModule)) {
- if (si->hWnd)
- SendMessage(si->hWnd, GC_CONTROL_MSG, SESSION_TERMINATE, 0);
- DoEventHook(si->ptszID, si->pszModule, GC_SESSION_TERMINATE, NULL, NULL, (INT_PTR)si->pItemData);
-
- if (pLast == NULL)
- chatApi.wndList = si->next;
- else
- pLast->next = si->next;
+ if (si->pDlg)
+ SendMessage(si->pDlg->GetHwnd(), GC_CONTROL_MSG, SESSION_TERMINATE, 0);
+ DoEventHook(si, GC_SESSION_TERMINATE, NULL, NULL, (INT_PTR)si->pItemData);
// contact may have been deleted here already, since function may be called after deleting
// contact so the handle may be invalid, therefore db_get_b shall return 0
@@ -118,18 +125,10 @@ int SM_RemoveSession(const wchar_t *pszID, const char *pszModule, BOOL removeCon db_delete_contact(si->hContact);
SM_FreeSession(si);
+ g_arSessions.remove(i);
if (pszID)
return 1;
-
- if (pLast)
- si = pLast->next;
- else
- si = chatApi.wndList;
- }
- else {
- pLast = si;
- si = si->next;
}
}
return FALSE;
@@ -138,14 +137,14 @@ int SM_RemoveSession(const wchar_t *pszID, const char *pszModule, BOOL removeCon SESSION_INFO* SM_FindSession(const wchar_t *pszID, const char *pszModule)
{
if (!pszID || !pszModule)
- return NULL;
+ return nullptr;
- mir_cslock lck(csChat);
- for (SESSION_INFO *si = chatApi.wndList; si != NULL; si = si->next)
- if (!mir_wstrcmpi(si->ptszID, pszID) && !mir_strcmpi(si->pszModule, pszModule))
- return si;
+ SESSION_INFO tmp;
+ tmp.pszModule = (char*)pszModule;
+ tmp.ptszID = (wchar_t*)pszID;
- return NULL;
+ mir_cslock lck(csChat);
+ return g_arSessions.find(&tmp);
}
BOOL SM_SetOffline(const wchar_t *pszID, const char *pszModule)
@@ -153,7 +152,8 @@ BOOL SM_SetOffline(const wchar_t *pszID, const char *pszModule) if (!pszModule)
return FALSE;
- for (SESSION_INFO *si = chatApi.wndList; si != NULL; si = si->next) {
+ for (int i = 0; i < g_arSessions.getCount(); i++) {
+ SESSION_INFO *si = g_arSessions[i];
if ((pszID && mir_wstrcmpi(si->ptszID, pszID)) || mir_strcmpi(si->pszModule, pszModule))
continue;
@@ -231,7 +231,8 @@ BOOL SM_RemoveUser(const wchar_t *pszID, const char *pszModule, const wchar_t *p if (!pszModule || !pszUID)
return FALSE;
- for (SESSION_INFO *si = chatApi.wndList; si != NULL; si = si->next) {
+ for (int i = 0; i < g_arSessions.getCount(); i++) {
+ SESSION_INFO *si = g_arSessions[i];
if ((pszID && mir_wstrcmpi(si->ptszID, pszID)) || mir_strcmpi(si->pszModule, pszModule))
continue;
@@ -245,8 +246,8 @@ BOOL SM_RemoveUser(const wchar_t *pszID, const char *pszModule, const wchar_t *p si->pMe = NULL;
chatApi.UM_RemoveUser(&si->pUsers, pszUID);
- if (si->hWnd)
- SendMessage(si->hWnd, GC_UPDATENICKLIST, 0, 0);
+ if (si->pDlg)
+ SendMessage(si->pDlg->GetHwnd(), GC_UPDATENICKLIST, 0, 0);
if (pszID)
return TRUE;
@@ -271,8 +272,8 @@ BOOL SM_GiveStatus(const wchar_t *pszID, const char *pszModule, const wchar_t *p USERINFO *ui = chatApi.UM_GiveStatus(si->pUsers, pszUID, chatApi.TM_StringToWord(si->pStatuses, pszStatus));
if (ui) {
SM_MoveUser(si->ptszID, si->pszModule, ui->pszUID);
- if (si->hWnd)
- SendMessage(si->hWnd, GC_UPDATENICKLIST, 0, 0);
+ if (si->pDlg)
+ SendMessage(si->pDlg->GetHwnd(), GC_UPDATENICKLIST, 0, 0);
}
return TRUE;
}
@@ -286,8 +287,8 @@ BOOL SM_SetContactStatus(const wchar_t *pszID, const char *pszModule, const wcha USERINFO *ui = chatApi.UM_SetContactStatus(si->pUsers, pszUID, wStatus);
if (ui) {
SM_MoveUser(si->ptszID, si->pszModule, ui->pszUID);
- if (si->hWnd)
- SendMessage(si->hWnd, GC_UPDATENICKLIST, 0, 0);
+ if (si->pDlg)
+ SendMessage(si->pDlg->GetHwnd(), GC_UPDATENICKLIST, 0, 0);
}
return TRUE;
}
@@ -301,8 +302,8 @@ BOOL SM_TakeStatus(const wchar_t *pszID, const char *pszModule, const wchar_t *p USERINFO *ui = chatApi.UM_TakeStatus(si->pUsers, pszUID, chatApi.TM_StringToWord(si->pStatuses, pszStatus));
if (ui) {
SM_MoveUser(si->ptszID, si->pszModule, ui->pszUID);
- if (si->hWnd)
- SendMessage(si->hWnd, GC_UPDATENICKLIST, 0, 0);
+ if (si->pDlg)
+ SendMessage(si->pDlg->GetHwnd(), GC_UPDATENICKLIST, 0, 0);
}
return TRUE;
}
@@ -312,12 +313,13 @@ LRESULT SM_SendMessage(const wchar_t *pszID, const char *pszModule, UINT msg, WP if (pszModule == NULL)
return 0;
- for (SESSION_INFO *si = chatApi.wndList; si != NULL; si = si->next) {
+ for (int i = 0; i < g_arSessions.getCount(); i++) {
+ SESSION_INFO *si = g_arSessions[i];
if ((pszID && mir_wstrcmpi(si->ptszID, pszID)) || mir_strcmpi(si->pszModule, pszModule))
continue;
- if (si->hWnd) {
- LRESULT i = SendMessage(si->hWnd, msg, wParam, lParam);
+ if (si->pDlg) {
+ LRESULT i = SendMessage(si->pDlg->GetHwnd(), msg, wParam, lParam);
if (pszID)
return i;
}
@@ -329,15 +331,16 @@ LRESULT SM_SendMessage(const wchar_t *pszID, const char *pszModule, UINT msg, WP static BOOL SM_BroadcastMessage(const char *pszModule, UINT msg, WPARAM wParam, LPARAM lParam, BOOL bAsync)
{
- for (SESSION_INFO *si = chatApi.wndList; si != NULL; si = si->next) {
+ for (int i = 0; i < g_arSessions.getCount(); i++) {
+ SESSION_INFO *si = g_arSessions[i];
if (pszModule && _strcmpi(si->pszModule, pszModule))
continue;
- if (si->hWnd) {
+ if (si->pDlg) {
if (bAsync)
- PostMessage(si->hWnd, msg, wParam, lParam);
+ PostMessage(si->pDlg->GetHwnd(), msg, wParam, lParam);
else
- SendMessage(si->hWnd, msg, wParam, lParam);
+ SendMessage(si->pDlg->GetHwnd(), msg, wParam, lParam);
}
}
return TRUE;
@@ -348,7 +351,8 @@ BOOL SM_SetStatus(const wchar_t *pszID, const char *pszModule, int wStatus) if (!pszModule)
return FALSE;
- for (SESSION_INFO *si = chatApi.wndList; si != NULL; si = si->next) {
+ for (int i = 0; i < g_arSessions.getCount(); i++) {
+ SESSION_INFO *si = g_arSessions[i];
if ((pszID && mir_wstrcmpi(si->ptszID, pszID)) || mir_strcmpi(si->pszModule, pszModule))
continue;
@@ -374,14 +378,15 @@ BOOL SM_ChangeNick(const wchar_t *pszID, const char *pszModule, GCEVENT *gce) if (!pszModule)
return FALSE;
- for (SESSION_INFO *si = chatApi.wndList; si != NULL; si = si->next) {
+ for (int i = 0; i < g_arSessions.getCount(); i++) {
+ SESSION_INFO *si = g_arSessions[i];
if ((!pszID || !mir_wstrcmpi(si->ptszID, pszID)) && !mir_strcmpi(si->pszModule, pszModule)) {
USERINFO *ui = chatApi.UM_FindUser(si->pUsers, gce->ptszUID);
if (ui) {
replaceStrW(ui->pszNick, gce->ptszText);
SM_MoveUser(si->ptszID, si->pszModule, ui->pszUID);
- if (si->hWnd)
- SendMessage(si->hWnd, GC_UPDATENICKLIST, 0, 0);
+ if (si->pDlg)
+ SendMessage(si->pDlg->GetHwnd(), GC_UPDATENICKLIST, 0, 0);
if (chatApi.OnChangeNick)
chatApi.OnChangeNick(si);
}
@@ -395,17 +400,16 @@ BOOL SM_ChangeNick(const wchar_t *pszID, const char *pszModule, GCEVENT *gce) void SM_RemoveAll(void)
{
- while (chatApi.wndList) {
- SESSION_INFO *pLast = chatApi.wndList->next;
+ for (int i = 0; i < g_arSessions.getCount(); i++) {
+ SESSION_INFO *si = g_arSessions[i];
- if (chatApi.wndList->hWnd)
- SendMessage(chatApi.wndList->hWnd, GC_CONTROL_MSG, SESSION_TERMINATE, 0);
- DoEventHook(chatApi.wndList->ptszID, chatApi.wndList->pszModule, GC_SESSION_TERMINATE, NULL, NULL, (INT_PTR)chatApi.wndList->pItemData);
+ if (si->pDlg)
+ SendMessage(si->pDlg->GetHwnd(), GC_CONTROL_MSG, SESSION_TERMINATE, 0);
+ DoEventHook(si, GC_SESSION_TERMINATE, NULL, NULL, (INT_PTR)si->pItemData);
- SM_FreeSession(chatApi.wndList);
- chatApi.wndList = pLast;
+ SM_FreeSession(si);
}
- chatApi.wndList = NULL;
+ g_arSessions.destroy();
}
static void SM_AddCommand(const wchar_t *pszID, const char *pszModule, const char* lpNewCommand)
@@ -480,9 +484,11 @@ static int SM_GetCount(const char *pszModule) {
int count = 0;
- for (SESSION_INFO *si = chatApi.wndList; si != NULL; si = si->next)
+ for (int i = 0; i < g_arSessions.getCount(); i++) {
+ SESSION_INFO *si = g_arSessions[i];
if (!mir_strcmpi(pszModule, si->pszModule))
count++;
+ }
return count;
}
@@ -490,7 +496,8 @@ static int SM_GetCount(const char *pszModule) static SESSION_INFO* SM_FindSessionByIndex(const char *pszModule, int iItem)
{
int count = 0;
- for (SESSION_INFO *si = chatApi.wndList; si != NULL; si = si->next) {
+ for (int i = 0; i < g_arSessions.getCount(); i++) {
+ SESSION_INFO *si = g_arSessions[i];
if (!mir_strcmpi(pszModule, si->pszModule)) {
if (iItem == count)
return si;
@@ -508,7 +515,8 @@ char* SM_GetUsers(SESSION_INFO *si) return NULL;
USERINFO *utemp = NULL;
- for (SESSION_INFO *p = chatApi.wndList; p != NULL; p = p->next) {
+ for (int i = 0; i < g_arSessions.getCount(); i++) {
+ SESSION_INFO *p = g_arSessions[i];
if (si == p) {
if ((utemp = p->pUsers) == NULL)
return NULL;
@@ -536,8 +544,10 @@ char* SM_GetUsers(SESSION_INFO *si) static void SM_InvalidateLogDirectories()
{
- for (SESSION_INFO *si = chatApi.wndList; si; si = si->next)
+ for (int i = 0; i < g_arSessions.getCount(); i++) {
+ SESSION_INFO *si = g_arSessions[i];
si->pszLogFileName[0] = si->pszLogFileName[1] = 0;
+ }
}
//---------------------------------------------------
@@ -1031,6 +1041,12 @@ static BOOL LM_RemoveAll(LOGINFO **ppLogListStart, LOGINFO **ppLogListEnd) return TRUE;
}
+static BOOL DoEventHook(const wchar_t *pszID, const char *pszModule, int iType, const USERINFO *pUser, const wchar_t* pszText, INT_PTR dwItem)
+{
+ SESSION_INFO *si = chatApi.SM_FindSession(pszID, pszModule);
+ return (si) ? DoEventHook(si, iType, pUser, pszText, dwItem) : FALSE;
+}
+
MIR_APP_DLL(CHAT_MANAGER*) Chat_GetInterface(CHAT_MANAGER_INITDATA *pInit, int _hLangpack)
{
if (pInit == NULL)
@@ -1041,18 +1057,15 @@ MIR_APP_DLL(CHAT_MANAGER*) Chat_GetInterface(CHAT_MANAGER_INITDATA *pInit, int _ if (g_cbSession) { // reallocate old sessions
mir_cslock lck(csChat);
- SESSION_INFO *pPrev = NULL;
- for (SESSION_INFO *p = chatApi.wndList; p; p = p->next) {
+
+ for (int i = 0; i < g_arSessions.getCount(); i++) {
+ SESSION_INFO *p = g_arSessions[i];
SESSION_INFO *p1 = (SESSION_INFO*)mir_realloc(p, pInit->cbSession);
memset(PBYTE(p1) + sizeof(GCSessionInfoBase), 0, pInit->cbSession - sizeof(GCSessionInfoBase));
if (p1 != p) { // realloc could change a pointer, reinsert a structure
- if (chatApi.wndList == p)
- chatApi.wndList = p1;
- if (pPrev != NULL)
- pPrev->next = p1;
- p = p1;
+ g_arSessions.remove(i);
+ g_arSessions.insert(p1);
}
- pPrev = p;
}
}
if (g_cbModuleInfo) { // reallocate old modules
diff --git a/src/mir_app/src/chat_svc.cpp b/src/mir_app/src/chat_svc.cpp index 2d8dc7cb24..a3f8f492d0 100644 --- a/src/mir_app/src/chat_svc.cpp +++ b/src/mir_app/src/chat_svc.cpp @@ -220,12 +220,7 @@ EXTERN_C MIR_APP_DLL(GCSessionInfoBase*) Chat_NewSession( si->ptszID = mir_wstrdup(ptszID);
si->pszModule = mir_strdup(pszModule);
- if (chatApi.wndList == NULL) // list is empty
- chatApi.wndList = si;
- else {
- si->next = chatApi.wndList;
- chatApi.wndList = si;
- }
+ chatApi.arSessions.insert(si);
lck.unlock();
// set the defaults
@@ -413,7 +408,8 @@ static BOOL AddEventToAllMatchingUID(GCEVENT *gce) {
int bManyFix = 0;
- for (SESSION_INFO *p = chatApi.wndList; p != NULL; p = p->next) {
+ for (int i = 0; i < g_arSessions.getCount(); i++) {
+ SESSION_INFO *p = g_arSessions[i];
if (!p->bInitDone || mir_strcmpi(p->pszModule, gce->pDest->pszModule))
continue;
@@ -423,11 +419,11 @@ static BOOL AddEventToAllMatchingUID(GCEVENT *gce) if (chatApi.OnEventBroadcast)
chatApi.OnEventBroadcast(p, gce);
- if (p->hWnd && p->bInitDone) {
+ if (p->pDlg && p->bInitDone) {
if (SM_AddEvent(p->ptszID, p->pszModule, gce, FALSE))
- SendMessage(p->hWnd, GC_ADDLOG, 0, 0);
+ SendMessage(p->pDlg->GetHwnd(), GC_ADDLOG, 0, 0);
else
- SendMessage(p->hWnd, GC_REDRAWLOG2, 0, 0);
+ SendMessage(p->pDlg->GetHwnd(), GC_REDRAWLOG2, 0, 0);
}
if (!(gce->dwFlags & GCEF_NOTNOTIFY)) {
@@ -569,11 +565,11 @@ EXTERN_C MIR_APP_DLL(int) Chat_Event(GCEVENT *gce) }
int isOk = SM_AddEvent(pWnd, pMod, gce, bIsHighlighted);
- if (si->hWnd) {
+ if (si->pDlg) {
if (isOk)
- SendMessage(si->hWnd, GC_ADDLOG, 0, 0);
+ SendMessage(si->pDlg->GetHwnd(), GC_ADDLOG, 0, 0);
else
- SendMessage(si->hWnd, GC_REDRAWLOG2, 0, 0);
+ SendMessage(si->pDlg->GetHwnd(), GC_REDRAWLOG2, 0, 0);
}
if (!(gce->dwFlags & GCEF_NOTNOTIFY)) {
@@ -637,8 +633,8 @@ MIR_APP_DLL(int) Chat_ChangeSessionName(const char *szModule, const wchar_t *wsz replaceStrW(si->ptszName, wszNewName);
db_set_ws(si->hContact, szModule, "Nick", wszNewName);
- if (si->hWnd)
- SendMessage(si->hWnd, GC_UPDATETITLE, 0, 0);
+ if (si->pDlg)
+ SendMessage(si->pDlg->GetHwnd(), GC_UPDATETITLE, 0, 0);
}
return 0;
}
@@ -649,7 +645,8 @@ MIR_APP_DLL(int) Chat_ChangeUserId(const char *szModule, const wchar_t *wszId, c return GC_EVENT_ERROR;
mir_cslock lck(csChat);
- for (SESSION_INFO *si = chatApi.wndList; si != NULL; si = si->next) {
+ for (int i = 0; i < g_arSessions.getCount(); i++) {
+ SESSION_INFO *si = g_arSessions[i];
if ((wszId && mir_wstrcmpi(si->ptszID, wszId)) || mir_strcmpi(si->pszModule, szModule))
continue;
@@ -676,12 +673,13 @@ MIR_APP_DLL(int) Chat_SendUserMessage(const char *szModule, const wchar_t *wszId return GC_EVENT_ERROR;
mir_cslock lck(csChat);
- for (SESSION_INFO *si = chatApi.wndList; si != NULL; si = si->next) {
+ for (int i = 0; i < g_arSessions.getCount(); i++) {
+ SESSION_INFO *si = g_arSessions[i];
if ((wszId && mir_wstrcmpi(si->ptszID, wszId)) || mir_strcmpi(si->pszModule, szModule))
continue;
if (si->iType == GCW_CHATROOM || si->iType == GCW_PRIVMESS)
- DoEventHook(si->ptszID, si->pszModule, GC_USER_MESSAGE, NULL, wszText, 0);
+ DoEventHook(si, GC_USER_MESSAGE, NULL, wszText, 0);
if (wszId)
break;
}
@@ -702,8 +700,8 @@ MIR_APP_DLL(int) Chat_SetStatusbarText(const char *szModule, const wchar_t *wszI else
db_set_s(si->hContact, si->pszModule, "StatusBar", "");
- if (si->hWnd)
- SendMessage(si->hWnd, GC_UPDATESTATUSBAR, 0, 0);
+ if (si->pDlg)
+ SendMessage(si->pDlg->GetHwnd(), GC_UPDATESTATUSBAR, 0, 0);
}
return 0;
}
@@ -714,13 +712,14 @@ MIR_APP_DLL(int) Chat_SetStatusEx(const char *szModule, const wchar_t *wszId, in return GC_EVENT_ERROR;
mir_cslock lck(csChat);
- for (SESSION_INFO *si = chatApi.wndList; si != NULL; si = si->next) {
+ for (int i = 0; i < g_arSessions.getCount(); i++) {
+ SESSION_INFO *si = g_arSessions[i];
if ((wszId && mir_wstrcmpi(si->ptszID, wszId)) || mir_strcmpi(si->pszModule, szModule))
continue;
chatApi.UM_SetStatusEx(si->pUsers, wszText, flags);
- if (si->hWnd)
- RedrawWindow(GetDlgItem(si->hWnd, IDC_LIST), NULL, NULL, RDW_INVALIDATE);
+ if (si->pDlg)
+ RedrawWindow(GetDlgItem(si->pDlg->GetHwnd(), IDC_LIST), NULL, NULL, RDW_INVALIDATE);
if (wszId)
break;
}
diff --git a/src/mir_app/src/chat_tools.cpp b/src/mir_app/src/chat_tools.cpp index 39ad6f98a4..13f573a2c4 100644 --- a/src/mir_app/src/chat_tools.cpp +++ b/src/mir_app/src/chat_tools.cpp @@ -154,8 +154,8 @@ static LRESULT CALLBACK PopupDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPA if (cli.pfnGetEvent(si->hContact, 0))
cli.pfnRemoveEvent(si->hContact, GC_FAKE_EVENT);
- if (si->hWnd && KillTimer(si->hWnd, TIMERID_FLASHWND))
- FlashWindow(si->hWnd, FALSE);
+ if (si->pDlg && KillTimer(si->pDlg->GetHwnd(), TIMERID_FLASHWND))
+ FlashWindow(si->pDlg->GetHwnd(), FALSE);
PUDeletePopup(hWnd);
break;
@@ -273,7 +273,7 @@ BOOL DoSoundsFlashPopupTrayStuff(SESSION_INFO *si, GCEVENT *gce, BOOL bHighlight if (!gce || !si || gce->bIsMe || si->iType == GCW_SERVER)
return FALSE;
- BOOL bInactive = si->hWnd == NULL || GetForegroundWindow() != si->hWnd;
+ BOOL bInactive = si->pDlg == NULL || GetForegroundWindow() != si->pDlg->GetHwnd();
int iEvent = gce->pDest->iType;
@@ -631,15 +631,14 @@ BOOL DoEventHookAsync(HWND hwnd, const wchar_t *pszID, const char *pszModule, in return TRUE;
}
-BOOL DoEventHook(const wchar_t *pszID, const char *pszModule, int iType, const USERINFO *pUser, const wchar_t* pszText, INT_PTR dwItem)
+BOOL DoEventHook(SESSION_INFO *si, int iType, const USERINFO *pUser, const wchar_t* pszText, INT_PTR dwItem)
{
- SESSION_INFO *si = chatApi.SM_FindSession(pszID, pszModule);
- if (si == NULL)
+ if (si == nullptr)
return FALSE;
- GCDEST gcd = { (char*)pszModule, pszID, iType };
+ GCDEST gcd = { si->pszModule, si->ptszID, iType };
GCHOOK gch = { 0 };
- if (pUser != NULL) {
+ if (pUser != nullptr) {
gch.ptszUID = pUser->pszUID;
gch.ptszNick = pUser->pszNick;
}
diff --git a/src/mir_app/src/netlibsock.cpp b/src/mir_app/src/netlibsock.cpp index 57cb023b4b..7bfbd3c7df 100644 --- a/src/mir_app/src/netlibsock.cpp +++ b/src/mir_app/src/netlibsock.cpp @@ -69,7 +69,7 @@ MIR_APP_DLL(int) Netlib_Recv(HNETLIBCONN nlc, char *buf, int len, int flags) recvResult = NetlibHttpGatewayRecv(nlc, buf, len, flags);
else {
if (!nlc->foreBuf.isEmpty()) {
- recvResult = min(len, nlc->foreBuf.length());
+ recvResult = min(len, (int)nlc->foreBuf.length());
memcpy(buf, nlc->foreBuf.data(), recvResult);
nlc->foreBuf.remove(recvResult);
}
|