mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-08-31 14:38:15 +00:00
Handle ttl_period locally.
This commit is contained in:
@@ -749,6 +749,9 @@ void ApplyChannelUpdate(
|
||||
channel->clearGroupCall();
|
||||
}
|
||||
|
||||
if (const auto ttl = update.vttl()) {
|
||||
channel->applyMessagesTTL(*ttl);
|
||||
}
|
||||
channel->setFullFlags(update.vflags().v);
|
||||
channel->setUserpicPhoto(update.vchat_photo());
|
||||
if (const auto migratedFrom = update.vmigrated_from_chat_id()) {
|
||||
|
@@ -84,6 +84,11 @@ bool ChatData::canEditPreHistoryHidden() const {
|
||||
return amCreator();
|
||||
}
|
||||
|
||||
bool ChatData::canDeleteMessages() const {
|
||||
return amCreator()
|
||||
|| (adminRights() & AdminRight::f_delete_messages);
|
||||
}
|
||||
|
||||
bool ChatData::canAddMembers() const {
|
||||
return amIn() && !amRestricted(Restriction::f_invite_users);
|
||||
}
|
||||
@@ -372,6 +377,9 @@ void ApplyChatUpdate(not_null<ChatData*> chat, const MTPDchatFull &update) {
|
||||
chat->clearGroupCall();
|
||||
}
|
||||
|
||||
if (const auto ttl = update.vttl()) {
|
||||
chat->applyMessagesTTL(*ttl);
|
||||
}
|
||||
if (const auto info = update.vbot_info()) {
|
||||
for (const auto &item : info->v) {
|
||||
item.match([&](const MTPDbotInfo &data) {
|
||||
|
@@ -128,16 +128,17 @@ public:
|
||||
[[nodiscard]] AdminRights defaultAdminRights(not_null<UserData*> user);
|
||||
|
||||
// Like in ChannelData.
|
||||
bool canWrite() const;
|
||||
bool canEditInformation() const;
|
||||
bool canEditPermissions() const;
|
||||
bool canEditUsername() const;
|
||||
bool canEditPreHistoryHidden() const;
|
||||
bool canAddMembers() const;
|
||||
bool canAddAdmins() const;
|
||||
bool canBanMembers() const;
|
||||
bool canSendPolls() const;
|
||||
bool anyoneCanAddMembers() const;
|
||||
[[nodiscard]] bool canWrite() const;
|
||||
[[nodiscard]] bool canEditInformation() const;
|
||||
[[nodiscard]] bool canEditPermissions() const;
|
||||
[[nodiscard]] bool canEditUsername() const;
|
||||
[[nodiscard]] bool canEditPreHistoryHidden() const;
|
||||
[[nodiscard]] bool canDeleteMessages() const;
|
||||
[[nodiscard]] bool canAddMembers() const;
|
||||
[[nodiscard]] bool canAddAdmins() const;
|
||||
[[nodiscard]] bool canBanMembers() const;
|
||||
[[nodiscard]] bool canSendPolls() const;
|
||||
[[nodiscard]] bool anyoneCanAddMembers() const;
|
||||
|
||||
void applyEditAdmin(not_null<UserData*> user, bool isAdmin);
|
||||
|
||||
|
@@ -945,6 +945,35 @@ void PeerData::setLoadedStatus(LoadedStatus status) {
|
||||
_loadedStatus = status;
|
||||
}
|
||||
|
||||
TimeId PeerData::messagesTTL() const {
|
||||
return (_ttlMyPeriod && _ttlPeerPeriod)
|
||||
? std::min(_ttlMyPeriod, _ttlPeerPeriod)
|
||||
: std::max(_ttlMyPeriod, _ttlPeerPeriod);
|
||||
}
|
||||
|
||||
void PeerData::setMessagesTTL(
|
||||
TimeId myPeriod,
|
||||
TimeId peerPeriod,
|
||||
bool oneSide) {
|
||||
_ttlMyPeriod = myPeriod;
|
||||
_ttlPeerPeriod = peerPeriod;
|
||||
_ttlOneSide = oneSide;
|
||||
}
|
||||
|
||||
void PeerData::applyMessagesTTL(const MTPPeerHistoryTTL &ttl) {
|
||||
ttl.match([&](const MTPDpeerHistoryTTL &data) {
|
||||
setMessagesTTL(
|
||||
data.vttl_period().v,
|
||||
data.vttl_period().v,
|
||||
false);
|
||||
}, [&](const MTPDpeerHistoryTTLPM &data) {
|
||||
setMessagesTTL(
|
||||
data.vmy_ttl_period().value_or_empty(),
|
||||
data.vpeer_ttl_period().value_or_empty(),
|
||||
data.is_my_oneside());
|
||||
});
|
||||
}
|
||||
|
||||
namespace Data {
|
||||
|
||||
std::vector<ChatRestrictions> ListOfRestrictions() {
|
||||
|
@@ -17,6 +17,11 @@ class UserData;
|
||||
class ChatData;
|
||||
class ChannelData;
|
||||
|
||||
using ChatAdminRight = MTPDchatAdminRights::Flag;
|
||||
using ChatRestriction = MTPDchatBannedRights::Flag;
|
||||
using ChatAdminRights = MTPDchatAdminRights::Flags;
|
||||
using ChatRestrictions = MTPDchatBannedRights::Flags;
|
||||
|
||||
namespace Ui {
|
||||
class EmptyUserpic;
|
||||
} // namespace Ui
|
||||
@@ -30,23 +35,13 @@ namespace Data {
|
||||
|
||||
class Session;
|
||||
class GroupCall;
|
||||
class CloudImageView;
|
||||
|
||||
int PeerColorIndex(PeerId peerId);
|
||||
int PeerColorIndex(int32 bareId);
|
||||
style::color PeerUserpicColor(PeerId peerId);
|
||||
PeerId FakePeerIdForJustName(const QString &name);
|
||||
|
||||
} // namespace Data
|
||||
|
||||
using ChatAdminRight = MTPDchatAdminRights::Flag;
|
||||
using ChatRestriction = MTPDchatBannedRights::Flag;
|
||||
using ChatAdminRights = MTPDchatAdminRights::Flags;
|
||||
using ChatRestrictions = MTPDchatBannedRights::Flags;
|
||||
|
||||
namespace Data {
|
||||
|
||||
class CloudImageView;
|
||||
|
||||
class RestrictionCheckResult {
|
||||
public:
|
||||
[[nodiscard]] static RestrictionCheckResult Allowed() {
|
||||
@@ -386,6 +381,19 @@ public:
|
||||
}
|
||||
void setLoadedStatus(LoadedStatus status);
|
||||
|
||||
[[nodiscard]] TimeId myMessagesTTL() const {
|
||||
return _ttlMyPeriod;
|
||||
}
|
||||
[[nodiscard]] TimeId peerMessagesTTL() const {
|
||||
return _ttlPeerPeriod;
|
||||
}
|
||||
[[nodiscard]] bool oneSideTTL() const {
|
||||
return _ttlOneSide;
|
||||
}
|
||||
[[nodiscard]] TimeId messagesTTL() const;
|
||||
void setMessagesTTL(TimeId myPeriod, TimeId peerPeriod, bool oneSide);
|
||||
void applyMessagesTTL(const MTPPeerHistoryTTL &ttl);
|
||||
|
||||
[[nodiscard]] Data::GroupCall *groupCall() const;
|
||||
|
||||
const PeerId id;
|
||||
@@ -429,6 +437,10 @@ private:
|
||||
base::flat_set<QChar> _nameFirstLetters;
|
||||
|
||||
crl::time _lastFullUpdate = 0;
|
||||
|
||||
TimeId _ttlMyPeriod = 0;
|
||||
TimeId _ttlPeerPeriod = 0;
|
||||
bool _ttlOneSide = false;
|
||||
bool _hasPinnedMessages = false;
|
||||
|
||||
Settings _settings = { kSettingsUnknown };
|
||||
|
@@ -1846,33 +1846,7 @@ bool Session::checkEntitiesAndViewsUpdate(const MTPDmessage &data) {
|
||||
if (!existing) {
|
||||
return false;
|
||||
}
|
||||
existing->updateSentContent({
|
||||
qs(data.vmessage()),
|
||||
Api::EntitiesFromMTP(
|
||||
&session(),
|
||||
data.ventities().value_or_empty())
|
||||
}, data.vmedia());
|
||||
existing->updateReplyMarkup(data.vreply_markup());
|
||||
existing->updateForwardedInfo(data.vfwd_from());
|
||||
existing->setViewsCount(data.vviews().value_or(-1));
|
||||
if (const auto replies = data.vreplies()) {
|
||||
existing->setReplies(*replies);
|
||||
} else {
|
||||
existing->clearReplies();
|
||||
}
|
||||
existing->setForwardsCount(data.vforwards().value_or(-1));
|
||||
if (const auto reply = data.vreply_to()) {
|
||||
reply->match([&](const MTPDmessageReplyHeader &data) {
|
||||
existing->setReplyToTop(
|
||||
data.vreply_to_top_id().value_or(
|
||||
data.vreply_to_msg_id().v));
|
||||
});
|
||||
}
|
||||
existing->setPostAuthor(data.vpost_author().value_or_empty());
|
||||
existing->indexAsNewItem();
|
||||
existing->contributeToSlowmode(data.vdate().v);
|
||||
requestItemTextRefresh(existing);
|
||||
updateDependentMessages(existing);
|
||||
existing->applySentMessage(data);
|
||||
const auto result = (existing->mainView() != nullptr);
|
||||
if (result) {
|
||||
stickers().checkSavedGif(existing);
|
||||
|
@@ -256,6 +256,9 @@ void ApplyUserUpdate(not_null<UserData*> user, const MTPDuserFull &update) {
|
||||
MTP_inputNotifyPeer(user->input),
|
||||
update.vnotify_settings());
|
||||
|
||||
if (const auto ttl = update.vttl()) {
|
||||
user->applyMessagesTTL(*ttl);
|
||||
}
|
||||
if (const auto info = update.vbot_info()) {
|
||||
user->setBotInfo(*info);
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user