Example #1
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="message"></param>
        /// <param name="users">All users from dialogs. Is need to find out friends related to this dialog.</param>
        /// <param name="photo"></param>
        public Dialog(Message message, IList<UserInfo> users)
        {
            bool isConference = message.Chatid > 0 ? true : false;

            if (isConference)
                _chatid = message.Chatid;
            else
            {
                _chatid = message.Mid;
                _mid = message.Mid;
            }

            _uid = message.Uid;
            _isConference = isConference;
            _isRead = message.IsRead;
            _attachmentCount = 1;

            if (string.IsNullOrEmpty(message.Body))
            {
                if (message.Attachments != null && message.Attachments.Any())
                {
                    var att = message.Attachments.FirstOrDefault();

                    if (att != null)
                        _lastMessage = att.Type;
                }
                else if (message.FwdMessages != null && message.FwdMessages.Any())
                {
                    _lastMessage = AppResources.ForwardedContentLabel;
                }
                else if (message.GeoLocation != null)
                {
                    _lastMessage = AppResources.LocContentLabel;
                }
                else
                {
                    _lastMessage = "<>";
                }
            }
            else
                _lastMessage = CommonHelper.GetFormattedMessage(message.Body);

            _time = message.Date;
            IsOut = message.IsOut;
            _dateTime = CommonHelper.GetFormattedDialogTime(_time);

            if (isConference)
            {
                _title = message.Title;
                _isOnline = false;
            }
            else
            {
                UserInfo user = users.FirstOrDefault(x => x.Uid == message.Uid);

                if (user != null)
                {
                    _title = user.FullName;
                    _isOnline = user.IsOnline;
                    _photoUri = user.Photo;
                }
            }

            _chatActive = message.ChatActive;
        }
Example #2
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <param name="isConference"></param>
        /// <returns></returns>
        public ChatViewModel GetChatViewModel(int id, bool isConference)
        {
            _currentChatId = id;
            _isCurrentConference = isConference;

            try
            {
                var currentMessages = _messagesCache.GetItems(id);

                string title = EntitiesHelpers.GetChatTitle(id, isConference);

                // Load only 30 first from cache.
                int finish = currentMessages.Count - MESSAGES_COUNT;
                if (finish < 0)
                    finish = 0;

                int count = MESSAGES_COUNT;
                if (currentMessages.Count < count)
                    count = currentMessages.Count;

                var filtered = new Message[count];// new List<Message>(MESSAGES_COUNT);
                for (int i = currentMessages.Count - 1, j = count - 1; i >= finish; i--, j--)
                    filtered[j] = currentMessages[i];

                _currentChatViewModel = new ChatViewModel(id, title, isConference, filtered, _imageCache);

                if (!currentMessages.Any()) // Get messages only first time for this chat.
                {
                    MessagesGet getMessages = null;
                    if (isConference)
                        getMessages = new MessagesGet(-1, id, 0, MESSAGES_COUNT, _UpdateCurrentMessagesList);
                    else
                        getMessages = new MessagesGet(id, -1, 0, MESSAGES_COUNT, _UpdateCurrentMessagesList);

                    getMessages.Execute();
                }
                else
                    _UpdateReadStatusOfMessages(currentMessages); // This method will be called in _UpdateCurrentMessagesList

                _currentChatViewModel.UpdateStatusInfo();
            }
            catch (Exception ex)
            {
                Debug.WriteLine("GetChatViewModel failed: " + ex.Message);
            }

            return _currentChatViewModel;
        }