summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2023-04-23 19:36:38 +0300
committerGeorge Hazan <ghazan@miranda.im>2023-04-23 19:36:38 +0300
commitc8a01589f0570bc9f630c4b498c6fb0cc54c79a4 (patch)
treebc55a0f16aed3e113b595251f5c5ee2d10c3689a
parent1d193f3a887f84ea657f39f9bb3a2e4537426a61 (diff)
Telegram: file events to store server message id & groupchat user id, if present
-rw-r--r--include/m_protosvc.h2
-rw-r--r--protocols/Telegram/src/proto.cpp20
-rw-r--r--protocols/Telegram/src/proto.h9
-rw-r--r--protocols/Telegram/src/server.cpp14
-rw-r--r--protocols/Telegram/src/utils.cpp28
-rw-r--r--src/core/stdfile/src/file.cpp2
-rw-r--r--src/mir_app/src/chat_tools.cpp11
7 files changed, 68 insertions, 18 deletions
diff --git a/include/m_protosvc.h b/include/m_protosvc.h
index d61165f403..76ed0eb260 100644
--- a/include/m_protosvc.h
+++ b/include/m_protosvc.h
@@ -779,6 +779,8 @@ struct PROTORECVFILE
int fileCount; // number of files being transferred
MAllCStringArray files; // array of file names
LPARAM lParam; // extra space for the network level protocol module
+ const char *szId; // server message id
+ const char *szUserId; // groupchat user id
};
#define PSR_FILE "/RecvFile"
diff --git a/protocols/Telegram/src/proto.cpp b/protocols/Telegram/src/proto.cpp
index cd88af4b70..a07932b3d4 100644
--- a/protocols/Telegram/src/proto.cpp
+++ b/protocols/Telegram/src/proto.cpp
@@ -307,6 +307,26 @@ int CTelegramProto::FileResume(HANDLE hTransfer, int, const wchar_t *pwszFilenam
return 0;
}
+////////////////////////////////////////////////////////////////////////////////////////
+// RecvFile - writes down an incoming file transfer to db
+
+MEVENT CTelegramProto::RecvFile(MCONTACT hContact, PROTORECVFILE *pre)
+{
+ MEVENT hEvent = CSuper::RecvFile(hContact, pre);
+ if (hEvent) {
+ if (auto *ft = (TG_FILE_REQUEST *)pre->lParam) {
+ DBVARIANT dbv = { DBVT_UTF8 };
+ dbv.pszVal = ft->m_uniqueId.GetBuffer();
+ db_event_setJson(hEvent, "u", &dbv);
+
+ dbv.type = DBVT_DWORD;
+ dbv.dVal = ft->m_fileId;
+ db_event_setJson(hEvent, "id", &dbv);
+ }
+ }
+ return hEvent;
+}
+
/////////////////////////////////////////////////////////////////////////////////////////
void CTelegramProto::OnSearchResults(td::ClientManager::Response &response)
diff --git a/protocols/Telegram/src/proto.h b/protocols/Telegram/src/proto.h
index a386466176..562be0e434 100644
--- a/protocols/Telegram/src/proto.h
+++ b/protocols/Telegram/src/proto.h
@@ -84,7 +84,7 @@ struct TG_USER : public MZeroedObject
hContact(_2),
isGroupChat(_3)
{
- chatId = (isGroupChat) ? -1 :id;
+ chatId = (isGroupChat) ? -1 : id;
}
int64_t id, chatId;
@@ -223,7 +223,7 @@ class CTelegramProto : public PROTO<CTelegramProto>
void ProcessSuperGroup(TD::updateSupergroup *pObj);
void ProcessUser(TD::updateUser *pObj);
- CMStringA GetMessageText(TG_USER *pUser, TD::MessageContent *pBody);
+ CMStringA GetMessageText(TG_USER *pUser, const TD::message *pMsg);
void UpdateString(MCONTACT hContact, const char *pszSetting, const std::string &str);
@@ -245,6 +245,8 @@ class CTelegramProto : public PROTO<CTelegramProto>
void Chat_SendPrivateMessage(GCHOOK *gch);
void Chat_LogMenu(GCHOOK *gch);
+ bool GetGcUserId(TG_USER *pUser, const TD::message *pMsg, char *dest);
+
// Search
TD::array<TD::int53> m_searchIds;
@@ -262,6 +264,7 @@ class CTelegramProto : public PROTO<CTelegramProto>
TG_USER* AddUser(int64_t id, bool bIsChat);
TG_USER* AddFakeUser(int64_t id, bool bIsChat);
TG_USER* GetSender(const TD::MessageSender *pSender);
+
int64_t GetId(MCONTACT);
void SetId(MCONTACT, int64_t id);
@@ -289,6 +292,8 @@ public:
INT_PTR GetCaps(int type, MCONTACT hContact = NULL) override;
+ MEVENT RecvFile(MCONTACT hContact, PROTORECVFILE *pre) override;
+
HANDLE SearchByName(const wchar_t *nick, const wchar_t *firstName, const wchar_t *lastName) override;
int SendMsg(MCONTACT hContact, int flags, const char *pszMessage) override;
int SetStatus(int iNewStatus) override;
diff --git a/protocols/Telegram/src/server.cpp b/protocols/Telegram/src/server.cpp
index 920d772902..469db0e971 100644
--- a/protocols/Telegram/src/server.cpp
+++ b/protocols/Telegram/src/server.cpp
@@ -530,7 +530,7 @@ void CTelegramProto::ProcessMarkRead(TD::updateChatReadInbox *pObj)
void CTelegramProto::ProcessMessage(TD::updateNewMessage *pObj)
{
- auto &pMessage = pObj->message_;
+ auto *pMessage = pObj->message_.get();
auto *pUser = FindChat(pMessage->chat_id_);
if (pUser == nullptr) {
@@ -538,7 +538,7 @@ void CTelegramProto::ProcessMessage(TD::updateNewMessage *pObj)
return;
}
- CMStringA szText(GetMessageText(pUser, pMessage->content_.get()));
+ CMStringA szText(GetMessageText(pUser, pMessage));
if (szText.IsEmpty()) {
debugLogA("this message was not processed, ignored");
return;
@@ -564,14 +564,8 @@ void CTelegramProto::ProcessMessage(TD::updateNewMessage *pObj)
pre.timestamp = pMessage->date_;
if (pMessage->is_outgoing_)
pre.flags |= PREF_SENT;
- if (pUser->isGroupChat) {
- if (auto *pSender = GetSender(pMessage->sender_id_.get())) {
- _i64toa(pSender->id, szUserId, 10);
- pre.szUserId = szUserId;
- if (pUser->m_si && !pSender->wszFirstName.IsEmpty())
- g_chatApi.UM_AddUser(pUser->m_si, Utf2T(szUserId), pSender->getDisplayName(), ID_STATUS_ONLINE);
- }
- }
+ if (GetGcUserId(pUser, pMessage, szUserId))
+ pre.szUserId = szUserId;
ProtoChainRecvMsg(pUser->hContact, &pre);
}
diff --git a/protocols/Telegram/src/utils.cpp b/protocols/Telegram/src/utils.cpp
index ef2636563f..28b3204cf7 100644
--- a/protocols/Telegram/src/utils.cpp
+++ b/protocols/Telegram/src/utils.cpp
@@ -222,8 +222,30 @@ void CTelegramProto::Popup(MCONTACT hContact, const wchar_t *szMsg, const wchar_
/////////////////////////////////////////////////////////////////////////////////////////
-CMStringA CTelegramProto::GetMessageText(TG_USER *pUser, TD::MessageContent *pBody)
+bool CTelegramProto::GetGcUserId(TG_USER *pUser, const TD::message *pMsg, char *dest)
{
+ if (pUser->isGroupChat) {
+ if (auto *pSender = GetSender(pMsg->sender_id_.get())) {
+ _i64toa(pSender->id, dest, 10);
+ if (pUser->m_si && !pSender->wszFirstName.IsEmpty())
+ g_chatApi.UM_AddUser(pUser->m_si, Utf2T(dest), pSender->getDisplayName(), ID_STATUS_ONLINE);
+ return true;
+ }
+ }
+
+ *dest = 0;
+ return false;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
+CMStringA CTelegramProto::GetMessageText(TG_USER *pUser, const TD::message *pMsg)
+{
+ const TD::MessageContent *pBody = pMsg->content_.get();
+
+ char szId[100], szUserId[100];
+ _i64toa(pMsg->id_, szId, 10);
+
switch (pBody->get_id()) {
case TD::messageDocument::ID:
{
@@ -253,6 +275,10 @@ CMStringA CTelegramProto::GetMessageText(TG_USER *pUser, TD::MessageContent *pBo
pre.timestamp = time(0);
pre.files.a = &pszFileName;
pre.lParam = (LPARAM)pRequest;
+ pre.szId = szId;
+ if (GetGcUserId(pUser, pMsg, szUserId))
+ pre.szUserId = szUserId;
+
if (!pDoc->caption_->text_.empty())
pre.descr.a = pDoc->caption_->text_.c_str();
ProtoChainRecvFile(pUser->hContact, &pre);
diff --git a/src/core/stdfile/src/file.cpp b/src/core/stdfile/src/file.cpp
index e8573eca6b..159a421fe6 100644
--- a/src/core/stdfile/src/file.cpp
+++ b/src/core/stdfile/src/file.cpp
@@ -321,6 +321,8 @@ static INT_PTR Proto_RecvFileT(WPARAM, LPARAM lParam)
DB::EventInfo dbei;
dbei.szModule = Proto_GetBaseAccountName(ccs->hContact);
dbei.timestamp = pre->timestamp;
+ dbei.szId = pre->szId;
+ dbei.szUserId = pre->szUserId;
dbei.eventType = EVENTTYPE_FILE;
dbei.flags = DBEF_UTF;
if (pre->dwFlags & PREF_CREATEREAD)
diff --git a/src/mir_app/src/chat_tools.cpp b/src/mir_app/src/chat_tools.cpp
index 4ed79d4cc7..e06e4ab30f 100644
--- a/src/mir_app/src/chat_tools.cpp
+++ b/src/mir_app/src/chat_tools.cpp
@@ -733,13 +733,14 @@ void Chat_EventToGC(SESSION_INFO *si, MEVENT hDbEvent)
if (mir_strcmp(szProto, dbei.szModule) || !g_chatApi.DbEventIsShown(dbei) || !dbei.szUserId)
return;
- CMStringA szText((char *)dbei.pBlob);
- szText.Replace("%", "%%");
+ Utf2T wszUserId(dbei.szUserId);
+ CMStringW wszText(ptrW(DbEvent_GetTextW(&dbei, CP_UTF8)));
+ wszText.Replace(L"%", L"%%");
GCEVENT gce = { si, GC_EVENT_MESSAGE };
- gce.dwFlags = GCEF_ADDTOLOG | GCEF_UTF8;
- gce.pszUID.a = dbei.szUserId;
- gce.pszText.a = szText;
+ gce.dwFlags = GCEF_ADDTOLOG;
+ gce.pszUID.w = wszUserId;
+ gce.pszText.w = wszText;
gce.time = dbei.timestamp;
gce.hEvent = hDbEvent;
Chat_Event(&gce);