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 static ImageSource GetConversationAvatarImageSource(ConversationLight conversation) { ImageSource result = null; if (conversation != null) { String filePath = null; try { if (conversation.Type == Rainbow.Model.Conversation.ConversationType.User) { filePath = AvatarPool.Instance.GetContactAvatarPath(conversation.PeerId); } else if (conversation.Type == Rainbow.Model.Conversation.ConversationType.Room) { filePath = AvatarPool.Instance.GetBubbleAvatarPath(conversation.PeerId); } } catch (Exception exc) { log.Warn("[GetConversationAvatarImageSource] PeerId:[{0}] - exception occurs to create avatar:[{1}]", conversation.PeerId, Util.SerializeException(exc)); } if (!String.IsNullOrEmpty(filePath)) { if (File.Exists(filePath)) { //log.Debug("[SetConversationAvatar] - file used - filePath:[{0}] - PeerId:[{1}]", filePath, conversation.PeerId); try { result = ImageSource.FromFile(filePath); } catch (Exception exc) { log.Warn("[GetConversationAvatarImageSource] PeerId:[{0}] - exception occurs to display avatar[{1}]", conversation.PeerId, Util.SerializeException(exc)); } } //else // log.Warn("[SetConversationAvatar] - file not found - filePath:[{0}] - PeerId:[{1}]", filePath, conversation.PeerId); } } return(result); }