示例#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);
                }
            }
        }
示例#2
0
        public void UpdateConversationNameByPeerId(string peerId, String name)
        {
            ConversationLightViewModel conversation = GetConversationByPeerId(peerId);

            if (conversation != null)
            {
                conversation.Name = name;
            }
        }
示例#3
0
        /// <summary>
        /// Update the ViewModel using the Presence Level of the specified JID
        /// </summary>
        /// <param name="jid">Jid of the contact</param>
        /// <param name="presence">Presence of the contact</param>
        public void UpdateModelUsingPresence(String jid, Presence presence)
        {
            ConversationLightViewModel conversation = GetConversationByJid(jid);

            if (conversation != null)
            {
                conversation.PresenceSource = InstantMessaging.Helpers.Helper.GetPresenceSourceFromPresence(presence, jid == CurrentApplication.CurrentUserJid);
            }
        }
示例#4
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);
            }
        }
示例#5
0
        public static BitmapImage GetConversationAvatarImageSource(ConversationLightViewModel conversation)
        {
            BitmapImage result = null;

            if (conversation != null)
            {
                result = GetAvatarImageSourceByPeerIdAndType(conversation.PeerId, conversation.Type);
            }
            return(result);
        }
示例#6
0
 public void UpdateRBConversationToModel(Rainbow.Model.Conversation rbConversation)
 {
     if (rbConversation != null)
     {
         ConversationLightViewModel newConversation = Helper.GetConversationFromRBConversation(rbConversation);
         if (newConversation != null)
         {
             newConversation.AvatarImageSource = Helper.GetConversationAvatarImageSource(newConversation);
             UpdateConversationToModel(newConversation);
         }
     }
 }
示例#7
0
        private ConversationLightViewModel GetConversationByPeerId(String peerId)
        {
            ConversationLightViewModel conversationFound = null;

            lock (lockObservableConversations)
            {
                foreach (ConversationLightViewModel conversation in ConversationsLightList)
                {
                    if (conversation.PeerId == peerId)
                    {
                        conversationFound = conversation;
                        break;
                    }
                }
            }
            return(conversationFound);
        }
示例#8
0
        private void SetConversationAvatar(ConversationLightViewModel conversation)
        {
            if (conversation == null)
            {
                return;
            }

            String filePath = null;

            try
            {
                if (conversation.Type == Rainbow.Model.Conversation.ConversationType.User)
                {
                    filePath = AvatarPool.GetContactAvatarPath(conversation.PeerId);
                }
                else if (conversation.Type == Rainbow.Model.Conversation.ConversationType.Room)
                {
                    filePath = AvatarPool.GetBubbleAvatarPath(conversation.PeerId);
                }
            }
            catch (Exception exc)
            {
                log.LogWarning("[SetConversationAvatar] PeerId:[{0}] - exception occurs to create avatar:[{1}]", conversation.PeerId, Util.SerializeException(exc));
            }

            if (!String.IsNullOrEmpty(filePath))
            {
                if (File.Exists(filePath))
                {
                    log.LogDebug("[SetConversationAvatar] - file used - filePath:[{0}] - PeerId:[{1}]", filePath, conversation.PeerId);
                    try
                    {
                        conversation.AvatarImageSource = Helper.BitmapImageFromFile(filePath);
                    }
                    catch (Exception exc)
                    {
                        log.LogWarning("[SetConversationAvatar] PeerId:[{0}] - exception occurs to display avatar[{1}]", conversation.PeerId, Util.SerializeException(exc));
                    }
                }
                else
                {
                    log.LogWarning("[SetConversationAvatar] - file not found - filePath:[{0}] - PeerId:[{1}]", filePath, conversation.PeerId);
                }
            }
        }
示例#9
0
        private ConversationLightViewModel GetConversationLightCopy(ConversationLightViewModel conversationLightViewModel)
        {
            ConversationLightViewModel result = new ConversationLightViewModel();

            result.Id                  = conversationLightViewModel.Id;
            result.Jid                 = conversationLightViewModel.Jid;
            result.PeerId              = conversationLightViewModel.PeerId;
            result.Type                = conversationLightViewModel.Type;
            result.Name                = conversationLightViewModel.Name;
            result.Topic               = conversationLightViewModel.Topic;
            result.LastMessage         = conversationLightViewModel.LastMessage;
            result.PresenceSource      = conversationLightViewModel.PresenceSource;
            result.NbMsgUnread         = conversationLightViewModel.NbMsgUnread;
            result.LastMessageDateTime = conversationLightViewModel.LastMessageDateTime;

            result.AvatarImageSource = conversationLightViewModel.AvatarImageSource;

            return(result);
        }
