mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Added new class Api::ChatParticipant.
This commit is contained in:
parent
503814ad4e
commit
c65468f270
2 changed files with 169 additions and 2 deletions
|
@ -270,6 +270,120 @@ void ApplyBotsList(
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
ChatParticipant::ChatParticipant(
|
||||||
|
const MTPChannelParticipant &p,
|
||||||
|
not_null<PeerData*> peer) {
|
||||||
|
_peer = p.match([](const MTPDchannelParticipantBanned &data) {
|
||||||
|
return peerFromMTP(data.vpeer());
|
||||||
|
}, [](const MTPDchannelParticipantLeft &data) {
|
||||||
|
return peerFromMTP(data.vpeer());
|
||||||
|
}, [](const auto &data) {
|
||||||
|
return peerFromUser(data.vuser_id());
|
||||||
|
});
|
||||||
|
|
||||||
|
p.match([&](const MTPDchannelParticipantCreator &data) {
|
||||||
|
_canBeEdited = (peer->session().userPeerId() == _peer);
|
||||||
|
_type = Type::Creator;
|
||||||
|
_rights = ChatAdminRightsInfo(data.vadmin_rights());
|
||||||
|
_rank = qs(data.vrank().value_or_empty());
|
||||||
|
}, [&](const MTPDchannelParticipantAdmin &data) {
|
||||||
|
_canBeEdited = data.is_can_edit();
|
||||||
|
_type = Type::Admin;
|
||||||
|
_rank = qs(data.vrank().value_or_empty());
|
||||||
|
_rights = ChatAdminRightsInfo(data.vadmin_rights());
|
||||||
|
_by = peerToUser(peerFromUser(data.vpromoted_by()));
|
||||||
|
}, [&](const MTPDchannelParticipantSelf &data) {
|
||||||
|
_type = Type::Member;
|
||||||
|
_by = peerToUser(peerFromUser(data.vinviter_id()));
|
||||||
|
}, [&](const MTPDchannelParticipant &data) {
|
||||||
|
_type = Type::Member;
|
||||||
|
}, [&](const MTPDchannelParticipantBanned &data) {
|
||||||
|
_restrictions = ChatRestrictionsInfo(data.vbanned_rights());
|
||||||
|
_by = peerToUser(peerFromUser(data.vkicked_by()));
|
||||||
|
|
||||||
|
_type = (_restrictions.flags & ChatRestriction::ViewMessages)
|
||||||
|
? Type::Banned
|
||||||
|
: Type::Restricted;
|
||||||
|
}, [&](const MTPDchannelParticipantLeft &data) {
|
||||||
|
_type = Type::Left;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
ChatParticipant::ChatParticipant(
|
||||||
|
Type type,
|
||||||
|
PeerId peerId,
|
||||||
|
UserId by,
|
||||||
|
ChatRestrictionsInfo restrictions,
|
||||||
|
ChatAdminRightsInfo rights,
|
||||||
|
bool canBeEdited,
|
||||||
|
QString rank)
|
||||||
|
: _type(type)
|
||||||
|
, _peer(peerId)
|
||||||
|
, _by(by)
|
||||||
|
, _canBeEdited(canBeEdited)
|
||||||
|
, _rank(rank)
|
||||||
|
, _restrictions(std::move(restrictions))
|
||||||
|
, _rights(std::move(rights)) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void ChatParticipant::tryApplyCreatorTo(
|
||||||
|
not_null<ChannelData*> channel) const {
|
||||||
|
if (isCreator() && isUser()) {
|
||||||
|
if (const auto info = channel->mgInfo.get()) {
|
||||||
|
info->creator = channel->owner().userLoaded(userId());
|
||||||
|
info->creatorRank = rank();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ChatParticipant::isUser() const {
|
||||||
|
return peerIsUser(_peer);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ChatParticipant::isCreator() const {
|
||||||
|
return _type == Type::Creator;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ChatParticipant::isCreatorOrAdmin() const {
|
||||||
|
return _type == Type::Creator || _type == Type::Admin;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ChatParticipant::isKicked() const {
|
||||||
|
return _type == Type::Banned;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ChatParticipant::canBeEdited() const {
|
||||||
|
return _canBeEdited;
|
||||||
|
}
|
||||||
|
|
||||||
|
UserId ChatParticipant::by() const {
|
||||||
|
return _by;
|
||||||
|
}
|
||||||
|
|
||||||
|
PeerId ChatParticipant::id() const {
|
||||||
|
return _peer;
|
||||||
|
}
|
||||||
|
|
||||||
|
UserId ChatParticipant::userId() const {
|
||||||
|
return peerToUser(_peer);
|
||||||
|
}
|
||||||
|
|
||||||
|
ChatRestrictionsInfo ChatParticipant::restrictions() const {
|
||||||
|
return _restrictions;
|
||||||
|
}
|
||||||
|
|
||||||
|
ChatAdminRightsInfo ChatParticipant::rights() const {
|
||||||
|
return _rights;
|
||||||
|
}
|
||||||
|
|
||||||
|
ChatParticipant::Type ChatParticipant::type() const {
|
||||||
|
return _type;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString ChatParticipant::rank() const {
|
||||||
|
return _rank;
|
||||||
|
}
|
||||||
|
|
||||||
ChatParticipants::ChatParticipants(not_null<ApiWrap*> api)
|
ChatParticipants::ChatParticipants(not_null<ApiWrap*> api)
|
||||||
: _api(&api->instance()) {
|
: _api(&api->instance()) {
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,16 +7,69 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "data/data_chat_participant_status.h"
|
||||||
#include "mtproto/sender.h"
|
#include "mtproto/sender.h"
|
||||||
#include "base/timer.h"
|
#include "base/timer.h"
|
||||||
|
|
||||||
class ApiWrap;
|
class ApiWrap;
|
||||||
class ChannelData;
|
class ChannelData;
|
||||||
|
|
||||||
struct ChatRestrictionsInfo;
|
|
||||||
|
|
||||||
namespace Api {
|
namespace Api {
|
||||||
|
|
||||||
|
class ChatParticipant final {
|
||||||
|
public:
|
||||||
|
enum class Type {
|
||||||
|
Creator,
|
||||||
|
Admin,
|
||||||
|
Member,
|
||||||
|
Restricted,
|
||||||
|
Left,
|
||||||
|
Banned,
|
||||||
|
};
|
||||||
|
|
||||||
|
explicit ChatParticipant(
|
||||||
|
const MTPChannelParticipant &p,
|
||||||
|
not_null<PeerData*> peer);
|
||||||
|
ChatParticipant(
|
||||||
|
Type type,
|
||||||
|
PeerId peerId,
|
||||||
|
UserId by,
|
||||||
|
ChatRestrictionsInfo restrictions,
|
||||||
|
ChatAdminRightsInfo rights,
|
||||||
|
bool canBeEdited = false,
|
||||||
|
QString rank = QString());
|
||||||
|
|
||||||
|
bool isUser() const;
|
||||||
|
bool isCreator() const;
|
||||||
|
bool isCreatorOrAdmin() const;
|
||||||
|
bool isKicked() const;
|
||||||
|
bool canBeEdited() const;
|
||||||
|
|
||||||
|
UserId by() const;
|
||||||
|
PeerId id() const;
|
||||||
|
UserId userId() const;
|
||||||
|
|
||||||
|
ChatRestrictionsInfo restrictions() const;
|
||||||
|
ChatAdminRightsInfo rights() const;
|
||||||
|
|
||||||
|
Type type() const;
|
||||||
|
QString rank() const;
|
||||||
|
|
||||||
|
void tryApplyCreatorTo(not_null<ChannelData*> channel) const;
|
||||||
|
private:
|
||||||
|
Type _type = Type::Member;
|
||||||
|
|
||||||
|
PeerId _peer;
|
||||||
|
UserId _by; // Banned/Restricted/Promoted.
|
||||||
|
|
||||||
|
bool _canBeEdited = false;
|
||||||
|
|
||||||
|
QString _rank;
|
||||||
|
|
||||||
|
ChatRestrictionsInfo _restrictions;
|
||||||
|
ChatAdminRightsInfo _rights;
|
||||||
|
};
|
||||||
|
|
||||||
class ChatParticipants final {
|
class ChatParticipants final {
|
||||||
public:
|
public:
|
||||||
using TLMembers = MTPchannels_ChannelParticipants;
|
using TLMembers = MTPchannels_ChannelParticipants;
|
||||||
|
|
Loading…
Add table
Reference in a new issue