Пример #1
0
        public void DeleteParticipant(TLUserBase user)
        {
            if (CurrentItem.IsForbidden)
            {
                return;
            }
            if (user == null)
            {
                return;
            }

            var broadcast = CurrentItem as TLBroadcastChat;
            var channel   = CurrentItem as TLChannel;

            if (broadcast != null && channel == null)
            {
                var broadcastChat = (TLBroadcastChat)CurrentItem;

                var serviceMessage = new TLMessageService17
                {
                    ToId = new TLPeerBroadcast {
                        Id = broadcastChat.Id
                    },
                    FromId = new TLInt(StateService.CurrentUserId),
                    Out    = new TLBool(true),
                    Date   = TLUtils.DateToUniversalTimeTLInt(MTProtoService.ClientTicksDelta, DateTime.Now),
                    Action = new TLMessageActionChatDeleteUser {
                        UserId = user.Id
                    }
                };
                serviceMessage.SetUnread(new TLBool(false));

                for (var i = 0; i < broadcastChat.ParticipantIds.Count; i++)
                {
                    if (user.Id.Value == broadcastChat.ParticipantIds[i].Value)
                    {
                        broadcastChat.ParticipantIds.RemoveAt(i);
                        break;
                    }
                }

                broadcastChat.ParticipantIds.Remove(user.Id);

                CacheService.SyncBroadcast(broadcastChat,
                                           result =>
                {
                    EventAggregator.Publish(serviceMessage);
                    UpdateTitles();
                });
            }
            else
            {
                if (user.Index == StateService.CurrentUserId)
                {
                    DeleteAndExitGroup();
                    return;
                }

                IsWorking = true;
                MTProtoService.DeleteChatUserAsync(CurrentItem.Id, user.ToInputUser(),
                                                   statedMessage =>
                {
                    IsWorking = false;
                    BeginOnUIThread(() => Items.Remove(user));

                    var updates = statedMessage as TLUpdates;
                    if (updates != null)
                    {
                        var updateNewMessage = updates.Updates.FirstOrDefault(x => x is TLUpdateNewMessage) as TLUpdateNewMessage;
                        if (updateNewMessage != null)
                        {
                            EventAggregator.Publish(updateNewMessage.Message);
                        }
                    }
                    UpdateTitles();
                },
                                                   error =>
                {
                    Execute.ShowDebugMessage("messages.deleteChatUser error " + error);
                    IsWorking = false;
                });
            }
        }