コード例 #1
0
 /// <summary>
 /// Add one RB Conversation in the ViewModel
 /// </summary>
 /// <param name="rbConversation">a Rainbow Conversation object</param>
 private void AddRBConversationToModel(Rainbow.Model.Conversation rbConversation)
 {
     if (rbConversation != null)
     {
         // Now add it to the model
         ConversationModel newConversation;
         newConversation = Helper.GetConversationFromRBConversation(rbConversation);
         if (newConversation != null)
         {
             newConversation.SelectionCommand = DynamicList.SelectedItemCommand;
             AddConversationToModel(newConversation);
         }
     }
 }
コード例 #2
0
        private void UpdateRBConversationToModel(Rainbow.Model.Conversation rbConversation)
        {
            // Ensure to be on Main UI Thread
            if (!MainThread.IsMainThread)
            {
                MainThread.BeginInvokeOnMainThread(() => UpdateRBConversationToModel(rbConversation));
                return;
            }


            log.LogDebug("[UpdateRBConversationToModel] - IN");
            if (rbConversation != null)
            {
                // Now add it to the model
                ConversationModel newConversation = Helper.GetConversationFromRBConversation(rbConversation);
                newConversation.SelectionCommand = DynamicList.SelectedItemCommand;

                ConversationModel oldConversation = GetConversationById(newConversation.Id);

                if (oldConversation == null)
                {
                    AddConversationToModel(newConversation);
                }
                else
                {
                    lock (lockObservableConversations)
                    {
                        Boolean needChangeOrder = (oldConversation.LastMessageDateTime != newConversation.LastMessageDateTime);

                        oldConversation.Id   = newConversation.Id;
                        oldConversation.Peer = newConversation.Peer;

                        oldConversation.NbMsgUnread = newConversation.NbMsgUnread;

                        oldConversation.LastMessage         = newConversation.LastMessage;
                        oldConversation.LastMessageDateTime = newConversation.LastMessageDateTime;

                        if (needChangeOrder)
                        {
                            int oldIndex = 0;
                            int newIndex = -1;

                            int nb = DynamicList.Items.Count;

                            // Get old Index
                            for (int i = 0; i < nb; i++)
                            {
                                if (DynamicList.Items[i].Id == oldConversation.Id)
                                {
                                    oldIndex = i;
                                    break;
                                }
                            }

                            // Try to update order only if are not already the first row
                            if (oldIndex != 0)
                            {
                                // Get new Index
                                for (int i = 0; i < nb; i++)
                                {
                                    if (oldConversation.LastMessageDateTime.ToUniversalTime() > DynamicList.Items[i].LastMessageDateTime.ToUniversalTime())
                                    {
                                        newIndex = i;
                                        break;
                                    }
                                }

                                // If we have found no new index, we need to move it to the end
                                if (newIndex == -1)
                                {
                                    newIndex = nb - 1;
                                }

                                // Update order only if indexes are different
                                if (oldIndex != newIndex)
                                {
                                    DynamicList.Items.Move(oldIndex, newIndex);
                                }

                                log.LogDebug("[UpdateRBConversationToModel] MOVED - oldIndex:[{0}] - newIndex:[{1}] - nb:[{2}] - TopDate:[{3}] - LastMessageDateTime:[{4}]", oldIndex, newIndex, nb, DynamicList.Items[0].LastMessageDateTime.ToString("o"), oldConversation.LastMessageDateTime.ToString("o"));
                            }
                            else
                            {
                                log.LogDebug("[UpdateRBConversationToModel] NOT MOVED - oldIndex:[{0}] - nb:[{1}] - TopDate:[{2}] - LastMessageDateTime:[{3}]", oldIndex, nb, DynamicList.Items[0].LastMessageDateTime.ToString("o"), oldConversation.LastMessageDateTime.ToString("o"));
                            }
                        }
                    }

                    // Check if we need to update the view due to DateTime purpose
                    CheckIfUpdateModelForDateTimePurpose(newConversation.LastMessageDateTime);
                }
            }
            log.LogDebug("[UpdateRBConversationToModel] - OUT");
        }