mirror of
https://github.com/ars3niy/tdlib-purple
synced 2025-09-01 14:35:11 +00:00
Implemented user information
This commit is contained in:
@@ -255,6 +255,18 @@ const td::td_api::user *TdAccountData::getUserByPrivateChat(const td::td_api::ch
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void TdAccountData::getUsersByDisplayName(const char *displayName,
|
||||
std::vector<const td::td_api::user*> &users)
|
||||
{
|
||||
users.clear();
|
||||
if (!displayName || (*displayName == '\0'))
|
||||
return;
|
||||
|
||||
for (const UserMap::value_type &entry: m_userInfo)
|
||||
if (getDisplayName(entry.second.get()) == displayName)
|
||||
users.push_back(entry.second.get());
|
||||
}
|
||||
|
||||
const td::td_api::basicGroup *TdAccountData::getBasicGroup(int32_t groupId) const
|
||||
{
|
||||
auto it = m_groups.find(groupId);
|
||||
|
@@ -90,6 +90,8 @@ public:
|
||||
const td::td_api::user *getUser(int32_t userId) const;
|
||||
const td::td_api::user *getUserByPhone(const char *phoneNumber) const;
|
||||
const td::td_api::user *getUserByPrivateChat(const td::td_api::chat &chat);
|
||||
void getUsersByDisplayName(const char *displayName,
|
||||
std::vector<const td::td_api::user*> &users);
|
||||
const td::td_api::basicGroup *getBasicGroup(int32_t groupId) const;
|
||||
const td::td_api::basicGroupFullInfo *getBasicGroupInfo(int32_t groupId) const;
|
||||
const td::td_api::supergroup *getSupergroup(int32_t groupId) const;
|
||||
@@ -140,8 +142,8 @@ private:
|
||||
|
||||
using ChatMap = std::map<int64_t, ChatInfo>;
|
||||
using UserMap = std::map<int32_t, TdUserPtr>;
|
||||
std::map<int32_t, TdUserPtr> m_userInfo;
|
||||
std::map<int64_t, ChatInfo> m_chatInfo;
|
||||
UserMap m_userInfo;
|
||||
ChatMap m_chatInfo;
|
||||
std::map<int32_t, GroupInfo> m_groups;
|
||||
std::map<int32_t, TdSupergroupPtr> m_supergroups;
|
||||
int m_lastChatPurpleId = 0;
|
||||
|
@@ -65,12 +65,26 @@ const char *getPurpleStatusId(const td::td_api::UserStatus &tdStatus)
|
||||
return purple_primitive_get_id_from_type(PURPLE_STATUS_OFFLINE);
|
||||
}
|
||||
|
||||
std::string getPurpleUserName(const td::td_api::user &user)
|
||||
std::string getPurpleBuddyName(const td::td_api::user &user)
|
||||
{
|
||||
// Prepend "id" so it's not accidentally equal to our phone number which is account name
|
||||
return "id" + std::to_string(user.id_);
|
||||
}
|
||||
|
||||
void getUsersByPurpleName(const char *username, std::vector<const td::td_api::user*> &users,
|
||||
TdAccountData &accountData)
|
||||
{
|
||||
int32_t userId = stringToUserId(username);
|
||||
|
||||
if (userId != 0) {
|
||||
users.clear();
|
||||
const td::td_api::user *user = accountData.getUser(userId);
|
||||
if (user)
|
||||
users.push_back(user);
|
||||
} else
|
||||
accountData.getUsersByDisplayName(username, users);
|
||||
}
|
||||
|
||||
PurpleConversation *getImConversation(PurpleAccount *account, const char *username)
|
||||
{
|
||||
PurpleConversation *conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, username, account);
|
||||
@@ -301,7 +315,7 @@ void showMessageText(PurpleAccount *account, const td::td_api::chat &chat, const
|
||||
|
||||
const td::td_api::user *privateUser = accountData.getUserByPrivateChat(chat);
|
||||
if (privateUser) {
|
||||
std::string userName = getPurpleUserName(*privateUser);
|
||||
std::string userName = getPurpleBuddyName(*privateUser);
|
||||
showMessageTextIm(account, userName.c_str(), text, notification, message.timestamp, flags);
|
||||
}
|
||||
|
||||
@@ -416,7 +430,7 @@ void setChatMembers(PurpleConvChat *purpleChat, const td::td_api::basicGroupFull
|
||||
if (!user)
|
||||
continue;
|
||||
|
||||
std::string userName = getPurpleUserName(*user);
|
||||
std::string userName = getPurpleBuddyName(*user);
|
||||
const char *phoneNumber = getCanonicalPhoneNumber(user->phone_number_.c_str());
|
||||
if (purple_find_buddy(account, userName.c_str()))
|
||||
// libpurple will be able to map user name to alias because there is a buddy
|
||||
|
@@ -27,7 +27,9 @@ public:
|
||||
|
||||
std::string messageTypeToString(const td::td_api::MessageContent &content);
|
||||
const char *getPurpleStatusId(const td::td_api::UserStatus &tdStatus);
|
||||
std::string getPurpleUserName(const td::td_api::user &user);
|
||||
std::string getPurpleBuddyName(const td::td_api::user &user);
|
||||
void getUsersByPurpleName(const char *username, std::vector<const td::td_api::user*> &users,
|
||||
TdAccountData &accountData);
|
||||
PurpleConversation *getImConversation(PurpleAccount *account, const char *username);
|
||||
PurpleConvChat *getChatConversation(PurpleAccount *account, const td::td_api::chat &chat,
|
||||
int chatPurpleId, TdAccountData &accountData);
|
||||
|
@@ -406,7 +406,7 @@ void PurpleTdClient::loginCreatePrivateChatResponse(uint64_t requestId, td::td_a
|
||||
|
||||
void PurpleTdClient::updatePrivateChat(const td::td_api::chat &chat, const td::td_api::user &user)
|
||||
{
|
||||
std::string purpleUserName = getPurpleUserName(user);
|
||||
std::string purpleUserName = getPurpleBuddyName(user);
|
||||
|
||||
PurpleBuddy *buddy = purple_find_buddy(m_account, purpleUserName.c_str());
|
||||
if (buddy == NULL) {
|
||||
@@ -525,7 +525,7 @@ void PurpleTdClient::updatePurpleChatListAndReportConnected()
|
||||
const td::td_api::user *user = m_data.getUserByPrivateChat(*chat);
|
||||
if (user) {
|
||||
updatePrivateChat(*chat, *user);
|
||||
std::string userName = getPurpleUserName(*user);
|
||||
std::string userName = getPurpleBuddyName(*user);
|
||||
purple_prpl_got_user_status(m_account, userName.c_str(),
|
||||
getPurpleStatusId(*user->status_), NULL);
|
||||
}
|
||||
@@ -899,7 +899,7 @@ void PurpleTdClient::updateUserStatus(uint32_t userId, td::td_api::object_ptr<td
|
||||
{
|
||||
const td::td_api::user *user = m_data.getUser(userId);
|
||||
if (user) {
|
||||
std::string userName = getPurpleUserName(*user);
|
||||
std::string userName = getPurpleBuddyName(*user);
|
||||
purple_prpl_got_user_status(m_account, userName.c_str(), getPurpleStatusId(*status), NULL);
|
||||
}
|
||||
}
|
||||
@@ -1030,7 +1030,7 @@ void PurpleTdClient::showUserChatAction(int32_t userId, bool isTyping)
|
||||
{
|
||||
const td::td_api::user *user = m_data.getUser(userId);
|
||||
if (user) {
|
||||
std::string userName = getPurpleUserName(*user);
|
||||
std::string userName = getPurpleBuddyName(*user);
|
||||
if (isTyping)
|
||||
serv_got_typing(purple_account_get_connection(m_account),
|
||||
userName.c_str(), REMOTE_TYPING_NOTICE_TIMEOUT,
|
||||
@@ -1223,3 +1223,8 @@ void PurpleTdClient::removeTempFile(int64_t messageId)
|
||||
remove(path.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void PurpleTdClient::getUsers(const char *username, std::vector<const td::td_api::user *> &users)
|
||||
{
|
||||
getUsersByPurpleName(username, users, m_data);
|
||||
}
|
||||
|
@@ -17,6 +17,7 @@ public:
|
||||
bool joinChat(const char *chatName);
|
||||
int sendGroupMessage(int purpleChatId, const char *message);
|
||||
bool joinChatByLink(const char *inviteLink);
|
||||
void getUsers(const char *username, std::vector<const td::td_api::user *> &users);
|
||||
private:
|
||||
using TdObjectPtr = td::td_api::object_ptr<td::td_api::Object>;
|
||||
using ResponseCb = void (PurpleTdClient::*)(uint64_t requestId, TdObjectPtr object);
|
||||
|
@@ -114,8 +114,27 @@ static unsigned int tgprpl_send_typing (PurpleConnection *gc, const char *who, P
|
||||
|
||||
static void tgprpl_info_show (PurpleConnection *gc, const char *who)
|
||||
{
|
||||
//tgl_do_get_channel_info (gc_get_tls (gc), P->id, FALSE, tgp_info_load_channel_done, P);
|
||||
//tgl_do_get_user_info (gc_get_tls (gc), P->id, 0, tgp_info_load_user_done, P);
|
||||
PurpleTdClient *tdClient = static_cast<PurpleTdClient *>(purple_connection_get_protocol_data(gc));
|
||||
std::vector<const td::td_api::user *> users;
|
||||
tdClient->getUsers(who, users);
|
||||
|
||||
PurpleNotifyUserInfo *info = purple_notify_user_info_new();
|
||||
if (users.empty())
|
||||
purple_notify_user_info_add_section_header(info, _("User not found"));
|
||||
|
||||
for (const td::td_api::user *user: users) {
|
||||
if (purple_notify_user_info_get_entries(info))
|
||||
purple_notify_user_info_add_section_break(info);
|
||||
|
||||
purple_notify_user_info_add_pair(info, _("First name"), user->first_name_.c_str());
|
||||
purple_notify_user_info_add_pair(info, _("Last name"), user->last_name_.c_str());
|
||||
if (!user->username_.empty())
|
||||
purple_notify_user_info_add_pair(info, _("Username"), user->username_.c_str());
|
||||
if (!user->phone_number_.empty())
|
||||
purple_notify_user_info_add_pair(info, _("Phone number"), user->phone_number_.c_str());
|
||||
}
|
||||
|
||||
purple_notify_userinfo(gc, who, info, NULL, NULL);
|
||||
}
|
||||
|
||||
static void tgprpl_set_status (PurpleAccount *acct, PurpleStatus *status)
|
||||
|
@@ -520,10 +520,35 @@ void *purple_notify_message(void *handle, PurpleNotifyMsgType type,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PurpleNotifyUserInfo *purple_notify_user_info_new(void)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void purple_notify_user_info_add_section_header(PurpleNotifyUserInfo *user_info, const char *label)
|
||||
{
|
||||
}
|
||||
|
||||
GList *purple_notify_user_info_get_entries(PurpleNotifyUserInfo *user_info)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void purple_notify_user_info_add_section_break(PurpleNotifyUserInfo *user_info)
|
||||
{
|
||||
}
|
||||
|
||||
void purple_notify_user_info_add_pair(PurpleNotifyUserInfo *user_info, const char *label, const char *value)
|
||||
{
|
||||
}
|
||||
|
||||
void *purple_notify_userinfo(PurpleConnection *gc, const char *who,
|
||||
PurpleNotifyUserInfo *user_info, PurpleNotifyCloseCallback cb,
|
||||
gpointer user_data)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gboolean purple_plugin_register(PurplePlugin *plugin)
|
||||
{
|
||||
// TODO maybe event
|
||||
|
Reference in New Issue
Block a user