diff options
| author | George Hazan <ghazan@miranda.im> | 2022-11-14 20:04:02 +0300 | 
|---|---|---|
| committer | George Hazan <ghazan@miranda.im> | 2022-11-14 20:04:02 +0300 | 
| commit | 2d74ff3a09c40efda6ad6e9c6b569820776a54f1 (patch) | |
| tree | a30fa0bca0c7dec52fa5b554b7eccd0993d254fa | |
| parent | e097a96ae55208292e1800c75b6a1f7766e38964 (diff) | |
basic set for storing group chat messages in a database + reusing log settings like show 10 recent messages
| -rw-r--r-- | include/m_chat.h | 1 | ||||
| -rw-r--r-- | include/m_chat_int.h | 2 | ||||
| -rw-r--r-- | plugins/Scriver/src/msgdialog.cpp | 59 | ||||
| -rw-r--r-- | plugins/Scriver/src/msgs.h | 1 | ||||
| -rw-r--r-- | plugins/Scriver/src/msgutils.cpp | 59 | ||||
| -rw-r--r-- | plugins/TabSRMM/src/msgdialog.cpp | 5 | ||||
| -rw-r--r-- | protocols/WhatsApp/src/appsync.cpp | 20 | ||||
| -rw-r--r-- | protocols/WhatsApp/src/message.cpp | 21 | ||||
| -rw-r--r-- | protocols/WhatsApp/src/proto.cpp | 2 | ||||
| -rw-r--r-- | src/core/stdmsg/src/msgdialog.cpp | 85 | ||||
| -rw-r--r-- | src/core/stdmsg/src/msgs.h | 1 | ||||
| -rw-r--r-- | src/mir_app/src/chat.h | 2 | ||||
| -rw-r--r-- | src/mir_app/src/chat_svc.cpp | 1 | 
13 files changed, 143 insertions, 116 deletions
diff --git a/include/m_chat.h b/include/m_chat.h index efe95dbfad..4a58d625c5 100644 --- a/include/m_chat.h +++ b/include/m_chat.h @@ -133,6 +133,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.  #define GC_ACKMSG          0x0020 // the protocol must acknowlege messages sent
  #define GC_TYPNOTIF        0x0040 // enable typing notifications.
  #define GC_CHANMGR         0x0080 // enable the 'channel settings' button
 +#define GC_DATABASE        0x0100 // all events are backed in the database
  // Error messages
  #define GC_ERROR                1 // An internal error occurred.
 diff --git a/include/m_chat_int.h b/include/m_chat_int.h index c449f3dd26..31e2163d4e 100644 --- a/include/m_chat_int.h +++ b/include/m_chat_int.h @@ -98,7 +98,7 @@ struct MIR_APP_EXPORT GCModuleInfoBase : public MZeroedObject, public MNonCopyab  	bool     bBold, bItalics, bUnderline;
  	bool     bColor, bBkgColor;
 -	bool     bChanMgr, bAckMsg;
 +	bool     bChanMgr, bAckMsg, bDatabase;
  	int      iMaxText;
  };
 diff --git a/plugins/Scriver/src/msgdialog.cpp b/plugins/Scriver/src/msgdialog.cpp index ee2af9e908..82be284693 100644 --- a/plugins/Scriver/src/msgdialog.cpp +++ b/plugins/Scriver/src/msgdialog.cpp @@ -239,64 +239,17 @@ bool CMsgDialog::OnInitDialog()  		m_pParent->AddChild(this);
  		PopupWindow(false);
 +
 +		if (m_si->pMI->bDatabase) {
 +			FindFirstEvent();
 +			SendMessage(m_hwnd, DM_REMAKELOG, 0, 0);
 +		}
  	}
  	else {
  		m_nickList.Hide();
  		m_splitterX.Hide();
 -		bool notifyUnread = false;
 -		if (m_hContact) {
 -			int historyMode = g_plugin.iHistoryMode;
 -			// This finds the first message to display, it works like shit
 -			m_hDbEventFirst = db_event_firstUnread(m_hContact);
 -			if (m_hDbEventFirst != 0) {
 -				DBEVENTINFO dbei = {};
 -				db_event_get(m_hDbEventFirst, &dbei);
 -				if (DbEventIsMessageOrCustom(&dbei) && !(dbei.flags & DBEF_READ) && !(dbei.flags & DBEF_SENT))
 -					notifyUnread = true;
 -			}
 -
 -			DB::ECPTR pCursor(DB::EventsRev(m_hContact, m_hDbEventFirst));
 -
 -			DBEVENTINFO dbei = {};
 -			MEVENT hPrevEvent;
 -			switch (historyMode) {
 -			case LOADHISTORY_COUNT:
 -				for (int i = g_plugin.iLoadCount; i > 0; i--) {
 -					hPrevEvent = pCursor.FetchNext();
 -					if (hPrevEvent == 0)
 -						break;
 -
 -					dbei.cbBlob = 0;
 -					m_hDbEventFirst = hPrevEvent;
 -					db_event_get(m_hDbEventFirst, &dbei);
 -					if (!DbEventIsShown(dbei))
 -						i++;
 -				}
 -				break;
 -
 -			case LOADHISTORY_TIME:
 -				if (m_hDbEventFirst == 0)
 -					dbei.timestamp = time(0);
 -				else
 -					db_event_get(m_hDbEventFirst, &dbei);
 -
 -				uint32_t firstTime = dbei.timestamp - 60 * g_plugin.iLoadTime;
 -				for (;;) {
 -					hPrevEvent = pCursor.FetchNext();
 -					if (hPrevEvent == 0)
 -						break;
 -
 -					dbei.cbBlob = 0;
 -					db_event_get(hPrevEvent, &dbei);
 -					if (dbei.timestamp < firstTime)
 -						break;
 -					if (DbEventIsShown(dbei))
 -						m_hDbEventFirst = hPrevEvent;
 -				}
 -				break;
 -			}
 -		}
 +		bool notifyUnread = FindFirstEvent();
  		m_pParent->AddChild(this);
 diff --git a/plugins/Scriver/src/msgs.h b/plugins/Scriver/src/msgs.h index 98588d167b..0a2d30257e 100644 --- a/plugins/Scriver/src/msgs.h +++ b/plugins/Scriver/src/msgs.h @@ -88,6 +88,7 @@ class CMsgDialog : public CSrmmBaseDialog  	friend INT_PTR CALLBACK InfobarWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
  	void   ClearLog(void);
 +	bool   FindFirstEvent(void);
  	HICON  GetTabIcon(void);
  	void   GetTitlebarIcon(struct TitleBarData *tbd);
  	void   Init(void);
 diff --git a/plugins/Scriver/src/msgutils.cpp b/plugins/Scriver/src/msgutils.cpp index 807ab5ccc1..68eaf56b40 100644 --- a/plugins/Scriver/src/msgutils.cpp +++ b/plugins/Scriver/src/msgutils.cpp @@ -36,6 +36,65 @@ void CMsgDialog::CloseTab()  	Close();  } +bool CMsgDialog::FindFirstEvent() +{ +	bool notifyUnread = false; + +	if (m_hContact) { +		int historyMode = g_plugin.iHistoryMode; +		// This finds the first message to display, it works like shit +		m_hDbEventFirst = db_event_firstUnread(m_hContact); +		if (m_hDbEventFirst != 0) { +			DBEVENTINFO dbei = {}; +			db_event_get(m_hDbEventFirst, &dbei); +			if (DbEventIsMessageOrCustom(&dbei) && !(dbei.flags & DBEF_READ) && !(dbei.flags & DBEF_SENT)) +				notifyUnread = true; +		} + +		DB::ECPTR pCursor(DB::EventsRev(m_hContact, m_hDbEventFirst)); + +		DBEVENTINFO dbei = {}; +		MEVENT hPrevEvent; +		switch (historyMode) { +		case LOADHISTORY_COUNT: +			for (int i = g_plugin.iLoadCount; i > 0; i--) { +				hPrevEvent = pCursor.FetchNext(); +				if (hPrevEvent == 0) +					break; + +				dbei.cbBlob = 0; +				m_hDbEventFirst = hPrevEvent; +				db_event_get(m_hDbEventFirst, &dbei); +				if (!DbEventIsShown(dbei)) +					i++; +			} +			break; + +		case LOADHISTORY_TIME: +			if (m_hDbEventFirst == 0) +				dbei.timestamp = time(0); +			else +				db_event_get(m_hDbEventFirst, &dbei); + +			uint32_t firstTime = dbei.timestamp - 60 * g_plugin.iLoadTime; +			for (;;) { +				hPrevEvent = pCursor.FetchNext(); +				if (hPrevEvent == 0) +					break; + +				dbei.cbBlob = 0; +				db_event_get(hPrevEvent, &dbei); +				if (dbei.timestamp < firstTime) +					break; +				if (DbEventIsShown(dbei)) +					m_hDbEventFirst = hPrevEvent; +			} +			break; +		} +	} +	return notifyUnread; +} +  void CMsgDialog::FixTabIcons()  {  	HICON hIcon; diff --git a/plugins/TabSRMM/src/msgdialog.cpp b/plugins/TabSRMM/src/msgdialog.cpp index 9d66f8c95e..2257567ffe 100644 --- a/plugins/TabSRMM/src/msgdialog.cpp +++ b/plugins/TabSRMM/src/msgdialog.cpp @@ -571,6 +571,11 @@ bool CMsgDialog::OnInitDialog()  		m_hTabIcon = m_hTabStatusIcon;
  		UpdateNickList();
 +
 +		if (m_si->pMI->bDatabase) {
 +			FindFirstEvent();
 +			RemakeLog();
 +		}
  	}
  	else {
  		FindFirstEvent();
 diff --git a/protocols/WhatsApp/src/appsync.cpp b/protocols/WhatsApp/src/appsync.cpp index 8ab4416fc3..f976c580b6 100644 --- a/protocols/WhatsApp/src/appsync.cpp +++ b/protocols/WhatsApp/src/appsync.cpp @@ -273,6 +273,16 @@ void WhatsAppProto::ProcessHistorySync(const Wa__HistorySync *pSync)  				CMStringA szMessageText(GetMessageText(pMessage->message->message));  				if (!szMessageText.IsEmpty()) {  					auto *key = pMessage->message->key; + +					PROTORECVEVENT pre = {}; +					pre.timestamp = pMessage->message->messagetimestamp; +					pre.szMessage = szMessageText.GetBuffer(); +					pre.szMsgId = key->id; +					pre.flags = PREF_CREATEREAD; +					if (key->fromme) +						pre.flags |= PREF_SENT; +					ProtoChainRecvMsg(pUser->hContact, &pre); +  					if (pUser->bIsGroupChat) {  						GCEVENT gce = {m_szModuleName, 0, GC_EVENT_MESSAGE};  						gce.dwFlags = GCEF_UTF8; @@ -283,16 +293,6 @@ void WhatsAppProto::ProcessHistorySync(const Wa__HistorySync *pSync)  						gce.time = pMessage->message->messagetimestamp;  						Chat_Event(&gce);  					} -					else { -						PROTORECVEVENT pre = {}; -						pre.timestamp = pMessage->message->messagetimestamp; -						pre.szMessage = szMessageText.GetBuffer(); -						pre.szMsgId = key->id; -						pre.flags = PREF_CREATEREAD; -						if (key->fromme) -							pre.flags |= PREF_SENT; -						ProtoChainRecvMsg(pUser->hContact, &pre); -					}  				}  			}  		} diff --git a/protocols/WhatsApp/src/message.cpp b/protocols/WhatsApp/src/message.cpp index ab9da0102a..4eeb62872a 100644 --- a/protocols/WhatsApp/src/message.cpp +++ b/protocols/WhatsApp/src/message.cpp @@ -209,6 +209,16 @@ void WhatsAppProto::ProcessMessage(WAMSG type, const Wa__WebMessageInfo &msg)  	if (pUser) {  		CMStringA szMessageText(GetMessageText(body));  		if (!szMessageText.IsEmpty()) { +			PROTORECVEVENT pre = {}; +			pre.timestamp = timestamp; +			pre.szMessage = szMessageText.GetBuffer(); +			pre.szMsgId = msgId; +			if (type.bOffline) +				pre.flags |= PREF_CREATEREAD; +			if (key->fromme) +				pre.flags |= PREF_SENT; +			ProtoChainRecvMsg(pUser->hContact, &pre); +  			if (pUser->bIsGroupChat) {  				GCEVENT gce = {m_szModuleName, 0, GC_EVENT_MESSAGE};  				gce.dwFlags = GCEF_UTF8; @@ -219,17 +229,6 @@ void WhatsAppProto::ProcessMessage(WAMSG type, const Wa__WebMessageInfo &msg)  				gce.time = timestamp;  				Chat_Event(&gce);  			} -			else { -				PROTORECVEVENT pre = {}; -				pre.timestamp = timestamp; -				pre.szMessage = szMessageText.GetBuffer(); -				pre.szMsgId = msgId; -				if (type.bOffline) -					pre.flags |= PREF_CREATEREAD; -				if (key->fromme) -					pre.flags |= PREF_SENT; -				ProtoChainRecvMsg(pUser->hContact, &pre); -			}  		}  	} diff --git a/protocols/WhatsApp/src/proto.cpp b/protocols/WhatsApp/src/proto.cpp index fbc81be06f..fe036b40b5 100644 --- a/protocols/WhatsApp/src/proto.cpp +++ b/protocols/WhatsApp/src/proto.cpp @@ -93,7 +93,7 @@ WhatsAppProto::WhatsAppProto(const char *proto_name, const wchar_t *username) :  	// groupchat initialization  	GCREGISTER gcr = {}; -	gcr.dwFlags = GC_TYPNOTIF; +	gcr.dwFlags = GC_TYPNOTIF | GC_DATABASE;  	gcr.ptszDispName = m_tszUserName;  	gcr.pszModule = m_szModuleName;  	Chat_Register(&gcr); diff --git a/src/core/stdmsg/src/msgdialog.cpp b/src/core/stdmsg/src/msgdialog.cpp index 63ed7f47fa..8e0c4ff3ed 100644 --- a/src/core/stdmsg/src/msgdialog.cpp +++ b/src/core/stdmsg/src/msgdialog.cpp @@ -140,50 +140,16 @@ bool CMsgDialog::OnInitDialog()  		UpdateStatusBar();
  		UpdateTitle();
 -		NotifyEvent(MSG_WINDOW_EVT_OPEN);
 +		if (m_si->pMI->bDatabase) {
 +			FindFirstEvent();
 +			RemakeLog();
 +		}
  	}
  	else {
  		m_nickList.Hide();
  		m_splitterX.Hide();
 -		// This finds the first message to display, it works like shit
 -		m_hDbEventFirst = db_event_firstUnread(m_hContact);
 -		{
 -			DB::ECPTR pCursor(DB::EventsRev(m_hContact, m_hDbEventFirst));
 -
 -			switch (g_plugin.iLoadHistory) {
 -			case LOADHISTORY_COUNT:
 -				for (int i = g_plugin.nLoadCount; i--;) {
 -					MEVENT hPrevEvent = pCursor.FetchNext();
 -					if (hPrevEvent == 0)
 -						break;
 -
 -					DBEVENTINFO dbei = {};
 -					m_hDbEventFirst = hPrevEvent;
 -					db_event_get(hPrevEvent, &dbei);
 -					if (!DbEventIsShown(&dbei))
 -						i++;
 -				}
 -				break;
 -
 -			case LOADHISTORY_TIME:
 -				DBEVENTINFO dbei = {};
 -				if (m_hDbEventFirst == 0)
 -					dbei.timestamp = (uint32_t)time(0);
 -				else
 -					db_event_get(m_hDbEventFirst, &dbei);
 -
 -				uint32_t firstTime = dbei.timestamp - 60 * g_plugin.nLoadTime;
 -				while (MEVENT hPrevEvent = pCursor.FetchNext()) {
 -					dbei.cbBlob = 0;
 -					db_event_get(hPrevEvent, &dbei);
 -					if (dbei.timestamp < firstTime)
 -						break;
 -					m_hDbEventFirst = hPrevEvent;
 -				}
 -				break;
 -			}
 -		}
 +		FindFirstEvent();
  		bool bUpdate = false;
  		DB::ECPTR pCursor(DB::EventsRev(m_hContact));
 @@ -1335,6 +1301,47 @@ void CMsgDialog::CloseTab()  	else SendMessage(m_hwndParent, WM_CLOSE, 0, 0);
  }
 +void CMsgDialog::FindFirstEvent()
 +{
 +	// This finds the first message to display, it works like shit
 +	m_hDbEventFirst = db_event_firstUnread(m_hContact);
 +
 +	DB::ECPTR pCursor(DB::EventsRev(m_hContact, m_hDbEventFirst));
 +
 +	switch (g_plugin.iLoadHistory) {
 +	case LOADHISTORY_COUNT:
 +		for (int i = g_plugin.nLoadCount; i--;) {
 +			MEVENT hPrevEvent = pCursor.FetchNext();
 +			if (hPrevEvent == 0)
 +				break;
 +
 +			DBEVENTINFO dbei = {};
 +			m_hDbEventFirst = hPrevEvent;
 +			db_event_get(hPrevEvent, &dbei);
 +			if (!DbEventIsShown(&dbei))
 +				i++;
 +		}
 +		break;
 +
 +	case LOADHISTORY_TIME:
 +		DBEVENTINFO dbei = {};
 +		if (m_hDbEventFirst == 0)
 +			dbei.timestamp = (uint32_t)time(0);
 +		else
 +			db_event_get(m_hDbEventFirst, &dbei);
 +
 +		uint32_t firstTime = dbei.timestamp - 60 * g_plugin.nLoadTime;
 +		while (MEVENT hPrevEvent = pCursor.FetchNext()) {
 +			dbei.cbBlob = 0;
 +			db_event_get(hPrevEvent, &dbei);
 +			if (dbei.timestamp < firstTime)
 +				break;
 +			m_hDbEventFirst = hPrevEvent;
 +		}
 +		break;
 +	}
 +}
 +
  void CMsgDialog::NotifyTyping(int mode)
  {
  	if (!m_hContact)
 diff --git a/src/core/stdmsg/src/msgs.h b/src/core/stdmsg/src/msgs.h index d9bc5f78dc..f21110e641 100644 --- a/src/core/stdmsg/src/msgs.h +++ b/src/core/stdmsg/src/msgs.h @@ -55,6 +55,7 @@ class CMsgDialog : public CSrmmBaseDialog  	friend class CTabbedWindow;
  	typedef CSrmmBaseDialog CSuper;
 +	void FindFirstEvent();
  	void Init(void);
  	void NotifyTyping(int mode);
  	void SetButtonsPos(void);
 diff --git a/src/mir_app/src/chat.h b/src/mir_app/src/chat.h index ed4e28aa22..cab71e9849 100644 --- a/src/mir_app/src/chat.h +++ b/src/mir_app/src/chat.h @@ -81,7 +81,7 @@ SESSION_INFO* SM_FindSession(const wchar_t *pszID, const char *pszModule);  SESSION_INFO* SM_FindSessionByIndex(const char *pszModule, int iItem);
  STATUSINFO*   TM_AddStatus(STATUSINFO **ppStatusList, const wchar_t *pszStatus, int *iCount);
 -uint16_t          TM_StringToWord(STATUSINFO *pStatusList, const wchar_t *pszStatus);
 +uint16_t      TM_StringToWord(STATUSINFO *pStatusList, const wchar_t *pszStatus);
  BOOL          UM_RemoveAll(SESSION_INFO *si);
  BOOL          UM_SetStatusEx(SESSION_INFO *si, const wchar_t* pszText, int flags);
 diff --git a/src/mir_app/src/chat_svc.cpp b/src/mir_app/src/chat_svc.cpp index e1c3ad4596..0043df7ae6 100644 --- a/src/mir_app/src/chat_svc.cpp +++ b/src/mir_app/src/chat_svc.cpp @@ -190,6 +190,7 @@ MIR_APP_DLL(int) Chat_Register(const GCREGISTER *gcr)  	mi->bBkgColor = (gcr->dwFlags & GC_BKGCOLOR) != 0;
  	mi->bAckMsg = (gcr->dwFlags & GC_ACKMSG) != 0;
  	mi->bChanMgr = (gcr->dwFlags & GC_CHANMGR) != 0;
 +	mi->bDatabase = (gcr->dwFlags & GC_DATABASE) != 0;
  	mi->iMaxText = gcr->iMaxText;
  	mi->pszHeader = g_chatApi.Log_CreateRtfHeader();
  | 
