示例#1
0
        public static TLChannelAdminRights GetDefaultAdminRights(bool supergroup, TLChannelParticipantRoleBase role)
        {
            if (role is TLChannelRoleEditor)
            {
                var rights = new TLChannelAdminRights {
                    Flags = new TLInt(0)
                };
                if (supergroup)
                {
                    rights.ChannelInfo    = true;
                    rights.DeleteMessages = true;
                    rights.BanUsers       = true;
                    rights.InviteLinks    = true;
                    rights.PinMessages    = true;
                    rights.AddAdmins      = false;
                }
                else
                {
                    rights.ChannelInfo    = true;
                    rights.PostMessages   = true;
                    rights.EditMessages   = true;
                    rights.DeleteMessages = true;
                    rights.InviteUsers    = true;
                    rights.AddAdmins      = false;
                }
            }

            return(new TLChannelAdminRights {
                Flags = new TLInt(0)
            });
        }
示例#2
0
        public void EditAdminAsync(TLChannel channel, TLInputUserBase userId, TLChannelParticipantRoleBase role, Action <TLUpdatesBase> callback, Action <TLRPCError> faultCallback = null)
        {
            var obj = new TLChannelsEditAdmin {
                Channel = channel.ToInputChannel(), UserId = userId, Role = role
            };

            const string caption = "channels.editAdmin";

            SendInformativeMessage <TLUpdatesBase>(caption, obj,
                                                   result =>
            {
                var multiPts = result as ITLMultiPts;
                if (multiPts != null)
                {
                    _updatesService.SetState(multiPts, caption);
                }
                else
                {
                    ProcessUpdates(result, null);
                }

                GetFullChannelAsync(channel.ToInputChannel(),
                                    messagesChatFull => callback?.Invoke(result),
                                    faultCallback);
            },
                                                   faultCallback);
        }
        public AddChatParticipantViewModel(ICacheService cacheService, ICommonErrorHandler errorHandler, IStateService stateService, INavigationService navigationService, IMTProtoService mtProtoService, ITelegramEventAggregator eventAggregator)
            : base(cacheService, errorHandler, stateService, navigationService, mtProtoService, eventAggregator)
        {
            if (StateService.CurrentRole != null)
            {
                _currentRole             = StateService.CurrentRole;
                StateService.CurrentRole = null;
            }

            if (StateService.CurrentChat != null)
            {
                _currentChat             = StateService.CurrentChat;
                StateService.CurrentChat = null;
            }

            if (StateService.RemovedUsers != null)
            {
                foreach (var user in StateService.RemovedUsers)
                {
                    _removedUsers[user.Index] = user;
                }
                StateService.RemovedUsers = null;
            }

            if (StateService.RequestForwardingCount)
            {
                _requestForwardingCount             = true;
                StateService.RequestForwardingCount = false;
            }

            _inviteVisibility            = StateService.IsInviteVisible ? Visibility.Visible : Visibility.Collapsed;
            StateService.IsInviteVisible = false;

            BeginOnThreadPool(() =>
            {
                var isAuthorized = SettingsHelper.GetValue <bool>(Constants.IsAuthorizedKey);
                if (isAuthorized)
                {
                    var contacts = CacheService.GetContacts();
                    Status       = string.Empty;
                    Items.Clear();
                    foreach (var contact in contacts.OrderBy(x => x.FullName))
                    {
                        if (!(contact is TLUserEmpty) && contact.Index != StateService.CurrentUserId && !_removedUsers.ContainsKey(contact.Index))
                        {
                            Items.Add(contact);
                        }
                    }
                }

                BeginOnUIThread(() =>
                {
                    if (StateService.RemoveBackEntry)
                    {
                        NavigationService.RemoveBackEntry();
                        StateService.RemoveBackEntry = false;
                    }
                });
            });
        }
        public void EditAdminAsync(TLChannel channel, TLInputUserBase userId, TLChannelParticipantRoleBase role, Action <TLBool> callback, Action <TLRPCError> faultCallback = null)
        {
            var obj = new TLEditAdmin {
                Channel = channel.ToInputChannel(), UserId = userId, Role = role
            };

            const string caption = "channels.editAdmin";

            SendInformativeMessage <TLBool>(caption, obj,
                                            result =>
            {
                if (result.Value)
                {
                    if (channel.AdminsCount != null)
                    {
                        if (role is TLChannelRoleEmpty)
                        {
                            channel.AdminsCount = new TLInt(channel.AdminsCount.Value - 1);
                        }
                        else
                        {
                            channel.AdminsCount = new TLInt(channel.AdminsCount.Value + 1);
                        }

                        _cacheService.Commit();
                    }
                }

                callback.SafeInvoke(result);
            },
                                            faultCallback);
        }
示例#5
0
        public SearchContactsViewModel(ICacheService cacheService, ICommonErrorHandler errorHandler, IStateService stateService, INavigationService navigationService, IMTProtoService mtProtoService, ITelegramEventAggregator eventAggregator)
            : base(cacheService, errorHandler, stateService, navigationService, mtProtoService, eventAggregator)
        {
            EventAggregator.Subscribe(this);

            Items  = new ObservableCollection <TLObject>();
            Status = string.Empty;

            _currentChat             = StateService.CurrentChat;
            StateService.CurrentChat = null;

            if (StateService.CurrentAdminRights != null)
            {
                _currentAdminRights             = StateService.CurrentAdminRights;
                StateService.CurrentAdminRights = null;
            }

            if (StateService.CurrentRole != null)
            {
                _currentRole             = StateService.CurrentRole;
                StateService.CurrentRole = null;
            }

            if (StateService.RequestForwardingCount)
            {
                RequestForwardingCount = true;
                StateService.RequestForwardingCount = false;
            }

            if (StateService.NavigateToDialogDetails)
            {
                NavigateToDialogDetails = true;
                StateService.NavigateToDialogDetails = false;
            }

            if (StateService.NavigateToSecretChat)
            {
                NavigateToSecretChat = true;
                StateService.NavigateToSecretChat = false;
                _dhConfig             = StateService.DHConfig;
                StateService.DHConfig = null;

                if (_dhConfig == null)
                {
                    Execute.BeginOnThreadPool(GetDHConfig);
                }
            }
        }
示例#6
0
        public void EditChatAdminAsync(TLInputChannelBase channel, TLInputUserBase userId, TLChannelParticipantRoleBase role, Action <bool> callback, Action <TLRPCError> faultCallback = null)
        {
            var obj = new TLChannelsEditAdmin {
                Channel = channel, UserId = userId, Role = role
            };

            SendInformativeMessage("channels.editAdmin", obj, callback, faultCallback);
        }