Beispiel #1
0
        private void AddConversationToModel(ConversationLightViewModel newConversation)
        {
            if (newConversation != null)
            {
                // First remove this conversation if already in the model
                RemoveRBConversationFromModel(newConversation.Id);

                lock (lockObservableConversations)
                {
                    Boolean itemAdded = false;
                    int     nb        = ConversationsLightList.Count;
                    for (int i = 0; i < nb; i++)
                    {
                        if (newConversation.LastMessageDateTime.ToUniversalTime() > ConversationsLightList[i].LastMessageDateTime.ToUniversalTime())
                        {
                            ConversationsLightList.Insert(i, newConversation);
                            log.LogDebug("[AddConversationToModel] INSERT Conversation.id:[{0}] IN index:[{1}]", newConversation.Id, i);
                            itemAdded = true;
                            break;
                        }
                    }
                    if (!itemAdded)
                    {
                        ConversationsLightList.Add(newConversation);
                        log.LogDebug("[AddConversationToModel] ADD Conversation.id:[{0}] ", newConversation.Id);
                    }

                    // Check if we nee to update the view due to DateTime purpose
                    //CheckIfUpdateModelForDateTimePurpose(newConversation.LastMessageDateTime);
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Remove one RB Conversation (by ID) from the ViewModel
        /// </summary>
        /// <param name="id">Rainbow Conversation's ID</param>
        public void RemoveRBConversationFromModel(String id)
        {
            ConversationLightViewModel result = GetConversationById(id);

            if (result != null)
            {
                lock (lockObservableConversations)
                    ConversationsLightList.Remove(result);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Replace the current ViewModel by all Rainbow Conversations provided
        /// </summary>
        /// <param name="rbConversations">List of Rainbow Conversations</param>
        public void ResetModelWithRbConversations(List <Rainbow.Model.Conversation> rbConversations)
        {
            lock (lockObservableConversations)
            {
                // Clear the list
                ConversationsLightList.Clear();

                foreach (Rainbow.Model.Conversation rbConversation in rbConversations)
                {
                    AddRBConversationToModel(rbConversation);
                }
            }

            //TODO - need to check dates to update display
            //CheckIfUpdateModelForDateTimePurpose(conversationList[0].LastMessageDateTime);
        }
Beispiel #4
0
        private void LoadFakeConversations()
        {
            DateTime utcNow = DateTime.UtcNow;

            ConversationLightViewModel conversationLight = null;

            // SET NEW FAKE Conversation Light
            conversationLight                     = new ConversationLightViewModel();
            conversationLight.Id                  = "convID1";
            conversationLight.Jid                 = "*****@*****.**";
            conversationLight.PeerId              = "peerId1";
            conversationLight.Type                = "user";
            conversationLight.Name                = conversationLight.Id + "User Name1";
            conversationLight.Topic               = "";
            conversationLight.PresenceSource      = "presence_online.png";
            conversationLight.NbMsgUnread         = 1;
            conversationLight.LastMessage         = "Last message";
            conversationLight.LastMessageDateTime = utcNow;
            //conversationLight.LastMessageTimeDisplay = Helpers.Helper.HumanizeDateTime(conversationLight.LastMessageDateTime);
            conversationLight.AvatarImageSource = Helper.GetBitmapImageFromResource("avatar1.jpg");

            ConversationsLightList.Add(conversationLight);

            // SET NEW FAKE Conversation Light
            conversationLight                     = new ConversationLightViewModel();
            conversationLight.Id                  = "convID2";
            conversationLight.Jid                 = "*****@*****.**";
            conversationLight.PeerId              = "peerId2";
            conversationLight.Type                = "user";
            conversationLight.Name                = conversationLight.Id + "User Name2 avec tres tres tres tres long";
            conversationLight.Topic               = "";
            conversationLight.PresenceSource      = "presence_busy.png";
            conversationLight.NbMsgUnread         = 15;
            conversationLight.LastMessage         = "-01:00 Last message very veryveryveryveryvery veryvery veryvery veryvery veryvery veryvery veryvery veryvery veryverylong";
            conversationLight.LastMessageDateTime = utcNow.AddHours(-1);
            //conversationLight.LastMessageTimeDisplay = Helpers.Helper.HumanizeDateTime(conversationLight.LastMessageDateTime);
            conversationLight.AvatarImageSource = Helper.GetBitmapImageFromResource("avatar2.jpg");

            ConversationsLightList.Add(conversationLight);

            // SET NEW FAKE Conversation Light
            conversationLight                     = new ConversationLightViewModel();
            conversationLight.Id                  = "convID3";
            conversationLight.Jid                 = "*****@*****.**";
            conversationLight.PeerId              = "peerId3";
            conversationLight.Type                = "group";
            conversationLight.Name                = conversationLight.Id + "Group Name3";
            conversationLight.Topic               = "";
            conversationLight.PresenceSource      = "";
            conversationLight.NbMsgUnread         = 0;
            conversationLight.LastMessage         = "+01:00 Last message";
            conversationLight.LastMessageDateTime = utcNow.AddHours(1);
            //conversationLight.LastMessageTimeDisplay = Helpers.Helper.HumanizeDateTime(conversationLight.LastMessageDateTime);
            conversationLight.AvatarImageSource = Helper.GetBitmapImageFromResource("avatar3.jpg");

            ConversationsLightList.Add(conversationLight);

            // SET NEW FAKE Conversation Light
            conversationLight                     = new ConversationLightViewModel();
            conversationLight.Id                  = "convID4";
            conversationLight.Jid                 = "*****@*****.**";
            conversationLight.PeerId              = "peerId4";
            conversationLight.Type                = "group";
            conversationLight.Name                = conversationLight.Id + "Group Name4 tres tres tres long";
            conversationLight.Topic               = "";
            conversationLight.PresenceSource      = "";
            conversationLight.NbMsgUnread         = 99;
            conversationLight.LastMessage         = "-02:00 Last message";
            conversationLight.LastMessageDateTime = utcNow.AddHours(-2);
            //conversationLight.LastMessageTimeDisplay = Helpers.Helper.HumanizeDateTime(conversationLight.LastMessageDateTime);
            conversationLight.AvatarImageSource = Helper.GetBitmapImageFromResource("avatar4.jpg");

            ConversationsLightList.Add(conversationLight);

            // SET NEW FAKE Conversation Light
            conversationLight                     = new ConversationLightViewModel();
            conversationLight.Id                  = "convID5";
            conversationLight.Jid                 = "*****@*****.**";
            conversationLight.PeerId              = "peerId6";
            conversationLight.Type                = "group";
            conversationLight.Name                = conversationLight.Id + "Group Name6";
            conversationLight.Topic               = "";
            conversationLight.PresenceSource      = "";
            conversationLight.NbMsgUnread         = 99;
            conversationLight.LastMessage         = "-1 day";
            conversationLight.LastMessageDateTime = utcNow.AddDays(-1);
            //conversationLight.LastMessageTimeDisplay = Helpers.Helper.HumanizeDateTime(conversationLight.LastMessageDateTime);
            conversationLight.AvatarImageSource = Helper.GetBitmapImageFromResource("avatar1.jpg");

            ConversationsLightList.Add(conversationLight);

            // SET NEW FAKE Conversation Light
            conversationLight                     = new ConversationLightViewModel();
            conversationLight.Id                  = "convID6";
            conversationLight.Jid                 = "*****@*****.**";
            conversationLight.PeerId              = "peerId6";
            conversationLight.Type                = "group";
            conversationLight.Name                = conversationLight.Id + "Group Name6 tres tres tres tres long";
            conversationLight.Topic               = "";
            conversationLight.PresenceSource      = "";
            conversationLight.NbMsgUnread         = 25;
            conversationLight.LastMessage         = "-1 Year Last message";
            conversationLight.LastMessageDateTime = utcNow.AddYears(-1);
            //conversationLight.LastMessageTimeDisplay = Helpers.Helper.HumanizeDateTime(conversationLight.LastMessageDateTime);
            conversationLight.AvatarImageSource = Helper.GetBitmapImageFromResource("avatar2.jpg");

            ConversationsLightList.Add(conversationLight);


            // SET NEW FAKE Conversation Light
            conversationLight                     = new ConversationLightViewModel();
            conversationLight.Id                  = "convID7";
            conversationLight.Jid                 = "*****@*****.**";
            conversationLight.PeerId              = "peerId7";
            conversationLight.Type                = "group";
            conversationLight.Name                = conversationLight.Id + "Group Name7 tres tres tres long";
            conversationLight.Topic               = "";
            conversationLight.PresenceSource      = "";
            conversationLight.NbMsgUnread         = 0;
            conversationLight.LastMessage         = "-1 Month Last message";
            conversationLight.LastMessageDateTime = utcNow.AddMonths(-1);
            //conversationLight.LastMessageTimeDisplay = Helpers.Helper.HumanizeDateTime(conversationLight.LastMessageDateTime);
            conversationLight.AvatarImageSource = Helper.GetBitmapImageFromResource("avatar3.jpg");

            ConversationsLightList.Add(conversationLight);
        }
Beispiel #5
0
        private void UpdateConversationToModel(ConversationLightViewModel newConversation)
        {
            if (newConversation != null)
            {
                ConversationLightViewModel oldConversation = GetConversationById(newConversation.Id);

                // If it's an unknown conversation remove it
                if (oldConversation == null)
                {
                    AddConversationToModel(newConversation);
                    return;
                }

                lock (lockObservableConversations)
                {
                    oldConversation.Id             = newConversation.Id;
                    oldConversation.Jid            = newConversation.Jid;
                    oldConversation.PeerId         = newConversation.PeerId;
                    oldConversation.Type           = newConversation.Type;
                    oldConversation.Name           = newConversation.Name;
                    oldConversation.Topic          = newConversation.Topic;
                    oldConversation.LastMessage    = newConversation.LastMessage;
                    oldConversation.PresenceSource = newConversation.PresenceSource;
                    oldConversation.NbMsgUnread    = newConversation.NbMsgUnread;

                    // Do we need to sort the list ? Only if DateTime is different
                    if (oldConversation.LastMessageDateTime != newConversation.LastMessageDateTime)
                    {
                        int nb       = ConversationsLightList.Count;
                        int oldIndex = -1;
                        int newIndex = -1;

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

                        // Check  old index found
                        if (oldIndex == -1)
                        {
                            log.LogError("[UpdateConversationToModel] There is a pb to get old index ...");
                            return;
                        }

                        // Get new index
                        for (int i = 0; i < nb; i++)
                        {
                            if (newConversation.LastMessageDateTime.ToUniversalTime() > ConversationsLightList[i].LastMessageDateTime.ToUniversalTime())
                            {
                                newIndex = i;
                                break;
                            }
                        }

                        if (newIndex == -1)
                        {
                            newIndex = nb - 1;
                        }

                        // Now set the new date
                        oldConversation.LastMessageDateTime = newConversation.LastMessageDateTime;

                        if (oldIndex != newIndex)
                        {
                            log.LogInformation("[UpdateConversationToModel] Move conversation from oldIndex:[{0}] to newIndex:[{1}]", oldIndex, newIndex);

                            // Move to corretc index
                            ConversationsLightList.Move(oldIndex, newIndex);
                        }
                        else
                        {
                            log.LogInformation("[UpdateConversationToModel] DON'T Move conversation - same indexes - oldIndex:[{0}] - newIndex:[{1}]", oldIndex, newIndex);
                        }
                    }
                }
            }
        }