2020-02-23 14:02:47 +01:00
|
|
|
#ifndef _ACCOUNT_DATA_H
|
|
|
|
#define _ACCOUNT_DATA_H
|
|
|
|
|
2020-07-27 10:52:44 +02:00
|
|
|
#include "buildopt.h"
|
2020-10-04 15:17:04 +02:00
|
|
|
#include "identifiers.h"
|
2021-01-01 14:47:21 +01:00
|
|
|
#include "transceiver.h"
|
2020-02-23 14:02:47 +01:00
|
|
|
#include <td/telegram/td_api.h>
|
2020-07-26 23:44:51 +02:00
|
|
|
|
2020-02-23 14:02:47 +01:00
|
|
|
#include <map>
|
|
|
|
#include <mutex>
|
2020-05-31 15:55:28 +02:00
|
|
|
#include <set>
|
2021-01-03 02:01:05 +01:00
|
|
|
#include <list>
|
2020-05-22 13:05:11 +02:00
|
|
|
#include <purple.h>
|
2020-02-23 14:02:47 +01:00
|
|
|
|
2020-07-26 23:44:51 +02:00
|
|
|
#ifndef NoVoip
|
2020-07-27 16:56:42 +02:00
|
|
|
#include <VoIPController.h>
|
2020-07-26 23:44:51 +02:00
|
|
|
#else
|
|
|
|
|
|
|
|
namespace tgvoip {
|
|
|
|
struct VoIPController {};
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-05-04 17:32:33 +02:00
|
|
|
bool isPhoneNumber(const char *s);
|
|
|
|
const char *getCanonicalPhoneNumber(const char *s);
|
2020-10-04 15:17:04 +02:00
|
|
|
UserId purpleBuddyNameToUserId(const char *s);
|
2020-10-04 16:52:57 +02:00
|
|
|
SecretChatId purpleBuddyNameToSecretChatId(const char *s);
|
2020-05-20 15:13:06 +02:00
|
|
|
bool isPrivateChat(const td::td_api::chat &chat);
|
2020-10-04 16:46:38 +02:00
|
|
|
UserId getUserIdByPrivateChat(const td::td_api::chat &chat);
|
2020-05-29 21:29:07 +02:00
|
|
|
bool isChatInContactList(const td::td_api::chat &chat, const td::td_api::user *privateChatUser);
|
2020-10-04 16:46:38 +02:00
|
|
|
BasicGroupId getBasicGroupId(const td::td_api::chat &chat);
|
|
|
|
SupergroupId getSupergroupId(const td::td_api::chat &chat);
|
|
|
|
SecretChatId getSecretChatId(const td::td_api::chat &chat);
|
2020-05-10 14:24:15 +02:00
|
|
|
bool isGroupMember(const td::td_api::object_ptr<td::td_api::ChatMemberStatus> &status);
|
2021-12-06 19:56:53 +01:00
|
|
|
bool isSameUser(const td::td_api::MessageSender &member1, const td::td_api::MessageSender &member2);
|
2020-05-04 17:32:33 +02:00
|
|
|
|
2020-02-23 14:02:47 +01:00
|
|
|
enum {
|
|
|
|
CHAT_HISTORY_REQUEST_LIMIT = 50,
|
|
|
|
CHAT_HISTORY_RETRIEVE_LIMIT = 100
|
|
|
|
};
|
|
|
|
|
2020-05-11 19:35:27 +02:00
|
|
|
class PendingRequest {
|
|
|
|
public:
|
|
|
|
uint64_t requestId;
|
|
|
|
|
|
|
|
PendingRequest(uint64_t requestId) : requestId(requestId) {}
|
2020-05-22 14:48:17 +02:00
|
|
|
virtual ~PendingRequest() {}
|
2020-05-11 19:35:27 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class GroupInfoRequest: public PendingRequest {
|
|
|
|
public:
|
2020-10-04 15:17:04 +02:00
|
|
|
BasicGroupId groupId;
|
2020-05-11 19:35:27 +02:00
|
|
|
|
2020-10-04 15:17:04 +02:00
|
|
|
GroupInfoRequest(uint64_t requestId, BasicGroupId groupId)
|
|
|
|
: PendingRequest(requestId), groupId(groupId) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
class SupergroupInfoRequest: public PendingRequest {
|
|
|
|
public:
|
|
|
|
SupergroupId groupId;
|
|
|
|
|
|
|
|
SupergroupInfoRequest(uint64_t requestId, SupergroupId groupId)
|
2020-05-11 19:35:27 +02:00
|
|
|
: PendingRequest(requestId), groupId(groupId) {}
|
|
|
|
};
|
|
|
|
|
2020-07-05 15:01:24 +02:00
|
|
|
class GroupMembersRequestCont: public PendingRequest {
|
|
|
|
public:
|
2020-10-04 15:17:04 +02:00
|
|
|
SupergroupId groupId;
|
2020-07-05 15:01:24 +02:00
|
|
|
td::td_api::object_ptr<td::td_api::chatMembers> members;
|
|
|
|
|
2020-10-04 15:17:04 +02:00
|
|
|
GroupMembersRequestCont(uint64_t requestId, SupergroupId groupId, td::td_api::chatMembers *members)
|
2020-07-05 15:01:24 +02:00
|
|
|
: PendingRequest(requestId), groupId(groupId), members(std::move(members)) {}
|
|
|
|
};
|
|
|
|
|
2020-05-13 12:31:03 +02:00
|
|
|
class ContactRequest: public PendingRequest {
|
|
|
|
public:
|
|
|
|
std::string phoneNumber;
|
|
|
|
std::string alias;
|
|
|
|
std::string groupName;
|
2020-10-04 15:17:04 +02:00
|
|
|
UserId userId;
|
2020-05-13 12:31:03 +02:00
|
|
|
|
|
|
|
ContactRequest(uint64_t requestId, const std::string &phoneNumber, const std::string &alias,
|
2020-10-04 15:17:04 +02:00
|
|
|
const std::string &groupName, UserId userId)
|
2020-05-13 12:31:03 +02:00
|
|
|
: PendingRequest(requestId), phoneNumber(phoneNumber), alias(alias), groupName(groupName),
|
|
|
|
userId(userId) {}
|
|
|
|
};
|
|
|
|
|
2020-05-12 19:37:59 +02:00
|
|
|
class GroupJoinRequest: public PendingRequest {
|
|
|
|
public:
|
2020-08-13 13:34:23 +02:00
|
|
|
enum class Type {
|
|
|
|
InviteLink,
|
|
|
|
Username,
|
|
|
|
};
|
|
|
|
std::string joinString;
|
|
|
|
Type type;
|
2020-10-04 15:17:04 +02:00
|
|
|
ChatId chatId;
|
2020-05-12 19:37:59 +02:00
|
|
|
|
2020-08-13 13:34:23 +02:00
|
|
|
GroupJoinRequest(uint64_t requestId, const std::string &joinString, Type type,
|
2020-10-04 15:17:04 +02:00
|
|
|
ChatId chatId = ChatId::invalid)
|
2020-08-13 13:34:23 +02:00
|
|
|
: PendingRequest(requestId), joinString(joinString), type(type), chatId(chatId) {}
|
2020-05-12 19:37:59 +02:00
|
|
|
};
|
|
|
|
|
2020-05-16 00:16:06 +02:00
|
|
|
class SendMessageRequest: public PendingRequest {
|
|
|
|
public:
|
2020-10-04 15:17:04 +02:00
|
|
|
ChatId chatId;
|
2020-05-16 00:16:06 +02:00
|
|
|
std::string tempFile;
|
|
|
|
|
2020-10-04 15:17:04 +02:00
|
|
|
SendMessageRequest(uint64_t requestId, ChatId chatId, const char *tempFile)
|
2020-07-26 14:51:51 +02:00
|
|
|
: PendingRequest(requestId), chatId(chatId), tempFile(tempFile ? tempFile : "") {}
|
2020-05-16 00:16:06 +02:00
|
|
|
};
|
|
|
|
|
2020-05-28 21:29:58 +02:00
|
|
|
class UploadRequest: public PendingRequest {
|
|
|
|
public:
|
|
|
|
PurpleXfer *xfer;
|
2020-10-04 15:17:04 +02:00
|
|
|
ChatId chatId;
|
2020-05-28 21:29:58 +02:00
|
|
|
|
2020-10-04 15:17:04 +02:00
|
|
|
UploadRequest(uint64_t requestId, PurpleXfer *xfer, ChatId chatId)
|
2020-05-28 21:29:58 +02:00
|
|
|
: PendingRequest(requestId), xfer(xfer), chatId(chatId) {}
|
|
|
|
};
|
|
|
|
|
2020-06-04 01:28:49 +02:00
|
|
|
struct TgMessageInfo {
|
|
|
|
enum class Type {
|
2020-10-12 18:15:24 +02:00
|
|
|
Photo,
|
2020-06-04 01:28:49 +02:00
|
|
|
Sticker,
|
|
|
|
Other
|
|
|
|
};
|
2020-10-12 22:41:13 +02:00
|
|
|
MessageId id;
|
2020-06-04 01:28:49 +02:00
|
|
|
Type type;
|
2020-10-04 18:57:14 +02:00
|
|
|
std::string incomingGroupchatSender;
|
2020-06-04 01:28:49 +02:00
|
|
|
time_t timestamp;
|
|
|
|
bool outgoing;
|
2020-08-23 19:11:46 +02:00
|
|
|
bool sentLocally = false; // For outgoing messages, whether sent by this very client
|
2020-10-11 10:55:42 +02:00
|
|
|
MessageId repliedMessageId;
|
2020-06-04 01:28:49 +02:00
|
|
|
td::td_api::object_ptr<td::td_api::message> repliedMessage;
|
|
|
|
std::string forwardedFrom;
|
2020-10-11 20:25:20 +02:00
|
|
|
|
|
|
|
void assign(const TgMessageInfo &other)
|
|
|
|
{
|
2020-10-12 22:41:13 +02:00
|
|
|
id = other.id;
|
2020-10-11 20:25:20 +02:00
|
|
|
type = other.type;
|
|
|
|
incomingGroupchatSender = other.incomingGroupchatSender;
|
|
|
|
timestamp = other.timestamp;
|
|
|
|
outgoing = other.outgoing;
|
|
|
|
sentLocally = other.sentLocally;
|
|
|
|
repliedMessageId = other.repliedMessageId;
|
|
|
|
repliedMessage = nullptr;
|
|
|
|
forwardedFrom = other.forwardedFrom;
|
|
|
|
}
|
2020-06-04 01:28:49 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class PurpleTdClient;
|
|
|
|
|
|
|
|
// Used for matching completed downloads to chats they belong to, and for starting PurpleXfer for
|
|
|
|
// time-consuming downloads
|
|
|
|
class DownloadRequest: public PendingRequest {
|
|
|
|
public:
|
2020-10-04 15:17:04 +02:00
|
|
|
ChatId chatId;
|
2020-10-11 20:25:20 +02:00
|
|
|
|
|
|
|
// For inline downloads this is a copy of original TgMessageInfo from IncomingMessage.
|
2020-06-04 01:28:49 +02:00
|
|
|
TgMessageInfo message;
|
2020-10-11 20:25:20 +02:00
|
|
|
|
2020-06-04 01:28:49 +02:00
|
|
|
int32_t fileId;
|
|
|
|
int32_t fileSize;
|
|
|
|
int32_t downloadedSize;
|
|
|
|
std::string fileDescription;
|
|
|
|
int tempFd = -1;
|
|
|
|
std::string tempFileName;
|
|
|
|
td::td_api::object_ptr<td::td_api::file> thumbnail;
|
|
|
|
|
|
|
|
// Could not pass object_ptr through variadic funciton :(
|
2020-10-04 15:17:04 +02:00
|
|
|
DownloadRequest(uint64_t requestId, ChatId chatId, TgMessageInfo &message,
|
2020-06-04 01:28:49 +02:00
|
|
|
int32_t fileId, int32_t fileSize, const std::string &fileDescription,
|
2020-10-12 19:48:44 +02:00
|
|
|
td::td_api::file *thumbnail)
|
2020-10-11 20:25:20 +02:00
|
|
|
: PendingRequest(requestId), chatId(chatId), fileId(fileId),
|
2020-06-04 01:28:49 +02:00
|
|
|
fileSize(fileSize), downloadedSize(0), fileDescription(fileDescription),
|
2020-10-12 19:48:44 +02:00
|
|
|
thumbnail(thumbnail)
|
2020-10-11 20:25:20 +02:00
|
|
|
{
|
|
|
|
// If download is started while the message is in PendingMessageQueue, repliedMessage will
|
|
|
|
// be on IncomingMessage, and one here in TgMessageInfo will be NULL. In this case,
|
|
|
|
// repliedMessage will be moved onto DownloadRequest if message leaves PendingMessageQueue
|
|
|
|
// before download is complete (meaning it took more than 1 second to download).
|
|
|
|
this->message.assign(message);
|
|
|
|
if (message.repliedMessage)
|
|
|
|
this->message.repliedMessage = std::move(message.repliedMessage);
|
|
|
|
}
|
2020-06-04 01:28:49 +02:00
|
|
|
};
|
|
|
|
|
2020-06-04 22:57:01 +02:00
|
|
|
class AvatarDownloadRequest: public PendingRequest {
|
|
|
|
public:
|
2020-10-04 15:17:04 +02:00
|
|
|
UserId userId;
|
|
|
|
ChatId chatId;
|
2020-06-04 22:57:01 +02:00
|
|
|
|
|
|
|
AvatarDownloadRequest(uint64_t requestId, const td::td_api::user *user)
|
2020-10-04 15:17:04 +02:00
|
|
|
: PendingRequest(requestId), userId(getId(*user)), chatId(ChatId::invalid) {}
|
2020-06-04 22:57:01 +02:00
|
|
|
AvatarDownloadRequest(uint64_t requestId, const td::td_api::chat *chat)
|
2020-10-04 15:17:04 +02:00
|
|
|
: PendingRequest(requestId), userId(UserId::invalid), chatId(getId(*chat)) {}
|
2020-06-04 22:57:01 +02:00
|
|
|
};
|
|
|
|
|
2020-06-06 20:12:12 +02:00
|
|
|
class NewPrivateChatForMessage: public PendingRequest {
|
|
|
|
public:
|
|
|
|
std::string username;
|
|
|
|
std::string message;
|
|
|
|
PurpleXfer *fileUpload;
|
|
|
|
|
|
|
|
NewPrivateChatForMessage(uint64_t requestId, const char *username, const char *message)
|
|
|
|
: PendingRequest(requestId), username(username), message(message ? message : nullptr),
|
|
|
|
fileUpload(nullptr) {}
|
|
|
|
|
|
|
|
NewPrivateChatForMessage(uint64_t requestId, const char *username, PurpleXfer *upload)
|
|
|
|
: PendingRequest(requestId), username(username), fileUpload(upload) {}
|
|
|
|
};
|
|
|
|
|
2020-06-07 14:07:58 +02:00
|
|
|
class ChatActionRequest: public PendingRequest {
|
2020-06-07 13:09:35 +02:00
|
|
|
public:
|
2020-06-07 14:07:58 +02:00
|
|
|
enum class Type: uint8_t {
|
|
|
|
Kick,
|
2020-06-07 15:18:22 +02:00
|
|
|
Invite,
|
|
|
|
GenerateInviteLink
|
2020-06-07 14:07:58 +02:00
|
|
|
};
|
2020-10-04 15:17:04 +02:00
|
|
|
Type type;
|
|
|
|
ChatId chatId;
|
|
|
|
ChatActionRequest(uint64_t requestId, Type type, ChatId chatId)
|
2020-06-07 14:07:58 +02:00
|
|
|
: PendingRequest(requestId), type(type), chatId(chatId) {}
|
2020-06-07 13:09:35 +02:00
|
|
|
};
|
|
|
|
|
2020-10-10 15:51:16 +02:00
|
|
|
struct IncomingMessage {
|
|
|
|
td::td_api::object_ptr<td::td_api::message> message;
|
|
|
|
td::td_api::object_ptr<td::td_api::message> repliedMessage;
|
2020-10-25 16:20:13 +01:00
|
|
|
td::td_api::object_ptr<td::td_api::file> thumbnail;
|
2020-10-12 22:41:13 +02:00
|
|
|
std::string inlineDownloadedFilePath;
|
2020-10-11 19:41:18 +02:00
|
|
|
|
|
|
|
// This doesn't have to be a separate struct, it exists for historical reasons.
|
|
|
|
// Could be refactored.
|
|
|
|
TgMessageInfo messageInfo;
|
|
|
|
|
2020-10-11 12:54:20 +02:00
|
|
|
int32_t selectedPhotoSizeId;
|
|
|
|
unsigned inlineFileSizeLimit;
|
2020-10-11 14:38:37 +02:00
|
|
|
bool standardDownloadConfigured;
|
2020-10-25 14:57:45 +01:00
|
|
|
bool repliedMessageFetchDoneOrFailed;
|
2020-10-12 22:41:13 +02:00
|
|
|
bool inlineDownloadComplete;
|
|
|
|
bool inlineDownloadTimeout;
|
2020-10-18 18:33:41 +02:00
|
|
|
bool animatedStickerConverted;
|
|
|
|
bool animatedStickerConvertSuccess;
|
|
|
|
int animatedStickerImageId;
|
2020-10-10 15:51:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class PendingMessageQueue {
|
|
|
|
public:
|
2021-01-03 01:54:17 +01:00
|
|
|
enum class MessageAction {
|
|
|
|
Append,
|
|
|
|
Prepend
|
|
|
|
};
|
|
|
|
static constexpr MessageAction Append = MessageAction::Append;
|
|
|
|
static constexpr MessageAction Prepend = MessageAction::Prepend;
|
2020-10-10 15:51:16 +02:00
|
|
|
using TdMessagePtr = td::td_api::object_ptr<td::td_api::message>;
|
|
|
|
|
2021-01-03 02:01:05 +01:00
|
|
|
IncomingMessage &addPendingMessage(IncomingMessage &&message, MessageAction action);
|
2020-10-10 15:51:16 +02:00
|
|
|
void setMessageReady(ChatId chatId, MessageId messageId,
|
|
|
|
std::vector<IncomingMessage> &readyMessages);
|
2021-01-03 02:01:05 +01:00
|
|
|
IncomingMessage addReadyMessage(IncomingMessage &&message, MessageAction action);
|
2020-10-10 15:51:16 +02:00
|
|
|
IncomingMessage *findPendingMessage(ChatId chatId, MessageId messageId);
|
|
|
|
void flush(std::vector<IncomingMessage> &messages);
|
2021-01-02 21:54:31 +01:00
|
|
|
void setChatNotReady(ChatId chatId);
|
|
|
|
void setChatReady(ChatId chatId, std::vector<IncomingMessage> &readyMessages);
|
2021-01-02 22:57:20 +01:00
|
|
|
bool isChatReady(ChatId chatId);
|
2020-10-10 15:51:16 +02:00
|
|
|
private:
|
|
|
|
struct Message {
|
|
|
|
IncomingMessage message;
|
|
|
|
bool ready;
|
|
|
|
};
|
|
|
|
struct ChatQueue {
|
2021-01-03 01:54:17 +01:00
|
|
|
ChatId chatId;
|
|
|
|
bool ready = true;
|
|
|
|
std::list<Message> messages;
|
2020-10-10 15:51:16 +02:00
|
|
|
};
|
|
|
|
std::vector<ChatQueue> m_queues;
|
|
|
|
|
|
|
|
std::vector<ChatQueue>::iterator getChatQueue(ChatId chatId);
|
2021-01-03 01:54:17 +01:00
|
|
|
Message &addMessage(ChatQueue &queue, MessageAction action);
|
2021-01-02 21:54:31 +01:00
|
|
|
void extractReadyMessages(std::vector<ChatQueue>::iterator pQueue,
|
|
|
|
std::vector<IncomingMessage> &readyMessages);
|
2020-10-10 15:51:16 +02:00
|
|
|
};
|
|
|
|
|
2020-12-31 17:10:52 +01:00
|
|
|
struct ReadReceipt {
|
|
|
|
ChatId chatId;
|
|
|
|
MessageId messageId;
|
|
|
|
};
|
|
|
|
|
2020-02-23 14:02:47 +01:00
|
|
|
class TdAccountData {
|
|
|
|
public:
|
2020-06-01 11:12:26 +02:00
|
|
|
using TdUserPtr = td::td_api::object_ptr<td::td_api::user>;
|
|
|
|
using TdChatPtr = td::td_api::object_ptr<td::td_api::chat>;
|
|
|
|
using TdGroupPtr = td::td_api::object_ptr<td::td_api::basicGroup>;
|
|
|
|
using TdGroupInfoPtr = td::td_api::object_ptr<td::td_api::basicGroupFullInfo>;
|
|
|
|
using TdSupergroupPtr = td::td_api::object_ptr<td::td_api::supergroup>;
|
|
|
|
using TdSupergroupInfoPtr = td::td_api::object_ptr<td::td_api::supergroupFullInfo>;
|
2020-07-05 15:01:24 +02:00
|
|
|
using TdChatMembersPtr = td::td_api::object_ptr<td::td_api::chatMembers>;
|
2020-10-04 16:46:38 +02:00
|
|
|
using SecretChatPtr = td::td_api::object_ptr<td::td_api::secretChat>;
|
2020-02-23 14:02:47 +01:00
|
|
|
|
2020-06-06 13:57:36 +02:00
|
|
|
struct {
|
|
|
|
unsigned maxCaptionLength = 0;
|
|
|
|
unsigned maxMessageLength = 0;
|
|
|
|
} options;
|
|
|
|
|
2021-01-01 14:47:21 +01:00
|
|
|
PurpleAccount *const purpleAccount;
|
|
|
|
TdTransceiver &transceiver;
|
|
|
|
TdAccountData(PurpleAccount *purpleAccount, TdTransceiver &transceiver)
|
|
|
|
: purpleAccount(purpleAccount), transceiver(transceiver) {}
|
2020-05-22 13:05:11 +02:00
|
|
|
|
2020-02-23 14:02:47 +01:00
|
|
|
void updateUser(TdUserPtr user);
|
2020-10-04 15:17:04 +02:00
|
|
|
void setUserStatus(UserId UserId, td::td_api::object_ptr<td::td_api::UserStatus> status);
|
|
|
|
void updateSmallProfilePhoto(UserId userId, td::td_api::object_ptr<td::td_api::file> photo);
|
2020-05-09 14:07:21 +02:00
|
|
|
void updateBasicGroup(TdGroupPtr group);
|
2020-10-04 15:17:04 +02:00
|
|
|
void setBasicGroupInfoRequested(BasicGroupId groupId);
|
|
|
|
bool isBasicGroupInfoRequested(BasicGroupId groupId);
|
|
|
|
void updateBasicGroupInfo(BasicGroupId groupId, TdGroupInfoPtr groupInfo);
|
2020-05-09 14:07:21 +02:00
|
|
|
void updateSupergroup(TdSupergroupPtr group);
|
2020-10-04 15:17:04 +02:00
|
|
|
void setSupergroupInfoRequested(SupergroupId groupId);
|
|
|
|
bool isSupergroupInfoRequested(SupergroupId groupId);
|
|
|
|
void updateSupergroupInfo(SupergroupId groupId, TdSupergroupInfoPtr groupInfo);
|
|
|
|
void updateSupergroupMembers(SupergroupId groupId, TdChatMembersPtr members);
|
2020-05-09 14:07:21 +02:00
|
|
|
|
2020-05-02 12:35:31 +02:00
|
|
|
void addChat(TdChatPtr chat); // Updates existing chat if any
|
2021-12-06 19:56:53 +01:00
|
|
|
void updateChatPosition(ChatId chatId, td::td_api::object_ptr<td::td_api::chatPosition> &&position);
|
2020-10-04 15:17:04 +02:00
|
|
|
void updateChatTitle(ChatId chatId, const std::string &title);
|
|
|
|
void updateSmallChatPhoto(ChatId chatId, td::td_api::object_ptr<td::td_api::file> photo);
|
|
|
|
void setContacts(const td::td_api::users &users);
|
|
|
|
void getContactsWithNoChat(std::vector<UserId> &userIds);
|
2020-05-20 21:31:58 +02:00
|
|
|
void getChats(std::vector<const td::td_api::chat *> &chats) const;
|
2020-10-04 15:17:04 +02:00
|
|
|
void deleteChat(ChatId id);
|
2020-10-09 23:40:34 +02:00
|
|
|
void addExpectedChat(ChatId id);
|
|
|
|
bool isExpectedChat(ChatId chatId);
|
|
|
|
void removeExpectedChat(ChatId id);
|
2020-05-05 18:35:06 +02:00
|
|
|
|
2020-10-04 15:17:04 +02:00
|
|
|
const td::td_api::chat *getChat(ChatId chatId) const;
|
|
|
|
int getPurpleChatId(ChatId tdChatId);
|
2020-05-10 14:24:15 +02:00
|
|
|
const td::td_api::chat *getChatByPurpleId(int32_t purpleChatId) const;
|
2020-10-04 15:17:04 +02:00
|
|
|
const td::td_api::chat *getPrivateChatByUserId(UserId userId) const;
|
|
|
|
const td::td_api::user *getUser(UserId userId) const;
|
2020-05-09 14:07:21 +02:00
|
|
|
const td::td_api::user *getUserByPhone(const char *phoneNumber) const;
|
|
|
|
const td::td_api::user *getUserByPrivateChat(const td::td_api::chat &chat);
|
2020-05-29 19:39:22 +02:00
|
|
|
std::string getDisplayName(const td::td_api::user &user) const;
|
2020-10-04 15:17:04 +02:00
|
|
|
std::string getDisplayName(UserId userId) const;
|
2020-05-16 20:38:58 +02:00
|
|
|
void getUsersByDisplayName(const char *displayName,
|
|
|
|
std::vector<const td::td_api::user*> &users);
|
2020-06-11 00:04:29 +02:00
|
|
|
|
2020-10-04 15:17:04 +02:00
|
|
|
const td::td_api::basicGroup *getBasicGroup(BasicGroupId groupId) const;
|
|
|
|
const td::td_api::basicGroupFullInfo *getBasicGroupInfo(BasicGroupId groupId) const;
|
|
|
|
const td::td_api::supergroup *getSupergroup(SupergroupId groupId) const;
|
|
|
|
const td::td_api::supergroupFullInfo *getSupergroupInfo(SupergroupId groupId) const;
|
|
|
|
const td::td_api::chatMembers*getSupergroupMembers(SupergroupId groupId) const;
|
|
|
|
const td::td_api::chat *getBasicGroupChatByGroup(BasicGroupId groupId) const;
|
|
|
|
const td::td_api::chat *getSupergroupChatByGroup(SupergroupId groupId) const;
|
2020-06-11 00:04:29 +02:00
|
|
|
bool isGroupChatWithMembership(const td::td_api::chat &chat) const;
|
2020-05-09 14:07:21 +02:00
|
|
|
|
2020-10-04 16:46:38 +02:00
|
|
|
const td::td_api::chat *getChatBySecretChat(SecretChatId secretChatId);
|
|
|
|
|
2020-05-11 19:35:27 +02:00
|
|
|
template<typename ReqType, typename... ArgsType>
|
|
|
|
void addPendingRequest(ArgsType... args)
|
|
|
|
{
|
|
|
|
m_requests.push_back(std::make_unique<ReqType>(args...));
|
|
|
|
}
|
|
|
|
template<typename ReqType>
|
2020-05-13 12:31:03 +02:00
|
|
|
void addPendingRequest(uint64_t requestId, std::unique_ptr<ReqType> &&request)
|
|
|
|
{
|
|
|
|
m_requests.push_back(std::move(request));
|
|
|
|
m_requests.back()->requestId = requestId;
|
|
|
|
}
|
|
|
|
template<typename ReqType>
|
2020-05-11 19:35:27 +02:00
|
|
|
std::unique_ptr<ReqType> getPendingRequest(uint64_t requestId)
|
|
|
|
{
|
|
|
|
return std::unique_ptr<ReqType>(dynamic_cast<ReqType *>(getPendingRequestImpl(requestId).release()));
|
|
|
|
}
|
2020-06-02 18:42:19 +02:00
|
|
|
template<typename ReqType>
|
|
|
|
ReqType *findPendingRequest(uint64_t requestId)
|
|
|
|
{
|
|
|
|
return dynamic_cast<ReqType *>(findPendingRequestImpl(requestId));
|
|
|
|
}
|
2020-03-21 14:32:33 +01:00
|
|
|
|
2020-10-04 15:17:04 +02:00
|
|
|
const ContactRequest * findContactRequest(UserId userId);
|
2020-05-16 13:38:00 +02:00
|
|
|
void addTempFileUpload(int64_t messageId, const std::string &path);
|
|
|
|
std::string extractTempFileUpload(int64_t messageId);
|
2020-06-04 01:28:49 +02:00
|
|
|
DownloadRequest * findDownloadRequest(int32_t fileId);
|
2021-01-09 12:17:38 +01:00
|
|
|
void extractFileTransferRequests(std::vector<PurpleXfer *> &transfers);
|
2020-05-16 13:38:00 +02:00
|
|
|
|
2020-10-04 15:17:04 +02:00
|
|
|
void addFileTransfer(int32_t fileId, PurpleXfer *xfer, ChatId chatId);
|
|
|
|
bool getFileTransfer(int32_t fileId, PurpleXfer *&xfer, ChatId &chatId);
|
2020-06-02 18:42:19 +02:00
|
|
|
bool getFileIdForTransfer(PurpleXfer *xfer, int &fileId);
|
|
|
|
void removeFileTransfer(int32_t fileId);
|
2021-01-09 12:17:38 +01:00
|
|
|
void removeAllFileTransfers(std::vector<PurpleXfer *> &transfers);
|
2020-05-31 15:55:28 +02:00
|
|
|
|
|
|
|
void addSecretChat(td::td_api::object_ptr<td::td_api::secretChat> secretChat);
|
2020-10-04 16:46:38 +02:00
|
|
|
const td::td_api::secretChat *getSecretChat(SecretChatId id);
|
2020-10-05 23:29:20 +02:00
|
|
|
void deleteSecretChat(SecretChatId id);
|
2020-06-06 22:33:56 +02:00
|
|
|
|
2020-10-04 15:17:04 +02:00
|
|
|
auto getBasicGroupsWithMember(UserId userId) ->
|
|
|
|
std::vector<std::pair<BasicGroupId, const td::td_api::basicGroupFullInfo *>>;
|
2020-07-26 23:44:51 +02:00
|
|
|
|
|
|
|
bool hasActiveCall();
|
2020-07-27 16:56:42 +02:00
|
|
|
void setActiveCall(int32_t id);
|
|
|
|
int32_t getActiveCallId() const { return m_callId; }
|
2020-07-26 23:44:51 +02:00
|
|
|
tgvoip::VoIPController *getCallData();
|
|
|
|
void removeActiveCall();
|
2020-10-10 15:51:16 +02:00
|
|
|
|
|
|
|
PendingMessageQueue pendingMessages;
|
2020-12-31 17:10:52 +01:00
|
|
|
|
|
|
|
void addPendingReadReceipt(ChatId chatId, MessageId messageId);
|
2021-01-01 14:47:21 +01:00
|
|
|
void extractPendingReadReceipts(ChatId chatId, std::vector<ReadReceipt> &receipts);
|
2020-05-13 12:31:03 +02:00
|
|
|
private:
|
2020-05-29 12:43:09 +02:00
|
|
|
TdAccountData(const TdAccountData &other) = delete;
|
|
|
|
TdAccountData &operator=(const TdAccountData &other) = delete;
|
|
|
|
|
2020-05-29 19:39:22 +02:00
|
|
|
struct UserInfo {
|
|
|
|
TdUserPtr user;
|
|
|
|
std::string displayName;
|
|
|
|
};
|
|
|
|
|
2020-05-09 18:58:04 +02:00
|
|
|
struct ChatInfo {
|
|
|
|
int32_t purpleId;
|
|
|
|
TdChatPtr chat;
|
|
|
|
|
|
|
|
ChatInfo() : purpleId(0), chat() {}
|
2020-05-08 17:01:12 +02:00
|
|
|
};
|
|
|
|
|
2020-05-11 19:35:27 +02:00
|
|
|
struct GroupInfo {
|
|
|
|
TdGroupPtr group;
|
|
|
|
TdGroupInfoPtr fullInfo;
|
2020-05-20 21:31:58 +02:00
|
|
|
bool fullInfoRequested = false;
|
2020-05-11 19:35:27 +02:00
|
|
|
};
|
|
|
|
|
2020-06-01 11:12:26 +02:00
|
|
|
struct SupergroupInfo {
|
|
|
|
TdSupergroupPtr group;
|
|
|
|
TdSupergroupInfoPtr fullInfo;
|
2020-07-05 15:01:24 +02:00
|
|
|
TdChatMembersPtr members;
|
2020-06-01 11:12:26 +02:00
|
|
|
bool fullInfoRequested = false;
|
|
|
|
};
|
|
|
|
|
2020-05-16 00:16:06 +02:00
|
|
|
struct SendMessageInfo {
|
|
|
|
int64_t messageId;
|
|
|
|
std::string tempFile;
|
|
|
|
};
|
|
|
|
|
2020-06-02 18:42:19 +02:00
|
|
|
struct FileTransferInfo {
|
2020-05-28 21:29:58 +02:00
|
|
|
int32_t fileId;
|
2020-10-04 15:17:04 +02:00
|
|
|
ChatId chatId;
|
2020-05-28 21:29:58 +02:00
|
|
|
PurpleXfer *xfer;
|
|
|
|
};
|
|
|
|
|
2020-10-04 15:17:04 +02:00
|
|
|
using ChatMap = std::map<ChatId, ChatInfo>;
|
|
|
|
using UserMap = std::map<UserId, UserInfo>;
|
2020-05-16 20:38:58 +02:00
|
|
|
UserMap m_userInfo;
|
|
|
|
ChatMap m_chatInfo;
|
2020-10-04 15:17:04 +02:00
|
|
|
std::map<BasicGroupId, GroupInfo> m_groups;
|
|
|
|
std::map<SupergroupId, SupergroupInfo> m_supergroups;
|
2020-10-04 16:46:38 +02:00
|
|
|
std::map<SecretChatId, SecretChatPtr> m_secretChats;
|
2020-05-09 19:46:02 +02:00
|
|
|
int m_lastChatPurpleId = 0;
|
2020-05-05 18:35:06 +02:00
|
|
|
|
2020-05-02 12:53:25 +02:00
|
|
|
// List of contacts for which private chat is not known yet.
|
2020-10-04 15:17:04 +02:00
|
|
|
std::vector<UserId> m_contactUserIdsNoChat;
|
2020-05-05 18:35:06 +02:00
|
|
|
|
|
|
|
// Used to remember stuff during asynchronous communication when adding contact
|
2020-05-09 14:07:21 +02:00
|
|
|
std::vector<ContactRequest> m_addContactRequests;
|
2020-05-05 18:35:06 +02:00
|
|
|
|
2020-10-09 23:40:34 +02:00
|
|
|
// Chats we want to libpurple-join when we get an updateNewChat about them
|
|
|
|
std::vector<ChatId> m_expectedChats;
|
|
|
|
|
2020-05-11 19:35:27 +02:00
|
|
|
std::vector<std::unique_ptr<PendingRequest>> m_requests;
|
2020-05-31 15:55:28 +02:00
|
|
|
|
|
|
|
// Newly sent messages containing inline images, for which a temporary file must be removed when
|
|
|
|
// transfer is completed
|
2020-05-16 00:16:06 +02:00
|
|
|
std::vector<SendMessageInfo> m_sentMessages;
|
2020-05-31 15:55:28 +02:00
|
|
|
|
2020-06-02 18:42:19 +02:00
|
|
|
// Currently active file transfers for which PurpleXfer is used
|
|
|
|
std::vector<FileTransferInfo> m_fileTransfers;
|
2020-05-11 19:35:27 +02:00
|
|
|
|
2020-07-26 23:44:51 +02:00
|
|
|
// Voice call data
|
|
|
|
std::unique_ptr<tgvoip::VoIPController> m_callData;
|
2020-07-27 16:56:42 +02:00
|
|
|
int32_t m_callId;
|
2020-07-26 23:44:51 +02:00
|
|
|
|
2020-05-28 21:29:58 +02:00
|
|
|
std::unique_ptr<PendingRequest> getPendingRequestImpl(uint64_t requestId);
|
2020-06-02 18:42:19 +02:00
|
|
|
PendingRequest * findPendingRequestImpl(uint64_t requestId);
|
2020-12-31 17:10:52 +01:00
|
|
|
|
2021-01-01 14:47:21 +01:00
|
|
|
// Read receipts not sent immediately due to away status (grouped per chat)
|
|
|
|
std::vector<std::vector<ReadReceipt>> m_pendingReadReceipts;
|
2020-02-23 14:02:47 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|