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-06-13 16:01:05 +02:00
|
|
|
#include <thread>
|
2020-05-11 20:18:25 +02:00
|
|
|
|
2020-06-05 20:14:17 +02:00
|
|
|
const char *errorCodeMessage();
|
|
|
|
|
2020-09-02 21:20:53 +02:00
|
|
|
std::string getUnsupportedMessageDescription(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);
|
2020-10-04 17:54:32 +02:00
|
|
|
std::string getSecretChatBuddyName(SecretChatId secretChatId);
|
2020-06-06 20:12:12 +02:00
|
|
|
std::vector<const td::td_api::user *> getUsersByPurpleName(const char *buddyName, TdAccountData &account,
|
|
|
|
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-08-27 17:23:59 +02:00
|
|
|
void updatePrivateChat(TdAccountData &account, const td::td_api::chat *chat, const td::td_api::user &user);
|
2020-10-04 15:17:04 +02:00
|
|
|
void updateBasicGroupChat(TdAccountData &account, BasicGroupId groupId);
|
|
|
|
void updateSupergroupChat(TdAccountData &account, SupergroupId groupId);
|
2020-05-22 13:46:37 +02:00
|
|
|
void removeGroupChat(PurpleAccount *purpleAccount, const td::td_api::chat &chat);
|
2020-07-25 12:49:38 +02:00
|
|
|
std::string makeBasicDisplayName(const td::td_api::user &user);
|
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-08-13 13:34:23 +02:00
|
|
|
std::vector<PurpleChat *> findChatsByJoinString(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-06-06 11:16:43 +02:00
|
|
|
std::string getMessageText(const td::td_api::formattedText &text);
|
2020-08-27 17:32:17 +02:00
|
|
|
std::string makeInlineImageText(int imgstoreId);
|
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-06-06 20:12:12 +02:00
|
|
|
void showMessageTextIm(TdAccountData &account, const char *purpleUserName, const char *text,
|
|
|
|
const char *notification, time_t timestamp, PurpleMessageFlags flags);
|
2020-06-07 14:07:58 +02:00
|
|
|
void showChatNotification(TdAccountData &account, const td::td_api::chat &chat,
|
|
|
|
const char *notification, PurpleMessageFlags extraFlags = (PurpleMessageFlags)0);
|
2020-08-14 22:07:22 +02:00
|
|
|
void showGenericFileInline(const td::td_api::chat &chat, const TgMessageInfo &message,
|
|
|
|
const std::string &filePath, const std::string &fileDescription,
|
|
|
|
TdAccountData &account);
|
2020-06-05 20:14:17 +02:00
|
|
|
void notifySendFailed(const td::td_api::updateMessageSendFailed &sendFailed, TdAccountData &account);
|
2020-06-02 17:25:06 +02:00
|
|
|
void updateChatConversation(PurpleConvChat *purpleChat, const td::td_api::basicGroupFullInfo &groupInfo,
|
|
|
|
const TdAccountData &account);
|
|
|
|
void updateChatConversation(PurpleConvChat *purpleChat, const td::td_api::supergroupFullInfo &groupInfo,
|
2020-05-22 13:05:11 +02:00
|
|
|
const TdAccountData &account);
|
2020-07-05 15:01:24 +02:00
|
|
|
void updateSupergroupChatMembers(PurpleConvChat *purpleChat, const td::td_api::chatMembers &members,
|
|
|
|
const TdAccountData &account);
|
2020-05-11 20:18:25 +02:00
|
|
|
|
2020-10-04 15:17:04 +02:00
|
|
|
int transmitMessage(ChatId chatId, const char *message, TdTransceiver &transceiver,
|
2020-05-22 13:05:11 +02:00
|
|
|
TdAccountData &account, TdTransceiver::ResponseCb response);
|
2020-05-15 19:46:07 +02:00
|
|
|
|
2020-05-25 23:21:04 +02:00
|
|
|
void requestRecoveryEmailConfirmation(PurpleConnection *gc, const char *emailInfo);
|
|
|
|
|
2020-06-06 13:57:36 +02:00
|
|
|
void updateOption(const td::td_api::updateOption &option, TdAccountData &account);
|
2020-06-11 00:04:29 +02:00
|
|
|
void populateGroupChatList(PurpleRoomlist *roomlist, const std::vector<const td::td_api::chat *> &chats,
|
|
|
|
const TdAccountData &account);
|
2020-05-31 15:55:28 +02:00
|
|
|
|
2020-06-13 16:01:05 +02:00
|
|
|
class AccountThread {
|
|
|
|
public:
|
|
|
|
using Callback = void (PurpleTdClient::*)(AccountThread *thread);
|
|
|
|
static void setSingleThread();
|
2020-08-15 19:48:05 +02:00
|
|
|
static bool isSingleThread();
|
2020-06-13 16:01:05 +02:00
|
|
|
|
|
|
|
AccountThread(PurpleAccount *purpleAccount, Callback callback);
|
|
|
|
virtual ~AccountThread() {}
|
|
|
|
void startThread();
|
|
|
|
private:
|
|
|
|
std::thread m_thread;
|
|
|
|
std::string m_accountUserName;
|
|
|
|
std::string m_accountProtocolId;
|
|
|
|
Callback m_callback;
|
|
|
|
|
|
|
|
void threadFunc();
|
|
|
|
static gboolean mainThreadCallback(gpointer data);
|
|
|
|
protected:
|
|
|
|
virtual void run() = 0;
|
|
|
|
};
|
|
|
|
|
2020-05-11 20:18:25 +02:00
|
|
|
#endif
|