2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 14:38:15 +00:00

Don't use MTP* for PeerSettings flags.

This commit is contained in:
John Preston
2021-07-08 17:30:27 +03:00
parent 878c890bc2
commit f22e68fc32
8 changed files with 55 additions and 52 deletions

View File

@@ -574,6 +574,22 @@ void PeerData::checkFolder(FolderId folderId) {
}
}
void PeerData::setSettings(const MTPPeerSettings &data) {
data.match([&](const MTPDpeerSettings &data) {
using Flag = PeerSetting;
setSettings((data.is_add_contact() ? Flag::AddContact : Flag())
| (data.is_autoarchived() ? Flag::AutoArchived : Flag())
| (data.is_block_contact() ? Flag::BlockContact : Flag())
//| (data.is_invite_members() ? Flag::InviteMembers : Flag())
| (data.is_need_contacts_exception()
? Flag::NeedContactsException
: Flag())
//| (data.is_report_geo() ? Flag::ReportGeo : Flag())
| (data.is_report_spam() ? Flag::ReportSpam : Flag())
| (data.is_share_contact() ? Flag::ShareContact : Flag()));
});
}
void PeerData::fillNames() {
_nameWords.clear();
_nameFirstLetters.clear();

View File

@@ -188,25 +188,26 @@ private:
};
class PeerData {
private:
static constexpr auto kSettingsUnknown = MTPDpeerSettings::Flag(1U << 9);
enum class PeerSetting {
ReportSpam = (1 << 0),
AddContact = (1 << 1),
BlockContact = (1 << 2),
ShareContact = (1 << 3),
NeedContactsException = (1 << 4),
AutoArchived = (1 << 5),
Unknown = (1 << 6),
};
inline constexpr bool is_flag_type(PeerSetting) { return true; };
using PeerSettings = base::flags<PeerSetting>;
class PeerData {
protected:
PeerData(not_null<Data::Session*> owner, PeerId id);
PeerData(const PeerData &other) = delete;
PeerData &operator=(const PeerData &other) = delete;
public:
static constexpr auto kEssentialSettings = 0
| MTPDpeerSettings::Flag::f_report_spam
| MTPDpeerSettings::Flag::f_add_contact
| MTPDpeerSettings::Flag::f_block_contact
| MTPDpeerSettings::Flag::f_share_contact
| kSettingsUnknown;
using Settings = Data::Flags<
MTPDpeerSettings::Flags,
kEssentialSettings.value()>;
using Settings = Data::Flags<PeerSettings>;
virtual ~PeerData();
@@ -414,20 +415,22 @@ public:
void checkFolder(FolderId folderId);
void setSettings(MTPDpeerSettings::Flags which) {
void setSettings(PeerSettings which) {
_settings.set(which);
}
auto settings() const {
return (_settings.current() & kSettingsUnknown)
return (_settings.current() & PeerSetting::Unknown)
? std::nullopt
: std::make_optional(_settings.current());
}
auto settingsValue() const {
return (_settings.current() & kSettingsUnknown)
return (_settings.current() & PeerSetting::Unknown)
? _settings.changes()
: (_settings.value() | rpl::type_erased());
}
void setSettings(const MTPPeerSettings &data);
enum class BlockStatus : char {
Unknown,
Blocked,
@@ -503,7 +506,7 @@ private:
TimeId _ttlPeriod = 0;
bool _hasPinnedMessages = false;
Settings _settings = { kSettingsUnknown };
Settings _settings = PeerSettings(PeerSetting::Unknown);
BlockStatus _blockStatus = BlockStatus::Unknown;
LoadedStatus _loadedStatus = LoadedStatus::Not;

View File

@@ -192,11 +192,7 @@ void ApplyUserUpdate(not_null<UserData*> user, const MTPDuserFull &update) {
if (const auto photo = update.vprofile_photo()) {
user->owner().processPhoto(*photo);
}
const auto settings = update.vsettings().match([&](
const MTPDpeerSettings &data) {
return data.vflags().v;
});
user->setSettings(settings);
user->setSettings(update.vsettings());
user->session().api().applyNotifySettings(
MTP_inputNotifyPeer(user->input),
update.vnotify_settings());