Esempio n. 1
0
        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);
        }
Esempio n. 2
0
 private String GetCurrentContactId()
 {
     if (currentContactId == null)
     {
         InstantMessaging.App XamarinApplication = (InstantMessaging.App)Xamarin.Forms.Application.Current;
         currentContactId = XamarinApplication.RbContacts.GetCurrentContactId();
     }
     return(currentContactId);
 }
        /// <summary>
        /// Constructor
        /// </summary>
        public ConversationsViewModel()
        {
            Conversations = new ObservableRangeCollection <ConversationLight>();

            // Get Xamarin Application
            XamarinApplication = (InstantMessaging.App)Xamarin.Forms.Application.Current;

            // Manage event(s) from AvatarPool
            avatarPool = AvatarPool.Instance;
            avatarPool.ContactAvatarChanged += AvatarPool_ContactAvatarChanged;
            avatarPool.BubbleAvatarChanged  += AvatarPool_BubbleAvatarChanged;
        }
        public LoginPage()
        {
            InitializeComponent();

            ViewModel.Connect = "Connect";
            ViewModel.IsBusy  = false;

            XamarinApplication = (InstantMessaging.App)Xamarin.Forms.Application.Current;

            // Set default values for login / pwd
            EntryLogin.Text    = XamarinApplication.RbApplication.GetUserLoginFromCache();
            EntryPassword.Text = XamarinApplication.RbApplication.GetUserPasswordFromCache();

            XamarinApplication.RbApplication.ConnectionStateChanged  += RbApplication_ConnectionStateChanged;
            XamarinApplication.RbApplication.InitializationPerformed += RbApplication_InitializationPerformed;
        }
