2020-05-15 19:46:07 +02:00
|
|
|
#ifndef _CLIENT_UTILS_H
|
|
|
|
#define _CLIENT_UTILS_H
|
2020-05-11 20:18:25 +02:00
|
|
|
|
|
|
|
#include "account-data.h"
|
2020-05-15 19:46:07 +02:00
|
|
|
#include "transceiver.h"
|
2020-05-11 20:18:25 +02:00
|
|
|
#include <purple.h>
|
|
|
|
|
2020-05-13 19:15:15 +02:00
|
|
|
struct TgMessageInfo {
|
2020-05-29 11:18:54 +02:00
|
|
|
enum class Type {
|
|
|
|
Sticker,
|
|
|
|
Other
|
|
|
|
};
|
|
|
|
Type type;
|
2020-05-13 19:15:15 +02:00
|
|
|
std::string sender;
|
|
|
|
time_t timestamp;
|
|
|
|
bool outgoing;
|
2020-05-16 13:38:00 +02:00
|
|
|
int64_t repliedMessageId;
|
2020-05-30 10:07:55 +02:00
|
|
|
td::td_api::object_ptr<td::td_api::message> repliedMessage;
|
2020-05-16 15:32:56 +02:00
|
|
|
std::string forwardedFrom;
|
2020-05-13 19:15:15 +02:00
|
|
|
};
|
|
|
|
|
2020-05-30 10:07:55 +02:00
|
|
|
using FileDownloadCb = void (PurpleTdClient::*)(int64_t chatId, TgMessageInfo &message,
|
2020-05-27 20:21:00 +02:00
|
|
|
const std::string &filePath, const char *caption,
|
2020-05-27 22:14:35 +02:00
|
|
|
const std::string &fileDescription,
|
2020-05-27 20:21:00 +02:00
|
|
|
td::td_api::object_ptr<td::td_api::file> thumbnail);
|
|
|
|
|
2020-05-13 19:15:15 +02:00
|
|
|
// Matching completed downloads to chats they belong to
|
|
|
|
class DownloadRequest: public PendingRequest {
|
|
|
|
public:
|
2020-05-27 20:21:00 +02:00
|
|
|
int64_t chatId;
|
|
|
|
TgMessageInfo message;
|
2020-05-27 22:14:35 +02:00
|
|
|
std::string fileDescription;
|
2020-05-13 19:15:15 +02:00
|
|
|
td::td_api::object_ptr<td::td_api::file> thumbnail;
|
2020-05-27 20:21:00 +02:00
|
|
|
FileDownloadCb callback;
|
2020-05-13 19:15:15 +02:00
|
|
|
|
|
|
|
// Could not pass object_ptr through variadic funciton :(
|
2020-05-30 10:07:55 +02:00
|
|
|
DownloadRequest(uint64_t requestId, int64_t chatId, TgMessageInfo &message,
|
2020-05-27 22:14:35 +02:00
|
|
|
const std::string &fileDescription,
|
2020-05-27 20:21:00 +02:00
|
|
|
td::td_api::file *thumbnail, FileDownloadCb callback)
|
2020-05-30 10:07:55 +02:00
|
|
|
: PendingRequest(requestId), chatId(chatId), message(std::move(message)),
|
2020-05-27 22:14:35 +02:00
|
|
|
fileDescription(fileDescription), thumbnail(thumbnail), callback(callback) {}
|
2020-05-13 19:15:15 +02:00
|
|
|
};
|
|
|
|
|
2020-05-11 20:18:25 +02:00
|
|
|
std::string messageTypeToString(const td::td_api::MessageContent &content);
|
2020-05-20 18:31:37 +02:00
|
|
|
std::string proxyTypeToString(PurpleProxyType proxyType);
|
|
|
|
|
|
|
|
const char * getPurpleStatusId(const td::td_api::UserStatus &tdStatus);
|
2020-05-16 20:38:58 +02:00
|
|
|
std::string getPurpleBuddyName(const td::td_api::user &user);
|
|
|
|
void getUsersByPurpleName(const char *username, std::vector<const td::td_api::user*> &users,
|
2020-05-22 13:05:11 +02:00
|
|
|
TdAccountData &account);
|
|
|
|
int64_t getPrivateChatIdByPurpleName(const char *buddyName, TdAccountData &account,
|
2020-05-20 12:45:46 +02:00
|
|
|
const char *action);
|
2020-05-11 20:18:25 +02:00
|
|
|
PurpleConversation *getImConversation(PurpleAccount *account, const char *username);
|
2020-05-22 13:05:11 +02:00
|
|
|
PurpleConvChat * getChatConversation(TdAccountData &account, const td::td_api::chat &chat,
|
|
|
|
int chatPurpleId);
|
2020-05-20 18:31:37 +02:00
|
|
|
PurpleConvChat * findChatConversation(PurpleAccount *account, const td::td_api::chat &chat);
|
2020-05-22 13:05:11 +02:00
|
|
|
void updatePrivateChat(TdAccountData &account, const td::td_api::chat &chat, const td::td_api::user &user);
|
|
|
|
void updateBasicGroupChat(TdAccountData &account, int32_t groupId);
|
|
|
|
void updateSupergroupChat(TdAccountData &account, int32_t groupId);
|
2020-05-22 13:46:37 +02:00
|
|
|
void removeGroupChat(PurpleAccount *purpleAccount, const td::td_api::chat &chat);
|
2020-05-12 09:35:40 +02:00
|
|
|
std::string getSenderPurpleName(const td::td_api::chat &chat, const td::td_api::message &message,
|
2020-05-22 13:05:11 +02:00
|
|
|
TdAccountData &account);
|
2020-05-16 15:32:56 +02:00
|
|
|
std::string getForwardSource(const td::td_api::messageForwardInfo &forwardInfo,
|
|
|
|
TdAccountData &accountData);
|
2020-05-14 14:42:05 +02:00
|
|
|
void getNamesFromAlias(const char *alias, std::string &firstName, std::string &lastName);
|
2020-05-12 19:37:59 +02:00
|
|
|
std::vector<PurpleChat *> findChatsByInviteLink(const std::string &inviteLink);
|
2020-05-22 14:48:17 +02:00
|
|
|
std::vector<PurpleChat *> findChatsByNewGroup(const char *name, int type);
|
2020-05-12 09:35:40 +02:00
|
|
|
|
2020-05-29 12:16:03 +02:00
|
|
|
std::string getSenderDisplayName(const td::td_api::chat &chat, const TgMessageInfo &message,
|
|
|
|
PurpleAccount *account);
|
|
|
|
std::string makeNoticeWithSender(const td::td_api::chat &chat, const TgMessageInfo &message,
|
|
|
|
const char *noticeText, PurpleAccount *account);
|
2020-05-22 13:05:11 +02:00
|
|
|
void showMessageText(TdAccountData &account, const td::td_api::chat &chat, const TgMessageInfo &message,
|
|
|
|
const char *text, const char *notification, uint32_t extraFlags = 0);
|
2020-05-29 12:43:09 +02:00
|
|
|
void showGenericFile(const td::td_api::chat &chat, const TgMessageInfo &message,
|
2020-05-29 12:16:03 +02:00
|
|
|
const std::string &filePath, const std::string &fileDescription,
|
2020-05-29 12:43:09 +02:00
|
|
|
TdAccountData &account);
|
|
|
|
void showWebpSticker(const td::td_api::chat &chat, const TgMessageInfo &message,
|
|
|
|
const std::string &filePath, const std::string &fileDescription,
|
|
|
|
TdAccountData &account);
|
2020-05-11 20:18:25 +02:00
|
|
|
void setChatMembers(PurpleConvChat *purpleChat, const td::td_api::basicGroupFullInfo &groupInfo,
|
2020-05-22 13:05:11 +02:00
|
|
|
const TdAccountData &account);
|
2020-05-11 20:18:25 +02:00
|
|
|
|
2020-05-16 00:16:06 +02:00
|
|
|
void transmitMessage(int64_t chatId, const char *message, TdTransceiver &transceiver,
|
2020-05-22 13:05:11 +02:00
|
|
|
TdAccountData &account, TdTransceiver::ResponseCb response);
|
2020-05-28 21:29:58 +02:00
|
|
|
void startDocumentUpload(int64_t chatId, const std::string &filename, PurpleXfer *xfer,
|
|
|
|
TdTransceiver &transceiver, TdAccountData &account,
|
|
|
|
TdTransceiver::ResponseCb response);
|
|
|
|
void uploadResponseError(PurpleXfer *xfer, const std::string &message, TdAccountData &account);
|
|
|
|
void startDocumentUploadProgress(int64_t chatId, PurpleXfer *xfer, const td::td_api::file &file,
|
|
|
|
TdTransceiver &transceiver, TdAccountData &account);
|
|
|
|
void updateDocumentUploadProgress(const td::td_api::file &file, TdTransceiver &transceiver,
|
|
|
|
TdAccountData &account);
|
2020-05-15 19:46:07 +02:00
|
|
|
|
2020-05-25 23:21:04 +02:00
|
|
|
void requestRecoveryEmailConfirmation(PurpleConnection *gc, const char *emailInfo);
|
|
|
|
|
2020-05-27 00:51:35 +02:00
|
|
|
unsigned getFileSize(const td::td_api::file &file);
|
2020-05-26 20:06:09 +02:00
|
|
|
unsigned getFileSizeKb(const td::td_api::file &file);
|
|
|
|
|
2020-05-27 22:14:35 +02:00
|
|
|
template<typename DocumentType>
|
|
|
|
std::string makeDocumentDescription(const DocumentType *document)
|
|
|
|
{
|
|
|
|
if (!document)
|
|
|
|
// Unlikely error message not worth translating
|
|
|
|
return "(faulty file)";
|
|
|
|
return document->file_name_ + " [" + document->mime_type_ + "]";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string makeDocumentDescription(const td::td_api::voiceNote *document);
|
2020-05-31 14:27:35 +02:00
|
|
|
std::string makeDocumentDescription(const td::td_api::videoNote *document);
|
2020-05-27 22:14:35 +02:00
|
|
|
|
2020-05-31 15:55:28 +02:00
|
|
|
void updateSecretChat(td::td_api::object_ptr<td::td_api::secretChat> secretChat,
|
|
|
|
TdTransceiver &transceiver, TdAccountData &account);
|
|
|
|
|
2020-05-11 20:18:25 +02:00
|
|
|
#endif
|