diff --git a/Telegram/Resources/scheme.tl b/Telegram/Resources/scheme.tl index ffff090d9..f962c152f 100644 --- a/Telegram/Resources/scheme.tl +++ b/Telegram/Resources/scheme.tl @@ -219,11 +219,11 @@ userStatusLastMonth#77ebc742 = UserStatus; chatEmpty#9ba2d800 id:int = Chat; chat#d91cdd54 flags:# creator:flags.0?true kicked:flags.1?true left:flags.2?true admins_enabled:flags.3?true admin:flags.4?true deactivated:flags.5?true id:int title:string photo:ChatPhoto participants_count:int date:int version:int migrated_to:flags.6?InputChannel = Chat; chatForbidden#7328bdb id:int title:string = Chat; -channel#a14dca52 flags:# creator:flags.0?true kicked:flags.1?true left:flags.2?true editor:flags.3?true moderator:flags.4?true broadcast:flags.5?true verified:flags.7?true megagroup:flags.8?true restricted:flags.9?true democracy:flags.10?true signatures:flags.11?true min:flags.12?true id:int access_hash:flags.13?long title:string username:flags.6?string photo:ChatPhoto date:int version:int restriction_reason:flags.9?string = Chat; -channelForbidden#8537784f flags:# broadcast:flags.5?true megagroup:flags.8?true id:int access_hash:long title:string = Chat; +channel#cb44b1c flags:# creator:flags.0?true left:flags.2?true broadcast:flags.5?true verified:flags.7?true megagroup:flags.8?true restricted:flags.9?true democracy:flags.10?true signatures:flags.11?true min:flags.12?true id:int access_hash:flags.13?long title:string username:flags.6?string photo:ChatPhoto date:int version:int restriction_reason:flags.9?string admin_rights:flags.14?ChannelAdminRights banned_rights:flags.15?ChannelBannedRights = Chat; +channelForbidden#289da732 flags:# broadcast:flags.5?true megagroup:flags.8?true id:int access_hash:long title:string until_date:flags.16?int = Chat; chatFull#2e02a614 id:int participants:ChatParticipants chat_photo:Photo notify_settings:PeerNotifySettings exported_invite:ExportedChatInvite bot_info:Vector = ChatFull; -channelFull#c3d5512f flags:# can_view_participants:flags.3?true can_set_username:flags.6?true id:int about:string participants_count:flags.0?int admins_count:flags.1?int kicked_count:flags.2?int read_inbox_max_id:int read_outbox_max_id:int unread_count:int chat_photo:Photo notify_settings:PeerNotifySettings exported_invite:ExportedChatInvite bot_info:Vector migrated_from_chat_id:flags.4?int migrated_from_max_id:flags.4?int pinned_msg_id:flags.5?int = ChatFull; +channelFull#95cb5f57 flags:# can_view_participants:flags.3?true can_set_username:flags.6?true id:int about:string participants_count:flags.0?int admins_count:flags.1?int kicked_count:flags.2?int banned_count:flags.2?int read_inbox_max_id:int read_outbox_max_id:int unread_count:int chat_photo:Photo notify_settings:PeerNotifySettings exported_invite:ExportedChatInvite bot_info:Vector migrated_from_chat_id:flags.4?int migrated_from_max_id:flags.4?int pinned_msg_id:flags.5?int = ChatFull; chatParticipant#c8d7493e user_id:int inviter_id:int date:int = ChatParticipant; chatParticipantCreator#da13538a user_id:int = ChatParticipant; @@ -449,7 +449,7 @@ photos.photo#20212ca8 photo:Photo users:Vector = photos.Photo; upload.file#96a18d5 type:storage.FileType mtime:int bytes:bytes = upload.File; upload.fileCdnRedirect#1508485a dc_id:int file_token:bytes encryption_key:bytes encryption_iv:bytes = upload.File; -dcOption#5d8c6cc flags:# ipv6:flags.0?true media_only:flags.1?true tcpo_only:flags.2?true cdn:flags.3?true id:int ip_address:string port:int = DcOption; +dcOption#5d8c6cc flags:# ipv6:flags.0?true media_only:flags.1?true tcpo_only:flags.2?true cdn:flags.3?true static:flags.4?true id:int ip_address:string port:int = DcOption; config#7feec888 flags:# phonecalls_enabled:flags.1?true date:int expires:int test_mode:Bool this_dc:int dc_options:Vector chat_size_max:int megagroup_size_max:int forwarded_count_max:int online_update_period_ms:int offline_blur_timeout_ms:int offline_idle_timeout_ms:int online_cloud_timeout_ms:int notify_cloud_delay_ms:int notify_default_delay_ms:int chat_big_size:int push_chat_period_ms:int push_chat_limit:int saved_gifs_limit:int edit_time_limit:int rating_e_decay:int stickers_recent_limit:int tmp_sessions:flags.0?int pinned_dialogs_count_max:int call_receive_timeout_ms:int call_ring_timeout_ms:int call_connect_timeout_ms:int call_packet_timeout_ms:int me_url_prefix:string suggested_lang_code:flags.2?string lang_pack_version:flags.2?int disabled_features:Vector = Config; @@ -649,19 +649,16 @@ channelMessagesFilter#cd77d957 flags:# exclude_new_messages:flags.1?true ranges: channelParticipant#15ebac1d user_id:int date:int = ChannelParticipant; channelParticipantSelf#a3289a6d user_id:int inviter_id:int date:int = ChannelParticipant; -channelParticipantModerator#91057fef user_id:int inviter_id:int date:int = ChannelParticipant; -channelParticipantEditor#98192d61 user_id:int inviter_id:int date:int = ChannelParticipant; -channelParticipantKicked#8cc5e69a user_id:int kicked_by:int date:int = ChannelParticipant; channelParticipantCreator#e3e2e1f9 user_id:int = ChannelParticipant; +channelParticipantAdmin#a82fa898 flags:# can_edit:flags.0?true user_id:int inviter_id:int promoted_by:int date:int admin_rights:ChannelAdminRights = ChannelParticipant; +channelParticipantBanned#222c1886 flags:# left:flags.0?true user_id:int kicked_by:int date:int banned_rights:ChannelBannedRights = ChannelParticipant; channelParticipantsRecent#de3f3c79 = ChannelParticipantsFilter; channelParticipantsAdmins#b4608969 = ChannelParticipantsFilter; -channelParticipantsKicked#3c37bb7a = ChannelParticipantsFilter; +channelParticipantsKicked#a3b54985 q:string = ChannelParticipantsFilter; channelParticipantsBots#b0d1865b = ChannelParticipantsFilter; - -channelRoleEmpty#b285a0c6 = ChannelParticipantRole; -channelRoleModerator#9618d975 = ChannelParticipantRole; -channelRoleEditor#820bfe8c = ChannelParticipantRole; +channelParticipantsBanned#1427a5e1 q:string = ChannelParticipantsFilter; +channelParticipantsSearch#656ac4b q:string = ChannelParticipantsFilter; channels.channelParticipants#f56ee2a8 count:int participants:Vector users:Vector = channels.ChannelParticipants; @@ -730,6 +727,7 @@ topPeerCategoryBotsInline#148677e2 = TopPeerCategory; topPeerCategoryCorrespondents#637b7ed = TopPeerCategory; topPeerCategoryGroups#bd17a14a = TopPeerCategory; topPeerCategoryChannels#161d9628 = TopPeerCategory; +topPeerCategoryPhoneCalls#1e76a78c = TopPeerCategory; topPeerCategoryPeers#fb834291 category:TopPeerCategory count:int peers:Vector = TopPeerCategoryPeers; @@ -800,9 +798,10 @@ pageBlockEmbedPost#292c7be9 url:string webpage_id:long author_photo_id:long auth pageBlockCollage#8b31c4f items:Vector caption:RichText = PageBlock; pageBlockSlideshow#130c8963 items:Vector caption:RichText = PageBlock; pageBlockChannel#ef1751b5 channel:Chat = PageBlock; +pageBlockAudio#31b81a7f audio_id:long caption:RichText = PageBlock; -pagePart#8dee6c44 blocks:Vector photos:Vector videos:Vector = Page; -pageFull#d7a19d69 blocks:Vector photos:Vector videos:Vector = Page; +pagePart#8e3f9ebe blocks:Vector photos:Vector documents:Vector = Page; +pageFull#556ec7aa blocks:Vector photos:Vector documents:Vector = Page; phoneCallDiscardReasonMissed#85e42301 = PhoneCallDiscardReason; phoneCallDiscardReasonDisconnect#e095c1a0 = PhoneCallDiscardReason; @@ -881,6 +880,31 @@ langPackDifference#f385c1f6 lang_code:string from_version:int version:int string langPackLanguage#117698f1 name:string native_name:string lang_code:string = LangPackLanguage; +channelAdminRights#5d7ceba5 flags:# change_info:flags.0?true post_messages:flags.1?true edit_messages:flags.2?true delete_messages:flags.3?true ban_users:flags.4?true invite_users:flags.5?true invite_link:flags.6?true pin_messages:flags.7?true add_admins:flags.9?true = ChannelAdminRights; + +channelBannedRights#58cf4249 flags:# view_messages:flags.0?true send_messages:flags.1?true send_media:flags.2?true send_stickers:flags.3?true send_gifs:flags.4?true send_games:flags.5?true send_inline:flags.6?true embed_links:flags.7?true until_date:int = ChannelBannedRights; + +channelAdminLogEventActionChangeTitle#e6dfb825 prev_value:string new_value:string = ChannelAdminLogEventAction; +channelAdminLogEventActionChangeAbout#55188a2e prev_value:string new_value:string = ChannelAdminLogEventAction; +channelAdminLogEventActionChangeUsername#6a4afc38 prev_value:string new_value:string = ChannelAdminLogEventAction; +channelAdminLogEventActionChangePhoto#b82f55c3 prev_photo:ChatPhoto new_photo:ChatPhoto = ChannelAdminLogEventAction; +channelAdminLogEventActionToggleInvites#1b7907ae new_value:Bool = ChannelAdminLogEventAction; +channelAdminLogEventActionToggleSignatures#26ae0971 new_value:Bool = ChannelAdminLogEventAction; +channelAdminLogEventActionUpdatePinned#e9e82c18 message:Message = ChannelAdminLogEventAction; +channelAdminLogEventActionEditMessage#709b2405 prev_message:Message new_message:Message = ChannelAdminLogEventAction; +channelAdminLogEventActionDeleteMessage#42e047bb message:Message = ChannelAdminLogEventAction; +channelAdminLogEventActionParticipantJoin#183040d3 = ChannelAdminLogEventAction; +channelAdminLogEventActionParticipantLeave#f89777f2 = ChannelAdminLogEventAction; +channelAdminLogEventActionParticipantInvite#e31c34d8 participant:ChannelParticipant = ChannelAdminLogEventAction; +channelAdminLogEventActionParticipantToggleBan#e6d83d7e prev_participant:ChannelParticipant new_participant:ChannelParticipant = ChannelAdminLogEventAction; +channelAdminLogEventActionParticipantToggleAdmin#d5676710 prev_participant:ChannelParticipant new_participant:ChannelParticipant = ChannelAdminLogEventAction; + +channelAdminLogEvent#3b5a3e40 id:long date:int user_id:int action:ChannelAdminLogEventAction = ChannelAdminLogEvent; + +channels.adminLogResults#ed8af74d events:Vector chats:Vector users:Vector = channels.AdminLogResults; + +channelAdminLogEventsFilter#ea107ae4 flags:# join:flags.0?true leave:flags.1?true invite:flags.2?true ban:flags.3?true unban:flags.4?true kick:flags.5?true unkick:flags.6?true promote:flags.7?true demote:flags.8?true info:flags.9?true settings:flags.10?true pinned:flags.11?true edit:flags.12?true delete:flags.13?true = ChannelAdminLogEventsFilter; + ---functions--- invokeAfterMsg#cb9f372d {X:Type} msg_id:long query:!X = X; @@ -950,13 +974,13 @@ contacts.exportCard#84e53737 = Vector; contacts.importCard#4fe196fe export_card:Vector = User; contacts.search#11f812d8 q:string limit:int = contacts.Found; contacts.resolveUsername#f93ccba3 username:string = contacts.ResolvedPeer; -contacts.getTopPeers#d4982db5 flags:# correspondents:flags.0?true bots_pm:flags.1?true bots_inline:flags.2?true groups:flags.10?true channels:flags.15?true offset:int limit:int hash:int = contacts.TopPeers; +contacts.getTopPeers#d4982db5 flags:# correspondents:flags.0?true bots_pm:flags.1?true bots_inline:flags.2?true phone_calls:flags.3?true groups:flags.10?true channels:flags.15?true offset:int limit:int hash:int = contacts.TopPeers; contacts.resetTopPeerRating#1ae373ac category:TopPeerCategory peer:InputPeer = Bool; messages.getMessages#4222fa74 id:Vector = messages.Messages; messages.getDialogs#191ba9c5 flags:# exclude_pinned:flags.0?true offset_date:int offset_id:int offset_peer:InputPeer limit:int = messages.Dialogs; messages.getHistory#afa92846 peer:InputPeer offset_id:int offset_date:int add_offset:int limit:int max_id:int min_id:int = messages.Messages; -messages.search#d4569248 flags:# peer:InputPeer q:string filter:MessagesFilter min_date:int max_date:int offset:int max_id:int limit:int = messages.Messages; +messages.search#f288a275 flags:# peer:InputPeer q:string from_id:flags.0?InputUser filter:MessagesFilter min_date:int max_date:int offset:int max_id:int limit:int = messages.Messages; messages.readHistory#e306d3a peer:InputPeer max_id:int = messages.AffectedMessages; messages.deleteHistory#1c015b09 flags:# just_clear:flags.0?true peer:InputPeer max_id:int = messages.AffectedHistory; messages.deleteMessages#e58e95d2 flags:# revoke:flags.0?true id:Vector = messages.AffectedMessages; @@ -1078,7 +1102,7 @@ channels.getChannels#a7f6bbb id:Vector = messages.Chats; channels.getFullChannel#8736a09 channel:InputChannel = messages.ChatFull; channels.createChannel#f4893d7f flags:# broadcast:flags.0?true megagroup:flags.1?true title:string about:string = Updates; channels.editAbout#13e27f1e channel:InputChannel about:string = Bool; -channels.editAdmin#eb7611d0 channel:InputChannel user_id:InputUser role:ChannelParticipantRole = Updates; +channels.editAdmin#20b88214 channel:InputChannel user_id:InputUser admin_rights:ChannelAdminRights = Updates; channels.editTitle#566decd0 channel:InputChannel title:string = Updates; channels.editPhoto#f12e57c9 channel:InputChannel photo:InputChatPhoto = Updates; channels.checkUsername#10e6bd2c channel:InputChannel username:string = Bool; @@ -1086,7 +1110,6 @@ channels.updateUsername#3514b3de channel:InputChannel username:string = Bool; channels.joinChannel#24b524c5 channel:InputChannel = Updates; channels.leaveChannel#f836aa95 channel:InputChannel = Updates; channels.inviteToChannel#199f3a6c channel:InputChannel users:Vector = Updates; -channels.kickFromChannel#a672de14 channel:InputChannel user_id:InputUser kicked:Bool = Updates; channels.exportInvite#c7560885 channel:InputChannel = ExportedChatInvite; channels.deleteChannel#c0111fe3 channel:InputChannel = Updates; channels.toggleInvites#49609307 channel:InputChannel enabled:Bool = Updates; @@ -1094,6 +1117,8 @@ channels.exportMessageLink#c846d22d channel:InputChannel id:int = ExportedMessag channels.toggleSignatures#1f69b606 channel:InputChannel enabled:Bool = Updates; channels.updatePinnedMessage#a72ded52 flags:# silent:flags.0?true channel:InputChannel id:int = Updates; channels.getAdminedPublicChannels#8d8d82d7 = messages.Chats; +channels.editBanned#bfd915cd channel:InputChannel user_id:InputUser banned_rights:ChannelBannedRights = Updates; +channels.getAdminLog#33ddf480 flags:# channel:InputChannel q:string events_filter:flags.0?ChannelAdminLogEventsFilter admins:flags.1?Vector max_id:long min_id:long limit:int = channels.AdminLogResults; bots.sendCustomRequest#aa2769ed custom_method:string params:DataJSON = DataJSON; bots.answerWebhookJSONQuery#e6213f4d query_id:long data:DataJSON = Bool; @@ -1105,7 +1130,10 @@ payments.sendPaymentForm#2b8879b3 flags:# msg_id:int requested_info_id:flags.0?s payments.getSavedInfo#227d824b = payments.SavedInfo; payments.clearSavedInfo#d83d70c1 flags:# credentials:flags.0?true info:flags.1?true = Bool; -stickers.createStickerSet#4da2730c flags:# masks:flags.0?true user_id:InputUser title:string short_name:string stickers:Vector = Bool; +stickers.createStickerSet#9bd86e6a flags:# masks:flags.0?true user_id:InputUser title:string short_name:string stickers:Vector = messages.StickerSet; +stickers.removeStickerFromSet#4255934 sticker:InputDocument = Bool; +stickers.changeStickerPosition#4ed705ca sticker:InputDocument position:int = Bool; +stickers.addStickerToSet#8653febe stickerset:InputStickerSet sticker:InputStickerSetItem = messages.StickerSet; phone.getCallConfig#55451fa9 = DataJSON; phone.requestCall#5b95b3d4 user_id:InputUser random_id:int g_a_hash:bytes protocol:PhoneCallProtocol = phone.PhoneCall; @@ -1121,4 +1149,4 @@ langpack.getStrings#2e1ee318 lang_code:string keys:Vector = Vector; -// LAYER 67 +// LAYER 68 diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index be2a71f02..ca694f7ea 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -218,9 +218,9 @@ void ApiWrap::gotChatFull(PeerData *peer, const MTPmessages_ChatFull &result, mt auto &vc = d.vchats.v; auto badVersion = false; if (peer->isChat()) { - badVersion = (!vc.isEmpty() && vc.at(0).type() == mtpc_chat && vc.at(0).c_chat().vversion.v < peer->asChat()->version); + badVersion = (!vc.isEmpty() && vc[0].type() == mtpc_chat && vc[0].c_chat().vversion.v < peer->asChat()->version); } else if (peer->isChannel()) { - badVersion = (!vc.isEmpty() && vc.at(0).type() == mtpc_channel && vc.at(0).c_channel().vversion.v < peer->asChannel()->version); + badVersion = (!vc.isEmpty() && vc[0].type() == mtpc_channel && vc[0].c_channel().vversion.v < peer->asChannel()->version); } App::feedUsers(d.vusers); @@ -342,16 +342,16 @@ void ApiWrap::gotChatFull(PeerData *peer, const MTPmessages_ChatFull &result, mt } if (req) { - QMap::iterator i = _fullPeerRequests.find(peer); + auto i = _fullPeerRequests.find(peer); if (i != _fullPeerRequests.cend() && i.value() == req) { _fullPeerRequests.erase(i); } } if (badVersion) { - if (peer->isChat()) { - peer->asChat()->version = vc.at(0).c_chat().vversion.v; - } else if (peer->isChannel()) { - peer->asChannel()->version = vc.at(0).c_channel().vversion.v; + if (auto chat = peer->asChat()) { + chat->version = vc[0].c_chat().vversion.v; + } else if (auto channel = peer->asChannel()) { + channel->version = vc[0].c_channel().vversion.v; } requestPeer(peer); } @@ -403,18 +403,18 @@ void ApiWrap::requestPeer(PeerData *peer) { if (auto chats = Api::getChatsFromMessagesChats(result)) { auto &v = chats->v; bool badVersion = false; - if (peer->isChat()) { - badVersion = (!v.isEmpty() && v.at(0).type() == mtpc_chat && v.at(0).c_chat().vversion.v < peer->asChat()->version); - } else if (peer->isChannel()) { - badVersion = (!v.isEmpty() && v.at(0).type() == mtpc_channel && v.at(0).c_chat().vversion.v < peer->asChannel()->version); + if (auto chat = peer->asChat()) { + badVersion = (!v.isEmpty() && v[0].type() == mtpc_chat && v[0].c_chat().vversion.v < chat->version); + } else if (auto channel = peer->asChannel()) { + badVersion = (!v.isEmpty() && v[0].type() == mtpc_channel && v[0].c_channel().vversion.v < channel->version); } auto chat = App::feedChats(*chats); if (chat == peer) { if (badVersion) { - if (peer->isChat()) { - peer->asChat()->version = v.at(0).c_chat().vversion.v; - } else if (peer->isChannel()) { - peer->asChannel()->version = v.at(0).c_channel().vversion.v; + if (auto chat = peer->asChat()) { + chat->version = v[0].c_chat().vversion.v; + } else if (auto channel = peer->asChannel()) { + channel->version = v[0].c_channel().vversion.v; } requestPeer(peer); } @@ -478,7 +478,7 @@ void ApiWrap::requestLastParticipants(ChannelData *channel, bool fromStart) { return; } - auto needAdmins = channel->amEditor(); + auto needAdmins = channel->canViewAdmins(); auto adminsOutdated = (channel->mgInfo->lastParticipantsStatus & MegagroupInfo::LastParticipantsAdminsOutdated) != 0; if ((needAdmins && adminsOutdated) || channel->lastParticipantsCountOutdated()) { fromStart = true; @@ -560,11 +560,14 @@ void ApiWrap::lastParticipantsDone(ChannelData *peer, const MTPchannels_ChannelP switch (participant.type()) { case mtpc_channelParticipant: userId = participant.c_channelParticipant().vuser_id.v; break; case mtpc_channelParticipantSelf: userId = participant.c_channelParticipantSelf().vuser_id.v; break; - case mtpc_channelParticipantModerator: userId = participant.c_channelParticipantModerator().vuser_id.v; break; - case mtpc_channelParticipantEditor: userId = participant.c_channelParticipantEditor().vuser_id.v; admin = true; break; - case mtpc_channelParticipantKicked: userId = participant.c_channelParticipantKicked().vuser_id.v; break; + case mtpc_channelParticipantAdmin: userId = participant.c_channelParticipantAdmin().vuser_id.v; admin = true; break; + case mtpc_channelParticipantBanned: userId = participant.c_channelParticipantBanned().vuser_id.v; break; case mtpc_channelParticipantCreator: userId = participant.c_channelParticipantCreator().vuser_id.v; admin = true; break; } + if (!userId) { + continue; + } + auto u = App::user(userId); if (bots) { if (u->botInfo) { @@ -642,17 +645,11 @@ void ApiWrap::requestSelfParticipant(ChannelData *channel) { channel->inviter = _session->userId(); channel->inviteDate = date(MTP_int(channel->date)); } break; - case mtpc_channelParticipantModerator: { - auto &d = p.vparticipant.c_channelParticipantModerator(); + case mtpc_channelParticipantAdmin: { + auto &d = p.vparticipant.c_channelParticipantAdmin(); channel->inviter = d.vinviter_id.v; channel->inviteDate = date(d.vdate); } break; - case mtpc_channelParticipantEditor: { - auto &d = p.vparticipant.c_channelParticipantEditor(); - channel->inviter = d.vinviter_id.v; - channel->inviteDate = date(d.vdate); - } break; - } if (App::main()) App::main()->onSelfParticipantUpdated(channel); @@ -671,44 +668,44 @@ void ApiWrap::kickParticipant(PeerData *peer, UserData *user) { if (_kickRequests.contains(kick)) return; if (auto channel = peer->asChannel()) { - auto requestId = request(MTPchannels_KickFromChannel(channel->inputChannel, user->inputUser, MTP_bool(true))).done([this, peer, user](const MTPUpdates &result) { - applyUpdates(result); + //auto requestId = request(MTPchannels_KickFromChannel(channel->inputChannel, user->inputUser, MTP_bool(true))).done([this, peer, user](const MTPUpdates &result) { + // applyUpdates(result); - _kickRequests.remove(KickRequest(peer, user)); - if (auto channel = peer->asMegagroup()) { - auto megagroupInfo = channel->mgInfo; + // _kickRequests.remove(KickRequest(peer, user)); + // if (auto channel = peer->asMegagroup()) { + // auto megagroupInfo = channel->mgInfo; - auto i = megagroupInfo->lastParticipants.indexOf(user); - if (i >= 0) { - megagroupInfo->lastParticipants.removeAt(i); - } + // auto i = megagroupInfo->lastParticipants.indexOf(user); + // if (i >= 0) { + // megagroupInfo->lastParticipants.removeAt(i); + // } - if (channel->membersCount() > 1) { - channel->setMembersCount(channel->membersCount() - 1); - } else { - megagroupInfo->lastParticipantsStatus |= MegagroupInfo::LastParticipantsCountOutdated; - megagroupInfo->lastParticipantsCount = 0; - } - channel->setKickedCount(channel->kickedCount() + 1); - if (megagroupInfo->lastAdmins.contains(user)) { - megagroupInfo->lastAdmins.remove(user); - if (channel->adminsCount() > 1) { - channel->setAdminsCount(channel->adminsCount() - 1); - } - Notify::peerUpdatedDelayed(channel, Notify::PeerUpdate::Flag::AdminsChanged); - } - megagroupInfo->bots.remove(user); - if (megagroupInfo->bots.isEmpty() && megagroupInfo->botStatus > 0) { - megagroupInfo->botStatus = -1; - } - } - Notify::peerUpdatedDelayed(peer, Notify::PeerUpdate::Flag::MembersChanged); - fullPeerUpdated().notify(peer); - }).fail([this, kick](const RPCError &error) { - _kickRequests.remove(kick); - }).send(); + // if (channel->membersCount() > 1) { + // channel->setMembersCount(channel->membersCount() - 1); + // } else { + // megagroupInfo->lastParticipantsStatus |= MegagroupInfo::LastParticipantsCountOutdated; + // megagroupInfo->lastParticipantsCount = 0; + // } + // channel->setKickedCount(channel->kickedCount() + 1); + // if (megagroupInfo->lastAdmins.contains(user)) { + // megagroupInfo->lastAdmins.remove(user); + // if (channel->adminsCount() > 1) { + // channel->setAdminsCount(channel->adminsCount() - 1); + // } + // Notify::peerUpdatedDelayed(channel, Notify::PeerUpdate::Flag::AdminsChanged); + // } + // megagroupInfo->bots.remove(user); + // if (megagroupInfo->bots.isEmpty() && megagroupInfo->botStatus > 0) { + // megagroupInfo->botStatus = -1; + // } + // } + // Notify::peerUpdatedDelayed(peer, Notify::PeerUpdate::Flag::MembersChanged); + // fullPeerUpdated().notify(peer); + //}).fail([this, kick](const RPCError &error) { + // _kickRequests.remove(kick); + //}).send(); - _kickRequests.insert(kick, requestId); + //_kickRequests.insert(kick, requestId); } } @@ -717,22 +714,22 @@ void ApiWrap::unblockParticipant(PeerData *peer, UserData *user) { if (_kickRequests.contains(kick)) return; if (auto channel = peer->asChannel()) { - auto requestId = request(MTPchannels_KickFromChannel(channel->inputChannel, user->inputUser, MTP_bool(false))).done([this, peer, user](const MTPUpdates &result) { - applyUpdates(result); + //auto requestId = request(MTPchannels_KickFromChannel(channel->inputChannel, user->inputUser, MTP_bool(false))).done([this, peer, user](const MTPUpdates &result) { + // applyUpdates(result); - _kickRequests.remove(KickRequest(peer, user)); - if (auto channel = peer->asMegagroup()) { - if (channel->kickedCount() > 0) { - channel->setKickedCount(channel->kickedCount() - 1); - } else { - channel->updateFull(true); - } - } - }).fail([this, kick](const RPCError &error) { - _kickRequests.remove(kick); - }).send(); + // _kickRequests.remove(KickRequest(peer, user)); + // if (auto channel = peer->asMegagroup()) { + // if (channel->kickedCount() > 0) { + // channel->setKickedCount(channel->kickedCount() - 1); + // } else { + // channel->updateFull(true); + // } + // } + //}).fail([this, kick](const RPCError &error) { + // _kickRequests.remove(kick); + //}).send(); - _kickRequests.insert(kick, requestId); + //_kickRequests.insert(kick, requestId); } } diff --git a/Telegram/SourceFiles/app.cpp b/Telegram/SourceFiles/app.cpp index 740deb32e..d6f7b082c 100644 --- a/Telegram/SourceFiles/app.cpp +++ b/Telegram/SourceFiles/app.cpp @@ -640,7 +640,7 @@ namespace { cdata->flags = d.vflags.v; cdata->count = d.vparticipants_count.v; - cdata->isForbidden = false; + cdata->setIsForbidden(false); if (canEdit != cdata->canEdit()) { update.flags |= UpdateFlag::ChatCanEdit; } @@ -659,13 +659,13 @@ namespace { cdata->count = -1; cdata->invalidateParticipants(); cdata->flags = 0; - cdata->isForbidden = true; + cdata->setIsForbidden(true); if (canEdit != cdata->canEdit()) { update.flags |= UpdateFlag::ChatCanEdit; } } break; case mtpc_channel: { - auto &d(chat.c_channel()); + auto &d = chat.c_channel(); auto peerId = peerFromChannel(d.vid.v); minimal = d.is_min(); @@ -681,7 +681,7 @@ namespace { auto cdata = data->asChannel(); auto wasInChannel = cdata->amIn(); - auto canEditPhoto = cdata->canEditPhoto(); + auto canEditInformation = cdata->canEditInformation(); auto canViewAdmins = cdata->canViewAdmins(); auto canViewMembers = cdata->canViewMembers(); auto canAddMembers = cdata->canAddMembers(); @@ -691,6 +691,12 @@ namespace { auto mask = MTPDchannel::Flag::f_broadcast | MTPDchannel::Flag::f_verified | MTPDchannel::Flag::f_megagroup | MTPDchannel::Flag::f_democracy; cdata->flags = (cdata->flags & ~mask) | (d.vflags.v & mask); } else { + if (d.has_admin_rights() || cdata->hasAdminRights()) { + cdata->setAdminRights(d.has_admin_rights() ? d.vadmin_rights : MTP_channelAdminRights(MTP_flags(0))); + } + if (d.has_banned_rights() || cdata->hasBannedRights()) { + cdata->setBannedRights(d.has_banned_rights() ? d.vbanned_rights : MTP_channelBannedRights(MTP_flags(0), MTP_int(0))); + } cdata->inputChannel = MTP_inputChannel(d.vid, d.vaccess_hash); cdata->access = d.vaccess_hash.v; cdata->date = d.vdate.v; @@ -709,11 +715,11 @@ namespace { QString uname = d.has_username() ? textOneLine(qs(d.vusername)) : QString(); cdata->setName(qs(d.vtitle), uname); - cdata->isForbidden = false; + cdata->setIsForbidden(false); cdata->setPhoto(d.vphoto); if (wasInChannel != cdata->amIn()) update.flags |= UpdateFlag::ChannelAmIn; - if (canEditPhoto != cdata->canEditPhoto()) update.flags |= UpdateFlag::ChannelCanEditPhoto; + if (canEditInformation != cdata->canEditInformation()) update.flags |= UpdateFlag::ChannelCanEditInformation; if (canViewAdmins != cdata->canViewAdmins()) update.flags |= UpdateFlag::ChannelCanViewAdmins; if (canViewMembers != cdata->canViewMembers()) update.flags |= UpdateFlag::ChannelCanViewMembers; if (canAddMembers != cdata->canAddMembers()) update.flags |= UpdateFlag::ChannelCanAddMembers; @@ -731,7 +737,7 @@ namespace { auto cdata = data->asChannel(); auto wasInChannel = cdata->amIn(); - auto canEditPhoto = cdata->canEditPhoto(); + auto canEditInformation = cdata->canEditInformation(); auto canViewAdmins = cdata->canViewAdmins(); auto canViewMembers = cdata->canViewMembers(); auto canAddMembers = cdata->canAddMembers(); @@ -743,16 +749,23 @@ namespace { cdata->flags = (cdata->flags & ~mask) | (mtpCastFlags(d.vflags) & mask); cdata->flagsUpdated(); + if (cdata->hasAdminRights()) { + cdata->setAdminRights(MTP_channelAdminRights(MTP_flags(0))); + } + if (cdata->hasBannedRights()) { + cdata->setBannedRights(MTP_channelBannedRights(MTP_flags(0), MTP_int(0))); + } + cdata->setName(qs(d.vtitle), QString()); cdata->access = d.vaccess_hash.v; cdata->setPhoto(MTP_chatPhotoEmpty()); cdata->date = 0; cdata->setMembersCount(0); - cdata->isForbidden = true; + cdata->setIsForbidden(true); if (wasInChannel != cdata->amIn()) update.flags |= UpdateFlag::ChannelAmIn; - if (canEditPhoto != cdata->canEditPhoto()) update.flags |= UpdateFlag::ChannelCanEditPhoto; + if (canEditInformation != cdata->canEditInformation()) update.flags |= UpdateFlag::ChannelCanEditInformation; if (canViewAdmins != cdata->canViewAdmins()) update.flags |= UpdateFlag::ChannelCanViewAdmins; if (canViewMembers != cdata->canViewMembers()) update.flags |= UpdateFlag::ChannelCanViewMembers; if (canAddMembers != cdata->canAddMembers()) update.flags |= UpdateFlag::ChannelCanAddMembers; diff --git a/Telegram/SourceFiles/boxes/confirm_box.cpp b/Telegram/SourceFiles/boxes/confirm_box.cpp index adc65a5f9..8cef44744 100644 --- a/Telegram/SourceFiles/boxes/confirm_box.cpp +++ b/Telegram/SourceFiles/boxes/confirm_box.cpp @@ -408,9 +408,13 @@ bool PinMessageBox::pinFail(const RPCError &error) { DeleteMessagesBox::DeleteMessagesBox(QWidget*, HistoryItem *item, bool suggestModerateActions) : _singleItem(true) { _ids.push_back(item->fullId()); - if (suggestModerateActions && item->suggestBanReportDeleteAll()) { - _moderateFrom = item->from()->asUser(); - _moderateInChannel = item->history()->peer->asChannel(); + if (suggestModerateActions) { + _moderateBan = item->suggestBanReport(); + _moderateDeleteAll = item->suggestDeleteAllReport(); + if (_moderateBan || _moderateDeleteAll) { + _moderateFrom = item->from()->asUser(); + _moderateInChannel = item->history()->peer->asChannel(); + } } } @@ -428,9 +432,13 @@ void DeleteMessagesBox::prepare() { if (_moderateFrom) { t_assert(_moderateInChannel != nullptr); text = lang(lng_selected_delete_sure_this); - _banUser.create(this, lang(lng_ban_user), false, st::defaultBoxCheckbox); + if (_moderateBan) { + _banUser.create(this, lang(lng_ban_user), false, st::defaultBoxCheckbox); + } _reportSpam.create(this, lang(lng_report_spam), false, st::defaultBoxCheckbox); - _deleteAll.create(this, lang(lng_delete_all_from), false, st::defaultBoxCheckbox); + if (_moderateDeleteAll) { + _deleteAll.create(this, lang(lng_delete_all_from), false, st::defaultBoxCheckbox); + } } else { text = _singleItem ? lang(lng_selected_delete_sure_this) : lng_selected_delete_sure(lt_count, _ids.size()); auto canDeleteAllForEveryone = true; @@ -476,7 +484,14 @@ void DeleteMessagesBox::prepare() { auto fullHeight = st::boxPadding.top() + _text->height() + st::boxPadding.bottom(); if (_moderateFrom) { - fullHeight += st::boxMediumSkip + _banUser->heightNoMargins() + st::boxLittleSkip + _reportSpam->heightNoMargins() + st::boxLittleSkip + _deleteAll->heightNoMargins(); + fullHeight += st::boxMediumSkip; + if (_banUser) { + fullHeight += _banUser->heightNoMargins() + st::boxLittleSkip; + } + fullHeight += _reportSpam->heightNoMargins(); + if (_deleteAll) { + fullHeight += st::boxLittleSkip + _deleteAll->heightNoMargins(); + } } else if (_forEveryone) { fullHeight += st::boxMediumSkip + _forEveryone->heightNoMargins(); } @@ -487,9 +502,16 @@ void DeleteMessagesBox::resizeEvent(QResizeEvent *e) { BoxContent::resizeEvent(e); _text->moveToLeft(st::boxPadding.left(), st::boxPadding.top()); if (_moderateFrom) { - _banUser->moveToLeft(st::boxPadding.left(), _text->bottomNoMargins() + st::boxMediumSkip); - _reportSpam->moveToLeft(st::boxPadding.left(), _banUser->bottomNoMargins() + st::boxLittleSkip); - _deleteAll->moveToLeft(st::boxPadding.left(), _reportSpam->bottomNoMargins() + st::boxLittleSkip); + auto top = _text->bottomNoMargins() + st::boxMediumSkip; + if (_banUser) { + _banUser->moveToLeft(st::boxPadding.left(), top); + top += _banUser->heightNoMargins() + st::boxLittleSkip; + } + _reportSpam->moveToLeft(st::boxPadding.left(), top); + top += _reportSpam->heightNoMargins() + st::boxLittleSkip; + if (_deleteAll) { + _deleteAll->moveToLeft(st::boxPadding.left(), top); + } } else if (_forEveryone) { _forEveryone->moveToLeft(st::boxPadding.left(), _text->bottomNoMargins() + st::boxMediumSkip); } @@ -509,13 +531,13 @@ void DeleteMessagesBox::deleteAndClear() { } if (_moderateFrom) { - if (_banUser->checked()) { - MTP::send(MTPchannels_KickFromChannel(_moderateInChannel->inputChannel, _moderateFrom->inputUser, MTP_boolTrue()), App::main()->rpcDone(&MainWidget::sentUpdatesReceived)); + if (_banUser && _banUser->checked()) { +// MTP::send(MTPchannels_KickFromChannel(_moderateInChannel->inputChannel, _moderateFrom->inputUser, MTP_boolTrue()), App::main()->rpcDone(&MainWidget::sentUpdatesReceived)); } if (_reportSpam->checked()) { MTP::send(MTPchannels_ReportSpam(_moderateInChannel->inputChannel, _moderateFrom->inputUser, MTP_vector(1, MTP_int(_ids[0].msg)))); } - if (_deleteAll->checked()) { + if (_deleteAll && _deleteAll->checked()) { App::main()->deleteAllFromUser(_moderateInChannel, _moderateFrom); } } diff --git a/Telegram/SourceFiles/boxes/confirm_box.h b/Telegram/SourceFiles/boxes/confirm_box.h index d41c6b774..40f9784bc 100644 --- a/Telegram/SourceFiles/boxes/confirm_box.h +++ b/Telegram/SourceFiles/boxes/confirm_box.h @@ -189,6 +189,8 @@ private: bool _singleItem = false; UserData *_moderateFrom = nullptr; ChannelData *_moderateInChannel = nullptr; + bool _moderateBan = false; + bool _moderateDeleteAll = false; object_ptr _text = { nullptr }; object_ptr _forEveryone = { nullptr }; diff --git a/Telegram/SourceFiles/boxes/contacts_box.cpp b/Telegram/SourceFiles/boxes/contacts_box.cpp index 9c18b9f51..aeadcf90a 100644 --- a/Telegram/SourceFiles/boxes/contacts_box.cpp +++ b/Telegram/SourceFiles/boxes/contacts_box.cpp @@ -609,7 +609,7 @@ ContactsBox::Inner::Inner(QWidget *parent, UserData *bot) : TWidget(parent) addDialogsToList([](PeerData *peer) { if (peer->isChat() && peer->asChat()->canEdit()) { return true; - } else if (peer->isMegagroup() && (peer->asChannel()->amCreator() || peer->asChannel()->amEditor())) { + } else if (peer->isMegagroup() && peer->asChannel()->canAddMembers()) { return true; } return false; @@ -1414,7 +1414,7 @@ void ContactsBox::Inner::chooseParticipant() { if (_addAdminBox) _addAdminBox->deleteLater(); _addAdminBox = Ui::show(Box(lng_channel_admin_sure(lt_user, _addAdmin->firstName), base::lambda_guarded(this, [this] { if (_addAdminRequestId) return; - _addAdminRequestId = MTP::send(MTPchannels_EditAdmin(_channel->inputChannel, _addAdmin->inputUser, MTP_channelRoleEditor()), rpcDone(&Inner::addAdminDone), rpcFail(&Inner::addAdminFail)); +// _addAdminRequestId = MTP::send(MTPchannels_EditAdmin(_channel->inputChannel, _addAdmin->inputUser, MTP_channelRoleEditor()), rpcDone(&Inner::addAdminDone), rpcFail(&Inner::addAdminFail)); })), KeepOtherLayers); } else if (sharingBotGame()) { _addToPeer = peer; diff --git a/Telegram/SourceFiles/boxes/members_box.cpp b/Telegram/SourceFiles/boxes/members_box.cpp index 02fdada32..fb887b1d9 100644 --- a/Telegram/SourceFiles/boxes/members_box.cpp +++ b/Telegram/SourceFiles/boxes/members_box.cpp @@ -231,9 +231,9 @@ void MembersBox::Inner::mouseReleaseEvent(QMouseEvent *e) { auto text = (_filter == MembersFilter::Recent ? (_channel->isMegagroup() ? lng_profile_sure_kick : lng_profile_sure_kick_channel) : lng_profile_sure_kick_admin)(lt_user, _kickConfirm->firstName); _kickBox = Ui::show(Box(text, base::lambda_guarded(this, [this] { if (_filter == MembersFilter::Recent) { - _kickRequestId = MTP::send(MTPchannels_KickFromChannel(_channel->inputChannel, _kickConfirm->inputUser, MTP_bool(true)), rpcDone(&Inner::kickDone), rpcFail(&Inner::kickFail)); +// _kickRequestId = MTP::send(MTPchannels_KickFromChannel(_channel->inputChannel, _kickConfirm->inputUser, MTP_bool(true)), rpcDone(&Inner::kickDone), rpcFail(&Inner::kickFail)); } else { - _kickRequestId = MTP::send(MTPchannels_EditAdmin(_channel->inputChannel, _kickConfirm->inputUser, MTP_channelRoleEmpty()), rpcDone(&Inner::kickAdminDone), rpcFail(&Inner::kickFail)); + // _kickRequestId = MTP::send(MTPchannels_EditAdmin(_channel->inputChannel, _kickConfirm->inputUser, MTP_channelRoleEmpty()), rpcDone(&Inner::kickAdminDone), rpcFail(&Inner::kickFail)); } })), KeepOtherLayers); } @@ -433,9 +433,9 @@ MembersBox::Inner::MemberData *MembersBox::Inner::data(int32 index) { result->online = App::onlineText(_rows[index], t);// lng_mediaview_date_time(lt_date, _dates[index].date().toString(qsl("dd.MM.yy")), lt_time, _dates[index].time().toString(cTimeFormat())); result->onlineColor = App::onlineColorUse(_rows[index], t); if (_filter == MembersFilter::Recent) { - result->canKick = (_channel->amCreator() || _channel->amEditor() || _channel->amModerator()) ? (_roles[index] == MemberRole::None) : false; + result->canKick = _channel->canBanMembers() ? (_roles[index] == MemberRole::None) : false; } else if (_filter == MembersFilter::Admins) { - result->canKick = _channel->amCreator() ? (_roles[index] == MemberRole::Editor || _roles[index] == MemberRole::Moderator) : false; + result->canKick = _channel->amCreator() ? (_roles[index] == MemberRole::Admin) : false; } else { result->canKick = false; } @@ -548,28 +548,22 @@ void MembersBox::Inner::membersReceived(const MTPchannels_ChannelParticipants &r userId = i->c_channelParticipantSelf().vuser_id.v; addedTime = i->c_channelParticipantSelf().vdate.v; break; - case mtpc_channelParticipantModerator: - role = MemberRole::Moderator; - userId = i->c_channelParticipantModerator().vuser_id.v; - addedTime = i->c_channelParticipantModerator().vdate.v; - break; - case mtpc_channelParticipantEditor: - role = MemberRole::Editor; - userId = i->c_channelParticipantEditor().vuser_id.v; - addedTime = i->c_channelParticipantEditor().vdate.v; - break; - case mtpc_channelParticipantKicked: - userId = i->c_channelParticipantKicked().vuser_id.v; - addedTime = i->c_channelParticipantKicked().vdate.v; - role = MemberRole::Kicked; + case mtpc_channelParticipantAdmin: + role = MemberRole::Admin; + userId = i->c_channelParticipantAdmin().vuser_id.v; + addedTime = i->c_channelParticipantAdmin().vdate.v; break; case mtpc_channelParticipantCreator: userId = i->c_channelParticipantCreator().vuser_id.v; addedTime = _channel->date; role = MemberRole::Creator; break; + case mtpc_channelParticipantBanned: + userId = i->c_channelParticipantBanned().vuser_id.v; + addedTime = i->c_channelParticipantBanned().vdate.v; + role = MemberRole::Kicked; } - if (UserData *user = App::userLoaded(userId)) { + if (auto user = App::userLoaded(userId)) { _rows.push_back(user); _dates.push_back(date(addedTime)); _roles.push_back(role); @@ -581,7 +575,7 @@ void MembersBox::Inner::membersReceived(const MTPchannels_ChannelParticipants &r if (_filter == MembersFilter::Admins && _channel->isMegagroup() && _rows.size() < Global::ChatSizeMax()) { _channel->mgInfo->lastAdmins.clear(); for (int32 i = 0, l = _rows.size(); i != l; ++i) { - if (_roles.at(i) == MemberRole::Creator || _roles.at(i) == MemberRole::Editor) { + if (_roles.at(i) == MemberRole::Creator || _roles.at(i) == MemberRole::Admin) { _channel->mgInfo->lastAdmins.insert(_rows.at(i)); } } diff --git a/Telegram/SourceFiles/boxes/members_box.h b/Telegram/SourceFiles/boxes/members_box.h index 48084d930..5cd5e47a8 100644 --- a/Telegram/SourceFiles/boxes/members_box.h +++ b/Telegram/SourceFiles/boxes/members_box.h @@ -188,9 +188,8 @@ private: None, Self, Creator, - Editor, - Moderator, - Kicked + Admin, + Kicked, }; bool _loading = true; diff --git a/Telegram/SourceFiles/calls/calls_box_controller.cpp b/Telegram/SourceFiles/calls/calls_box_controller.cpp index 6bd0ccc55..1cf4027ae 100644 --- a/Telegram/SourceFiles/calls/calls_box_controller.cpp +++ b/Telegram/SourceFiles/calls/calls_box_controller.cpp @@ -215,7 +215,7 @@ void BoxController::preloadRows() { return; } - _loadRequestId = request(MTPmessages_Search(MTP_flags(0), MTP_inputPeerEmpty(), MTP_string(QString()), MTP_inputMessagesFilterPhoneCalls(MTP_flags(0)), MTP_int(0), MTP_int(0), MTP_int(0), MTP_int(_offsetId), MTP_int(_offsetId ? kFirstPageCount : kPerPageCount))).done([this](const MTPmessages_Messages &result) { + _loadRequestId = request(MTPmessages_Search(MTP_flags(0), MTP_inputPeerEmpty(), MTP_string(QString()), MTP_inputUserEmpty(), MTP_inputMessagesFilterPhoneCalls(MTP_flags(0)), MTP_int(0), MTP_int(0), MTP_int(0), MTP_int(_offsetId), MTP_int(_offsetId ? kFirstPageCount : kPerPageCount))).done([this](const MTPmessages_Messages &result) { _loadRequestId = 0; auto handleResult = [this](auto &data) { diff --git a/Telegram/SourceFiles/codegen/scheme/codegen_scheme.py b/Telegram/SourceFiles/codegen/scheme/codegen_scheme.py index 2dc15d935..7acc1dae4 100644 --- a/Telegram/SourceFiles/codegen/scheme/codegen_scheme.py +++ b/Telegram/SourceFiles/codegen/scheme/codegen_scheme.py @@ -822,12 +822,20 @@ for restype in typesList: for childName in parentFlagsList: parentName = parentFlags[childName]; for flag in parentFlagsCheck[childName]: - if (not flag in parentFlagsCheck[parentName]): - print('Flag ' + flag + ' not found in ' + parentName + ' which should be a flags-parent of ' + childName); - error - elif (parentFlagsCheck[childName][flag] != parentFlagsCheck[parentName][flag]): - print('Flag ' + flag + ' has different value in ' + parentName + ' which should be a flags-parent of ' + childName); - error +# +# 'channelForbidden' has 'until_date' flag and 'channel' doesn't have it. +# But as long as flags don't collide this is not a problem. +# +# if (not flag in parentFlagsCheck[parentName]): +# print('Flag ' + flag + ' not found in ' + parentName + ' which should be a flags-parent of ' + childName); +# error +# + if (flag in parentFlagsCheck[parentName]): + if (parentFlagsCheck[childName][flag] != parentFlagsCheck[parentName][flag]): + print('Flag ' + flag + ' has different value in ' + parentName + ' which should be a flags-parent of ' + childName); + error + else: + parentFlagsCheck[parentName][flag] = parentFlagsCheck[childName][flag]; inlineMethods += 'inline ' + parentName + '::Flags mtpCastFlags(' + childName + '::Flags flags) { return ' + parentName + '::Flags(QFlag(flags)); }\n'; inlineMethods += 'inline ' + parentName + '::Flags mtpCastFlags(MTPflags<' + childName + '::Flags> flags) { return mtpCastFlags(flags.v); }\n'; diff --git a/Telegram/SourceFiles/dialogswidget.cpp b/Telegram/SourceFiles/dialogswidget.cpp index f291ea806..73029162c 100644 --- a/Telegram/SourceFiles/dialogswidget.cpp +++ b/Telegram/SourceFiles/dialogswidget.cpp @@ -2652,7 +2652,7 @@ bool DialogsWidget::onSearchMessages(bool searchCache) { _searchFull = _searchFullMigrated = false; MTP::cancel(base::take(_searchRequest)); if (_searchInPeer) { - _searchRequest = MTP::send(MTPmessages_Search(MTP_flags(0), _searchInPeer->input, MTP_string(_searchQuery), MTP_inputMessagesFilterEmpty(), MTP_int(0), MTP_int(0), MTP_int(0), MTP_int(0), MTP_int(SearchPerPage)), rpcDone(&DialogsWidget::searchReceived, DialogsSearchPeerFromStart), rpcFail(&DialogsWidget::searchFailed, DialogsSearchPeerFromStart)); + _searchRequest = MTP::send(MTPmessages_Search(MTP_flags(0), _searchInPeer->input, MTP_string(_searchQuery), MTP_inputUserEmpty(), MTP_inputMessagesFilterEmpty(), MTP_int(0), MTP_int(0), MTP_int(0), MTP_int(0), MTP_int(SearchPerPage)), rpcDone(&DialogsWidget::searchReceived, DialogsSearchPeerFromStart), rpcFail(&DialogsWidget::searchFailed, DialogsSearchPeerFromStart)); } else { _searchRequest = MTP::send(MTPmessages_SearchGlobal(MTP_string(_searchQuery), MTP_int(0), MTP_inputPeerEmpty(), MTP_int(0), MTP_int(SearchPerPage)), rpcDone(&DialogsWidget::searchReceived, DialogsSearchFromStart), rpcFail(&DialogsWidget::searchFailed, DialogsSearchFromStart)); } @@ -2714,7 +2714,7 @@ void DialogsWidget::onSearchMore() { auto offsetPeer = _inner->lastSearchPeer(); auto offsetId = _inner->lastSearchId(); if (_searchInPeer) { - _searchRequest = MTP::send(MTPmessages_Search(MTP_flags(0), _searchInPeer->input, MTP_string(_searchQuery), MTP_inputMessagesFilterEmpty(), MTP_int(0), MTP_int(0), MTP_int(0), MTP_int(offsetId), MTP_int(SearchPerPage)), rpcDone(&DialogsWidget::searchReceived, offsetId ? DialogsSearchPeerFromOffset : DialogsSearchPeerFromStart), rpcFail(&DialogsWidget::searchFailed, offsetId ? DialogsSearchPeerFromOffset : DialogsSearchPeerFromStart)); + _searchRequest = MTP::send(MTPmessages_Search(MTP_flags(0), _searchInPeer->input, MTP_string(_searchQuery), MTP_inputUserEmpty(), MTP_inputMessagesFilterEmpty(), MTP_int(0), MTP_int(0), MTP_int(0), MTP_int(offsetId), MTP_int(SearchPerPage)), rpcDone(&DialogsWidget::searchReceived, offsetId ? DialogsSearchPeerFromOffset : DialogsSearchPeerFromStart), rpcFail(&DialogsWidget::searchFailed, offsetId ? DialogsSearchPeerFromOffset : DialogsSearchPeerFromStart)); } else { _searchRequest = MTP::send(MTPmessages_SearchGlobal(MTP_string(_searchQuery), MTP_int(offsetDate), offsetPeer ? offsetPeer->input : MTP_inputPeerEmpty(), MTP_int(offsetId), MTP_int(SearchPerPage)), rpcDone(&DialogsWidget::searchReceived, offsetId ? DialogsSearchFromOffset : DialogsSearchFromStart), rpcFail(&DialogsWidget::searchFailed, offsetId ? DialogsSearchFromOffset : DialogsSearchFromStart)); } @@ -2723,7 +2723,7 @@ void DialogsWidget::onSearchMore() { } } else if (_searchInMigrated && !_searchFullMigrated) { auto offsetMigratedId = _inner->lastSearchMigratedId(); - _searchRequest = MTP::send(MTPmessages_Search(MTP_flags(0), _searchInMigrated->input, MTP_string(_searchQuery), MTP_inputMessagesFilterEmpty(), MTP_int(0), MTP_int(0), MTP_int(0), MTP_int(offsetMigratedId), MTP_int(SearchPerPage)), rpcDone(&DialogsWidget::searchReceived, offsetMigratedId ? DialogsSearchMigratedFromOffset : DialogsSearchMigratedFromStart), rpcFail(&DialogsWidget::searchFailed, offsetMigratedId ? DialogsSearchMigratedFromOffset : DialogsSearchMigratedFromStart)); + _searchRequest = MTP::send(MTPmessages_Search(MTP_flags(0), _searchInMigrated->input, MTP_string(_searchQuery), MTP_inputUserEmpty(), MTP_inputMessagesFilterEmpty(), MTP_int(0), MTP_int(0), MTP_int(0), MTP_int(offsetMigratedId), MTP_int(SearchPerPage)), rpcDone(&DialogsWidget::searchReceived, offsetMigratedId ? DialogsSearchMigratedFromOffset : DialogsSearchMigratedFromStart), rpcFail(&DialogsWidget::searchFailed, offsetMigratedId ? DialogsSearchMigratedFromOffset : DialogsSearchMigratedFromStart)); } } } diff --git a/Telegram/SourceFiles/history/history_item.cpp b/Telegram/SourceFiles/history/history_item.cpp index 662c4ce8f..592cca1fe 100644 --- a/Telegram/SourceFiles/history/history_item.cpp +++ b/Telegram/SourceFiles/history/history_item.cpp @@ -754,7 +754,13 @@ void HistoryItem::setId(MsgId newId) { } bool HistoryItem::canPin() const { - return id > 0 && _history->peer->isMegagroup() && (_history->peer->asChannel()->amEditor() || _history->peer->asChannel()->amCreator()) && toHistoryMessage(); + if (id < 0 || !_history->peer->isMegagroup() || !toHistoryMessage()) { + return false; + } + if (auto channel = _history->peer->asMegagroup()) { + return channel->canPinMessages(); + } + return false; } bool HistoryItem::canForward() const { @@ -773,27 +779,28 @@ bool HistoryItem::canForward() const { } bool HistoryItem::canEdit(const QDateTime &cur) const { - auto messageToMyself = (_history->peer->id == AuthSession::CurrentUserPeerId()); + auto messageToMyself = _history->peer->isSelf(); auto messageTooOld = messageToMyself ? false : (date.secsTo(cur) >= Global::EditTimeLimit()); if (id < 0 || messageTooOld) { return false; } - if (auto msg = toHistoryMessage()) { - if (msg->Has() || msg->Has()) { + if (auto message = toHistoryMessage()) { + if (message->Has() || message->Has()) { return false; } - if (auto media = msg->getMedia()) { + if (auto media = message->getMedia()) { if (!media->canEditCaption() && media->type() != MediaTypeWebPage) { return false; } } - if (isPost()) { - auto channel = _history->peer->asChannel(); - return (channel->amCreator() || (channel->amEditor() && out())); + if (out() || messageToMyself) { + return true; + } + if (auto channel = _history->peer->asChannel()) { + return channel->canDeleteMessages(); } - return out() || messageToMyself; } return false; } @@ -811,16 +818,16 @@ bool HistoryItem::canDelete() const { return true; } if (isPost()) { - if (channel->amEditor() && out()) { + if (out()) { return true; } return false; } - return (channel->amEditor() || channel->amModerator() || out()); + return (channel->canDeleteMessages() || out()); } bool HistoryItem::canDeleteForEveryone(const QDateTime &cur) const { - auto messageToMyself = (_history->peer->id == AuthSession::CurrentUserPeerId()); + auto messageToMyself = _history->peer->isSelf(); auto messageTooOld = messageToMyself ? false : (date.secsTo(cur) >= Global::EditTimeLimit()); if (id < 0 || messageToMyself || messageTooOld || isPost()) { return false; @@ -848,6 +855,22 @@ bool HistoryItem::canDeleteForEveryone(const QDateTime &cur) const { return true; } +bool HistoryItem::suggestBanReport() const { + auto channel = history()->peer->asChannel(); + if (!channel || !channel->canBanMembers()) { + return false; + } + return !isPost() && !out() && from()->isUser() && toHistoryMessage(); +} + +bool HistoryItem::suggestDeleteAllReport() const { + auto channel = history()->peer->asChannel(); + if (!channel || !channel->canDeleteMessages()) { + return false; + } + return !isPost() && !out() && from()->isUser() && toHistoryMessage(); +} + QString HistoryItem::directLink() const { if (hasDirectLink()) { auto query = _history->peer->asChannel()->username + '/' + QString::number(id); diff --git a/Telegram/SourceFiles/history/history_item.h b/Telegram/SourceFiles/history/history_item.h index 1ae9a99f6..85fd055b9 100644 --- a/Telegram/SourceFiles/history/history_item.h +++ b/Telegram/SourceFiles/history/history_item.h @@ -684,12 +684,8 @@ public: bool canEdit(const QDateTime &cur) const; bool canDelete() const; bool canDeleteForEveryone(const QDateTime &cur) const; - - bool suggestBanReportDeleteAll() const { - auto channel = history()->peer->asChannel(); - if (!channel || (!channel->amEditor() && !channel->amCreator())) return false; - return !isPost() && !out() && from()->isUser() && toHistoryMessage(); - } + bool suggestBanReport() const; + bool suggestDeleteAllReport() const; bool hasDirectLink() const { return id > 0 && _history->peer->isChannel() && _history->peer->asChannel()->isPublic() && !_history->peer->isMegagroup(); diff --git a/Telegram/SourceFiles/historywidget.cpp b/Telegram/SourceFiles/historywidget.cpp index 9bc30a2c5..fd0ff9c24 100644 --- a/Telegram/SourceFiles/historywidget.cpp +++ b/Telegram/SourceFiles/historywidget.cpp @@ -5384,9 +5384,9 @@ void HistoryWidget::updatePinnedBar(bool force) { } bool HistoryWidget::pinnedMsgVisibilityUpdated() { - bool result = false; - MsgId pinnedMsgId = (_peer && _peer->isMegagroup()) ? _peer->asChannel()->mgInfo->pinnedMsgId : 0; - if (pinnedMsgId && !_peer->asChannel()->amCreator() && !_peer->asChannel()->amEditor()) { + auto result = false; + auto pinnedMsgId = (_peer && _peer->isMegagroup()) ? _peer->asChannel()->mgInfo->pinnedMsgId : 0; + if (pinnedMsgId && !_peer->asChannel()->canPinMessages()) { Global::HiddenPinnedMessagesMap::const_iterator it = Global::HiddenPinnedMessages().constFind(_peer->id); if (it != Global::HiddenPinnedMessages().cend()) { if (it.value() == pinnedMsgId) { @@ -5715,7 +5715,7 @@ void HistoryWidget::onPinnedHide() { return; } - if (_peer->asChannel()->amCreator() || _peer->asChannel()->amEditor()) { + if (_peer->asChannel()->canPinMessages()) { onUnpinMessage(); } else { Global::RefHiddenPinnedMessages().insert(_peer->id, _peer->asChannel()->mgInfo->pinnedMsgId); diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index 2232601e4..c0baa169d 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -1632,7 +1632,7 @@ bool MainWidget::preloadOverview(PeerData *peer, MediaOverviewType type) { return false; } - _overviewPreload[type].insert(peer, MTP::send(MTPmessages_Search(MTP_flags(0), peer->input, MTP_string(""), filter, MTP_int(0), MTP_int(0), MTP_int(0), MTP_int(0), MTP_int(0)), rpcDone(&MainWidget::overviewPreloaded, peer), rpcFail(&MainWidget::overviewFailed, peer), 0, 10)); + _overviewPreload[type].insert(peer, MTP::send(MTPmessages_Search(MTP_flags(0), peer->input, MTP_string(""), MTP_inputUserEmpty(), filter, MTP_int(0), MTP_int(0), MTP_int(0), MTP_int(0), MTP_int(0)), rpcDone(&MainWidget::overviewPreloaded, peer), rpcFail(&MainWidget::overviewFailed, peer), 0, 10)); return true; } @@ -1700,7 +1700,7 @@ void MainWidget::loadMediaBack(PeerData *peer, MediaOverviewType type, bool many return; } - _overviewLoad[type].insert(peer, MTP::send(MTPmessages_Search(MTP_flags(0), peer->input, MTPstring(), filter, MTP_int(0), MTP_int(0), MTP_int(0), MTP_int(minId), MTP_int(limit)), rpcDone(&MainWidget::overviewLoaded, history))); + _overviewLoad[type].insert(peer, MTP::send(MTPmessages_Search(MTP_flags(0), peer->input, MTPstring(), MTP_inputUserEmpty(), filter, MTP_int(0), MTP_int(0), MTP_int(0), MTP_int(minId), MTP_int(limit)), rpcDone(&MainWidget::overviewLoaded, history))); } void MainWidget::checkLastUpdate(bool afterSleep) { diff --git a/Telegram/SourceFiles/observer_peer.h b/Telegram/SourceFiles/observer_peer.h index 0ac021aff..d683bfe1b 100644 --- a/Telegram/SourceFiles/observer_peer.h +++ b/Telegram/SourceFiles/observer_peer.h @@ -35,42 +35,42 @@ struct PeerUpdate { enum class Flag { // Common flags - NameChanged = 0x00000001U, - UsernameChanged = 0x00000002U, - PhotoChanged = 0x00000004U, - AboutChanged = 0x00000008U, - NotificationsEnabled = 0x00000010U, - SharedMediaChanged = 0x00000020U, - MigrationChanged = 0x00000040U, - PinnedChanged = 0x00000080U, + NameChanged = 0x00000001U, + UsernameChanged = 0x00000002U, + PhotoChanged = 0x00000004U, + AboutChanged = 0x00000008U, + NotificationsEnabled = 0x00000010U, + SharedMediaChanged = 0x00000020U, + MigrationChanged = 0x00000040U, + PinnedChanged = 0x00000080U, // For chats and channels - InviteLinkChanged = 0x00000100U, - MembersChanged = 0x00000200U, - AdminsChanged = 0x00000400U, - BlockedUsersChanged = 0x00000800U, + InviteLinkChanged = 0x00000100U, + MembersChanged = 0x00000200U, + AdminsChanged = 0x00000400U, + BlockedUsersChanged = 0x00000800U, // For users - UserCanShareContact = 0x00010000U, - UserIsContact = 0x00020000U, - UserPhoneChanged = 0x00040000U, - UserIsBlocked = 0x00080000U, - BotCommandsChanged = 0x00100000U, - UserOnlineChanged = 0x00200000U, - BotCanAddToGroups = 0x00400000U, - UserCommonChatsChanged = 0x00800000U, - UserHasCalls = 0x01000000U, + UserCanShareContact = 0x00010000U, + UserIsContact = 0x00020000U, + UserPhoneChanged = 0x00040000U, + UserIsBlocked = 0x00080000U, + BotCommandsChanged = 0x00100000U, + UserOnlineChanged = 0x00200000U, + BotCanAddToGroups = 0x00400000U, + UserCommonChatsChanged = 0x00800000U, + UserHasCalls = 0x01000000U, // For chats - ChatCanEdit = 0x00010000U, + ChatCanEdit = 0x00010000U, // For channels - ChannelAmIn = 0x00010000U, - ChannelAmEditor = 0x00020000U, - ChannelCanEditPhoto = 0x00040000U, - ChannelCanAddMembers = 0x00080000U, - ChannelCanViewAdmins = 0x00100000U, - ChannelCanViewMembers = 0x00200000U, + ChannelAmIn = 0x00010000U, + ChannelAmEditor = 0x00020000U, + ChannelCanEditInformation = 0x00040000U, + ChannelCanAddMembers = 0x00080000U, + ChannelCanViewAdmins = 0x00100000U, + ChannelCanViewMembers = 0x00200000U, }; Q_DECLARE_FLAGS(Flags, Flag); Flags flags = 0; diff --git a/Telegram/SourceFiles/overviewwidget.cpp b/Telegram/SourceFiles/overviewwidget.cpp index da8868243..d553fde92 100644 --- a/Telegram/SourceFiles/overviewwidget.cpp +++ b/Telegram/SourceFiles/overviewwidget.cpp @@ -748,12 +748,12 @@ void OverviewInner::preloadMore() { if (!_searchRequest) { MTPmessagesFilter filter = (_type == OverviewLinks) ? MTP_inputMessagesFilterUrl() : MTP_inputMessagesFilterDocument(); if (!_searchFull) { - _searchRequest = MTP::send(MTPmessages_Search(MTP_flags(0), _history->peer->input, MTP_string(_searchQuery), filter, MTP_int(0), MTP_int(0), MTP_int(0), MTP_int(_lastSearchId), MTP_int(SearchPerPage)), rpcDone(&OverviewInner::searchReceived, _lastSearchId ? SearchFromOffset : SearchFromStart), rpcFail(&OverviewInner::searchFailed, _lastSearchId ? SearchFromOffset : SearchFromStart)); + _searchRequest = MTP::send(MTPmessages_Search(MTP_flags(0), _history->peer->input, MTP_string(_searchQuery), MTP_inputUserEmpty(), filter, MTP_int(0), MTP_int(0), MTP_int(0), MTP_int(_lastSearchId), MTP_int(SearchPerPage)), rpcDone(&OverviewInner::searchReceived, _lastSearchId ? SearchFromOffset : SearchFromStart), rpcFail(&OverviewInner::searchFailed, _lastSearchId ? SearchFromOffset : SearchFromStart)); if (!_lastSearchId) { _searchQueries.insert(_searchRequest, _searchQuery); } } else if (_migrated && !_searchFullMigrated) { - _searchRequest = MTP::send(MTPmessages_Search(MTP_flags(0), _migrated->peer->input, MTP_string(_searchQuery), filter, MTP_int(0), MTP_int(0), MTP_int(0), MTP_int(_lastSearchMigratedId), MTP_int(SearchPerPage)), rpcDone(&OverviewInner::searchReceived, _lastSearchMigratedId ? SearchMigratedFromOffset : SearchMigratedFromStart), rpcFail(&OverviewInner::searchFailed, _lastSearchMigratedId ? SearchMigratedFromOffset : SearchMigratedFromStart)); + _searchRequest = MTP::send(MTPmessages_Search(MTP_flags(0), _migrated->peer->input, MTP_string(_searchQuery), MTP_inputUserEmpty(), filter, MTP_int(0), MTP_int(0), MTP_int(0), MTP_int(_lastSearchMigratedId), MTP_int(SearchPerPage)), rpcDone(&OverviewInner::searchReceived, _lastSearchMigratedId ? SearchMigratedFromOffset : SearchMigratedFromStart), rpcFail(&OverviewInner::searchFailed, _lastSearchMigratedId ? SearchMigratedFromOffset : SearchMigratedFromStart)); } } } else if (App::main()) { @@ -1487,7 +1487,7 @@ bool OverviewInner::onSearchMessages(bool searchCache) { _searchQuery = q; _searchFull = _searchFullMigrated = false; auto filter = (_type == OverviewLinks) ? MTP_inputMessagesFilterUrl() : MTP_inputMessagesFilterDocument(); - _searchRequest = MTP::send(MTPmessages_Search(MTP_flags(0), _history->peer->input, MTP_string(_searchQuery), filter, MTP_int(0), MTP_int(0), MTP_int(0), MTP_int(0), MTP_int(SearchPerPage)), rpcDone(&OverviewInner::searchReceived, SearchFromStart), rpcFail(&OverviewInner::searchFailed, SearchFromStart)); + _searchRequest = MTP::send(MTPmessages_Search(MTP_flags(0), _history->peer->input, MTP_string(_searchQuery), MTP_inputUserEmpty(), filter, MTP_int(0), MTP_int(0), MTP_int(0), MTP_int(0), MTP_int(SearchPerPage)), rpcDone(&OverviewInner::searchReceived, SearchFromStart), rpcFail(&OverviewInner::searchFailed, SearchFromStart)); _searchQueries.insert(_searchRequest, _searchQuery); } return false; diff --git a/Telegram/SourceFiles/profile/profile_block_group_members.cpp b/Telegram/SourceFiles/profile/profile_block_group_members.cpp index ccf18e756..f2581a947 100644 --- a/Telegram/SourceFiles/profile/profile_block_group_members.cpp +++ b/Telegram/SourceFiles/profile/profile_block_group_members.cpp @@ -74,13 +74,13 @@ void GroupMembersWidget::addAdmin(PeerData *selectedPeer) { if (auto chat = peer()->asChat()) { // not supported } else if (auto channel = peer()->asMegagroup()) { - MTP::send(MTPchannels_EditAdmin(channel->inputChannel, user->inputUser, MTP_channelRoleEditor()), rpcDone(base::lambda_guarded(this, [this, channel, user](const MTPUpdates &result) { - if (App::main()) App::main()->sentUpdatesReceived(result); - channel->mgInfo->lastAdmins.insert(user); - channel->setAdminsCount(channel->adminsCount() + 1); - if (App::main()) emit App::main()->peerUpdated(channel); - Notify::peerUpdatedDelayed(channel, Notify::PeerUpdate::Flag::AdminsChanged); - }))); + //MTP::send(MTPchannels_EditAdmin(channel->inputChannel, user->inputUser, MTP_channelRoleEditor()), rpcDone(base::lambda_guarded(this, [this, channel, user](const MTPUpdates &result) { + // if (App::main()) App::main()->sentUpdatesReceived(result); + // channel->mgInfo->lastAdmins.insert(user); + // channel->setAdminsCount(channel->adminsCount() + 1); + // if (App::main()) emit App::main()->peerUpdated(channel); + // Notify::peerUpdatedDelayed(channel, Notify::PeerUpdate::Flag::AdminsChanged); + //}))); } }))); } @@ -93,15 +93,15 @@ void GroupMembersWidget::removeAdmin(PeerData *selectedPeer) { if (auto chat = peer()->asChat()) { // not supported } else if (auto channel = peer()->asMegagroup()) { - MTP::send(MTPchannels_EditAdmin(channel->inputChannel, user->inputUser, MTP_channelRoleEmpty()), rpcDone(base::lambda_guarded(this, [this, channel, user](const MTPUpdates &result) { - if (App::main()) App::main()->sentUpdatesReceived(result); - channel->mgInfo->lastAdmins.remove(user); - if (channel->adminsCount() > 1) { - channel->setAdminsCount(channel->adminsCount() - 1); - if (App::main()) emit App::main()->peerUpdated(channel); - } - Notify::peerUpdatedDelayed(channel, Notify::PeerUpdate::Flag::AdminsChanged); - }))); + //MTP::send(MTPchannels_EditAdmin(channel->inputChannel, user->inputUser, MTP_channelRoleEmpty()), rpcDone(base::lambda_guarded(this, [this, channel, user](const MTPUpdates &result) { + // if (App::main()) App::main()->sentUpdatesReceived(result); + // channel->mgInfo->lastAdmins.remove(user); + // if (channel->adminsCount() > 1) { + // channel->setAdminsCount(channel->adminsCount() - 1); + // if (App::main()) emit App::main()->peerUpdated(channel); + // } + // Notify::peerUpdatedDelayed(channel, Notify::PeerUpdate::Flag::AdminsChanged); + //}))); } }))); } @@ -326,7 +326,7 @@ void GroupMembersWidget::checkSelfAdmin(ChatData *chat) { void GroupMembersWidget::checkSelfAdmin(ChannelData *megagroup) { if (megagroup->mgInfo->lastParticipants.isEmpty()) return; - bool amAdmin = (megagroup->amCreator() || megagroup->amEditor()); + auto amAdmin = megagroup->hasAdminRights() || megagroup->amCreator(); auto self = App::self(); if (amAdmin && !megagroup->mgInfo->lastAdmins.contains(self)) { megagroup->mgInfo->lastAdmins.insert(self); @@ -468,12 +468,12 @@ bool GroupMembersWidget::addUsersToEnd(ChannelData *megagroup) { } void GroupMembersWidget::setItemFlags(Item *item, ChannelData *megagroup) { - auto amCreatorOrAdmin = (item->peer->id == AuthSession::CurrentUserPeerId()) && (megagroup->amCreator() || megagroup->amEditor()); + auto amCreatorOrAdmin = item->peer->isSelf() && (megagroup->hasAdminRights() || megagroup->amCreator()); auto isAdmin = megagroup->mgInfo->lastAdmins.contains(getMember(item)->user()); item->hasAdminStar = amCreatorOrAdmin || isAdmin; if (item->peer->isSelf()) { item->hasRemoveLink = false; - } else if (megagroup->amCreator() || (megagroup->amEditor() && !item->hasAdminStar)) { + } else if (megagroup->amCreator() || (megagroup->canBanMembers() && !item->hasAdminStar)) { item->hasRemoveLink = true; } else { item->hasRemoveLink = false; diff --git a/Telegram/SourceFiles/profile/profile_block_settings.cpp b/Telegram/SourceFiles/profile/profile_block_settings.cpp index c8dcd6f70..9f6733e49 100644 --- a/Telegram/SourceFiles/profile/profile_block_settings.cpp +++ b/Telegram/SourceFiles/profile/profile_block_settings.cpp @@ -75,7 +75,7 @@ void BlockedBoxController::preloadRows() { return; } - _loadRequestId = request(MTPchannels_GetParticipants(_channel->inputChannel, MTP_channelParticipantsKicked(), MTP_int(_offset), MTP_int(kBlockedPerPage))).done([this](const MTPchannels_ChannelParticipants &result) { + _loadRequestId = request(MTPchannels_GetParticipants(_channel->inputChannel, MTP_channelParticipantsKicked(MTP_string("")), MTP_int(_offset), MTP_int(kBlockedPerPage))).done([this](const MTPchannels_ChannelParticipants &result) { Expects(result.type() == mtpc_channels_channelParticipants); _loadRequestId = 0; @@ -92,11 +92,15 @@ void BlockedBoxController::preloadRows() { } else { for_const (auto &participant, list) { ++_offset; - if (participant.type() != mtpc_channelParticipantKicked) { - LOG(("API Error: Non kicked participant got while requesting for kicked participants: %1").arg(participant.type())); + if (participant.type() != mtpc_channelParticipantBanned) { + LOG(("API Error: Non banned participant got while requesting for kicked participants: %1").arg(participant.type())); + continue; + } + auto &kicked = participant.c_channelParticipantBanned(); + if (!kicked.is_left()) { + LOG(("API Error: Non left participant got while requesting for kicked participants.")); continue; } - auto &kicked = participant.c_channelParticipantKicked(); auto userId = kicked.vuser_id.v; if (auto user = App::userLoaded(userId)) { appendRow(user); @@ -265,7 +269,7 @@ void SettingsWidget::refreshManageAdminsButton() { void SettingsWidget::refreshManageBlockedUsersButton() { auto hasManageBlockedUsers = [this] { if (auto channel = peer()->asMegagroup()) { - return (channel->amCreator() || channel->amEditor()) && (channel->kickedCount() > 0); + return channel->canBanMembers() && (channel->kickedCount() > 0); } return false; }; diff --git a/Telegram/SourceFiles/profile/profile_cover.cpp b/Telegram/SourceFiles/profile/profile_cover.cpp index 72b7fd968..b74145b68 100644 --- a/Telegram/SourceFiles/profile/profile_cover.cpp +++ b/Telegram/SourceFiles/profile/profile_cover.cpp @@ -45,7 +45,7 @@ using UpdateFlag = Notify::PeerUpdate::Flag; const auto ButtonsUpdateFlags = UpdateFlag::UserCanShareContact | UpdateFlag::BotCanAddToGroups | UpdateFlag::ChatCanEdit - | UpdateFlag::ChannelCanEditPhoto + | UpdateFlag::ChannelCanEditInformation | UpdateFlag::ChannelCanAddMembers | UpdateFlag::ChannelAmIn; @@ -232,9 +232,9 @@ void CoverWidget::dropAreaHidden(CoverDropArea *dropArea) { bool CoverWidget::canEditPhoto() const { if (_peerChat && _peerChat->canEdit()) { return true; - } else if (_peerMegagroup && _peerMegagroup->canEditPhoto()) { + } else if (_peerMegagroup && _peerMegagroup->canEditInformation()) { return true; - } else if (_peerChannel && _peerChannel->canEditPhoto()) { + } else if (_peerChannel && _peerChannel->canEditInformation()) { return true; } return false; @@ -437,7 +437,7 @@ void CoverWidget::setChatButtons() { void CoverWidget::setMegagroupButtons() { if (_peerMegagroup->amIn()) { - if (_peerMegagroup->canEditPhoto()) { + if (_peerMegagroup->canEditInformation()) { addButton(langFactory(lng_profile_set_group_photo), SLOT(onSetPhoto())); } } else { diff --git a/Telegram/SourceFiles/profile/profile_fixed_bar.cpp b/Telegram/SourceFiles/profile/profile_fixed_bar.cpp index a6fc48fbe..86b138ad7 100644 --- a/Telegram/SourceFiles/profile/profile_fixed_bar.cpp +++ b/Telegram/SourceFiles/profile/profile_fixed_bar.cpp @@ -117,7 +117,7 @@ void FixedBar::setChatActions() { } void FixedBar::setMegagroupActions() { - if (_peerMegagroup->amCreator() || _peerMegagroup->amEditor()) { + if (_peerMegagroup->amCreator() || _peerMegagroup->canEditInformation()) { addRightAction(RightActionType::EditChannel, langFactory(lng_profile_edit_contact), SLOT(onEditChannel())); } } diff --git a/Telegram/SourceFiles/storage/localstorage.cpp b/Telegram/SourceFiles/storage/localstorage.cpp index 995404df9..7bb8383ac 100644 --- a/Telegram/SourceFiles/storage/localstorage.cpp +++ b/Telegram/SourceFiles/storage/localstorage.cpp @@ -3956,12 +3956,12 @@ void _writePeer(QDataStream &stream, PeerData *peer) { qint32 flagsData = (AppVersion >= 9012) ? chat->flags : (chat->haveLeft() ? 1 : 0); stream << chat->name << qint32(chat->count) << qint32(chat->date) << qint32(chat->version) << qint32(chat->creator); - stream << qint32(chat->isForbidden ? 1 : 0) << qint32(flagsData) << chat->inviteLink(); + stream << qint32(chat->isForbidden() ? 1 : 0) << qint32(flagsData) << chat->inviteLink(); } else if (peer->isChannel()) { ChannelData *channel = peer->asChannel(); stream << channel->name << quint64(channel->access) << qint32(channel->date) << qint32(channel->version); - stream << qint32(channel->isForbidden ? 1 : 0) << qint32(channel->flags) << channel->inviteLink(); + stream << qint32(channel->isForbidden() ? 1 : 0) << qint32(channel->flags) << channel->inviteLink(); } } @@ -4037,7 +4037,7 @@ PeerData *_readPeer(FileReadDescriptor &from, int32 fileVersion = 0) { chat->date = date; chat->version = version; chat->creator = creator; - chat->isForbidden = (forbidden == 1); + chat->setIsForbidden(forbidden == 1); chat->flags = MTPDchat::Flags(flags); chat->setInviteLink(inviteLink); @@ -4059,7 +4059,7 @@ PeerData *_readPeer(FileReadDescriptor &from, int32 fileVersion = 0) { channel->access = access; channel->date = date; channel->version = version; - channel->isForbidden = (forbidden == 1); + channel->setIsForbidden(forbidden == 1); channel->flags = MTPDchannel::Flags(flags); channel->setInviteLink(inviteLink); diff --git a/Telegram/SourceFiles/structs.h b/Telegram/SourceFiles/structs.h index aaed49f20..cd3456b07 100644 --- a/Telegram/SourceFiles/structs.h +++ b/Telegram/SourceFiles/structs.h @@ -583,9 +583,14 @@ public: UserId creator = 0; MTPDchat::Flags flags = 0; - bool isForbidden = false; + bool isForbidden() const { + return _isForbidden; + } + void setIsForbidden(bool forbidden) { + _isForbidden = forbidden; + } bool amIn() const { - return !isForbidden && !haveLeft() && !wasKicked(); + return !isForbidden() && !haveLeft() && !wasKicked(); } bool canEdit() const { return !isDeactivated() && (amCreator() || (adminsEnabled() ? amAdmin() : amIn())); @@ -633,6 +638,7 @@ public: } private: + bool _isForbidden = false; QString _inviteLink; }; @@ -764,6 +770,25 @@ public: } void setKickedCount(int newKickedCount); + bool haveLeft() const { + return flags & MTPDchannel::Flag::f_left; + } + bool amIn() const { + return !isForbidden() && !haveLeft(); + } + bool addsSignature() const { + return flags & MTPDchannel::Flag::f_signatures; + } + bool isForbidden() const { + return _isForbidden; + } + void setIsForbidden(bool forbidden) { + _isForbidden = forbidden; + } + bool isVerified() const { + return flags & MTPDchannel::Flag::f_verified; + } + int32 date = 0; int version = 0; MTPDchannel::Flags flags = { 0 }; @@ -794,22 +819,43 @@ public: return flags & MTPDchannel::Flag::f_creator; } bool amEditor() const { - return flags & MTPDchannel::Flag::f_editor; + return hasAdminRights(); } - bool amModerator() const { - return flags & MTPDchannel::Flag::f_moderator; + const MTPDchannelAdminRights &adminRights() const { + return _adminRights.c_channelAdminRights(); } - bool haveLeft() const { - return flags & MTPDchannel::Flag::f_left; + void setAdminRights(const MTPChannelAdminRights &rights) { + _adminRights = rights; } - bool wasKicked() const { - return flags & MTPDchannel::Flag::f_kicked; + bool hasAdminRights() const { + return (adminRights().vflags.v != 0); } - bool amIn() const { - return !isForbidden && !haveLeft() && !wasKicked(); + const MTPDchannelBannedRights &bannedRights() const { + return _bannedRights.c_channelBannedRights(); + } + void setBannedRights(const MTPChannelBannedRights &rights) { + _bannedRights = rights; + } + bool hasBannedRights() const { + return (bannedRights().vflags.v != 0); + } + bool hasBannedRights(int32 now) const { + return hasBannedRights() && (bannedRights().vuntil_date.v > now); + } + bool canBanMembers() const { + return adminRights().is_ban_users() || amCreator(); + } + bool canDeleteMessages() const { + return adminRights().is_delete_messages() || amCreator(); + } + bool canAddMembers() const { + return adminRights().is_invite_users() || amCreator() || (amIn() && (flags & MTPDchannel::Flag::f_democracy)); + } + bool canPinMessages() const { + return adminRights().is_pin_messages() || amCreator(); } bool canPublish() const { - return amCreator() || amEditor(); + return adminRights().is_post_messages() || amCreator(); } bool canWrite() const { return amIn() && (canPublish() || !isBroadcast()); @@ -818,30 +864,19 @@ public: return flagsFull & MTPDchannelFull::Flag::f_can_view_participants; } bool canViewAdmins() const { - return (isMegagroup() || amCreator() || amEditor() || amModerator()); + return (isMegagroup() || hasAdminRights() || amCreator()); } - bool addsSignature() const { - return flags & MTPDchannel::Flag::f_signatures; - } - bool isForbidden = true; - bool isVerified() const { - return flags & MTPDchannel::Flag::f_verified; - } - bool canAddMembers() const { - return amCreator() || amEditor() || (amIn() && (flags & MTPDchannel::Flag::f_democracy)); - } - bool canEditPhoto() const { - return amCreator() || (amEditor() && isMegagroup()); + bool canEditInformation() const { + return adminRights().is_change_info() || amCreator(); } bool canEditUsername() const { return amCreator() && (flagsFull & MTPDchannelFull::Flag::f_can_set_username); } bool canDelete() const { - return amCreator() && (membersCount() <= 1000); + constexpr auto kDeleteChannelMembersLimit = 1000; + return amCreator() && (membersCount() <= kDeleteChannelMembersLimit); } -// ImagePtr photoFull; - void setInviteLink(const QString &newInviteLink); QString inviteLink() const { return _inviteLink; @@ -902,10 +937,14 @@ private: PtsWaiter _ptsWaiter; TimeMs _lastFullUpdate = 0; + bool _isForbidden = true; int _membersCount = 1; int _adminsCount = 1; int _kickedCount = 0; + MTPChannelAdminRights _adminRights = MTP_channelAdminRights(MTP_flags(0)); + MTPChannelBannedRights _bannedRights = MTP_channelBannedRights(MTP_flags(0), MTP_int(0)); + QString _restrictionReason; QString _about;