public static ConversationLight GetConversationFromRBConversation(Rainbow.Model.Conversation rbConversation) { ConversationLight conversation = null; if (rbConversation != null) { InstantMessaging.App XamarinApplication = (InstantMessaging.App)Xamarin.Forms.Application.Current; AvatarPool avatarPool = AvatarPool.Instance; conversation = new ConversationLight(); 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 = XamarinApplication.RbContacts.GetContactFromContactId(rbConversation.PeerId); if (contact != null) { conversation.Name = Util.GetContactDisplayName(contact); conversation.Topic = ""; conversation.Jid = contact.Jid_im; Presence presence = XamarinApplication.RbContacts.GetAggregatedPresenceFromContactId(rbConversation.PeerId); conversation.PresenceSource = InstantMessaging.Helpers.Helper.GetPresenceSourceFromPresence(presence); } else { //log.Debug("[GetConversationFromRBConversation] - unknown contact - contactId:[{0}]", rbConversation.PeerId); XamarinApplication.RbContacts.GetContactFromContactIdFromServer(rbConversation.PeerId, null); } } else { //TODO ( bot case) //log.Debug("[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.NbMsgUnreadIsVisible = (conversation.NbMsgUnread > 0) ? "True" : "False"; conversation.LastMessage = rbConversation.LastMessageText; conversation.LastMessageDateTime = rbConversation.LastMessageDate; // Humanized the DateTime conversation.MessageTimeDisplay = Helpers.Helper.HumanizeDateTime(conversation.LastMessageDateTime); } return(conversation); }
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); } } }
public static ConversationModel GetConversationFromRBConversation(Rainbow.Model.Conversation rbConversation) { ConversationModel conversation = null; if (rbConversation != null) { conversation = new ConversationModel(); conversation.Id = rbConversation.Id; conversation.Peer.Id = rbConversation.PeerId; conversation.Peer.Jid = rbConversation.Jid_im; conversation.Peer.Type = rbConversation.Type; if (rbConversation.Type == Rainbow.Model.Conversation.ConversationType.Room) { conversation.Peer.DisplayName = rbConversation.Name; conversation.Topic = rbConversation.Topic; } else if (rbConversation.Type == Rainbow.Model.Conversation.ConversationType.User) { // Get Display name of this user Rainbow.Model.Contact contact = SdkWrapper.GetContactFromContactId(rbConversation.PeerId); if (contact != null) { conversation.Peer.DisplayName = Rainbow.Util.GetContactDisplayName(contact); conversation.Peer.DisplayPresence = true; conversation.Topic = ""; } else { //log.LogDebug("[GetConversationFromRBConversation] - unknown contact - contactId:[{0}]", rbConversation.PeerId); SdkWrapper.GetContactFromContactIdFromServer(rbConversation.PeerId, null); } } else { //TODO ( bot case) //log.LogDebug("[GetConversationFromRBConversation] Conversation from model not created - Id:[{0}]", rbConversation.Id); return(null); } conversation.NbMsgUnread = rbConversation.UnreadMessageNumber; conversation.LastMessage = rbConversation.LastMessageText; conversation.LastMessageDateTime = rbConversation.LastMessageDate; if (conversation.LastMessageDateTime == DateTime.MinValue) { conversation.LastMessageDateTime = rbConversation.CreationDate; } } return(conversation); }
/// <summary> /// Add one RB Conversation in the ViewModel /// </summary> /// <param name="rbConversation">a Rainbow Conversation object</param> public void AddRBConversationToModel(Rainbow.Model.Conversation rbConversation) { if (rbConversation != null) { // Now add it to the model ConversationLight newConversation; newConversation = Helper.GetConversationFromRBConversation(rbConversation); if (newConversation != null) { newConversation.AvatarSource = Helper.GetConversationAvatarImageSource(newConversation); AddConversationToModel(newConversation); } } }
public void UpdateRBConversationToModel(Rainbow.Model.Conversation rbConversation) { log.Debug("[UpdateRBConversationToModel] - IN"); if (rbConversation != null) { // Now add it to the model ConversationLight newConversation = Helper.GetConversationFromRBConversation(rbConversation); ConversationLight oldConversation = GetConversationById(newConversation.Id); if (oldConversation == null) { AddConversationToModel(newConversation); } else { lock (lockObservableConversations) { oldConversation.Id = newConversation.Id; oldConversation.Jid = newConversation.Jid; oldConversation.PeerId = newConversation.PeerId; oldConversation.Name = newConversation.Name; oldConversation.PresenceSource = newConversation.PresenceSource; oldConversation.NbMsgUnread = newConversation.NbMsgUnread; oldConversation.NbMsgUnreadIsVisible = (oldConversation.NbMsgUnread > 0) ? "True" : "False"; oldConversation.LastMessage = newConversation.LastMessage; oldConversation.LastMessageDateTime = newConversation.LastMessageDateTime; oldConversation.MessageTimeDisplay = newConversation.MessageTimeDisplay; int oldIndex = 0; int newIndex = -1; int nb = Conversations.Count; // Get old Index for (int i = 0; i < nb; i++) { if (Conversations[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() > Conversations[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) { Conversations.Move(oldIndex, newIndex); } log.Debug("[UpdateRBConversationToModel] MOVED - oldIndex:[{0}] - newIndex:[{1}] - nb:[{2}] - TopDate:[{3}] - LastMessageDateTime:[{4}]", oldIndex, newIndex, nb, Conversations[0].LastMessageDateTime.ToString("o"), oldConversation.LastMessageDateTime.ToString("o")); } else { log.Debug("[UpdateRBConversationToModel] NOT MOVED - oldIndex:[{0}] - nb:[{1}] - TopDate:[{2}] - LastMessageDateTime:[{3}]", oldIndex, nb, Conversations[0].LastMessageDateTime.ToString("o"), oldConversation.LastMessageDateTime.ToString("o")); } } // Check if we need to update the view due to DateTime purpose CheckIfUpdateModelForDateTimePurpose(newConversation.LastMessageDateTime); } } log.Debug("[UpdateRBConversationToModel] - OUT"); }
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); }