Example #1
0
        private void UpdateItems()
        {
            if (_currentChat == null)
            {
                return;
            }

            IsWorking = true;
            Status    = Items.Count > 0 ? string.Empty : AppResources.Loading;
            MTProtoService.GetFullChatAsync(_currentChat.Id,
                                            chatFull =>
            {
                IsWorking = false;
                Status    = string.Empty;

                var newUsersCache = new Dictionary <int, TLUserBase>();
                foreach (var user in chatFull.Users)
                {
                    newUsersCache[user.Index] = user;
                }

                var participants = chatFull.FullChat.Participants as IChatParticipants;
                if (participants != null)
                {
                    var usersCache = Items.ToDictionary(x => x.Index);

                    var onlineUsers = 0;
                    foreach (var participant in participants.Participants)
                    {
                        var user = newUsersCache[participant.UserId.Value];
                        if (user.Status is TLUserStatusOnline)
                        {
                            onlineUsers++;
                        }

                        user.IsSelected = IsEnabled;
                        if (!usersCache.ContainsKey(user.Index))
                        {
                            BeginOnUIThread(() => InsertInDescOrder(Items, user));
                        }
                    }
                    _currentChat.UsersOnline = onlineUsers;
                }

                var chatFull28 = chatFull.FullChat as TLChatFull28;
                if (chatFull28 != null)
                {
                    _currentChat.ExportedInvite = chatFull28.ExportedInvite;
                }
            },
                                            error =>
            {
                IsWorking = false;
                Status    = string.Empty;
            });
        }
        public string GetTypingString(TLPeerBase peer, IList <TypingUser> typingUsers)
        {
            if (peer is TLPeerUser)
            {
                var typingUser = typingUsers.FirstOrDefault();
                if (typingUser != null)
                {
                    var action = typingUser.Item2;
                    if (action is TLSendMessageUploadPhotoAction)
                    {
                        return(string.Format("{0}...", AppResources.SendingPhoto.ToLower(CultureInfo.InvariantCulture)));
                    }
                    if (action is TLSendMessageRecordAudioAction)
                    {
                        return(string.Format("{0}...", AppResources.RecordingAudio.ToLower(CultureInfo.InvariantCulture)));
                    }
                    if (action is TLSendMessageUploadAudioAction)
                    {
                        return(string.Format("{0}...", AppResources.RecordingAudio.ToLower(CultureInfo.InvariantCulture)));
                    }
                    if (action is TLSendMessageUploadDocumentAction)
                    {
                        return(string.Format("{0}...", AppResources.SendingFile.ToLower(CultureInfo.InvariantCulture)));
                    }
                    if (action is TLSendMessageRecordVideoAction)
                    {
                        return(string.Format("{0}...", AppResources.SendingVideo.ToLower(CultureInfo.InvariantCulture)));
                    }
                    if (action is TLSendMessageUploadVideoAction)
                    {
                        return(string.Format("{0}...", AppResources.SendingVideo.ToLower(CultureInfo.InvariantCulture)));
                    }
                }

                return(string.Format("{0}...", AppResources.Typing.ToLower(CultureInfo.InvariantCulture)));
            }

            if (typingUsers.Count == 1)
            {
                var userId = new TLInt(typingUsers[0].Item1);
                var user   = CacheService.GetUser(userId);
                if (user == null)
                {
                    var peerChat = peer as TLPeerChat;
                    if (peerChat != null)
                    {
                        MTProtoService.GetFullChatAsync(peerChat.Id, result => { }, error => { });
                    }

                    return(null);
                }

                var userName   = TLString.IsNullOrEmpty(user.FirstName) ? user.LastName : user.FirstName;
                var typingUser = typingUsers.FirstOrDefault();
                if (typingUser != null)
                {
                    var action = typingUser.Item2;
                    if (action is TLSendMessageUploadPhotoAction)
                    {
                        return(string.Format("{0} {1}...", userName, AppResources.IsSendingPhoto.ToLower(CultureInfo.InvariantCulture)));
                    }
                    if (action is TLSendMessageUploadAudioAction)
                    {
                        return(string.Format("{0} {1}...", userName, AppResources.IsRecordingAudio.ToLower(CultureInfo.InvariantCulture)));
                    }
                    if (action is TLSendMessageRecordAudioAction)
                    {
                        return(string.Format("{0} {1}...", userName, AppResources.IsRecordingAudio.ToLower(CultureInfo.InvariantCulture)));
                    }
                    if (action is TLSendMessageUploadDocumentAction)
                    {
                        return(string.Format("{0} {1}...", userName, AppResources.IsSendingFile.ToLower(CultureInfo.InvariantCulture)));
                    }
                    if (action is TLSendMessageRecordVideoAction)
                    {
                        return(string.Format("{0} {1}...", userName, AppResources.IsSendingVideo.ToLower(CultureInfo.InvariantCulture)));
                    }
                    if (action is TLSendMessageUploadVideoAction)
                    {
                        return(string.Format("{0} {1}...", userName, AppResources.IsSendingVideo.ToLower(CultureInfo.InvariantCulture)));
                    }
                }

                return(string.Format("{0} {1}...", userName, AppResources.IsTyping.ToLower(CultureInfo.InvariantCulture)));
            }

            if (typingUsers.Count <= 3)
            {
                var firstNames   = new List <string>(typingUsers.Count);
                var missingUsers = new List <TLInt>();
                foreach (var typingUser in typingUsers)
                {
                    var user = CacheService.GetUser(new TLInt(typingUser.Item1));
                    if (user != null)
                    {
                        var userName = TLString.IsNullOrEmpty(user.FirstName) ? user.LastName : user.FirstName;
                        firstNames.Add(userName.ToString());
                    }
                    else
                    {
                        missingUsers.Add(new TLInt(typingUser.Item1));
                    }
                }

                if (missingUsers.Count > 0)
                {
                    var peerChat = peer as TLPeerChat;
                    if (peerChat != null)
                    {
                        MTProtoService.GetFullChatAsync(peerChat.Id, result => { }, error => { });
                    }

                    return(null);
                }

                return(string.Format("{0} {1}...", string.Join(", ", firstNames),
                                     AppResources.AreTyping.ToLower(CultureInfo.InvariantCulture)));
            }

            return(string.Format("{0} {1}...", Language.Declension(
                                     typingUsers.Count,
                                     AppResources.CompanyNominativeSingular,
                                     AppResources.CompanyNominativePlural,
                                     AppResources.CompanyGenitiveSingular,
                                     AppResources.CompanyGenitivePlural).ToLower(CultureInfo.CurrentUICulture),
                                 AppResources.AreTyping.ToLower(CultureInfo.InvariantCulture)));
        }
