Exemple #1
0
        public void Reinitialize(ConversationHeader conversationHeader)
        {
            string     typingString     = this.TypingString;
            Visibility typingVisibility = this.TypingVisibility;

            this._conversationHeader = conversationHeader;
            this.TypingString        = typingString;
            this.TypingVisibility    = typingVisibility;
        }
        public static List <ConversationHeader> GetConversationHeaders(List <DialogHeaderInfo> dialogHeaderInfoList, List <User> users)
        {
            List <ConversationHeader> conversationHeaderList = new List <ConversationHeader>();

            foreach (DialogHeaderInfo dialogHeaderInfo in dialogHeaderInfoList)
            {
                List <long>        userIdsForMessage  = dialogHeaderInfo.message.GetAssociatedUserIds(true);
                ConversationHeader conversationHeader = new ConversationHeader(dialogHeaderInfo.message, users.Where <User>((Func <User, bool>)(u => userIdsForMessage.Contains((long)(int)u.uid))).ToList <User>(), dialogHeaderInfo.unread);
                conversationHeaderList.Add(conversationHeader);
            }
            return(conversationHeaderList);
        }
        public void Handle(NotificationTurnOnOff message)
        {
            ConversationHeader conversationHeader = this.Conversations.FirstOrDefault <ConversationHeader>((Func <ConversationHeader, bool>)(h =>
            {
                if (h.UserOrChatId == message.UserOrChatId)
                {
                    return(h.IsChat == message.IsChat);
                }
                return(false);
            }));

            if (conversationHeader == null)
            {
                return;
            }
            conversationHeader.RespondToSettingsChange();
        }
Exemple #4
0
        private User GetAssociatedUser(long id)
        {
            ConversationHeader conversationHeader = this._conversationHeader;
            User user;

            if (conversationHeader == null)
            {
                user = (User)null;
            }
            else
            {
                List <User> associatedUsers = conversationHeader._associatedUsers;
                if (associatedUsers == null)
                {
                    user = (User)null;
                }
                else
                {
                    Func <User, bool> predicate = (Func <User, bool>)(u => u.id == id);
                    user = associatedUsers.FirstOrDefault <User>(predicate);
                }
            }
            return(user ?? UsersService.Instance.GetCachedUser(id));
        }
