Ejemplo n.º 1
0
 public void AddRbFavoriteToModel(Rainbow.Model.Favorite favorite)
 {
     if (favorite != null)
     {
         // Now add it to the model
         FavoriteViewModel newFavorite;
         newFavorite = Helper.GetFavoriteFromRbFavorite(favorite);
         if (newFavorite != null)
         {
             newFavorite.AvatarImageSource = Helper.GetConversationAvatarImageSourceByPeerId(favorite.PeerId);
             AddFavoriteToModel(newFavorite);
         }
     }
 }
Ejemplo n.º 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);
        }