summaryrefslogtreecommitdiff
path: root/protocols/Telegram
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/Telegram')
-rw-r--r--protocols/Telegram/src/add_phone.cpp2
-rw-r--r--protocols/Telegram/src/avatars.cpp2
-rw-r--r--protocols/Telegram/src/proto.cpp5
-rw-r--r--protocols/Telegram/src/proto.h7
-rw-r--r--protocols/Telegram/src/server.cpp53
5 files changed, 62 insertions, 7 deletions
diff --git a/protocols/Telegram/src/add_phone.cpp b/protocols/Telegram/src/add_phone.cpp
index f2c0edf17d..ed2e8035a0 100644
--- a/protocols/Telegram/src/add_phone.cpp
+++ b/protocols/Telegram/src/add_phone.cpp
@@ -89,7 +89,7 @@ public:
}
};
-INT_PTR CTelegramProto::AddByPhone(WPARAM, LPARAM)
+INT_PTR CTelegramProto::SvcAddByPhone(WPARAM, LPARAM)
{
(new CAddPhoneContactDlg(this))->Show();
return 0;
diff --git a/protocols/Telegram/src/avatars.cpp b/protocols/Telegram/src/avatars.cpp
index 24301cb42c..bad675ad76 100644
--- a/protocols/Telegram/src/avatars.cpp
+++ b/protocols/Telegram/src/avatars.cpp
@@ -118,7 +118,7 @@ void __cdecl CTelegramProto::OfflineFileThread(void *pParam)
delete ofd;
}
-INT_PTR __cdecl CTelegramProto::OfflineFile(WPARAM param, LPARAM)
+INT_PTR __cdecl CTelegramProto::SvcOfflineFile(WPARAM param, LPARAM)
{
ForkThread((MyThreadFunc)&CTelegramProto::OfflineFileThread, (void *)param);
return 0;
diff --git a/protocols/Telegram/src/proto.cpp b/protocols/Telegram/src/proto.cpp
index 2daecb045a..b5edc01e8c 100644
--- a/protocols/Telegram/src/proto.cpp
+++ b/protocols/Telegram/src/proto.cpp
@@ -58,6 +58,7 @@ CTelegramProto::CTelegramProto(const char* protoName, const wchar_t* userName) :
CreateProtoService(PS_GETAVATARINFO, &CTelegramProto::SvcGetAvatarInfo);
CreateProtoService(PS_GETMYAVATAR, &CTelegramProto::SvcGetMyAvatar);
CreateProtoService(PS_SETMYAVATAR, &CTelegramProto::SvcSetMyAvatar);
+ CreateProtoService(PS_MENU_LOADHISTORY, &CTelegramProto::SvcLoadServerHistory);
HookProtoEvent(ME_HISTORY_EMPTY, &CTelegramProto::OnEmptyHistory);
HookProtoEvent(ME_OPT_INITIALISE, &CTelegramProto::OnOptionsInit);
@@ -72,7 +73,7 @@ CTelegramProto::CTelegramProto(const char* protoName, const wchar_t* userName) :
InitMenus();
// Offline file transfer
- CreateProtoService(PS_OFFLINEFILE, &CTelegramProto::OfflineFile);
+ CreateProtoService(PS_OFFLINEFILE, &CTelegramProto::SvcOfflineFile);
// create standard network connection
NETLIBUSER nlu = {};
@@ -166,7 +167,7 @@ void CTelegramProto::OnBuildProtoMenu()
// Groups uploader
mi.pszService = "/UploadGroups";
- CreateProtoService(mi.pszService, &CTelegramProto::AddByPhone);
+ CreateProtoService(mi.pszService, &CTelegramProto::SvcAddByPhone);
mi.name.a = LPGEN("Add phone contact");
mi.position = 200001;
mi.hIcolibItem = Skin_GetIconHandle(SKINICON_OTHER_ADDCONTACT);
diff --git a/protocols/Telegram/src/proto.h b/protocols/Telegram/src/proto.h
index 12d939a847..b6b70cb2a3 100644
--- a/protocols/Telegram/src/proto.h
+++ b/protocols/Telegram/src/proto.h
@@ -194,6 +194,7 @@ class CTelegramProto : public PROTO<CTelegramProto>
void OnEndSession(td::ClientManager::Response &response);
void OnGetFileInfo(td::ClientManager::Response &response, void *pUserInfo);
+ void OnGetHistory(td::ClientManager::Response &response, void *pUserInfo);
void OnSearchResults(td::ClientManager::Response &response);
void OnSendMessage(td::ClientManager::Response &response, void *pUserInfo);
void OnUpdateAuth(td::ClientManager::Response &response);
@@ -329,9 +330,9 @@ public:
// Services //////////////////////////////////////////////////////////////////////////
- INT_PTR __cdecl AddByPhone(WPARAM, LPARAM);
- INT_PTR __cdecl OfflineFile(WPARAM, LPARAM);
- INT_PTR __cdecl PreCreateOfflineFile(WPARAM, LPARAM);
+ INT_PTR __cdecl SvcAddByPhone(WPARAM, LPARAM);
+ INT_PTR __cdecl SvcOfflineFile(WPARAM, LPARAM);
+ INT_PTR __cdecl SvcLoadServerHistory(WPARAM, LPARAM);
// Options ///////////////////////////////////////////////////////////////////////////
diff --git a/protocols/Telegram/src/server.cpp b/protocols/Telegram/src/server.cpp
index 0cc0ed1f76..2b83443ec8 100644
--- a/protocols/Telegram/src/server.cpp
+++ b/protocols/Telegram/src/server.cpp
@@ -273,6 +273,59 @@ void CTelegramProto::SendQuery(TD::Function *pFunc, TG_QUERY_HANDLER_FULL pHandl
///////////////////////////////////////////////////////////////////////////////
+void CTelegramProto::OnGetHistory(td::ClientManager::Response &response, void *pUserInfo)
+{
+ if (!response.object)
+ return;
+
+ if (response.object->get_id() != TD::messages::ID) {
+ debugLogA("Gotten class ID %d instead of %d, exiting", response.object->get_id(), TD::messages::ID);
+ return;
+ }
+
+ auto *pUser = (TG_USER *)pUserInfo;
+ TD::int53 lastMsgId = INT64_MAX;
+ auto *pMessages = (TD::messages *)response.object.get();
+ for (auto &it : pMessages->messages_) {
+ auto *pMsg = it.get();
+ if (pMsg->id_ < lastMsgId)
+ lastMsgId = pMsg->id_;
+
+ char szMsgId[100], szUserId[100];
+ _i64toa(pMsg->id_, szMsgId, 10);
+ if (db_event_getById(m_szModuleName, szMsgId))
+ continue;
+
+ CMStringA szBody = GetMessageText(pUser, pMsg);
+
+ DBEVENTINFO dbei = {};
+ dbei.eventType = EVENTTYPE_MESSAGE;
+ dbei.szModule = m_szModuleName;
+ dbei.timestamp = pMsg->date_;
+ dbei.cbBlob = szBody.GetLength();
+ dbei.pBlob = (uint8_t*)szBody.c_str();
+ dbei.szId = szMsgId;
+ dbei.flags = DBEF_READ | DBEF_UTF | DBEF_HAS_ID;
+ if (pMsg->is_outgoing_)
+ dbei.flags |= DBEF_SENT;
+ if (this->GetGcUserId(pUser, pMsg, szUserId))
+ dbei.szUserId = szUserId;
+ db_event_add(pUser->hContact, &dbei);
+ }
+
+ if (lastMsgId != INT64_MAX)
+ SendQuery(new TD::getChatHistory(pUser->chatId, lastMsgId, 0, 100, false), &CTelegramProto::OnGetHistory, pUser);
+}
+
+INT_PTR CTelegramProto::SvcLoadServerHistory(WPARAM hContact, LPARAM)
+{
+ if (auto *pUser = FindUser(GetId(hContact)))
+ SendQuery(new TD::getChatHistory(pUser->chatId, 0, 0, 100, false), &CTelegramProto::OnGetHistory, pUser);
+ return 0;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+
void CTelegramProto::ProcessBasicGroup(TD::updateBasicGroup *pObj)
{
auto *pBasicGroup = pObj->basic_group_.get();