mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-08-30 22:16:14 +00:00
Extend pinned messages support.
Support them in saved messages and normal groups.
This commit is contained in:
@@ -330,6 +330,39 @@ void PeerData::setUserpicChecked(
|
||||
}
|
||||
}
|
||||
|
||||
bool PeerData::canPinMessages() const {
|
||||
if (const auto user = asUser()) {
|
||||
return user->isSelf();
|
||||
} else if (const auto chat = asChat()) {
|
||||
return chat->adminsEnabled() ? chat->amAdmin() : chat->amIn();
|
||||
} else if (const auto channel = asChannel()) {
|
||||
using AdminRight = ChannelData::AdminRight;
|
||||
if (channel->isMegagroup()) {
|
||||
return (channel->adminRights() & AdminRight::f_pin_messages)
|
||||
|| channel->amCreator();
|
||||
}
|
||||
return (channel->adminRights() & AdminRight::f_edit_messages)
|
||||
|| channel->amCreator();
|
||||
}
|
||||
Unexpected("Peer type in PeerData::canPinMessages.");
|
||||
}
|
||||
|
||||
void PeerData::setPinnedMessageId(MsgId messageId) {
|
||||
const auto min = [&] {
|
||||
if (const auto channel = asChannel()) {
|
||||
return channel->availableMinId();
|
||||
}
|
||||
return MsgId(0);
|
||||
}();
|
||||
messageId = (messageId > min) ? messageId : MsgId(0);
|
||||
if (_pinnedMessageId != messageId) {
|
||||
_pinnedMessageId = messageId;
|
||||
Notify::peerUpdatedDelayed(
|
||||
this,
|
||||
Notify::PeerUpdate::Flag::PinnedMessageChanged);
|
||||
}
|
||||
}
|
||||
|
||||
void PeerData::fillNames() {
|
||||
_nameWords.clear();
|
||||
_nameFirstLetters.clear();
|
||||
@@ -872,25 +905,12 @@ void ChannelData::setAvailableMinId(MsgId availableMinId) {
|
||||
if (auto history = App::historyLoaded(this)) {
|
||||
history->clearUpTill(availableMinId);
|
||||
}
|
||||
if (_pinnedMessageId <= _availableMinId) {
|
||||
_pinnedMessageId = MsgId(0);
|
||||
Notify::peerUpdatedDelayed(
|
||||
this,
|
||||
Notify::PeerUpdate::Flag::ChannelPinnedChanged);
|
||||
if (pinnedMessageId() <= _availableMinId) {
|
||||
clearPinnedMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ChannelData::setPinnedMessageId(MsgId messageId) {
|
||||
messageId = (messageId > _availableMinId) ? messageId : MsgId(0);
|
||||
if (_pinnedMessageId != messageId) {
|
||||
_pinnedMessageId = messageId;
|
||||
Notify::peerUpdatedDelayed(
|
||||
this,
|
||||
Notify::PeerUpdate::Flag::ChannelPinnedChanged);
|
||||
}
|
||||
}
|
||||
|
||||
void ChannelData::setFeed(not_null<Data::Feed*> feed) {
|
||||
setFeedPointer(feed);
|
||||
}
|
||||
@@ -948,15 +968,6 @@ bool ChannelData::canAddAdmins() const {
|
||||
|| amCreator();
|
||||
}
|
||||
|
||||
bool ChannelData::canPinMessages() const {
|
||||
if (isMegagroup()) {
|
||||
return (adminRights() & AdminRight::f_pin_messages)
|
||||
|| amCreator();
|
||||
}
|
||||
return (adminRights() & AdminRight::f_edit_messages)
|
||||
|| amCreator();
|
||||
}
|
||||
|
||||
bool ChannelData::canPublish() const {
|
||||
return (adminRights() & AdminRight::f_post_messages)
|
||||
|| amCreator();
|
||||
|
@@ -210,6 +210,15 @@ public:
|
||||
|
||||
ImagePtr currentUserpic() const;
|
||||
|
||||
bool canPinMessages() const;
|
||||
MsgId pinnedMessageId() const {
|
||||
return _pinnedMessageId;
|
||||
}
|
||||
void setPinnedMessageId(MsgId messageId);
|
||||
void clearPinnedMessage() {
|
||||
setPinnedMessageId(0);
|
||||
}
|
||||
|
||||
protected:
|
||||
void updateNameDelayed(
|
||||
const QString &newName,
|
||||
@@ -242,6 +251,7 @@ private:
|
||||
base::flat_set<QChar> _nameFirstLetters;
|
||||
|
||||
TimeMs _lastFullUpdate = 0;
|
||||
MsgId _pinnedMessageId = 0;
|
||||
|
||||
};
|
||||
|
||||
@@ -918,7 +928,6 @@ public:
|
||||
bool hiddenPreHistory() const;
|
||||
bool canAddMembers() const;
|
||||
bool canAddAdmins() const;
|
||||
bool canPinMessages() const;
|
||||
bool canPublish() const;
|
||||
bool canWrite() const;
|
||||
bool canViewMembers() const;
|
||||
@@ -999,14 +1008,6 @@ public:
|
||||
}
|
||||
void setAvailableMinId(MsgId availableMinId);
|
||||
|
||||
MsgId pinnedMessageId() const {
|
||||
return _pinnedMessageId;
|
||||
}
|
||||
void setPinnedMessageId(MsgId messageId);
|
||||
void clearPinnedMessage() {
|
||||
setPinnedMessageId(0);
|
||||
}
|
||||
|
||||
void setFeed(not_null<Data::Feed*> feed);
|
||||
void clearFeed();
|
||||
|
||||
@@ -1031,7 +1032,6 @@ private:
|
||||
int _restrictedCount = 0;
|
||||
int _kickedCount = 0;
|
||||
MsgId _availableMinId = 0;
|
||||
MsgId _pinnedMessageId = 0;
|
||||
|
||||
AdminRightFlags _adminRights;
|
||||
RestrictionFlags _restrictions;
|
||||
|
Reference in New Issue
Block a user