Пример #1
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);
        }
Пример #2
0
        public static FavoriteViewModel GetFavoriteFromRbFavorite(Rainbow.Model.Favorite rbFavorite)
        {
            FavoriteViewModel result = null;

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

                result = new FavoriteViewModel();

                Conversation rbConversation = CurrentApplication.RbConversations.GetConversationByPeerIdFromCache(rbFavorite.PeerId);

                if (rbConversation != null)
                {
                    result.IsVisible   = true;
                    result.Jid         = rbConversation.Jid_im;
                    result.NbMsgUnread = rbConversation.UnreadMessageNumber;

                    if (rbConversation.Type == Rainbow.Model.Conversation.ConversationType.Room)
                    {
                        result.Name           = rbConversation.Name;
                        result.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)
                        {
                            Presence presence = CurrentApplication.RbContacts.GetAggregatedPresenceFromContactId(rbConversation.PeerId);

                            result.Name           = Util.GetContactDisplayName(contact);
                            result.PresenceSource = InstantMessaging.Helpers.Helper.GetPresenceSourceFromPresence(presence, rbConversation.PeerId == CurrentApplication.CurrentUserId);
                        }
                        else
                        {
                            // We ask to have more info about this contact using AvatarPool
                            log.LogDebug("[GetFavoriteFromRbFavorite] - 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)
                            {
                                result.Name           = lightContact.DisplayName;
                                result.PresenceSource = "presence_offline.png";
                            }
                        }
                    }
                    else
                    {
                        //TODO (bot case)
                        log.LogDebug("[GetFavoriteFromRbFavorite] Conversation from model not created - Id:[{0}]", rbConversation.Id);
                        return(null);
                    }
                }
                else
                {
                    Bubble bubble = CurrentApplication.RbBubbles.GetBubbleByIdFromCache(rbFavorite.PeerId);
                    if (bubble != null)
                    {
                        result.IsVisible      = true;
                        result.Name           = bubble.Name;
                        result.Jid            = bubble.Jid;
                        result.NbMsgUnread    = 0;
                        result.PresenceSource = "";
                    }
                    else
                    {
                        result.IsVisible      = false;
                        result.Name           = "";
                        result.Jid            = "";
                        result.NbMsgUnread    = 0;
                        result.PresenceSource = "";

                        log.LogWarning("[GetFavoriteFromRbFavorite] Cannot get Conversation or Bubble object from Favorite - FavoriteId:[{0}] - FavoritePeerId:[{1}]", rbFavorite.Id, rbFavorite.PeerId);
                    }

                    //TODO - need to get conversation ?
                }

                result.Id       = rbFavorite.Id;
                result.PeerId   = rbFavorite.PeerId;
                result.Position = rbFavorite.Position;

                // Name, PresenceSource,  NbMsgUnread and IsVisible are set before
            }
            return(result);
        }