mirror of
https://github.com/ars3niy/tdlib-purple
synced 2025-08-22 09:57:52 +00:00
tdlib 1.7.8 compatibility: changed user, group and supergroup id to 64-bit
This commit is contained in:
parent
121c3dbddf
commit
ab5b78d018
@ -1,6 +1,7 @@
|
|||||||
#include "account-data.h"
|
#include "account-data.h"
|
||||||
#include "client-utils.h"
|
#include "client-utils.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#include "format.h"
|
||||||
#include <purple.h>
|
#include <purple.h>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
@ -419,8 +420,9 @@ void TdAccountData::addChat(TdChatPtr chat)
|
|||||||
auto pContact = std::find(m_contactUserIdsNoChat.begin(), m_contactUserIdsNoChat.end(),
|
auto pContact = std::find(m_contactUserIdsNoChat.begin(), m_contactUserIdsNoChat.end(),
|
||||||
getUserId(privType));
|
getUserId(privType));
|
||||||
if (pContact != m_contactUserIdsNoChat.end()) {
|
if (pContact != m_contactUserIdsNoChat.end()) {
|
||||||
purple_debug_misc(config::pluginId, "Private chat (id %" G_GINT64_FORMAT ") now known for user %d\n",
|
purpleDebug("Private chat (id {}) now known for user {}", {
|
||||||
chat->id_, privType.user_id_);
|
std::to_string(chat->id_), std::to_string(privType.user_id_)
|
||||||
|
});
|
||||||
m_contactUserIdsNoChat.erase(pContact);
|
m_contactUserIdsNoChat.erase(pContact);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -471,7 +473,7 @@ void TdAccountData::setContacts(const td::td_api::users &users)
|
|||||||
for (unsigned i = 0; i < users.user_ids_.size(); i++) {
|
for (unsigned i = 0; i < users.user_ids_.size(); i++) {
|
||||||
UserId userId = getUserId(users, i);
|
UserId userId = getUserId(users, i);
|
||||||
if (getPrivateChatByUserId(userId) == nullptr) {
|
if (getPrivateChatByUserId(userId) == nullptr) {
|
||||||
purple_debug_misc(config::pluginId, "Private chat not yet known for user %d\n", userId.value());
|
purpleDebug("Private chat not yet known for user {}", userId.value());
|
||||||
m_contactUserIdsNoChat.push_back(userId);
|
m_contactUserIdsNoChat.push_back(userId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -331,19 +331,17 @@ void updatePrivateChat(TdAccountData &account, const td::td_api::chat *chat, con
|
|||||||
|
|
||||||
static void updateGroupChat(TdAccountData &account, const td::td_api::chat &chat,
|
static void updateGroupChat(TdAccountData &account, const td::td_api::chat &chat,
|
||||||
const td::td_api::object_ptr<td::td_api::ChatMemberStatus> &groupStatus,
|
const td::td_api::object_ptr<td::td_api::ChatMemberStatus> &groupStatus,
|
||||||
const char *groupType, int32_t groupId)
|
const char *groupType, const std::string &groupId)
|
||||||
{
|
{
|
||||||
if (!isGroupMember(groupStatus)) {
|
if (!isGroupMember(groupStatus)) {
|
||||||
purple_debug_misc(config::pluginId, "Skipping %s %d because we are not a member\n",
|
purpleDebug("Skipping {} {} because we are not a member", {std::string(groupType), groupId});
|
||||||
groupType, groupId);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string chatName = getPurpleChatName(chat);
|
std::string chatName = getPurpleChatName(chat);
|
||||||
PurpleChat *purpleChat = purple_blist_find_chat(account.purpleAccount, chatName.c_str());
|
PurpleChat *purpleChat = purple_blist_find_chat(account.purpleAccount, chatName.c_str());
|
||||||
if (!purpleChat) {
|
if (!purpleChat) {
|
||||||
purple_debug_misc(config::pluginId, "Adding new chat for %s %d (%s)\n",
|
purpleDebug("Adding new chat for {} {} ({})", {std::string(groupType), groupId, chat.title_});
|
||||||
groupType, groupId, chat.title_.c_str());
|
|
||||||
purpleChat = purple_chat_new(account.purpleAccount, chat.title_.c_str(), getChatComponents(chat));
|
purpleChat = purple_chat_new(account.purpleAccount, chat.title_.c_str(), getChatComponents(chat));
|
||||||
purple_blist_add_chat(purpleChat, NULL, NULL);
|
purple_blist_add_chat(purpleChat, NULL, NULL);
|
||||||
} else {
|
} else {
|
||||||
@ -402,11 +400,11 @@ void updateBasicGroupChat(TdAccountData &account, BasicGroupId groupId)
|
|||||||
const td::td_api::chat *chat = account.getBasicGroupChatByGroup(groupId);
|
const td::td_api::chat *chat = account.getBasicGroupChatByGroup(groupId);
|
||||||
|
|
||||||
if (!group)
|
if (!group)
|
||||||
purple_debug_misc(config::pluginId, "Basic group %d does not exist yet\n", groupId.value());
|
purpleDebug("Basic group {} does not exist yet\n", groupId.value());
|
||||||
else if (!chat)
|
else if (!chat)
|
||||||
purple_debug_misc(config::pluginId, "Chat for basic group %d does not exist yet\n", groupId.value());
|
purpleDebug("Chat for basic group {} does not exist yet\n", groupId.value());
|
||||||
else
|
else
|
||||||
updateGroupChat(account, *chat, group->status_, "basic group", groupId.value());
|
updateGroupChat(account, *chat, group->status_, "basic group", std::to_string(groupId.value()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateSupergroupChat(TdAccountData &account, SupergroupId groupId)
|
void updateSupergroupChat(TdAccountData &account, SupergroupId groupId)
|
||||||
@ -415,11 +413,11 @@ void updateSupergroupChat(TdAccountData &account, SupergroupId groupId)
|
|||||||
const td::td_api::chat *chat = account.getSupergroupChatByGroup(groupId);
|
const td::td_api::chat *chat = account.getSupergroupChatByGroup(groupId);
|
||||||
|
|
||||||
if (!group)
|
if (!group)
|
||||||
purple_debug_misc(config::pluginId, "Supergroup %d does not exist yet\n", groupId.value());
|
purpleDebug("Supergroup {} does not exist yet\n", groupId.value());
|
||||||
else if (!chat)
|
else if (!chat)
|
||||||
purple_debug_misc(config::pluginId, "Chat for supergroup %d does not exist yet\n", groupId.value());
|
purpleDebug("Chat for supergroup {} does not exist yet\n", groupId.value());
|
||||||
else
|
else
|
||||||
updateGroupChat(account, *chat, group->status_, "supergroup", groupId.value());
|
updateGroupChat(account, *chat, group->status_, "supergroup", std::to_string(groupId.value()));
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string lastMessageSetting(ChatId chatId)
|
static std::string lastMessageSetting(ChatId chatId)
|
||||||
|
@ -25,3 +25,9 @@ std::string formatDuration(int32_t seconds)
|
|||||||
// TRANSLATOR: Time format. For HH:MM:SS use "{:02}:{:02}:{:02}" without the quotes.
|
// TRANSLATOR: Time format. For HH:MM:SS use "{:02}:{:02}:{:02}" without the quotes.
|
||||||
return fmt::format(_("{:02}:{:02}:{:02}"), hours, minutes, seconds);
|
return fmt::format(_("{:02}:{:02}:{:02}"), hours, minutes, seconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void purpleDebug(const char *fmt, std::initializer_list<std::string> args)
|
||||||
|
{
|
||||||
|
std::string message = formatMessage(fmt, args);
|
||||||
|
purple_debug_misc(config::pluginId, "%s\n", message.c_str());
|
||||||
|
}
|
||||||
|
11
format.h
11
format.h
@ -2,7 +2,9 @@
|
|||||||
#define _FORMAT_H
|
#define _FORMAT_H
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <purple.h>
|
||||||
#include "translate.h"
|
#include "translate.h"
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
std::string formatMessage(const char *fmt, std::initializer_list<std::string> args);
|
std::string formatMessage(const char *fmt, std::initializer_list<std::string> args);
|
||||||
std::string formatMessage(const char *fmt, const std::string &s);
|
std::string formatMessage(const char *fmt, const std::string &s);
|
||||||
@ -15,4 +17,13 @@ std::string formatMessage(const char *fmt, T arg)
|
|||||||
|
|
||||||
std::string formatDuration(int32_t seconds);
|
std::string formatDuration(int32_t seconds);
|
||||||
|
|
||||||
|
void purpleDebug(const char *fmt, std::initializer_list<std::string> args);
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
void purpleDebug(const char *fmt, T arg)
|
||||||
|
{
|
||||||
|
std::string message = formatMessage(fmt, arg);
|
||||||
|
purple_debug_misc(config::pluginId, "%s\n", message.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -37,7 +37,7 @@ public: \
|
|||||||
bool operator<(const classname &other) const { return (value() < other.value()); } \
|
bool operator<(const classname &other) const { return (value() < other.value()); } \
|
||||||
static const classname invalid;
|
static const classname invalid;
|
||||||
|
|
||||||
DEFINE_ID_CLASS(UserId, int32_t)
|
DEFINE_ID_CLASS(UserId, int64_t)
|
||||||
friend UserId getId(const td::td_api::user &user);
|
friend UserId getId(const td::td_api::user &user);
|
||||||
friend UserId getUserId(const td::td_api::chatTypePrivate &privType);
|
friend UserId getUserId(const td::td_api::chatTypePrivate &privType);
|
||||||
friend UserId getUserId(const td::td_api::chatMember &member);
|
friend UserId getUserId(const td::td_api::chatMember &member);
|
||||||
@ -64,13 +64,13 @@ DEFINE_ID_CLASS(ChatId, int64_t)
|
|||||||
friend ChatId stringToChatId(const char *s);
|
friend ChatId stringToChatId(const char *s);
|
||||||
};
|
};
|
||||||
|
|
||||||
DEFINE_ID_CLASS(BasicGroupId, int32_t)
|
DEFINE_ID_CLASS(BasicGroupId, int64_t)
|
||||||
friend BasicGroupId getId(const td::td_api::basicGroup &group);
|
friend BasicGroupId getId(const td::td_api::basicGroup &group);
|
||||||
friend BasicGroupId getBasicGroupId(const td::td_api::updateBasicGroupFullInfo &update);
|
friend BasicGroupId getBasicGroupId(const td::td_api::updateBasicGroupFullInfo &update);
|
||||||
friend BasicGroupId getBasicGroupId(const td::td_api::chatTypeBasicGroup &update);
|
friend BasicGroupId getBasicGroupId(const td::td_api::chatTypeBasicGroup &update);
|
||||||
};
|
};
|
||||||
|
|
||||||
DEFINE_ID_CLASS(SupergroupId, int32_t)
|
DEFINE_ID_CLASS(SupergroupId, int64_t)
|
||||||
friend SupergroupId getId(const td::td_api::supergroup &group);
|
friend SupergroupId getId(const td::td_api::supergroup &group);
|
||||||
friend SupergroupId getSupergroupId(const td::td_api::updateSupergroupFullInfo &update);
|
friend SupergroupId getSupergroupId(const td::td_api::updateSupergroupFullInfo &update);
|
||||||
friend SupergroupId getSupergroupId(const td::td_api::chatTypeSupergroup &update);
|
friend SupergroupId getSupergroupId(const td::td_api::chatTypeSupergroup &update);
|
||||||
|
@ -218,10 +218,11 @@ void PurpleTdClient::processUpdate(td::td_api::Object &update)
|
|||||||
case td::td_api::updateCall::ID: {
|
case td::td_api::updateCall::ID: {
|
||||||
auto &callUpdate = static_cast<const td::td_api::updateCall &>(update);
|
auto &callUpdate = static_cast<const td::td_api::updateCall &>(update);
|
||||||
if (callUpdate.call_) {
|
if (callUpdate.call_) {
|
||||||
purple_debug_misc(config::pluginId, "Call update: id %d, outgoing=%d, user id %d, state %d\n",
|
purpleDebug("Call update: id {}, outgoing={}, user id {}, state {}", {
|
||||||
callUpdate.call_->id_, callUpdate.call_->user_id_,
|
std::to_string(callUpdate.call_->id_),
|
||||||
(int)callUpdate.call_->is_outgoing_,
|
std::to_string(callUpdate.call_->user_id_),
|
||||||
callUpdate.call_->state_ ? callUpdate.call_->state_->get_id() : 0);
|
std::to_string((int)callUpdate.call_->is_outgoing_),
|
||||||
|
std::to_string(callUpdate.call_->state_ ? callUpdate.call_->state_->get_id() : 0)});
|
||||||
updateCall(*callUpdate.call_, m_data, m_transceiver);
|
updateCall(*callUpdate.call_, m_data, m_transceiver);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -696,7 +697,7 @@ void PurpleTdClient::requestMissingPrivateChats()
|
|||||||
} else {
|
} else {
|
||||||
UserId userId = m_usersForNewPrivateChats.back();
|
UserId userId = m_usersForNewPrivateChats.back();
|
||||||
m_usersForNewPrivateChats.pop_back();
|
m_usersForNewPrivateChats.pop_back();
|
||||||
purple_debug_misc(config::pluginId, "Requesting private chat for user id %d\n", userId.value());
|
purpleDebug("Requesting private chat for user id {}", userId.value());
|
||||||
td::td_api::object_ptr<td::td_api::createPrivateChat> createChat =
|
td::td_api::object_ptr<td::td_api::createPrivateChat> createChat =
|
||||||
td::td_api::make_object<td::td_api::createPrivateChat>(userId.value(), false);
|
td::td_api::make_object<td::td_api::createPrivateChat>(userId.value(), false);
|
||||||
m_transceiver.sendQuery(std::move(createChat), &PurpleTdClient::loginCreatePrivateChatResponse);
|
m_transceiver.sendQuery(std::move(createChat), &PurpleTdClient::loginCreatePrivateChatResponse);
|
||||||
@ -1031,7 +1032,7 @@ int PurpleTdClient::sendMessage(const char *buddyName, const char *message)
|
|||||||
// Message shall not be echoed: tdlib will shortly present it as a new message and it will be displayed then
|
// Message shall not be echoed: tdlib will shortly present it as a new message and it will be displayed then
|
||||||
return 0;
|
return 0;
|
||||||
} else if (privateUser) {
|
} else if (privateUser) {
|
||||||
purple_debug_misc(config::pluginId, "Requesting private chat for user id %d\n", privateUser->id_);
|
purpleDebug("Requesting private chat for user id {}", privateUser->id_);
|
||||||
td::td_api::object_ptr<td::td_api::createPrivateChat> createChat =
|
td::td_api::object_ptr<td::td_api::createPrivateChat> createChat =
|
||||||
td::td_api::make_object<td::td_api::createPrivateChat>(privateUser->id_, false);
|
td::td_api::make_object<td::td_api::createPrivateChat>(privateUser->id_, false);
|
||||||
uint64_t requestId = m_transceiver.sendQuery(std::move(createChat), &PurpleTdClient::sendMessageCreatePrivateChatResponse);
|
uint64_t requestId = m_transceiver.sendQuery(std::move(createChat), &PurpleTdClient::sendMessageCreatePrivateChatResponse);
|
||||||
@ -1102,9 +1103,6 @@ void PurpleTdClient::updateUser(td::td_api::object_ptr<td::td_api::user> userInf
|
|||||||
}
|
}
|
||||||
|
|
||||||
UserId userId = getId(*userInfo);
|
UserId userId = getId(*userInfo);
|
||||||
purple_debug_misc(config::pluginId, "Update user: %d '%s' '%s'\n", userId.value(),
|
|
||||||
userInfo->first_name_.c_str(), userInfo->last_name_.c_str());
|
|
||||||
|
|
||||||
m_data.updateUser(std::move(userInfo));
|
m_data.updateUser(std::move(userInfo));
|
||||||
|
|
||||||
// For chats, find_chat doesn't work if account is not yet connected, so just in case, don't
|
// For chats, find_chat doesn't work if account is not yet connected, so just in case, don't
|
||||||
@ -1175,7 +1173,6 @@ void PurpleTdClient::updateGroup(td::td_api::object_ptr<td::td_api::basicGroup>
|
|||||||
purple_debug_warning(config::pluginId, "updateBasicGroup with null group\n");
|
purple_debug_warning(config::pluginId, "updateBasicGroup with null group\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
purple_debug_misc(config::pluginId, "updateBasicGroup id=%d\n", group->id_);
|
|
||||||
|
|
||||||
BasicGroupId id = getId(*group);
|
BasicGroupId id = getId(*group);
|
||||||
m_data.updateBasicGroup(std::move(group));
|
m_data.updateBasicGroup(std::move(group));
|
||||||
@ -1193,7 +1190,6 @@ void PurpleTdClient::updateSupergroup(td::td_api::object_ptr<td::td_api::supergr
|
|||||||
purple_debug_warning(config::pluginId, "updateSupergroup with null group\n");
|
purple_debug_warning(config::pluginId, "updateSupergroup with null group\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
purple_debug_misc(config::pluginId, "updateSupergroup id=%d\n", group->id_);
|
|
||||||
|
|
||||||
SupergroupId id = getId(*group);
|
SupergroupId id = getId(*group);
|
||||||
m_data.updateSupergroup(std::move(group));
|
m_data.updateSupergroup(std::move(group));
|
||||||
@ -1213,8 +1209,10 @@ void PurpleTdClient::updateChat(const td::td_api::chat *chat)
|
|||||||
BasicGroupId basicGroupId = getBasicGroupId(*chat);
|
BasicGroupId basicGroupId = getBasicGroupId(*chat);
|
||||||
SupergroupId supergroupId = getSupergroupId(*chat);
|
SupergroupId supergroupId = getSupergroupId(*chat);
|
||||||
SecretChatId secretChatId = getSecretChatId(*chat);
|
SecretChatId secretChatId = getSecretChatId(*chat);
|
||||||
purple_debug_misc(config::pluginId, "Update chat: %" G_GINT64_FORMAT " private user=%d basic group=%d supergroup=%d\n",
|
purpleDebug("Update chat: {} private user={} basic group={} supergroup={}", {
|
||||||
chat->id_, privateChatUser ? privateChatUser->id_ : 0, basicGroupId.value(), supergroupId.value());
|
std::to_string(chat->id_), std::to_string(privateChatUser ? privateChatUser->id_ : 0),
|
||||||
|
std::to_string(basicGroupId.value()), std::to_string(supergroupId.value())
|
||||||
|
});
|
||||||
|
|
||||||
// For secret chats, chat photo is same as user profile photo, so hopefully already downloaded.
|
// For secret chats, chat photo is same as user profile photo, so hopefully already downloaded.
|
||||||
// But if not (such as when creating secret chat while downloading new photo for the user),
|
// But if not (such as when creating secret chat while downloading new photo for the user),
|
||||||
@ -1314,21 +1312,23 @@ void PurpleTdClient::handleUserChatAction(const td::td_api::updateUserChatAction
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chatUserId != getUserId(updateChatAction))
|
if (chatUserId != getUserId(updateChatAction)) {
|
||||||
purple_debug_warning(config::pluginId, "Got user action for private chat %" G_GINT64_FORMAT " (with user %d) for another user %d\n",
|
purpleDebug("Got user action for private chat {} (with user {}) for another user {}", {
|
||||||
updateChatAction.chat_id_, chatUserId.value(), updateChatAction.user_id_);
|
std::to_string(updateChatAction.chat_id_), std::to_string(chatUserId.value()),
|
||||||
else if (updateChatAction.action_) {
|
std::to_string(updateChatAction.user_id_)
|
||||||
|
});
|
||||||
|
} else if (updateChatAction.action_) {
|
||||||
if (updateChatAction.action_->get_id() == td::td_api::chatActionCancel::ID) {
|
if (updateChatAction.action_->get_id() == td::td_api::chatActionCancel::ID) {
|
||||||
purple_debug_misc(config::pluginId, "User (id %d) stopped chat action\n",
|
purpleDebug("User (id {}) stopped chat action", updateChatAction.user_id_);
|
||||||
updateChatAction.user_id_);
|
|
||||||
showUserChatAction(getUserId(updateChatAction), false);
|
showUserChatAction(getUserId(updateChatAction), false);
|
||||||
} else if (updateChatAction.action_->get_id() == td::td_api::chatActionStartPlayingGame::ID) {
|
} else if (updateChatAction.action_->get_id() == td::td_api::chatActionStartPlayingGame::ID) {
|
||||||
purple_debug_misc(config::pluginId, "User (id %d): treating chatActionStartPlayingGame as cancel\n",
|
purpleDebug("User (id %d): treating chatActionStartPlayingGame as cancel",
|
||||||
updateChatAction.user_id_);
|
updateChatAction.user_id_);
|
||||||
showUserChatAction(getUserId(updateChatAction), false);
|
showUserChatAction(getUserId(updateChatAction), false);
|
||||||
} else {
|
} else {
|
||||||
purple_debug_misc(config::pluginId, "User (id %d) started chat action (id %d)\n",
|
purpleDebug("User (id {}) started chat action (id {})", {
|
||||||
updateChatAction.user_id_, updateChatAction.action_->get_id());
|
std::to_string(updateChatAction.user_id_), std::to_string(updateChatAction.action_->get_id())
|
||||||
|
});
|
||||||
showUserChatAction(getUserId(updateChatAction), true);
|
showUserChatAction(getUserId(updateChatAction), true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1430,7 +1430,7 @@ void PurpleTdClient::addBuddySearchChatResponse(uint64_t requestId, td::td_api::
|
|||||||
void PurpleTdClient::addContactById(UserId userId, const std::string &phoneNumber, const std::string &alias,
|
void PurpleTdClient::addContactById(UserId userId, const std::string &phoneNumber, const std::string &alias,
|
||||||
const std::string &groupName)
|
const std::string &groupName)
|
||||||
{
|
{
|
||||||
purple_debug_misc(config::pluginId, "Adding contact: id=%d alias=%s\n", userId.value(), alias.c_str());
|
purpleDebug("Adding contact: id={} alias={}", {std::to_string(userId.value()), alias});
|
||||||
std::string firstName, lastName;
|
std::string firstName, lastName;
|
||||||
getNamesFromAlias(alias.c_str(), firstName, lastName);
|
getNamesFromAlias(alias.c_str(), firstName, lastName);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user