mirror of
https://github.com/ars3niy/tdlib-purple
synced 2025-08-29 13:07:39 +00:00
tdlib 1.7.4 compatibility: chat members can be not only users but also chats
Ignore non-user members: they are only possible in supergroups and then only as Left or Banned.
This commit is contained in:
parent
b2432c3cae
commit
121c3dbddf
@ -111,6 +111,19 @@ bool isGroupMember(const td::td_api::object_ptr<td::td_api::ChatMemberStatus> &s
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isSameUser(const td::td_api::MessageSender &member1, const td::td_api::MessageSender &member2)
|
||||||
|
{
|
||||||
|
if ((member1.get_id() == td::td_api::messageSenderUser::ID) &&
|
||||||
|
(member2.get_id() == td::td_api::messageSenderUser::ID))
|
||||||
|
{
|
||||||
|
const td::td_api::messageSenderUser &user1 = static_cast<const td::td_api::messageSenderUser &>(member1);
|
||||||
|
const td::td_api::messageSenderUser &user2 = static_cast<const td::td_api::messageSenderUser &>(member2);
|
||||||
|
return (user1.user_id_ == user2.user_id_);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
static std::string makeDisplayName(const td::td_api::user &user)
|
static std::string makeDisplayName(const td::td_api::user &user)
|
||||||
{
|
{
|
||||||
std::string result = makeBasicDisplayName(user);
|
std::string result = makeBasicDisplayName(user);
|
||||||
|
@ -32,6 +32,7 @@ BasicGroupId getBasicGroupId(const td::td_api::chat &chat);
|
|||||||
SupergroupId getSupergroupId(const td::td_api::chat &chat);
|
SupergroupId getSupergroupId(const td::td_api::chat &chat);
|
||||||
SecretChatId getSecretChatId(const td::td_api::chat &chat);
|
SecretChatId getSecretChatId(const td::td_api::chat &chat);
|
||||||
bool isGroupMember(const td::td_api::object_ptr<td::td_api::ChatMemberStatus> &status);
|
bool isGroupMember(const td::td_api::object_ptr<td::td_api::ChatMemberStatus> &status);
|
||||||
|
bool isSameUser(const td::td_api::MessageSender &member1, const td::td_api::MessageSender &member2);
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
CHAT_HISTORY_REQUEST_LIMIT = 50,
|
CHAT_HISTORY_REQUEST_LIMIT = 50,
|
||||||
|
@ -45,7 +45,11 @@ UserId getUserId(const td::td_api::chatTypePrivate &privType)
|
|||||||
|
|
||||||
UserId getUserId(const td::td_api::chatMember &member)
|
UserId getUserId(const td::td_api::chatMember &member)
|
||||||
{
|
{
|
||||||
return UserId(member.user_id_);
|
if (member.member_id_ && (member.member_id_->get_id() == td::td_api::messageSenderUser::ID)) {
|
||||||
|
const td::td_api::messageSenderUser &userInfo = static_cast<const td::td_api::messageSenderUser &>(*member.member_id_);
|
||||||
|
return UserId(userInfo.user_id_);
|
||||||
|
}
|
||||||
|
return UserId::invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
UserId getUserId(const td::td_api::call &call)
|
UserId getUserId(const td::td_api::call &call)
|
||||||
|
@ -794,15 +794,16 @@ void PurpleTdClient::supergroupAdministratorsResponse(uint64_t requestId, td::td
|
|||||||
if (object && (object->get_id() == td::td_api::chatMembers::ID)) {
|
if (object && (object->get_id() == td::td_api::chatMembers::ID)) {
|
||||||
td::td_api::object_ptr<td::td_api::chatMembers> newMembers =
|
td::td_api::object_ptr<td::td_api::chatMembers> newMembers =
|
||||||
td::move_tl_object_as<td::td_api::chatMembers>(object);
|
td::move_tl_object_as<td::td_api::chatMembers>(object);
|
||||||
for (auto &pMember: newMembers->members_) {
|
for (auto &pNewMember: newMembers->members_) {
|
||||||
if (! pMember) continue;
|
if (! pNewMember || !pNewMember->member_id_) continue;
|
||||||
int32_t userId = pMember->user_id_;
|
const td::td_api::MessageSender *pNewMemberInfo = pNewMember->member_id_.get();
|
||||||
if (std::find_if(members->members_.begin(), members->members_.end(),
|
if (std::find_if(members->members_.begin(), members->members_.end(),
|
||||||
[userId](const td::td_api::object_ptr<td::td_api::chatMember> &pMember) {
|
[pNewMemberInfo](const td::td_api::object_ptr<td::td_api::chatMember> &pExistingMember) {
|
||||||
return (pMember && (pMember->user_id_ == userId));
|
return pExistingMember && pExistingMember->member_id_ &&
|
||||||
|
isSameUser(*pExistingMember->member_id_, *pNewMemberInfo);
|
||||||
}) == members->members_.end())
|
}) == members->members_.end())
|
||||||
{
|
{
|
||||||
members->members_.push_back(std::move(pMember));
|
members->members_.push_back(std::move(pNewMember));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -180,21 +180,21 @@ TEST_F(GroupChatTest, ExistingBasicGroupReceiveMessageAtLogin_WithMemberList_Rem
|
|||||||
prpl.discardEvents();
|
prpl.discardEvents();
|
||||||
|
|
||||||
std::vector<object_ptr<chatMember>> members;
|
std::vector<object_ptr<chatMember>> members;
|
||||||
members.push_back(make_object<chatMember>(
|
members.push_back(makeChatMember(
|
||||||
userIds[0],
|
userIds[0],
|
||||||
userIds[1],
|
userIds[1],
|
||||||
0,
|
0,
|
||||||
make_object<chatMemberStatusMember>(),
|
make_object<chatMemberStatusMember>(),
|
||||||
nullptr
|
nullptr
|
||||||
));
|
));
|
||||||
members.push_back(make_object<chatMember>(
|
members.push_back(makeChatMember(
|
||||||
userIds[1],
|
userIds[1],
|
||||||
userIds[1],
|
userIds[1],
|
||||||
0,
|
0,
|
||||||
make_object<chatMemberStatusCreator>("", true),
|
make_object<chatMemberStatusCreator>("", true),
|
||||||
nullptr
|
nullptr
|
||||||
));
|
));
|
||||||
members.push_back(make_object<chatMember>(
|
members.push_back(makeChatMember(
|
||||||
selfId,
|
selfId,
|
||||||
userIds[1],
|
userIds[1],
|
||||||
0,
|
0,
|
||||||
@ -307,21 +307,21 @@ TEST_F(GroupChatTest, SendMessageWithMemberList)
|
|||||||
constexpr int purpleChatId = 1;
|
constexpr int purpleChatId = 1;
|
||||||
|
|
||||||
std::vector<object_ptr<chatMember>> members;
|
std::vector<object_ptr<chatMember>> members;
|
||||||
members.push_back(make_object<chatMember>(
|
members.push_back(makeChatMember(
|
||||||
userIds[0],
|
userIds[0],
|
||||||
userIds[1],
|
userIds[1],
|
||||||
0,
|
0,
|
||||||
make_object<chatMemberStatusMember>(),
|
make_object<chatMemberStatusMember>(),
|
||||||
nullptr
|
nullptr
|
||||||
));
|
));
|
||||||
members.push_back(make_object<chatMember>(
|
members.push_back(makeChatMember(
|
||||||
userIds[1],
|
userIds[1],
|
||||||
userIds[1],
|
userIds[1],
|
||||||
0,
|
0,
|
||||||
make_object<chatMemberStatusCreator>("", true),
|
make_object<chatMemberStatusCreator>("", true),
|
||||||
nullptr
|
nullptr
|
||||||
));
|
));
|
||||||
members.push_back(make_object<chatMember>(
|
members.push_back(makeChatMember(
|
||||||
selfId,
|
selfId,
|
||||||
userIds[1],
|
userIds[1],
|
||||||
0,
|
0,
|
||||||
@ -485,21 +485,21 @@ TEST_F(GroupChatTest, JoinBasicGroupByInviteLink)
|
|||||||
tgl.update(standardUpdateUser(0));
|
tgl.update(standardUpdateUser(0));
|
||||||
tgl.update(standardUpdateUser(1));
|
tgl.update(standardUpdateUser(1));
|
||||||
std::vector<object_ptr<chatMember>> members;
|
std::vector<object_ptr<chatMember>> members;
|
||||||
members.push_back(make_object<chatMember>(
|
members.push_back(makeChatMember(
|
||||||
userIds[0],
|
userIds[0],
|
||||||
userIds[1],
|
userIds[1],
|
||||||
0,
|
0,
|
||||||
make_object<chatMemberStatusMember>(),
|
make_object<chatMemberStatusMember>(),
|
||||||
nullptr
|
nullptr
|
||||||
));
|
));
|
||||||
members.push_back(make_object<chatMember>(
|
members.push_back(makeChatMember(
|
||||||
userIds[1],
|
userIds[1],
|
||||||
userIds[1],
|
userIds[1],
|
||||||
0,
|
0,
|
||||||
make_object<chatMemberStatusCreator>("", true),
|
make_object<chatMemberStatusCreator>("", true),
|
||||||
nullptr
|
nullptr
|
||||||
));
|
));
|
||||||
members.push_back(make_object<chatMember>(
|
members.push_back(makeChatMember(
|
||||||
selfId,
|
selfId,
|
||||||
userIds[1],
|
userIds[1],
|
||||||
0,
|
0,
|
||||||
@ -736,21 +736,21 @@ TEST_F(GroupChatTest, UsersWithSameName)
|
|||||||
constexpr int purpleChatId = 1;
|
constexpr int purpleChatId = 1;
|
||||||
|
|
||||||
std::vector<object_ptr<chatMember>> members;
|
std::vector<object_ptr<chatMember>> members;
|
||||||
members.push_back(make_object<chatMember>(
|
members.push_back(makeChatMember(
|
||||||
userIds[0],
|
userIds[0],
|
||||||
userIds[1],
|
userIds[1],
|
||||||
0,
|
0,
|
||||||
make_object<chatMemberStatusMember>(),
|
make_object<chatMemberStatusMember>(),
|
||||||
nullptr
|
nullptr
|
||||||
));
|
));
|
||||||
members.push_back(make_object<chatMember>(
|
members.push_back(makeChatMember(
|
||||||
userIds[1],
|
userIds[1],
|
||||||
userIds[1],
|
userIds[1],
|
||||||
0,
|
0,
|
||||||
make_object<chatMemberStatusCreator>("", true),
|
make_object<chatMemberStatusCreator>("", true),
|
||||||
nullptr
|
nullptr
|
||||||
));
|
));
|
||||||
members.push_back(make_object<chatMember>(
|
members.push_back(makeChatMember(
|
||||||
selfId,
|
selfId,
|
||||||
userIds[1],
|
userIds[1],
|
||||||
0,
|
0,
|
||||||
@ -835,21 +835,21 @@ TEST_F(GroupChatTest, GroupChatWithDeletedUser_WriteToNonContact)
|
|||||||
deletedUser->type_ = make_object<userTypeDeleted>();
|
deletedUser->type_ = make_object<userTypeDeleted>();
|
||||||
|
|
||||||
std::vector<object_ptr<chatMember>> members;
|
std::vector<object_ptr<chatMember>> members;
|
||||||
members.push_back(make_object<chatMember>(
|
members.push_back(makeChatMember(
|
||||||
userIds[0],
|
userIds[0],
|
||||||
userIds[0],
|
userIds[0],
|
||||||
0,
|
0,
|
||||||
make_object<chatMemberStatusCreator>("", true),
|
make_object<chatMemberStatusCreator>("", true),
|
||||||
nullptr
|
nullptr
|
||||||
));
|
));
|
||||||
members.push_back(make_object<chatMember>(
|
members.push_back(makeChatMember(
|
||||||
userIds[1], // Deleted user
|
userIds[1], // Deleted user
|
||||||
userIds[0],
|
userIds[0],
|
||||||
0,
|
0,
|
||||||
make_object<chatMemberStatusMember>(),
|
make_object<chatMemberStatusMember>(),
|
||||||
nullptr
|
nullptr
|
||||||
));
|
));
|
||||||
members.push_back(make_object<chatMember>(
|
members.push_back(makeChatMember(
|
||||||
selfId,
|
selfId,
|
||||||
userIds[0],
|
userIds[0],
|
||||||
0,
|
0,
|
||||||
@ -1574,3 +1574,5 @@ TEST_F(GroupChatTest, RejoinAtStartupBeforeUpdateNewChat_ChatListNullFirst)
|
|||||||
);
|
);
|
||||||
tgl.verifyRequest(getBasicGroupFullInfo(groupId));
|
tgl.verifyRequest(getBasicGroupFullInfo(groupId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Test non-user member
|
||||||
|
@ -81,14 +81,14 @@ TEST_F(SupergroupTest, AddSupergroupChatAtLogin_WithMemberList_OpenChatAfterFull
|
|||||||
fullInfo->description_ = "Description";
|
fullInfo->description_ = "Description";
|
||||||
|
|
||||||
auto members = make_object<chatMembers>();
|
auto members = make_object<chatMembers>();
|
||||||
members->members_.push_back(make_object<chatMember>(
|
members->members_.push_back(makeChatMember(
|
||||||
userIds[1],
|
userIds[1],
|
||||||
userIds[1],
|
userIds[1],
|
||||||
0,
|
0,
|
||||||
make_object<chatMemberStatusCreator>("", true),
|
make_object<chatMemberStatusCreator>("", true),
|
||||||
nullptr
|
nullptr
|
||||||
));
|
));
|
||||||
members->members_.push_back(make_object<chatMember>(
|
members->members_.push_back(makeChatMember(
|
||||||
selfId,
|
selfId,
|
||||||
userIds[1],
|
userIds[1],
|
||||||
0,
|
0,
|
||||||
@ -98,14 +98,14 @@ TEST_F(SupergroupTest, AddSupergroupChatAtLogin_WithMemberList_OpenChatAfterFull
|
|||||||
members->members_.push_back(nullptr);
|
members->members_.push_back(nullptr);
|
||||||
|
|
||||||
auto admins = make_object<chatMembers>();
|
auto admins = make_object<chatMembers>();
|
||||||
admins->members_.push_back(make_object<chatMember>(
|
admins->members_.push_back(makeChatMember(
|
||||||
userIds[0],
|
userIds[0],
|
||||||
userIds[1],
|
userIds[1],
|
||||||
0,
|
0,
|
||||||
make_object<chatMemberStatusAdministrator>(),
|
make_object<chatMemberStatusAdministrator>(),
|
||||||
nullptr
|
nullptr
|
||||||
));
|
));
|
||||||
admins->members_.push_back(make_object<chatMember>(
|
admins->members_.push_back(makeChatMember(
|
||||||
userIds[1],
|
userIds[1],
|
||||||
userIds[1],
|
userIds[1],
|
||||||
0,
|
0,
|
||||||
@ -203,14 +203,14 @@ TEST_F(SupergroupTest, ExistingSupergroupReceiveMessageAtLogin_WithMemberList_Op
|
|||||||
fullInfo->description_ = "Description";
|
fullInfo->description_ = "Description";
|
||||||
|
|
||||||
auto members = make_object<chatMembers>();
|
auto members = make_object<chatMembers>();
|
||||||
members->members_.push_back(make_object<chatMember>(
|
members->members_.push_back(makeChatMember(
|
||||||
userIds[1],
|
userIds[1],
|
||||||
userIds[1],
|
userIds[1],
|
||||||
0,
|
0,
|
||||||
make_object<chatMemberStatusCreator>("", true),
|
make_object<chatMemberStatusCreator>("", true),
|
||||||
nullptr
|
nullptr
|
||||||
));
|
));
|
||||||
members->members_.push_back(make_object<chatMember>(
|
members->members_.push_back(makeChatMember(
|
||||||
selfId,
|
selfId,
|
||||||
userIds[1],
|
userIds[1],
|
||||||
0,
|
0,
|
||||||
@ -220,14 +220,14 @@ TEST_F(SupergroupTest, ExistingSupergroupReceiveMessageAtLogin_WithMemberList_Op
|
|||||||
members->members_.push_back(nullptr);
|
members->members_.push_back(nullptr);
|
||||||
|
|
||||||
auto admins = make_object<chatMembers>();
|
auto admins = make_object<chatMembers>();
|
||||||
admins->members_.push_back(make_object<chatMember>(
|
admins->members_.push_back(makeChatMember(
|
||||||
userIds[0],
|
userIds[0],
|
||||||
userIds[1],
|
userIds[1],
|
||||||
0,
|
0,
|
||||||
make_object<chatMemberStatusAdministrator>(),
|
make_object<chatMemberStatusAdministrator>(),
|
||||||
nullptr
|
nullptr
|
||||||
));
|
));
|
||||||
admins->members_.push_back(make_object<chatMember>(
|
admins->members_.push_back(makeChatMember(
|
||||||
userIds[1],
|
userIds[1],
|
||||||
userIds[1],
|
userIds[1],
|
||||||
0,
|
0,
|
||||||
@ -634,3 +634,5 @@ TEST_F(SupergroupTest, ReceiveChannelPost)
|
|||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Test non-user member
|
||||||
|
@ -714,5 +714,12 @@ object_ptr<photo> makePhotoUploading(int32_t fileId, unsigned size, unsigned upl
|
|||||||
return make_object<photo>(false, nullptr, std::move(sizes));
|
return make_object<photo>(false, nullptr, std::move(sizes));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
object_ptr<chatMember> makeChatMember(int32_t userId, int32_t inviteUserId, time_t joinTime,
|
||||||
|
object_ptr<ChatMemberStatus> &&memberStatus, const void *)
|
||||||
|
{
|
||||||
|
return make_object<chatMember>(make_object<messageSenderUser>(userId),
|
||||||
|
inviteUserId, joinTime, std::move(memberStatus));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -73,6 +73,8 @@ object_ptr<photo> makePhotoLocal(int32_t fileId, unsigned size, const std::strin
|
|||||||
unsigned width, unsigned height);
|
unsigned width, unsigned height);
|
||||||
object_ptr<photo> makePhotoUploading(int32_t fileId, unsigned size, unsigned uploaded, const std::string &path,
|
object_ptr<photo> makePhotoUploading(int32_t fileId, unsigned size, unsigned uploaded, const std::string &path,
|
||||||
unsigned width, unsigned height);
|
unsigned width, unsigned height);
|
||||||
|
object_ptr<chatMember> makeChatMember(int32_t userId, int32_t inviteUserId, time_t joinTime,
|
||||||
|
object_ptr<ChatMemberStatus> &&memberStatus, const void *);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user