2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 06:26:18 +00:00

all MTP flags made strictly typed by scoped enums, in-message date display added for non-service messages

This commit is contained in:
John Preston
2016-03-19 19:55:15 +03:00
parent 9d00ec273b
commit 2ef8c44445
43 changed files with 6141 additions and 4167 deletions

View File

@@ -103,10 +103,12 @@ inline PeerId peerFromMessage(const MTPmessage &msg) {
}
return (from_id && peerToUser(to_id) == MTP::authedId()) ? from_id : to_id;
}
inline int32 flagsFromMessage(const MTPmessage &msg) {
inline MTPDmessage::Flags flagsFromMessage(const MTPmessage &msg) {
switch (msg.type()) {
case mtpc_message: return msg.c_message().vflags.v;
case mtpc_messageService: return msg.c_messageService().vflags.v;
// dirty type hack :( we assume that MTPDmessage::Flags has the same flags and perhaps more
case mtpc_messageService: return MTPDmessage::Flags(QFlag(msg.c_messageService().vflags.v));
}
return 0;
}
@@ -163,15 +165,16 @@ static const MsgId ServerMaxMsgId = 0x3FFFFFFF;
static const MsgId ShowAtUnreadMsgId = 0;
struct NotifySettings {
NotifySettings() : flags(MTPDinputPeerNotifySettings::flag_show_previews), mute(0), sound("default") {
NotifySettings() : flags(MTPDpeerNotifySettings::Flag::f_show_previews), mute(0), sound("default") {
}
int32 flags, mute;
MTPDpeerNotifySettings::Flags flags;
int32 mute;
string sound;
bool previews() const {
return flags & MTPDinputPeerNotifySettings::flag_show_previews;
return flags & MTPDpeerNotifySettings::Flag::f_show_previews;
}
bool silent() const {
return flags & MTPDinputPeerNotifySettings::flag_silent;
return flags & MTPDpeerNotifySettings::Flag::f_silent;
}
};
typedef NotifySettings *NotifySettingsPtr;
@@ -386,9 +389,9 @@ public:
uint64 access;
int32 flags;
MTPDuser::Flags flags;
bool isVerified() const {
return flags & MTPDuser::flag_verified;
return flags & MTPDuser::Flag::f_verified;
}
bool canWrite() const {
return access != UserNoAccess;
@@ -434,7 +437,7 @@ public:
void invalidateParticipants() {
participants = ChatData::Participants();
admins = ChatData::Admins();
flags &= ~MTPDchat::flag_admin;
flags &= ~MTPDchat::Flag::f_admin;
invitedByMe = ChatData::InvitedByMe();
botStatus = 0;
}
@@ -451,7 +454,7 @@ public:
int32 version;
int32 creator;
int32 flags;
MTPDchat::Flags flags;
bool isForbidden;
bool amIn() const {
return !isForbidden && !haveLeft() && !wasKicked();
@@ -463,25 +466,25 @@ public:
return !isDeactivated() && amIn();
}
bool haveLeft() const {
return flags & MTPDchat::flag_left;
return flags & MTPDchat::Flag::f_left;
}
bool wasKicked() const {
return flags & MTPDchat::flag_kicked;
return flags & MTPDchat::Flag::f_kicked;
}
bool adminsEnabled() const {
return flags & MTPDchat::flag_admins_enabled;
return flags & MTPDchat::Flag::f_admins_enabled;
}
bool amCreator() const {
return flags & MTPDchat::flag_creator;
return flags & MTPDchat::Flag::f_creator;
}
bool amAdmin() const {
return flags & MTPDchat::flag_admin;
return flags & MTPDchat::Flag::f_admin;
}
bool isDeactivated() const {
return flags & MTPDchat::flag_deactivated;
return flags & MTPDchat::Flag::f_deactivated;
}
bool isMigrated() const {
return flags & MTPDchat::flag_migrated_to;
return flags & MTPDchat::Flag::f_migrated_to;
}
typedef QMap<UserData*, int32> Participants;
Participants participants;
@@ -625,7 +628,8 @@ public:
int32 count, adminsCount;
int32 date;
int32 version;
int32 flags, flagsFull;
MTPDchannel::Flags flags;
MTPDchannelFull::Flags flagsFull;
MegagroupInfo *mgInfo;
bool lastParticipantsCountOutdated() const {
if (!mgInfo || !(mgInfo->lastParticipantsStatus & MegagroupInfo::LastParticipantsCountOutdated)) {
@@ -639,31 +643,31 @@ public:
}
void flagsUpdated();
bool isMegagroup() const {
return flags & MTPDchannel::flag_megagroup;
return flags & MTPDchannel::Flag::f_megagroup;
}
bool isBroadcast() const {
return flags & MTPDchannel::flag_broadcast;
return flags & MTPDchannel::Flag::f_broadcast;
}
bool isPublic() const {
return flags & MTPDchannel::flag_username;
return flags & MTPDchannel::Flag::f_username;
}
bool canEditUsername() const {
return amCreator() && (flagsFull & MTPDchannelFull::flag_can_set_username);
return amCreator() && (flagsFull & MTPDchannelFull::Flag::f_can_set_username);
}
bool amCreator() const {
return flags & MTPDchannel::flag_creator;
return flags & MTPDchannel::Flag::f_creator;
}
bool amEditor() const {
return flags & MTPDchannel::flag_editor;
return flags & MTPDchannel::Flag::f_editor;
}
bool amModerator() const {
return flags & MTPDchannel::flag_moderator;
return flags & MTPDchannel::Flag::f_moderator;
}
bool haveLeft() const {
return flags & MTPDchannel::flag_left;
return flags & MTPDchannel::Flag::f_left;
}
bool wasKicked() const {
return flags & MTPDchannel::flag_kicked;
return flags & MTPDchannel::Flag::f_kicked;
}
bool amIn() const {
return !isForbidden && !haveLeft() && !wasKicked();
@@ -675,17 +679,17 @@ public:
return amIn() && (canPublish() || !isBroadcast());
}
bool canViewParticipants() const {
return flagsFull & MTPDchannelFull::flag_can_view_participants;
return flagsFull & MTPDchannelFull::Flag::f_can_view_participants;
}
bool addsSignature() const {
return flags & MTPDchannel::flag_signatures;
return flags & MTPDchannel::Flag::f_signatures;
}
bool isForbidden;
bool isVerified() const {
return flags & MTPDchannel::flag_verified;
return flags & MTPDchannel::Flag::f_verified;
}
bool canAddParticipants() const {
return amCreator() || amEditor() || (flags & MTPDchannel::flag_democracy);
return amCreator() || amEditor() || (flags & MTPDchannel::Flag::f_democracy);
}
// ImagePtr photoFull;
@@ -1220,7 +1224,7 @@ public:
int32 width, height, duration;
QString message; // botContextMessageText
bool noWebPage;
bool noWebPage; //currently not used
EntitiesInText entities;
QString caption; // if message.isEmpty() use botContextMessageMediaAuto