summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2023-09-06 15:14:07 +0300
committerGeorge Hazan <george.hazan@gmail.com>2023-09-06 15:14:07 +0300
commit38b24044db30c606e9bb3ebe0849b16c9fdc6e62 (patch)
treeaf2822805df50b5f3cc18abc2d709ace3140342d
parent5e232971e1eb3a0ce665a3e34b982db49676e653 (diff)
fixes #3667 (Telegram: add message edit feature)
-rw-r--r--include/m_database.h2
-rw-r--r--include/m_protoint.h2
-rw-r--r--libs/win32/mir_app.libbin270920 -> 271000 bytes
-rw-r--r--libs/win32/mir_core.libbin493690 -> 493696 bytes
-rw-r--r--libs/win64/mir_app.libbin270070 -> 270156 bytes
-rw-r--r--libs/win64/mir_core.libbin498930 -> 498930 bytes
-rw-r--r--plugins/Dbx_sqlite/src/dbevents.cpp2
-rw-r--r--plugins/NewStory/src/history_control.cpp13
-rw-r--r--protocols/ICQ-WIM/src/proto.cpp4
-rw-r--r--protocols/ICQ-WIM/src/proto.h2
-rw-r--r--protocols/Telegram/src/proto.cpp23
-rw-r--r--protocols/Telegram/src/proto.h1
-rw-r--r--protocols/Telegram/src/server.cpp15
-rw-r--r--src/mir_app/src/mir_app.def2
-rw-r--r--src/mir_app/src/mir_app64.def2
-rw-r--r--src/mir_app/src/proto_accs.cpp10
-rw-r--r--src/mir_app/src/proto_interface.cpp2
-rw-r--r--src/mir_core/src/db.cpp14
18 files changed, 61 insertions, 33 deletions
diff --git a/include/m_database.h b/include/m_database.h
index e227badc18..d21537fc8d 100644
--- a/include/m_database.h
+++ b/include/m_database.h
@@ -293,7 +293,7 @@ EXTERN_C MIR_CORE_DLL(int) db_event_delete(MEVENT hDbEvent, bool bFromServer = f
// Edits an event in the database
// Returns 0 on success, or nonzero on error
-EXTERN_C MIR_CORE_DLL(int) db_event_edit(MEVENT hDbEvent, const DBEVENTINFO *dbei);
+EXTERN_C MIR_CORE_DLL(int) db_event_edit(MEVENT hDbEvent, const DBEVENTINFO *dbei, bool bFromServer = false);
// Tries to find an event by its id if present
// if an event is found, it's edited, otherwise a new event is added
diff --git a/include/m_protoint.h b/include/m_protoint.h
index 693656bb0d..2c1a7ffe53 100644
--- a/include/m_protoint.h
+++ b/include/m_protoint.h
@@ -270,7 +270,7 @@ public:
virtual void OnEventDeleted(MCONTACT, MEVENT);
// called when an event is altered in database
- virtual void OnEventEdited(MCONTACT, MEVENT);
+ virtual void OnEventEdited(MCONTACT, MEVENT, const DBEVENTINFO &dbei);
// called when an account gets physically removed from the database
virtual void OnErase();
diff --git a/libs/win32/mir_app.lib b/libs/win32/mir_app.lib
index 0d73750c4b..cef9bf721c 100644
--- a/libs/win32/mir_app.lib
+++ b/libs/win32/mir_app.lib
Binary files differ
diff --git a/libs/win32/mir_core.lib b/libs/win32/mir_core.lib
index 71763dc161..caf9e284f6 100644
--- a/libs/win32/mir_core.lib
+++ b/libs/win32/mir_core.lib
Binary files differ
diff --git a/libs/win64/mir_app.lib b/libs/win64/mir_app.lib
index bcb3f6e82d..b10de66983 100644
--- a/libs/win64/mir_app.lib
+++ b/libs/win64/mir_app.lib
Binary files differ
diff --git a/libs/win64/mir_core.lib b/libs/win64/mir_core.lib
index 13533c8cde..1a02538fe0 100644
--- a/libs/win64/mir_core.lib
+++ b/libs/win64/mir_core.lib
Binary files differ
diff --git a/plugins/Dbx_sqlite/src/dbevents.cpp b/plugins/Dbx_sqlite/src/dbevents.cpp
index 1206b30b09..d8f5bc242e 100644
--- a/plugins/Dbx_sqlite/src/dbevents.cpp
+++ b/plugins/Dbx_sqlite/src/dbevents.cpp
@@ -291,7 +291,7 @@ BOOL CDbxSQLite::EditEvent(MEVENT hDbEvent, const DBEVENTINFO *dbei)
lock.unlock();
DBFlush();
- NotifyEventHooks(g_hevEventEdited, 0, hDbEvent);
+ NotifyEventHooks(g_hevEventEdited, GetEventContact(hDbEvent), hDbEvent);
return 0;
}
diff --git a/plugins/NewStory/src/history_control.cpp b/plugins/NewStory/src/history_control.cpp
index ed4df6fd3f..bc48e35777 100644
--- a/plugins/NewStory/src/history_control.cpp
+++ b/plugins/NewStory/src/history_control.cpp
@@ -335,17 +335,16 @@ void NewstoryListData::EndEditItem(bool bAccept)
int iTextLen = GetWindowTextLengthW(hwndEditBox);
replaceStrW(pItem->wtext, (wchar_t *)mir_alloc((iTextLen + 1) * sizeof(wchar_t)));
- GetWindowTextW(hwndEditBox, pItem->wtext, iTextLen);
+ GetWindowTextW(hwndEditBox, pItem->wtext, iTextLen+1);
pItem->wtext[iTextLen] = 0;
if (pItem->hContact && pItem->hEvent) {
- ptrA szUtf(mir_utf8encodeW(pItem->wtext));
- pItem->dbe.cbBlob = (int)mir_strlen(szUtf) + 1;
- pItem->dbe.pBlob = (uint8_t *)szUtf.get();
- db_event_edit(pItem->hEvent, &pItem->dbe);
+ DBEVENTINFO dbei = pItem->dbe;
- if (auto *ppro = Proto_GetInstance(pItem->hContact))
- ppro->OnEventEdited(pItem->hContact, pItem->hEvent);
+ ptrA szUtf(mir_utf8encodeW(pItem->wtext));
+ dbei.cbBlob = (int)mir_strlen(szUtf) + 1;
+ dbei.pBlob = (uint8_t *)szUtf.get();
+ db_event_edit(pItem->hEvent, &dbei);
}
MTextDestroy(pItem->data); pItem->data = 0;
diff --git a/protocols/ICQ-WIM/src/proto.cpp b/protocols/ICQ-WIM/src/proto.cpp
index 356765e07b..343ac8fef5 100644
--- a/protocols/ICQ-WIM/src/proto.cpp
+++ b/protocols/ICQ-WIM/src/proto.cpp
@@ -177,7 +177,7 @@ void CIcqProto::OnReceiveOfflineFile(DB::FILE_BLOB &blob, void *ft)
}
}
-void CIcqProto::OnSendOfflineFile(DB::EventInfo &dbei, DB::FILE_BLOB &blob, void *hTransfer)
+void CIcqProto::OnSendOfflineFile(DB::EventInfo &, DB::FILE_BLOB &blob, void *hTransfer)
{
auto *ft = (IcqFileTransfer *)hTransfer;
@@ -193,7 +193,7 @@ void CIcqProto::OnSendOfflineFile(DB::EventInfo &dbei, DB::FILE_BLOB &blob, void
blob.setLocalName(ft->m_wszFileName);
}
-void CIcqProto::OnEventEdited(MCONTACT, MEVENT)
+void CIcqProto::OnEventEdited(MCONTACT, MEVENT, const DBEVENTINFO &)
{
}
diff --git a/protocols/ICQ-WIM/src/proto.h b/protocols/ICQ-WIM/src/proto.h
index 7ca0874770..1d51df8369 100644
--- a/protocols/ICQ-WIM/src/proto.h
+++ b/protocols/ICQ-WIM/src/proto.h
@@ -415,7 +415,7 @@ class CIcqProto : public PROTO<CIcqProto>
void OnContactAdded(MCONTACT) override;
void OnContactDeleted(MCONTACT) override;
MWindow OnCreateAccMgrUI(MWindow) override;
- void OnEventEdited(MCONTACT, MEVENT) override;
+ void OnEventEdited(MCONTACT, MEVENT, const DBEVENTINFO &dbei) override;
void OnMarkRead(MCONTACT, MEVENT) override;
void OnModulesLoaded() override;
void OnReceiveOfflineFile(DB::FILE_BLOB &blob, void *ft) override;
diff --git a/protocols/Telegram/src/proto.cpp b/protocols/Telegram/src/proto.cpp
index b3a6b2466e..98d055af2b 100644
--- a/protocols/Telegram/src/proto.cpp
+++ b/protocols/Telegram/src/proto.cpp
@@ -216,6 +216,24 @@ void CTelegramProto::OnEventDeleted(MCONTACT hContact, MEVENT hDbEvent)
}
}
+void CTelegramProto::OnEventEdited(MCONTACT hContact, MEVENT, const DBEVENTINFO &dbei)
+{
+ if (!hContact)
+ return;
+
+ auto *pUser = FindUser(GetId(hContact));
+ if (!pUser)
+ return;
+
+ if (dbei.szId && dbei.cbBlob && dbei.eventType == EVENTTYPE_MESSAGE) {
+ auto text = TD::make_object<TD::formattedText>();
+ text->text_ = (char*)dbei.pBlob;
+
+ auto content = TD::make_object<TD::inputMessageText>(std::move(text), false, false);
+ SendQuery(new TD::editMessageText(pUser->chatId, _atoi64(dbei.szId), 0, std::move(content)));
+ }
+}
+
void CTelegramProto::OnMarkRead(MCONTACT hContact, MEVENT hDbEvent)
{
if (!hContact)
@@ -225,9 +243,8 @@ void CTelegramProto::OnMarkRead(MCONTACT hContact, MEVENT hDbEvent)
if (!pUser)
return;
- DBEVENTINFO dbei = {};
- db_event_get(hDbEvent, &dbei);
- if (dbei.szId) {
+ DB::EventInfo dbei(hDbEvent, false);
+ if (dbei && dbei.szId) {
mir_cslock lck(m_csMarkRead);
if (m_markChatId) {
if (m_markChatId != hContact)
diff --git a/protocols/Telegram/src/proto.h b/protocols/Telegram/src/proto.h
index 32376a5710..ad11cce7bf 100644
--- a/protocols/Telegram/src/proto.h
+++ b/protocols/Telegram/src/proto.h
@@ -342,6 +342,7 @@ public:
MWindow OnCreateAccMgrUI(MWindow hwndParent) override;
void OnErase() override;
void OnEventDeleted(MCONTACT, MEVENT) override;
+ void OnEventEdited(MCONTACT, MEVENT, const DBEVENTINFO &dbei) override;
void OnMarkRead(MCONTACT, MEVENT) override;
void OnModulesLoaded() override;
void OnReceiveOfflineFile(DB::FILE_BLOB &blob, void *ft) override;
diff --git a/protocols/Telegram/src/server.cpp b/protocols/Telegram/src/server.cpp
index 4226d8a413..792f68140e 100644
--- a/protocols/Telegram/src/server.cpp
+++ b/protocols/Telegram/src/server.cpp
@@ -685,12 +685,21 @@ void CTelegramProto::ProcessMessageContent(TD::updateMessageContent *pObj)
return;
}
- /*
- CMStringA szText(GetMessageText(pUser, pObj->new_content_.get()));
+ auto msg = TD::make_object<TD::message>();
+ msg->content_ = std::move(pObj->new_content_);
+ CMStringA szText(GetMessageText(pUser, msg.get()));
if (szText.IsEmpty()) {
debugLogA("this message was not processed, ignored");
return;
- }*/
+ }
+
+ DBEVENTINFO dbei = {};
+ if (db_event_get(hDbEvent, &dbei))
+ return;
+
+ dbei.cbBlob = szText.GetLength();
+ dbei.pBlob = (uint8_t *)szText.c_str();
+ db_event_edit(hDbEvent, &dbei, true);
}
void CTelegramProto::ProcessOption(TD::updateOption *pObj)
diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def
index 3a1b7cd89d..08989886ce 100644
--- a/src/mir_app/src/mir_app.def
+++ b/src/mir_app/src/mir_app.def
@@ -708,7 +708,7 @@ Chat_CreateMenu @824 NONAME
?PasteFilesAsURL@CSrmmBaseDialog@@IAE_NPAUHDROP__@@@Z @825 NONAME
?Proto_GetInstance@@YGPAUPROTO_INTERFACE@@I@Z @826 NONAME
?Proto_GetInstance@@YGPAUPROTO_INTERFACE@@PBD@Z @827 NONAME
-?OnEventEdited@PROTO_INTERFACE@@UAEXII@Z @828 NONAME
+?OnEventEdited@PROTO_INTERFACE@@UAEXIIABUDBEVENTINFO@@@Z @828 NONAME
?GetChecker@MDatabaseCommon@@UAGPAUMIDatabaseChecker@@XZ @829 NONAME
?GetMenuItem@PROTO_INTERFACE@@QAEPAUTMO_IntMenuItem@@W4ProtoMenuItemType@@@Z @830 NONAME
_Netlib_GetTlsUnique@12 @831 NONAME
diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def
index eb3ea2ac3b..d15c8b7a46 100644
--- a/src/mir_app/src/mir_app64.def
+++ b/src/mir_app/src/mir_app64.def
@@ -708,7 +708,7 @@ Chat_CreateMenu @824 NONAME
?PasteFilesAsURL@CSrmmBaseDialog@@IEAA_NPEAUHDROP__@@@Z @825 NONAME
?Proto_GetInstance@@YAPEAUPROTO_INTERFACE@@I@Z @826 NONAME
?Proto_GetInstance@@YAPEAUPROTO_INTERFACE@@PEBD@Z @827 NONAME
-?OnEventEdited@PROTO_INTERFACE@@UEAAXII@Z @828 NONAME
+?OnEventEdited@PROTO_INTERFACE@@UEAAXIIAEBUDBEVENTINFO@@@Z @828 NONAME
?GetChecker@MDatabaseCommon@@UEAAPEAUMIDatabaseChecker@@XZ @829 NONAME
?GetMenuItem@PROTO_INTERFACE@@QEAAPEAUTMO_IntMenuItem@@W4ProtoMenuItemType@@@Z @830 NONAME
Netlib_GetTlsUnique @831 NONAME
diff --git a/src/mir_app/src/proto_accs.cpp b/src/mir_app/src/proto_accs.cpp
index 5cf681bf0f..20f25c851d 100644
--- a/src/mir_app/src/proto_accs.cpp
+++ b/src/mir_app/src/proto_accs.cpp
@@ -32,7 +32,7 @@ void BuildProtoMenus();
HICON Proto_GetIcon(PROTO_INTERFACE *ppro, int iconIndex);
static bool bModuleInitialized = false;
-static HANDLE hHooks[2];
+static HANDLE hHooks[1];
static int CompareAccounts(const PROTOACCOUNT* p1, const PROTOACCOUNT* p2)
{
@@ -150,13 +150,6 @@ void WriteDbAccounts()
/////////////////////////////////////////////////////////////////////////////////////////
-static int OnEventEdited(WPARAM hContact, LPARAM hDbEvent)
-{
- if (auto *ppro = Proto_GetInstance(hContact))
- ppro->OnEventEdited(hContact, hDbEvent);
- return 0;
-}
-
void InitStaticAccounts()
{
int count = 0;
@@ -218,7 +211,6 @@ int LoadAccountsModule(void)
}
hHooks[0] = HookEvent(ME_SYSTEM_PRESHUTDOWN, UninitializeStaticAccounts);
- hHooks[1] = HookEvent(ME_DB_EVENT_EDITED, OnEventEdited);
return 0;
}
diff --git a/src/mir_app/src/proto_interface.cpp b/src/mir_app/src/proto_interface.cpp
index db4da573d8..716cc7bb29 100644
--- a/src/mir_app/src/proto_interface.cpp
+++ b/src/mir_app/src/proto_interface.cpp
@@ -83,7 +83,7 @@ MWindow PROTO_INTERFACE::OnCreateAccMgrUI(MWindow)
void PROTO_INTERFACE::OnEventDeleted(MCONTACT, MEVENT)
{}
-void PROTO_INTERFACE::OnEventEdited(MCONTACT, MEVENT)
+void PROTO_INTERFACE::OnEventEdited(MCONTACT, MEVENT, const DBEVENTINFO &)
{}
void PROTO_INTERFACE::OnErase()
diff --git a/src/mir_core/src/db.cpp b/src/mir_core/src/db.cpp
index 982d289e29..0dec7c5ee6 100644
--- a/src/mir_core/src/db.cpp
+++ b/src/mir_core/src/db.cpp
@@ -426,9 +426,19 @@ MIR_CORE_DLL(int) db_event_delete(MEVENT hDbEvent, bool bFromServer)
return g_pCurrDb->DeleteEvent(hDbEvent);
}
-MIR_CORE_DLL(int) db_event_edit(MEVENT hDbEvent, const DBEVENTINFO *dbei)
+MIR_CORE_DLL(int) db_event_edit(MEVENT hDbEvent, const DBEVENTINFO *dbei, bool bFromServer)
{
- return (g_pCurrDb == nullptr) ? 0 : g_pCurrDb->EditEvent(hDbEvent, dbei);
+ if (g_pCurrDb == nullptr)
+ return 0;
+
+ int rc = g_pCurrDb->EditEvent(hDbEvent, dbei);
+ if (!rc && !bFromServer) {
+ MCONTACT hContact = g_pCurrDb->GetEventContact(hDbEvent);
+ if (auto *ppro = Proto_GetInstance(hContact))
+ ppro->OnEventEdited(hContact, hDbEvent, *dbei);
+ }
+
+ return rc;
}
MIR_CORE_DLL(MEVENT) db_event_first(MCONTACT hContact)