Esempio n. 5
0
        public static BitmapImage GetConversationAvatarImageSourceByPeerId(String peerId)
        {
            InstantMessaging.App CurrentApplication = (InstantMessaging.App)System.Windows.Application.Current;
            Conversation         conversation       = CurrentApplication.RbConversations.GetConversationByPeerIdFromCache(peerId);

            if (conversation != null)
            {
                return(GetAvatarImageSourceByPeerIdAndType(conversation.PeerId, conversation.Type));
            }
            else
            {
                // This peerId could be a Bubble wihtout an existing conversation
                Bubble bubble = CurrentApplication.RbBubbles.GetBubbleByIdFromCache(peerId);
                if (bubble != null)
                {
                    return(GetBubbleAvatarImageSource(peerId));
                }
            }
            return(null);
        }
        public ConversationsPage()
        {
            InitializeComponent();

            this.Appearing += ConversationsPage_Appearing;

            // Get Xamarin Application
            XamarinApplication = (InstantMessaging.App)Xamarin.Forms.Application.Current;

            // Manage event(s) from Rainbow SDK about CONVERSATIONS
            XamarinApplication.RbConversations.ConversationCreated += RbConversations_ConversationCreated;
            XamarinApplication.RbConversations.ConversationRemoved += RbConversations_ConversationRemoved;
            XamarinApplication.RbConversations.ConversationUpdated += RbConversations_ConversationUpdated;

            // Manage event(s) from Rainbow SDK about CONTACTS
            XamarinApplication.RbContacts.ContactPresenceChanged += RbContacts_ContactPresenceChanged;
            XamarinApplication.RbContacts.ContactAdded           += RbContacts_ContactAdded;
            XamarinApplication.RbContacts.ContactInfoChanged     += RbContacts_ContactInfoChanged;

            XamarinApplication.RbBubbles.BubbleInfoUpdated += RbBubbles_BubbleInfoUpdated;

            // Create ViewModel
            vm = new ConversationsViewModel();

            // Set the ViewModel as BindingContext
            BindingContext = vm;

            // Initialize the ViewModel
            vm.ResetModelWithRbConversations(XamarinApplication.RbConversations.GetAllConversationsFromCache());

            // Now allow Avatar download
            Rainbow.Helpers.AvatarPool.Instance.AllowAvatarDownload(true);

            // Now allow to ask server info about unknown contacts
            Rainbow.Helpers.AvatarPool.Instance.AllowToAskInfoForUnknownContact(true);
        }
        }                                                      // Need to be public - Used as Binding from XAML

        #endregion XAML BINDING ELEMENTS

        #region PUBLIC METHODS

        /// <summary>
        /// Constructor
        /// </summary>
        public ConversationStreamViewModel(String conversationId)
        {
            // Get Xamarin Application
            XamarinApplication = (InstantMessaging.App)Xamarin.Forms.Application.Current;

            // Manage event(s) from FilePool
            filePool = FilePool.Instance;
            filePool.FileDescriptorAvailable += FilePool_FileDescriptorAvailable;
            filePool.ThumbnailAvailable      += FilePool_ThumbnailAvailable;

            // Manage event(s) from AvatarPool
            avatarPool = AvatarPool.Instance;
            avatarPool.ContactAvatarChanged += AvatarPool_ContactAvatarChanged;
            avatarPool.BubbleAvatarChanged  += AvatarPool_BubbleAvatarChanged;

            // Manage event(s) from InstantMessaging
            XamarinApplication.RbInstantMessaging.MessageReceived   += RbInstantMessaging_MessageReceived;
            XamarinApplication.RbInstantMessaging.ReceiptReceived   += RbInstantMessaging_ReceiptReceived;
            XamarinApplication.RbInstantMessaging.MessagesAllRead   += RbInstantMessaging_MessagesAllRead;
            XamarinApplication.RbInstantMessaging.UserTypingChanged += RbInstantMessaging_UserTypingChanged;

            // Manage event(s) from Contacts
            XamarinApplication.RbContacts.ContactAdded       += RbContacts_ContactAdded;
            XamarinApplication.RbContacts.ContactInfoChanged += RbContacts_ContactInfoChanged;

            currentContactJid = XamarinApplication.RbContacts.GetCurrentContactJid();

            // Store conversation Id
            this.conversationId = conversationId;

            // Create default ConversationStream object
            ConversationStream = new ConversationStream
            {
                LoadingIndicatorIsVisible = "False",
                ListViewIsEnabled         = "True"
            };

            // Create default MessagesList  object
            MessagesList = new ObservableRangeCollection <InstantMessaging.Model.Message>();

            if (string.IsNullOrEmpty(this.conversationId))
            {
                //TODO
                Conversation = new ConversationLight();
            }
            else
            {
                // Get Rainbow Conversation object
                rbConversation = XamarinApplication.RbConversations.GetConversationByIdFromCache(this.conversationId);

                // Get Conversation Model Object using Rainbow Conversation
                Conversation = Helper.GetConversationFromRBConversation(rbConversation);
                if (Conversation != null)
                {
                    Conversation.AvatarSource = Helper.GetConversationAvatarImageSource(Conversation);
                }

                // Get Messages
                List <Rainbow.Model.Message> rbMessagesList = XamarinApplication.RbInstantMessaging.GetAllMessagesFromConversationIdFromCache(this.conversationId);
                if (rbMessagesList != null)
                {
                    if (rbMessagesList.Count > 0)
                    {
                        AddToModelRbMessages(rbMessagesList);
                    }

                    if (rbMessagesList.Count < NB_MESSAGE_LOADED_BY_ROW)
                    {
                        LoadMoreMessages();
                    }
                }
                else
                {
                    LoadMoreMessages();
                }
            }
        }
        private InstantMessaging.Model.Message GetMessageFromRBMessage(Rainbow.Model.Message rbMessage, String conversationType)
        {
            InstantMessaging.Model.Message message = null;
            if (rbMessage != null)
            {
                InstantMessaging.App XamarinApplication = (InstantMessaging.App)Xamarin.Forms.Application.Current;
                AvatarPool           avatarPool         = AvatarPool.Instance;

                //log.Debug("[GetMessageFromRBMessage] Message.Id:[{0}] - Message.ReplaceId:[{1}] - DateTime:[{2}] - Content:[{3}]", rbMessage.Id, rbMessage.ReplaceId, rbMessage.Date.ToString("o"), rbMessage.Content);

                message = new InstantMessaging.Model.Message();
                message.EventMessageBodyPart2Color = Color.Black; // Set default value

                Rainbow.Model.Contact contact = XamarinApplication.RbContacts.GetContactFromContactJid(rbMessage.FromJid);
                if (contact != null)
                {
                    message.PeerId = contact.Id;

                    message.PeerDisplayName = Util.GetContactDisplayName(contact);
                    message.BackgroundColor = Color.FromHex(Rainbow.Helpers.AvatarPool.GetColorFromDisplayName(message.PeerDisplayName));
                }
                else
                {
                    message.BackgroundColor = Color.FromHex(Rainbow.Helpers.AvatarPool.GetColorFromDisplayName(""));

                    // We ask to have more info about this contact usin AvatarPool
                    avatarPool.AddUnknownContactToPoolByJid(rbMessage.FromJid);
                }

                // We have the display name only in Room / Bubble context
                message.PeerDisplayNameIsVisible = (conversationType == Rainbow.Model.Conversation.ConversationType.Room) ? "True" : "False";

                message.Id      = rbMessage.Id;
                message.PeerJid = rbMessage.FromJid;

                message.MessageDateTime    = rbMessage.Date;
                message.MessageDateDisplay = Helper.HumanizeDateTime(rbMessage.Date);

                // Receipt
                SetReceiptPartOfMessage(message, rbMessage.Receipt);

                // Is-it an "Event message" ?
                String content;
                if (!String.IsNullOrEmpty(rbMessage.BubbleEvent))
                {
                    message.IsEventMessage        = "True";
                    message.EventMessageBodyPart1 = Helper.GetBubbleEventMessageBody(contact, rbMessage.BubbleEvent);
                }
                // Is-it an "CallLog message" ?
                else if (rbMessage.CallLogAttachment != null)
                {
                    SetCallLogPartOfMessage(message, rbMessage.CallLogAttachment);
                }
                else
                {
                    message.IsEventMessage     = "False";
                    message.BodyFontAttributes = FontAttributes.None;
                    message.BodyColor          = (message.PeerJid == currentContactJid) ? Color.Black : Color.White;

                    if (!String.IsNullOrEmpty(rbMessage.Content))
                    {
                        content = rbMessage.Content;
                    }
                    else
                    {
                        if (String.IsNullOrEmpty(rbMessage.ReplaceId))
                        {
                            content = "";
                        }
                        else
                        {
                            content = "This message was deleted.";
                            message.BodyFontAttributes = FontAttributes.Italic;
                            message.BodyColor          = (message.PeerJid == currentContactJid) ? Color.Gray : Color.FromHex(Rainbow.Helpers.AvatarPool.GetDarkerColorFromDisplayName(message.PeerDisplayName));
                        }
                    }

                    // Edited text visible ?
                    message.EditedIsVisible = String.IsNullOrEmpty(rbMessage.ReplaceId) ? "False" : "True";

                    // Reply part
                    // By default is not displayed
                    message.ReplyPartIsVisible = "False";
                    if (rbMessage.ReplyMessage != null)
                    {
                        // Store Id of this reply message
                        message.ReplyId = rbMessage.ReplyMessage.Id;

                        // Set background color
                        message.ReplyBackgroundColor = Color.FromHex(Rainbow.Helpers.AvatarPool.GetDarkerColorFromDisplayName(message.PeerDisplayName));

                        // We need to get Name and text of the replied message ...
                        Rainbow.Model.Message rbRepliedMessage = XamarinApplication.RbInstantMessaging.GetOneMessageFromConversationIdFromCache(this.conversationId, rbMessage.ReplyMessage.Id);
                        if (rbRepliedMessage != null)
                        {
                            SetReplyPartOfMessage(message, rbRepliedMessage);
                        }
                        else
                        {
                            AddUnknownRepliedMessageInvolved(rbMessage.ReplyMessage.Id, rbMessage.ReplyMessage.Stamp);
                        }
                    }
                    else
                    {
                        // Set default color to avoir warning
                        message.ReplyBackgroundColor = Color.White;
                    }

                    // FileAttachment
                    if (rbMessage.FileAttachment != null)
                    {
                        // Set Global info
                        message.FileAttachmentIsVisible  = "True";
                        message.FileDefaultInfoIsVisible = "True";
                        message.FileId   = rbMessage.FileAttachment.Id;
                        message.FileName = rbMessage.FileAttachment.Name;
                        message.FileSize = Helper.HumanizeFileSize(rbMessage.FileAttachment.Size);

                        if (filePool.IsThumbnailFileAvailable(conversationId, rbMessage.FileAttachment.Id, rbMessage.FileAttachment.Name))
                        {
                            SetFileAttachmentSourceOfMessage(message, rbMessage.FileAttachment.Id);
                        }
                        else
                        {
                            // Ask more info about this file
                            filePool.AskFileDescriptorDownload(this.conversationId, rbMessage.FileAttachment.Id);

                            // Set default icon
                            message.FileAttachmentSource       = "icon_unknown_blue";
                            message.FileAttachmentSourceWidth  = 50;
                            message.FileAttachmentSourceHeight = 50;
                        }
                    }
                    else
                    {
                        message.FileAttachmentIsVisible  = "False";
                        message.FileDefaultInfoIsVisible = "False";

                        message.FileAttachmentSourceWidth  = 0;
                        message.FileAttachmentSourceHeight = 0;
                    }

                    message.Body          = content;
                    message.BodyIsVisible = String.IsNullOrEmpty(message.Body) ? "False" : "True";
                }

                // We store info about this contact in message context
                AddContactInvolved(message.PeerJid);
            }
            return(message);
        }
Esempio n. 9
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);
        }
Esempio n. 10
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);
        }