示例#10
0
 private void AvatarPool_ContactAvatarChanged(object sender, Rainbow.Events.IdEventArgs e)
 {
     if (System.Windows.Application.Current != null)
     {
         System.Windows.Application.Current.Dispatcher.Invoke(new Action(() =>
         {
             ConversationLightViewModel conversation = GetConversationByPeerId(e.Id);
             if (conversation != null)
             {
                 log.LogDebug("[AvatarPool_ContactAvatarChanged] - contactId:[{0}] - conversationId:[{1}]", e.Id, conversation.Id);
                 conversation.AvatarImageSource = Helper.GetConversationAvatarImageSource(conversation);
             }
             //else
             //{
             //    log.LogDebug("[AvatarPool_ContactAvatarChanged] - Avatar contactId:[{0}] but no conversation found ...", e.Id);
             //}
         }));
     }
 }
示例#11
0
 public void ItemLeftClickCommand(object obj)
 {
     if ((obj != null) && (obj is ConversationLightViewModel))
     {
         ConversationLightViewModel conversation = obj as ConversationLightViewModel;
         if (conversation != null)
         {
             CurrentApplication.ApplicationMainWindow.SetConversationIdSelectionFromConversationsList(conversation.Id);
         }
         else
         {
             log.LogWarning("[ItemLeftClickCommand] Referenced object is null...");
         }
     }
     else
     {
         log.LogWarning("[ItemLeftClickCommand] Referenced object is null or it's an unknown type.");
     }
 }
示例#12
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);
        }
示例#13
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);
                        }
                    }
                }
            }
        }
示例#14
0
        public static ConversationLightViewModel GetConversationFromRBConversation(Rainbow.Model.Conversation rbConversation)
        {
            ConversationLightViewModel conversation = null;

            if (rbConversation != null)
            {
                InstantMessaging.App CurrentApplication = (InstantMessaging.App)System.Windows.Application.Current;
                AvatarPool           avatarPool         = AvatarPool.Instance;

                conversation = new ConversationLightViewModel();

                if (rbConversation.Type == Rainbow.Model.Conversation.ConversationType.Room)
                {
                    conversation.Name           = rbConversation.Name;
                    conversation.Topic          = rbConversation.Topic;
                    conversation.Jid            = rbConversation.Jid_im;
                    conversation.PresenceSource = "";
                }
                else if (rbConversation.Type == Rainbow.Model.Conversation.ConversationType.User)
                {
                    // Get Display name of this user
                    Rainbow.Model.Contact contact = CurrentApplication.RbContacts.GetContactFromContactId(rbConversation.PeerId);
                    if (contact != null)
                    {
                        conversation.Name  = Util.GetContactDisplayName(contact);
                        conversation.Topic = "";
                        conversation.Jid   = contact.Jid_im;

                        Presence presence = CurrentApplication.RbContacts.GetAggregatedPresenceFromContactId(rbConversation.PeerId);
                        conversation.PresenceSource = InstantMessaging.Helpers.Helper.GetPresenceSourceFromPresence(presence, rbConversation.PeerId == CurrentApplication.CurrentUserId);
                    }
                    else
                    {
                        // We ask to have more info about this contact using AvatarPool
                        log.LogDebug("[GetConversationFromRBConversation] - unknown contact - contactId:[{0}]", rbConversation.PeerId);
                        avatarPool.AddUnknownContactToPoolById(rbConversation.PeerId);

                        // Try to get info from pool
                        AvatarsData.LightContact lightContact = avatarPool.GetLightContact(rbConversation.PeerId, rbConversation.Jid_im);

                        if (lightContact != null)
                        {
                            conversation.Name           = lightContact.DisplayName;
                            conversation.Topic          = "";
                            conversation.PeerId         = lightContact.Id;
                            conversation.Jid            = lightContact.Jid;
                            conversation.PresenceSource = "presence_offline.png";
                        }
                    }
                }
                else
                {
                    //TODO ( bot case)
                    log.LogDebug("[GetConversationFromRBConversation] Conversation from model not created - Id:[{0}]", rbConversation.Id);
                    return(null);
                }

                conversation.Id     = rbConversation.Id;
                conversation.PeerId = rbConversation.PeerId;

                conversation.Type        = rbConversation.Type;
                conversation.NbMsgUnread = rbConversation.UnreadMessageNumber;

                conversation.LastMessage         = rbConversation.LastMessageText;
                conversation.LastMessageDateTime = rbConversation.LastMessageDate;
            }
            return(conversation);
        }