2020-02-23 14:02:47 +01:00
|
|
|
#ifndef _ACCOUNT_DATA_H
|
|
|
|
#define _ACCOUNT_DATA_H
|
|
|
|
|
|
|
|
#include <td/telegram/td_api.h>
|
|
|
|
#include <map>
|
|
|
|
#include <mutex>
|
|
|
|
|
|
|
|
enum {
|
|
|
|
CHAT_HISTORY_REQUEST_LIMIT = 50,
|
|
|
|
CHAT_HISTORY_RETRIEVE_LIMIT = 100
|
|
|
|
};
|
|
|
|
|
|
|
|
class TdAccountData {
|
|
|
|
public:
|
2020-02-27 21:16:12 +01:00
|
|
|
using TdUserPtr = td::td_api::object_ptr<td::td_api::user>;
|
|
|
|
using TdChatPtr = td::td_api::object_ptr<td::td_api::chat>;
|
|
|
|
using TdMessagePtr = td::td_api::object_ptr<td::td_api::message>;
|
2020-02-23 14:02:47 +01:00
|
|
|
|
|
|
|
void updateUser(TdUserPtr user);
|
2020-05-02 12:35:31 +02:00
|
|
|
void addChat(TdChatPtr chat); // Updates existing chat if any
|
|
|
|
void setContacts(const std::vector<std::int32_t> &userIds);
|
2020-02-23 14:02:47 +01:00
|
|
|
void setActiveChats(std::vector<std::int64_t> &&chats);
|
2020-05-02 12:35:31 +02:00
|
|
|
void getContactsWithNoChat(std::vector<std::int32_t> &userIds);
|
2020-02-23 14:02:47 +01:00
|
|
|
const td::td_api::chat *getChat(int64_t chatId) const;
|
2020-02-27 21:49:02 +01:00
|
|
|
const td::td_api::chat *getPrivateChatByUserId(int32_t userId) const;
|
2020-02-23 14:02:47 +01:00
|
|
|
const td::td_api::user *getUser(int32_t userId) const;
|
2020-02-27 21:49:02 +01:00
|
|
|
const td::td_api::user *getUserByPhone(const char *phoneNumber) const;
|
2020-05-04 14:08:57 +02:00
|
|
|
const td::td_api::user *getUserByPrivateChat(const td::td_api::chat &chat);
|
|
|
|
void getPrivateChats(std::vector<const td::td_api::chat *> &chats) const;
|
2020-05-04 17:16:13 +02:00
|
|
|
void addNewContactRequest(uint64_t requestId, const char *phoneNumber, const char *alias, int32_t userId = 0);
|
|
|
|
bool extractContactRequest(uint64_t requestId, std::string &phoneNumber, std::string &alias, int32_t &userId);
|
2020-02-23 14:02:47 +01:00
|
|
|
private:
|
2020-02-27 21:49:02 +01:00
|
|
|
using UserInfoMap = std::map<int32_t, TdUserPtr>;
|
|
|
|
using ChatInfoMap = std::map<int64_t, TdChatPtr>;
|
2020-03-21 14:32:33 +01:00
|
|
|
|
|
|
|
struct ContactRequest {
|
|
|
|
uint64_t requestId;
|
|
|
|
std::string phoneNumber;
|
2020-05-04 17:16:13 +02:00
|
|
|
std::string alias;
|
2020-03-24 00:14:19 +01:00
|
|
|
int32_t userId;
|
2020-03-21 14:32:33 +01:00
|
|
|
};
|
|
|
|
|
2020-02-27 21:49:02 +01:00
|
|
|
UserInfoMap m_userInfo;
|
|
|
|
ChatInfoMap m_chatInfo;
|
2020-05-02 12:53:25 +02:00
|
|
|
// List of contacts for which private chat is not known yet.
|
2020-05-02 12:35:31 +02:00
|
|
|
std::vector<int32_t> m_contactUserIdsNoChat;
|
2020-02-23 14:02:47 +01:00
|
|
|
// m_chatInfo can contain chats that are not in m_activeChats if some other chat contains
|
|
|
|
// messages forwarded from another channel
|
|
|
|
std::vector<int64_t> m_activeChats;
|
2020-03-21 14:32:33 +01:00
|
|
|
std::vector<ContactRequest> m_addContactRequests;
|
2020-02-23 14:02:47 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|