From b6926beda6415e0a53915cc2541c75daa768e05a Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sat, 19 Oct 2024 20:06:12 +0300 Subject: Telegram: an option not to store channel messages --- protocols/Telegram/res/resource.rc | 5 +++- protocols/Telegram/src/options.cpp | 4 ++- protocols/Telegram/src/proto.cpp | 3 ++- protocols/Telegram/src/proto.h | 19 +++++++------- protocols/Telegram/src/resource.h | 1 + protocols/Telegram/src/server.cpp | 51 +++++++++++++++++++++++--------------- 6 files changed, 51 insertions(+), 32 deletions(-) diff --git a/protocols/Telegram/res/resource.rc b/protocols/Telegram/res/resource.rc index 88de0a2305..cb6181fb51 100644 --- a/protocols/Telegram/res/resource.rc +++ b/protocols/Telegram/res/resource.rc @@ -97,7 +97,10 @@ BEGIN "Button",BS_AUTOCHECKBOX | WS_TABSTOP,4,83,294,10 CONTROL "Compress files on send",IDC_COMPRESS_FILES,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,4,96,294,10 PUSHBUTTON "Log out",IDC_LOGOUT,212,168,86,14 - CONTROL "Include URL preview into message text",IDC_USE_PREVIEW,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,4,109,294,10 + CONTROL "Include URL preview into message text",IDC_USE_PREVIEW, + "Button",BS_AUTOCHECKBOX | WS_TABSTOP,4,109,294,10 + CONTROL "Store channel messages in memory only",IDC_RESIDENT_CHANNELS, + "Button",BS_AUTOCHECKBOX | WS_TABSTOP,4,122,294,10 END IDD_OPTIONS_ADV DIALOGEX 0, 0, 310, 86 diff --git a/protocols/Telegram/src/options.cpp b/protocols/Telegram/src/options.cpp index bb27acf95a..8b31ce3c1c 100644 --- a/protocols/Telegram/src/options.cpp +++ b/protocols/Telegram/src/options.cpp @@ -22,7 +22,7 @@ along with this program. If not, see . class COptionsDlg : public CTelegramDlgBase { CCtrlButton btnLogout; - CCtrlCheck chkHideChats, chkUsePopups, chkCompressFiles, chkIncludePreviews; + CCtrlCheck chkHideChats, chkUsePopups, chkCompressFiles, chkIncludePreviews, chkResidentChannels; CCtrlCombo cmbCountry; CCtrlEdit edtGroup, edtPhone, edtDeviceName; ptrW m_wszOldGroup; @@ -39,6 +39,7 @@ public: edtDeviceName(this, IDC_DEVICE_NAME), chkCompressFiles(this, IDC_COMPRESS_FILES), chkIncludePreviews(this, IDC_USE_PREVIEW), + chkResidentChannels(this, IDC_RESIDENT_CHANNELS), m_wszOldGroup(mir_wstrdup(ppro->m_wszDefaultGroup)) { CreateLink(edtPhone, ppro->m_szOwnPhone); @@ -50,6 +51,7 @@ public: CreateLink(chkUsePopups, ppro->m_bUsePopups); CreateLink(chkCompressFiles, ppro->m_bCompressFiles); CreateLink(chkIncludePreviews, ppro->m_bIncludePreviews); + CreateLink(chkResidentChannels, ppro->m_bResidentChannels); } btnLogout.OnClick = Callback(this, &COptionsDlg::onClick_Logout); diff --git a/protocols/Telegram/src/proto.cpp b/protocols/Telegram/src/proto.cpp index 403a40f686..ab8a4f10b2 100644 --- a/protocols/Telegram/src/proto.cpp +++ b/protocols/Telegram/src/proto.cpp @@ -57,7 +57,8 @@ CTelegramProto::CTelegramProto(const char* protoName, const wchar_t* userName) : m_bUsePopups(this, "UsePopups", true), m_bCompressFiles(this, "CompressFiles", true), m_bHideGroupchats(this, "HideChats", true), - m_bIncludePreviews(this, "IncludePreview", true) + m_bIncludePreviews(this, "IncludePreview", true), + m_bResidentChannels(this, "ResidentChannels", false) { m_iOwnId = GetId(0); diff --git a/protocols/Telegram/src/proto.h b/protocols/Telegram/src/proto.h index a2bebd4b71..3b47eb22c0 100644 --- a/protocols/Telegram/src/proto.h +++ b/protocols/Telegram/src/proto.h @@ -436,17 +436,18 @@ public: // Options /////////////////////////////////////////////////////////////////////////// - CMOption m_iCountry; // set this status to m_iStatus1 after this interval of secs - CMOption m_szOwnPhone; // our own phone number - CMOption m_wszDefaultGroup; // clist group to store contacts - CMOption m_wszDeviceName; // how do you see this session in Device List - CMOption m_bHideGroupchats; // do not open chat windows on creation + CMOption m_iCountry; // set this status to m_iStatus1 after this interval of secs + CMOption m_szOwnPhone; // our own phone number + CMOption m_wszDefaultGroup; // clist group to store contacts + CMOption m_wszDeviceName; // how do you see this session in Device List + CMOption m_bHideGroupchats; // do not open chat windows on creation CMOption m_bUsePopups; - CMOption m_bIncludePreviews; // include URL previews into message text - CMOption m_bCompressFiles; // embed pictures & videos into a message on send - CMOption m_iTimeDiff1; // set this status to m_iStatus1 after this interval of secs + CMOption m_bIncludePreviews; // include URL previews into message text + CMOption m_bResidentChannels; // don't store channel messages in a database + CMOption m_bCompressFiles; // embed pictures & videos into a message on send + CMOption m_iTimeDiff1; // set this status to m_iStatus1 after this interval of secs CMOption m_iStatus1; - CMOption m_iTimeDiff2; // set this status to m_iStatus2 after this interval of secs + CMOption m_iTimeDiff2; // set this status to m_iStatus2 after this interval of secs CMOption m_iStatus2; // Processing Threads //////////////////////////////////////////////////////////////// diff --git a/protocols/Telegram/src/resource.h b/protocols/Telegram/src/resource.h index ba4fad485f..59a64c9a48 100644 --- a/protocols/Telegram/src/resource.h +++ b/protocols/Telegram/src/resource.h @@ -35,6 +35,7 @@ #define IDC_COMPRESS_FILES 1017 #define IDC_REACTIONS 1018 #define IDC_USE_PREVIEW 1018 +#define IDC_RESIDENT_CHANNELS 1019 #define IDC_SESSIONS 1023 #define IDC_SOFTWARE 1025 #define IDC_LOGOUT 1025 diff --git a/protocols/Telegram/src/server.cpp b/protocols/Telegram/src/server.cpp index 5c47412389..575287087f 100644 --- a/protocols/Telegram/src/server.cpp +++ b/protocols/Telegram/src/server.cpp @@ -927,28 +927,39 @@ void CTelegramProto::ProcessMessage(const TD::message *pMessage) hContact = si->hContact; } - DB::EventInfo dbei(hOldEvent); - dbei.szId = szMsgId; - dbei.cbBlob = szText.GetLength(); - dbei.timestamp = pMessage->date_; - if (pMessage->is_outgoing_) - dbei.flags |= DBEF_SENT; - if (!pUser->bInited) - dbei.flags |= DBEF_READ; - if (GetGcUserId(pUser, pMessage, szUserId)) - dbei.szUserId = szUserId; - if (auto iReplyId = getReplyId(pMessage->reply_to_.get())) { - szReplyId = msg2id(pMessage->chat_id_, iReplyId); - dbei.szReplyId = szReplyId; - } - - if (dbei) { - replaceStr(dbei.pBlob, szText.Detach()); - db_event_edit(hOldEvent, &dbei, true); + if (m_bResidentChannels && pUser->isChannel && pUser->m_si) { + GCEVENT gce = { pUser->m_si, GC_EVENT_MESSAGE }; + gce.dwFlags = GCEF_ADDTOLOG | GCEF_UTF8; + gce.pszText.a = szText; + gce.pszNick.a = szUserId; + gce.pszUID.a = szUserId; + gce.time = pMessage->date_; + Chat_Event(&gce); } else { - dbei.pBlob = szText.GetBuffer(); - ProtoChainRecvMsg(hContact, dbei); + DB::EventInfo dbei(hOldEvent); + dbei.szId = szMsgId; + dbei.cbBlob = szText.GetLength(); + dbei.timestamp = pMessage->date_; + if (pMessage->is_outgoing_) + dbei.flags |= DBEF_SENT; + if (!pUser->bInited) + dbei.flags |= DBEF_READ; + if (GetGcUserId(pUser, pMessage, szUserId)) + dbei.szUserId = szUserId; + if (auto iReplyId = getReplyId(pMessage->reply_to_.get())) { + szReplyId = msg2id(pMessage->chat_id_, iReplyId); + dbei.szReplyId = szReplyId; + } + + if (dbei) { + replaceStr(dbei.pBlob, szText.Detach()); + db_event_edit(hOldEvent, &dbei, true); + } + else { + dbei.pBlob = szText.GetBuffer(); + ProtoChainRecvMsg(hContact, dbei); + } } } -- cgit v1.2.3