mirror of
https://github.com/ars3niy/tdlib-purple
synced 2025-08-22 09:57:52 +00:00
tdlib 1.6.6 compatibility: switched to using td_api::chatPosition
This commit is contained in:
parent
9ad9a7ebb1
commit
59b2c0eb76
@ -70,7 +70,7 @@ UserId getUserIdByPrivateChat(const td::td_api::chat &chat)
|
||||
|
||||
bool isChatInContactList(const td::td_api::chat &chat, const td::td_api::user *privateChatUser)
|
||||
{
|
||||
return (chat.chat_list_ != nullptr) || (privateChatUser && privateChatUser->is_contact_);
|
||||
return !chat.positions_.empty() || (privateChatUser && privateChatUser->is_contact_);
|
||||
}
|
||||
|
||||
BasicGroupId getBasicGroupId(const td::td_api::chat &chat)
|
||||
@ -437,11 +437,28 @@ void TdAccountData::addChat(TdChatPtr chat)
|
||||
}
|
||||
}
|
||||
|
||||
void TdAccountData::updateChatChatList(ChatId chatId, td::td_api::object_ptr<td::td_api::ChatList> list)
|
||||
void TdAccountData::updateChatPosition(ChatId chatId, td::td_api::object_ptr<td::td_api::chatPosition> &&position)
|
||||
{
|
||||
auto it = m_chatInfo.find(chatId);
|
||||
if (it != m_chatInfo.end())
|
||||
it->second.chat->chat_list_ = std::move(list);
|
||||
if (position && position->list_ && (it != m_chatInfo.end())) {
|
||||
auto listId = position->list_->get_id();
|
||||
td::td_api::chat &chat = *it->second.chat;
|
||||
if (position->order_ == 0)
|
||||
chat.positions_.erase(
|
||||
std::remove_if(chat.positions_.begin(), chat.positions_.end(),
|
||||
[listId](const td::td_api::object_ptr<td::td_api::chatPosition> &chatPos) {
|
||||
return chatPos && (chatPos->list_->get_id() == listId);
|
||||
}),
|
||||
chat.positions_.end());
|
||||
else {
|
||||
auto pPosition = std::find_if(chat.positions_.begin(), chat.positions_.end(),
|
||||
[listId](const td::td_api::object_ptr<td::td_api::chatPosition> &chatPos) {
|
||||
return chatPos && (chatPos->list_->get_id() == listId);
|
||||
});
|
||||
if (pPosition != chat.positions_.end())
|
||||
*pPosition = std::move(position);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TdAccountData::updateChatTitle(ChatId chatId, const std::string &title)
|
||||
@ -461,13 +478,6 @@ void TdAccountData::updateSmallChatPhoto(ChatId chatId, td::td_api::object_ptr<t
|
||||
}
|
||||
}
|
||||
|
||||
void TdAccountData::updateChatOrder(ChatId chatId, int64_t order)
|
||||
{
|
||||
auto it = m_chatInfo.find(chatId);
|
||||
if (it != m_chatInfo.end())
|
||||
it->second.chat->order_ = order;
|
||||
}
|
||||
|
||||
void TdAccountData::setContacts(const td::td_api::users &users)
|
||||
{
|
||||
for (unsigned i = 0; i < users.user_ids_.size(); i++) {
|
||||
@ -708,24 +718,6 @@ void TdAccountData::deleteChat(ChatId id)
|
||||
m_chatInfo.erase(id);
|
||||
}
|
||||
|
||||
void TdAccountData::getSmallestOrderChat(const td::td_api::ChatList &list, ChatId &chatId, int64_t &order)
|
||||
{
|
||||
int64_t minOrder = INT64_MAX;
|
||||
ChatId id = ChatId::invalid;
|
||||
for (const ChatMap::value_type &entry: m_chatInfo) {
|
||||
int64_t order = entry.second.chat->order_;
|
||||
if (entry.second.chat->chat_list_ && (entry.second.chat->chat_list_->get_id() == list.get_id()) &&
|
||||
(order < minOrder))
|
||||
{
|
||||
minOrder = order;
|
||||
id = entry.first;
|
||||
}
|
||||
}
|
||||
|
||||
chatId = id;
|
||||
order = minOrder;
|
||||
}
|
||||
|
||||
void TdAccountData::addExpectedChat(ChatId id)
|
||||
{
|
||||
if (!isExpectedChat(id))
|
||||
|
@ -321,15 +321,13 @@ public:
|
||||
void updateSupergroupMembers(SupergroupId groupId, TdChatMembersPtr members);
|
||||
|
||||
void addChat(TdChatPtr chat); // Updates existing chat if any
|
||||
void updateChatChatList(ChatId chatId, td::td_api::object_ptr<td::td_api::ChatList> list);
|
||||
void updateChatPosition(ChatId chatId, td::td_api::object_ptr<td::td_api::chatPosition> &&position);
|
||||
void updateChatTitle(ChatId chatId, const std::string &title);
|
||||
void updateSmallChatPhoto(ChatId chatId, td::td_api::object_ptr<td::td_api::file> photo);
|
||||
void updateChatOrder(ChatId chatId, int64_t order);
|
||||
void setContacts(const td::td_api::users &users);
|
||||
void getContactsWithNoChat(std::vector<UserId> &userIds);
|
||||
void getChats(std::vector<const td::td_api::chat *> &chats) const;
|
||||
void deleteChat(ChatId id);
|
||||
void getSmallestOrderChat(const td::td_api::ChatList &list, ChatId &chatId, int64_t &order);
|
||||
void addExpectedChat(ChatId id);
|
||||
bool isExpectedChat(ChatId chatId);
|
||||
void removeExpectedChat(ChatId id);
|
||||
|
@ -121,12 +121,7 @@ SecretChatId stringToSecretChatId(const char *s)
|
||||
return SecretChatId::invalid;
|
||||
}
|
||||
|
||||
ChatId getChatId(const td::td_api::updateChatChatList &update)
|
||||
{
|
||||
return ChatId(update.chat_id_);
|
||||
}
|
||||
|
||||
ChatId getChatId(const td::td_api::updateChatOrder &update)
|
||||
ChatId getChatId(const td::td_api::updateChatPosition &update)
|
||||
{
|
||||
return ChatId(update.chat_id_);
|
||||
}
|
||||
|
@ -54,8 +54,7 @@ DEFINE_ID_CLASS(UserId, int64_t)
|
||||
|
||||
DEFINE_ID_CLASS(ChatId, int64_t)
|
||||
friend ChatId getId(const td::td_api::chat &chat);
|
||||
friend ChatId getChatId(const td::td_api::updateChatChatList &update);
|
||||
friend ChatId getChatId(const td::td_api::updateChatOrder &update);
|
||||
friend ChatId getChatId(const td::td_api::updateChatPosition &update);
|
||||
friend ChatId getChatId(const td::td_api::updateChatTitle &update);
|
||||
friend ChatId getChatId(const td::td_api::messageForwardOriginChannel &forwardOrigin);
|
||||
friend ChatId getChatId(const td::td_api::message &message);
|
||||
@ -110,8 +109,7 @@ UserId getUserId(const td::td_api::importedContacts &contacts, unsigned in
|
||||
UserId getUserId(const td::td_api::users &users, unsigned index);
|
||||
UserId stringToUserId(const char *s);
|
||||
|
||||
ChatId getChatId(const td::td_api::updateChatChatList &update);
|
||||
ChatId getChatId(const td::td_api::updateChatOrder &update);
|
||||
ChatId getChatId(const td::td_api::updateChatPosition &update);
|
||||
ChatId getChatId(const td::td_api::updateChatTitle &update);
|
||||
ChatId getChatId(const td::td_api::messageForwardOriginChannel &forwardOrigin);
|
||||
ChatId getChatId(const td::td_api::message &message);
|
||||
|
@ -161,21 +161,16 @@ void PurpleTdClient::processUpdate(td::td_api::Object &update)
|
||||
break;
|
||||
}
|
||||
|
||||
case td::td_api::updateChatChatList::ID: {
|
||||
auto &chatListUpdate = static_cast<td::td_api::updateChatChatList &>(update);
|
||||
purple_debug_misc(config::pluginId, "Incoming update: update chat list for chat %" G_GINT64_FORMAT "\n",
|
||||
chatListUpdate.chat_id_);
|
||||
m_data.updateChatChatList(getChatId(chatListUpdate), std::move(chatListUpdate.chat_list_));
|
||||
updateChat(m_data.getChat(getChatId(chatListUpdate)));
|
||||
case td::td_api::updateChatPosition::ID: {
|
||||
auto &chatPositionUpdate = static_cast<td::td_api::updateChatPosition &>(update);
|
||||
purple_debug_misc(config::pluginId, "Incoming update: update chat position for chat %" G_GINT64_FORMAT "\n",
|
||||
chatPositionUpdate.chat_id_);
|
||||
if (chatPositionUpdate.position_)
|
||||
m_data.updateChatPosition(getChatId(chatPositionUpdate), std::move(chatPositionUpdate.position_));
|
||||
updateChat(m_data.getChat(getChatId(chatPositionUpdate)));
|
||||
break;
|
||||
}
|
||||
|
||||
case td::td_api::updateChatOrder::ID: {
|
||||
auto &chatOrderUpdate = static_cast<td::td_api::updateChatOrder&>(update);
|
||||
m_data.updateChatOrder(getChatId(chatOrderUpdate), chatOrderUpdate.order_);
|
||||
break;
|
||||
};
|
||||
|
||||
case td::td_api::updateChatTitle::ID: {
|
||||
auto &chatTitleUpdate = static_cast<td::td_api::updateChatTitle &>(update);
|
||||
purple_debug_misc(config::pluginId, "Incoming update: update chat title for chat %" G_GINT64_FORMAT "\n",
|
||||
@ -649,12 +644,9 @@ void PurpleTdClient::getContactsResponse(uint64_t requestId, td::td_api::object_
|
||||
purple_debug_misc(config::pluginId, "getContacts response to request %" G_GUINT64_FORMAT "\n", requestId);
|
||||
if (object && (object->get_id() == td::td_api::users::ID)) {
|
||||
m_data.setContacts(*td::move_tl_object_as<td::td_api::users>(object));
|
||||
auto getChatsRequest = td::td_api::make_object<td::td_api::getChats>();
|
||||
auto getChatsRequest = td::td_api::make_object<td::td_api::loadChats>();
|
||||
getChatsRequest->chat_list_ = td::td_api::make_object<td::td_api::chatListMain>();
|
||||
getChatsRequest->offset_order_ = INT64_MAX;
|
||||
getChatsRequest->offset_chat_id_ = 0;
|
||||
getChatsRequest->limit_ = 200;
|
||||
m_lastChatOrderOffset = INT64_MAX;
|
||||
m_transceiver.sendQuery(std::move(getChatsRequest), &PurpleTdClient::getChatsResponse);
|
||||
} else
|
||||
notifyAuthError(object);
|
||||
@ -663,31 +655,18 @@ void PurpleTdClient::getContactsResponse(uint64_t requestId, td::td_api::object_
|
||||
void PurpleTdClient::getChatsResponse(uint64_t requestId, td::td_api::object_ptr<td::td_api::Object> object)
|
||||
{
|
||||
purple_debug_misc(config::pluginId, "getChats response to request %" G_GUINT64_FORMAT "\n", requestId);
|
||||
if (object && (object->get_id() == td::td_api::chats::ID)) {
|
||||
td::td_api::object_ptr<td::td_api::chats> chats = td::move_tl_object_as<td::td_api::chats>(object);
|
||||
if (chats->chat_ids_.empty()) {
|
||||
m_data.getContactsWithNoChat(m_usersForNewPrivateChats);
|
||||
requestMissingPrivateChats();
|
||||
} else {
|
||||
auto getChatsRequest = td::td_api::make_object<td::td_api::getChats>();
|
||||
if (object && (object->get_id() == td::td_api::ok::ID)) {
|
||||
auto getChatsRequest = td::td_api::make_object<td::td_api::loadChats>();
|
||||
getChatsRequest->chat_list_ = td::td_api::make_object<td::td_api::chatListMain>();
|
||||
ChatId chatId;
|
||||
int64_t chatOrder;
|
||||
m_data.getSmallestOrderChat(*getChatsRequest->chat_list_, chatId, chatOrder);
|
||||
if (chatOrder < m_lastChatOrderOffset) {
|
||||
getChatsRequest->offset_order_ = chatOrder;
|
||||
getChatsRequest->offset_chat_id_ = chatId.value();
|
||||
getChatsRequest->limit_ = 200;
|
||||
m_lastChatOrderOffset = chatOrder;
|
||||
m_transceiver.sendQuery(std::move(getChatsRequest), &PurpleTdClient::getChatsResponse);
|
||||
} else {
|
||||
std::string message = getDisplayedError(object);
|
||||
purple_debug_misc(config::pluginId, "Got no more chats: %s\n", message.c_str());
|
||||
m_data.getContactsWithNoChat(m_usersForNewPrivateChats);
|
||||
requestMissingPrivateChats();
|
||||
}
|
||||
}
|
||||
} else
|
||||
notifyAuthError(object);
|
||||
}
|
||||
|
||||
void PurpleTdClient::requestMissingPrivateChats()
|
||||
{
|
||||
@ -972,10 +951,11 @@ void PurpleTdClient::onIncomingMessage(td::td_api::object_ptr<td::td_api::messag
|
||||
handleIncomingMessage(m_data, *chat, std::move(message), PendingMessageQueue::Append);
|
||||
}
|
||||
|
||||
void PurpleTdClient::updateChatLastMessage(const td::td_api::updateChatLastMessage &lastMessage)
|
||||
void PurpleTdClient::updateChatLastMessage(td::td_api::updateChatLastMessage &lastMessage)
|
||||
{
|
||||
ChatId chatId = getChatId(lastMessage);
|
||||
m_data.updateChatOrder(chatId, lastMessage.order_);
|
||||
for (auto &chatPosition: lastMessage.positions_)
|
||||
m_data.updateChatPosition(chatId, std::move(chatPosition));
|
||||
if (lastMessage.last_message_)
|
||||
saveChatLastMessage(m_data, chatId, getId(*lastMessage.last_message_));
|
||||
else {
|
||||
|
@ -90,7 +90,7 @@ private:
|
||||
// Login sequence end
|
||||
|
||||
void onIncomingMessage(td::td_api::object_ptr<td::td_api::message> message);
|
||||
void updateChatLastMessage(const td::td_api::updateChatLastMessage &lastMessage);
|
||||
void updateChatLastMessage(td::td_api::updateChatLastMessage &lastMessage);
|
||||
|
||||
void updateUserStatus(UserId userId, td::td_api::object_ptr<td::td_api::UserStatus> status);
|
||||
void updateUser(td::td_api::object_ptr<td::td_api::user> user);
|
||||
@ -145,7 +145,6 @@ private:
|
||||
std::vector<UserId> m_usersForNewPrivateChats;
|
||||
bool m_chatListReady = false;
|
||||
bool m_isProxyAdded = false;
|
||||
int64_t m_lastChatOrderOffset = 0;
|
||||
std::vector<PurpleRoomlist *> m_pendingRoomLists;
|
||||
td::td_api::object_ptr<td::td_api::proxy> m_addedProxy;
|
||||
td::td_api::object_ptr<td::td_api::proxies> m_proxies;
|
||||
|
Loading…
x
Reference in New Issue
Block a user