Example #3
0
        private void UpdateItems()
        {
            var channel = CurrentItem as TLChannel;

            if (channel != null && channel.IsMegaGroup)
            {
                UpdateChannelItems(channel);
                return;
            }


            if (CurrentItem is TLBroadcastChat)
            {
                return;
            }

            IsWorking = true;
            MTProtoService.GetFullChatAsync(CurrentItem.Id,
                                            chatFull =>
            {
                IsWorking = false;

                var newUsersCache = new Dictionary <int, TLUserBase>();
                foreach (var user in chatFull.Users)
                {
                    newUsersCache[user.Index] = user;
                }

                var participants = chatFull.FullChat.Participants as IChatParticipants;
                if (participants != null)
                {
                    var usersCache = Items.ToDictionary(x => x.Index);

                    var onlineUsers = 0;
                    foreach (var participant in participants.Participants)
                    {
                        var user = newUsersCache[participant.UserId.Value];
                        if (user.Status is TLUserStatusOnline)
                        {
                            onlineUsers++;
                        }

                        if (!usersCache.ContainsKey(user.Index))
                        {
                            BeginOnUIThread(() => InsertInDescOrder(Items, user));
                        }
                    }
                    CurrentItem.UsersOnline = onlineUsers;
                }

                var chatFull28 = chatFull.FullChat as TLChatFull28;
                if (chatFull28 != null)
                {
                    CurrentItem.ExportedInvite = chatFull28.ExportedInvite;
                }

                UpdateNotificationSettings();
                UpdateTitles();
            },
                                            error =>
            {
                IsWorking = false;
            });
        }