Exemplo n.º 1
0
 private void ApplyUserProfiles(List <SearchConversationHeader> IntermediateStorage, string query)
 {
     UsersService.Instance.GetUsers(IntermediateStorage.SelectMany <SearchConversationHeader, User>((Func <SearchConversationHeader, IEnumerable <User> >)(d => (IEnumerable <User>)d._associatedUsers)).Select <User, long>((Func <User, long>)(u => u.uid)).Distinct <long>().ToList <long>(), (Action <BackendResult <List <User>, ResultCode> >)(result =>
     {
         if (string.Compare(this._localConversationsQuery, query) != 0)
         {
             this._isLoadingConversations = false;
             this.SearchConversationsOnline(this._localConversationsQuery);
         }
         else
         {
             if (result.ResultCode == ResultCode.Succeeded)
             {
                 foreach (SearchConversationHeader conversationHeader in IntermediateStorage)
                 {
                     SearchConversationHeader dialog = conversationHeader;
                     IEnumerable <User> source       = result.ResultData.Where <User>((Func <User, bool>)(u => dialog._associatedUsers.Select <User, long>((Func <User, long>)(c => c.uid)).Contains <long>(u.uid)));
                     dialog._associatedUsers         = source.ToList <User>();
                 }
                 IntermediateStorage.ForEach((Action <SearchConversationHeader>)(i => i.RefreshUIProperties(false)));
                 this.CachedConversations.Add(query, IntermediateStorage);
                 ((DependencyObject)Deployment.Current).Dispatcher.BeginInvoke((Action)(() => this.Conversations = new ObservableCollection <SearchConversationHeader>(IntermediateStorage)));
             }
             else
             {
                 Logger.Instance.Error("Failed to get user profiles");
             }
             this._isLoadingConversations = false;
         }
     }));
 }
Exemplo n.º 2
0
 private void SearchConversationsOnline(string query)
 {
     if (this._isLoadingConversations)
     {
         return;
     }
     this._isLoadingConversations = true;
     this.SetInProgressMain(true, "");
     BackendServices.MessagesService.SearchDialogs(query, (Action <BackendResult <List <object>, ResultCode> >)(res =>
     {
         this.SetInProgressMain(false, "");
         if (string.Compare(this._localConversationsQuery, query) != 0)
         {
             this._isLoadingConversations = false;
             this.SearchConversationsOnline(this._localConversationsQuery);
         }
         else if (res.ResultCode == ResultCode.Succeeded)
         {
             List <SearchConversationHeader> IntermediateStorage = new List <SearchConversationHeader>();
             foreach (object obj in res.ResultData.Where <object>((Func <object, bool>)(r => r != null)))
             {
                 if (obj is User)
                 {
                     User user = obj as User;
                     IntermediateStorage.Add(new SearchConversationHeader(new Message()
                     {
                         uid = (int)user.uid
                     }, new List <User>()
                     {
                         user
                     }));
                 }
                 if (obj is Chat)
                 {
                     Chat chat = obj as Chat;
                     List <SearchConversationHeader> conversationHeaderList = IntermediateStorage;
                     Message message         = new Message();
                     message.chat_id         = (int)chat.chat_id;
                     message.title           = chat.title;
                     message.chat_active_str = string.Join <long>(",", (IEnumerable <long>)chat.users);
                     message.photo_200       = chat.photo_200;
                     List <User> list        = chat.users.Select <long, User>((Func <long, User>)(c => new User()
                     {
                         uid = (long)(int)c
                     })).ToList <User>();
                     SearchConversationHeader conversationHeader = new SearchConversationHeader(message, list);
                     conversationHeaderList.Add(conversationHeader);
                 }
             }
             this.ApplyUserProfiles(IntermediateStorage, query);
         }
         else
         {
             this._isLoadingConversations = false;
             Logger.Instance.Error("Failed to search conversations");
         }
     }));
 }