summaryrefslogtreecommitdiff
path: root/plugins/Scriver
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2022-11-14 20:04:02 +0300
committerGeorge Hazan <ghazan@miranda.im>2022-11-14 20:04:02 +0300
commit2d74ff3a09c40efda6ad6e9c6b569820776a54f1 (patch)
treea30fa0bca0c7dec52fa5b554b7eccd0993d254fa /plugins/Scriver
parente097a96ae55208292e1800c75b6a1f7766e38964 (diff)
basic set for storing group chat messages in a database + reusing log settings like show 10 recent messages
Diffstat (limited to 'plugins/Scriver')
-rw-r--r--plugins/Scriver/src/msgdialog.cpp59
-rw-r--r--plugins/Scriver/src/msgs.h1
-rw-r--r--plugins/Scriver/src/msgutils.cpp59
3 files changed, 66 insertions, 53 deletions
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;