コード例 #1
0
 private void SearchMessages(string query, int count, Action callback = null)
 {
     if (this._isLoadingMessages)
     {
         return;
     }
     this._isLoadingMessages = true;
     this.SetInProgressMain(true, "");
     BackendServices.MessagesService.SearchMessages(query, VKConstants.DefaultSearchMessagesCount, count, (Action <BackendResult <MessageListResponse, ResultCode> >)(res =>
     {
         this.SetInProgressMain(false, "");
         if (string.Compare(this._localMessagesQuery, query) != 0)
         {
             this._isLoadingMessages = false;
             this.SearchMessages(this._localMessagesQuery, count, callback);
         }
         else if (res.ResultCode == ResultCode.Succeeded)
         {
             res.ResultData.Messages.Select <Message, int>((Func <Message, int>)(m => m.uid)).ToList <int>();
             if (string.Compare(this._localMessagesQuery, query) != 0)
             {
                 this._isLoadingMessages = false;
                 this.SearchMessages(this._localMessagesQuery, count, callback);
             }
             else
             {
                 this._availableMessages = res.ResultData.TotalCount;
                 this._loadedMessages    = this._loadedMessages + VKConstants.DefaultSearchMessagesCount;
                 ((DependencyObject)Deployment.Current).Dispatcher.BeginInvoke((Action)(() =>
                 {
                     foreach (ConversationHeader conversationHeader in ConversationsViewModel.GetConversationHeaders(res.ResultData.DialogHeaders, res.ResultData.Users))
                     {
                         this.Messages.Add(conversationHeader);
                     }
                     if (callback == null)
                     {
                         return;
                     }
                     callback();
                 }));
                 this._isLoadingMessages = false;
             }
         }
         else
         {
             this._isLoadingMessages = false;
             Logger.Instance.Error("Failed to search messages");
         }
     }));
 }
コード例 #2
0
 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++);
         }
     }))));
 }
コード例 #3
0
 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);
     }));
 }