Exemple #5
0
 public UsersTypingHelper(ConversationHeader conversationHeader)
 {
     this._conversationHeader = conversationHeader;
 }
 private string GetHeaderBody()
 {
     return(ConversationHeader.GetMessageHeaderText(this._message, this.User, this.User2));
 }
 internal void DeleteConversation(ConversationHeader conversation)
 {
     this.ConversationsGenCol.Delete(conversation);
     VKMessenger.Backend.BackendServices.MessagesService.DeleteDialog(conversation.UserOrChatId, conversation.IsChat, (Action <BackendResult <VKClient.Audio.Base.ResponseWithId, ResultCode> >)(res => { }));
 }
 private void ApplyNewMessagesFromInstantUpdate(List <Message> newMessages)
 {
     UsersService.Instance.GetUsers(Message.GetAssociatedUserIds(newMessages, true).Select <long, int>((Func <long, int>)(l => (int)l)).ToList <int>().Select <int, long>((Func <int, long>)(uid => (long)uid)).ToList <long>(), (Action <BackendResult <List <User>, ResultCode> >)(usersResult => Execute.ExecuteOnUIThread((Action)(() =>
     {
         List <ConversationHeader> source1 = new List <ConversationHeader>();
         List <DialogHeaderInfo> dialogHeaderInfoList = new List <DialogHeaderInfo>();
         foreach (IGrouping <int, Message> source2 in newMessages.Where <Message>((Func <Message, bool>)(m => m.chat_id == 0)).GroupBy <Message, int>((Func <Message, int>)(m => m.uid)))
         {
             Message userMessage = source2.LastOrDefault <Message>();
             if (userMessage != null)
             {
                 dialogHeaderInfoList.Add(new DialogHeaderInfo()
                 {
                     message = userMessage
                 });
                 ConversationHeader conversationHeader = this.Conversations.FirstOrDefault <ConversationHeader>((Func <ConversationHeader, bool>)(c =>
                 {
                     if (c._message.uid == userMessage.uid)
                     {
                         return(c._message.chat_id == 0);
                     }
                     return(false);
                 }));
                 if (conversationHeader != null)
                 {
                     dialogHeaderInfoList.Last <DialogHeaderInfo>().unread = userMessage.@out == 0 ? conversationHeader.Unread + 1 : conversationHeader.Unread;
                     source1.Add(conversationHeader);
                 }
             }
         }
         foreach (IGrouping <int, Message> source2 in newMessages.Where <Message>((Func <Message, bool>)(m => (uint)m.chat_id > 0U)).GroupBy <Message, int>((Func <Message, int>)(m => m.chat_id)))
         {
             Message chatMessage = source2.LastOrDefault <Message>();
             if (chatMessage != null)
             {
                 dialogHeaderInfoList.Add(new DialogHeaderInfo()
                 {
                     message = chatMessage
                 });
                 ConversationHeader conversationHeader = this.Conversations.FirstOrDefault <ConversationHeader>((Func <ConversationHeader, bool>)(c => c._message.chat_id == chatMessage.chat_id));
                 if (conversationHeader != null)
                 {
                     dialogHeaderInfoList.Last <DialogHeaderInfo>().unread = chatMessage.@out == 0 ? conversationHeader.Unread + 1 : conversationHeader.Unread;
                     source1.Add(conversationHeader);
                 }
             }
         }
         List <ConversationHeader> conversationHeaders = ConversationsViewModel.GetConversationHeaders(dialogHeaderInfoList, usersResult.ResultData);
         Logger.Instance.Info("Applying new messages. Found {0} headers to remove, {1} to add.", (object)source1.Count, (object)conversationHeaders.Count);
         foreach (ConversationHeader conversationHeader1 in source1)
         {
             UsersTypingHelper usersTypingHelper1 = conversationHeader1.UsersTypingHelper;
             if ((usersTypingHelper1 != null ? (usersTypingHelper1.AnyTypingNow ? 1 : 0) : 0) != 0)
             {
                 foreach (ConversationHeader conversationHeader2 in conversationHeaders)
                 {
                     if (conversationHeader1.IsChat == conversationHeader2.IsChat && conversationHeader1.UserOrChatId == conversationHeader2.UserOrChatId)
                     {
                         UsersTypingHelper usersTypingHelper2 = conversationHeader1.UsersTypingHelper;
                         usersTypingHelper2.SetUserIsNotTyping((long)conversationHeader2._message.user_id);
                         conversationHeader2.UsersTypingHelper = usersTypingHelper2;
                         usersTypingHelper2.Reinitialize(conversationHeader2);
                         break;
                     }
                 }
             }
         }
         foreach (ConversationHeader conversationHeader in source1.Distinct <ConversationHeader>())
         {
             this.ConversationsGenCol.Delete(conversationHeader);
         }
         int num = 0;
         foreach (ConversationHeader conversationHeader in (IEnumerable <ConversationHeader>)conversationHeaders.OrderByDescending <ConversationHeader, int>((Func <ConversationHeader, int>)(h => h._message.date)))
         {
             this.ConversationsGenCol.Insert(conversationHeader, num++);
         }
     }))));
 }
 internal void ProcessInstantUpdates(List <LongPollServerUpdateData> updates)
 {
     Execute.ExecuteOnUIThread((Action)(() =>
     {
         if (this != ConversationsViewModel.Instance)
         {
             return;
         }
         Dictionary <long, bool> dictionary1 = new Dictionary <long, bool>();
         Dictionary <long, bool> dictionary2 = new Dictionary <long, bool>();
         Dictionary <long, bool> dictionary3 = new Dictionary <long, bool>();
         List <Message> newMessages = new List <Message>();
         foreach (LongPollServerUpdateData update in updates)
         {
             LongPollServerUpdateData longPollServerUpdateData = update;
             if (longPollServerUpdateData.UpdateType == LongPollServerUpdateType.NewCounter)
             {
                 CountersManager.Current.SetUnreadMessages(longPollServerUpdateData.Counter);
             }
             if (longPollServerUpdateData.UpdateType == LongPollServerUpdateType.UserIsTyping || longPollServerUpdateData.UpdateType == LongPollServerUpdateType.UserIsTypingInChat)
             {
                 long chatId = longPollServerUpdateData.chat_id;
                 long userId = longPollServerUpdateData.user_id;
                 bool isChat = longPollServerUpdateData.UpdateType == LongPollServerUpdateType.UserIsTypingInChat;
                 ConversationHeader conversationHeader = this.Conversations.FirstOrDefault <ConversationHeader>((Func <ConversationHeader, bool>)(c =>
                 {
                     if (c.IsChat == isChat)
                     {
                         return(c.UserOrChatId == (isChat ? chatId : userId));
                     }
                     return(false);
                 }));
                 if (conversationHeader != null)
                 {
                     long userId1 = userId;
                     conversationHeader.SetUserIsTypingWithDelayedReset(userId1);
                 }
             }
             if (longPollServerUpdateData.UpdateType == LongPollServerUpdateType.UserBecameOnline)
             {
                 dictionary1[longPollServerUpdateData.user_id] = true;
                 if (longPollServerUpdateData.Platform != 7)
                 {
                     dictionary2[longPollServerUpdateData.user_id] = true;
                 }
             }
             if (longPollServerUpdateData.UpdateType == LongPollServerUpdateType.UserBecameOffline)
             {
                 dictionary1[longPollServerUpdateData.user_id] = false;
             }
             if (longPollServerUpdateData.UpdateType == LongPollServerUpdateType.MessageHasBeenRead)
             {
                 dictionary3[longPollServerUpdateData.message_id] = true;
             }
             if (longPollServerUpdateData.UpdateType == LongPollServerUpdateType.IncomingMessagesRead)
             {
                 long id = longPollServerUpdateData.chat_id == 0L ? longPollServerUpdateData.user_id : longPollServerUpdateData.chat_id;
                 ConversationHeader conversationHeader = this.Conversations.FirstOrDefault <ConversationHeader>((Func <ConversationHeader, bool>)(c => c.UserOrChatId == id));
                 if (conversationHeader != null)
                 {
                     conversationHeader.Unread = 0;
                 }
             }
             if (longPollServerUpdateData.UpdateType == LongPollServerUpdateType.MessageHasBeenAdded && longPollServerUpdateData.message != null)
             {
                 newMessages.Add(longPollServerUpdateData.message);
                 Extensions.UnixTimeStampToDateTime((double)longPollServerUpdateData.message.date, true);
                 if (longPollServerUpdateData.message.@out == 0 && !longPollServerUpdateData.IsHistoricData && string.IsNullOrWhiteSpace(longPollServerUpdateData.message.action))
                 {
                     bool isChat = (uint)longPollServerUpdateData.message.chat_id > 0U;
                     int id = isChat ? longPollServerUpdateData.message.chat_id : longPollServerUpdateData.message.uid;
                     if (!isChat)
                     {
                         if (longPollServerUpdateData.user != null)
                         {
                             string str1 = longPollServerUpdateData.user.first_name ?? "";
                             string str2 = longPollServerUpdateData.user.last_name ?? "";
                             string imageSrc = longPollServerUpdateData.user.photo_max ?? "";
                             MessengerStateManagerInstance.Current.HandleInAppNotification(str1 + " " + str2, ConversationHeader.GetMessageHeaderText(longPollServerUpdateData.message, longPollServerUpdateData.user, (User)null), (long)id, isChat.ToString(), imageSrc);
                         }
                         else
                         {
                             UsersService instance = UsersService.Instance;
                             List <long> userIds = new List <long>();
                             userIds.Add((long)longPollServerUpdateData.message.uid);
                             Action <BackendResult <List <User>, ResultCode> > callback = (Action <BackendResult <List <User>, ResultCode> >)(res =>
                             {
                                 if (res.ResultCode != ResultCode.Succeeded || res.ResultData == null || res.ResultData.Count <= 0)
                                 {
                                     return;
                                 }
                                 MessengerStateManagerInstance.Current.HandleInAppNotification(res.ResultData.First <User>().first_name + " " + res.ResultData.First <User>().last_name, ConversationHeader.GetMessageHeaderText(longPollServerUpdateData.message, res.ResultData.First <User>(), (User)null), (long)id, isChat.ToString(), res.ResultData.First <User>().photo_max);
                             });
                             instance.GetUsers(userIds, callback);
                         }
                     }
                     else
                     {
                         bool flag = !longPollServerUpdateData.message.push_settings.AreDisabledNow;
                         if (!flag)
                         {
                             string body = longPollServerUpdateData.message.body;
                             if (!string.IsNullOrWhiteSpace(body))
                             {
                                 foreach (object match in BrowserNavigationService.Regex_Mention.Matches(body))
                                 {
                                     if (match.ToString().ToLower().Contains(string.Format("[id{0}|", (object)AppGlobalStateManager.Current.LoggedInUserId)))
                                     {
                                         flag = true;
                                         break;
                                     }
                                 }
                             }
                         }
                         if (flag)
                         {
                             string imageSrc = longPollServerUpdateData.user.photo_max ?? "";
                             string messageHeaderText = ConversationHeader.GetMessageHeaderText(longPollServerUpdateData.message, longPollServerUpdateData.user, (User)null);
                             MessengerStateManagerInstance.Current.HandleInAppNotification(longPollServerUpdateData.message.title, messageHeaderText, (long)id, true.ToString(), imageSrc);
                         }
                     }
                 }
             }
             if (longPollServerUpdateData.UpdateType == LongPollServerUpdateType.ChatParamsWereChanged)
             {
                 long chatId = longPollServerUpdateData.chat_id;
                 Func <ConversationHeader, bool> func;
                 VKMessenger.Backend.BackendServices.ChatService.GetChatInfo(chatId, (Action <BackendResult <ChatInfo, ResultCode> >)(res =>
                 {
                     if (res.ResultCode != ResultCode.Succeeded)
                     {
                         return;
                     }
                     ChatInfo chatInfo = res.ResultData;
                     Execute.ExecuteOnUIThread((Action)(() =>
                     {
                         ConversationHeader conversationHeader = this.Conversations.FirstOrDefault <ConversationHeader>((func = (Func <ConversationHeader, bool>)(ch =>
                         {
                             if (ch.IsChat)
                             {
                                 return(ch.UserOrChatId == chatId);
                             }
                             return(false);
                         })));
                         if (conversationHeader == null)
                         {
                             return;
                         }
                         conversationHeader._message.title = chatInfo.chat.title;
                         conversationHeader._associatedUsers.Clear();
                         foreach (ChatUser chatParticipant in chatInfo.chat_participants)
                         {
                             User user = new User()
                             {
                                 uid = chatParticipant.uid,
                                 online = chatParticipant.online,
                                 photo_max = chatParticipant.photo_max,
                                 first_name = chatParticipant.first_name,
                                 last_name = chatParticipant.last_name,
                                 first_name_acc = chatParticipant.first_name_acc,
                                 last_name_acc = chatParticipant.last_name_acc
                             };
                             conversationHeader._associatedUsers.Add(user);
                         }
                         conversationHeader._message.chat_active_str = chatInfo.chat_participants.Select <ChatUser, long>((Func <ChatUser, long>)(c => c.uid)).ToList <long>().GetCommaSeparated();
                         conversationHeader.RefreshUIProperties(true);
                     }));
                 }));
             }
         }
         if (updates != null)
         {
             int count = updates.Count <LongPollServerUpdateData>((Func <LongPollServerUpdateData, bool>)(u =>
             {
                 if (u.UpdateType == LongPollServerUpdateType.MessageHasBeenAdded && !u.@out)
                 {
                     return(!u.IsHistoricData);
                 }
                 return(false);
             }));
             if (count > 0)
             {
                 this.IncreaseNumberOfUnreadMessagesBy(count);
             }
         }
         List <ConversationHeader> updatedHeaders = new List <ConversationHeader>();
         List <ConversationHeader> conversationHeaderList = new List <ConversationHeader>();
         if (dictionary1.Count > 0 || dictionary3.Count > 0)
         {
             foreach (ConversationHeader conversation in (Collection <ConversationHeader>) this.Conversations)
             {
                 bool flag = false;
                 if (dictionary3.ContainsKey((long)conversation._message.mid))
                 {
                     conversation._message.read_state = dictionary3[(long)conversation._message.mid] ? 1 : 0;
                     flag = true;
                 }
                 foreach (User associatedUser in conversation._associatedUsers)
                 {
                     if (dictionary1.ContainsKey(associatedUser.uid))
                     {
                         associatedUser.online = dictionary1[associatedUser.uid] ? 1 : 0;
                         associatedUser.online_mobile = dictionary2.ContainsKey(associatedUser.uid) ? 1 : 0;
                         flag = true;
                     }
                 }
                 if (flag)
                 {
                     updatedHeaders.Add(conversation);
                 }
             }
             if (updatedHeaders.Count > 0)
             {
                 ((DependencyObject)Deployment.Current).Dispatcher.BeginInvoke((Action)(() => updatedHeaders.ForEach((Action <ConversationHeader>)(h => h.RefreshUIProperties(false)))));
             }
         }
         if (newMessages.Count <= 0)
         {
             return;
         }
         this.ApplyNewMessagesFromInstantUpdate(newMessages);
         ConversationsViewModel.CheckNewMessagesForStickersPack(newMessages);
     }));
 }