Пример #1
0
        private void AddToMessages(ToxMessageViewModelBase message)
        {
            var successFulAppend = AppendToLastGroup(message);

            if (successFulAppend)
            {
                return;
            }

            var msgGroup = new MessageGroupViewModel(message.Sender);

            msgGroup.Messages.Add(message);
            MessageGroups.Add(msgGroup);
            RaiseMessageAdded(message);
        }
Пример #2
0
        /// <summary>
        ///     Try to append the message to the last message group. It's possible only if the last message group's sender is the
        ///     same as the message's sender.
        /// </summary>
        /// <param name="message">The message to append.</param>
        /// <param name="messageType">Type of the message.</param>
        /// <param name="sender">The sender of the message.</param>
        /// <param name="messageId">The message ID of the message.</param>
        /// <returns>True on success, false otherwise.</returns>
        private bool AppendToLastGroup(ToxMessageViewModelBase message)
        {
            if (MessageGroups.Count == 0 || MessageGroups.Last().Messages.Count == 0)
            {
                return(false);
            }

            // TODO: Implement and use simple equality operator below. It won't work for group chats like this.
            if (MessageGroups.Last().Sender.GetType() == message.Sender.GetType())
            {
                MessageGroups.Last()
                .Messages.Add(message);
                RaiseMessageAdded(message);
                return(true);
            }

            return(false);
        }
Пример #3
0
            private void MessageAddedHandler(object sender, ToxMessageViewModelBase message)
            {
                if (IsSticky())
                {
                    ScrollToBottom(true);
                }
                else
                {
                    // We only play the notification animation if the user receives a message.
                    // We do not disturb the user with his/her own messages, only give him/her the opportunity to
                    // scroll to the bottom fast to catch up with the recent messages.

                    _messageAddedNotificationGrid.Visibility = Visibility.Visible;

                    if (message is ReceivedMessageViewModel)
                    {
                        _messageAddedNotificationAnimation.Begin();
                    }
                }
            }
Пример #4
0
 private void RaiseMessageAdded(ToxMessageViewModelBase message)
 {
     MessageAdded?.Invoke(this, message);
 }
Пример #5
0
        /// <summary>
        ///     Try to append the message to the last message group. It's possible only if the last message group's sender is the
        ///     same as the message's sender.
        /// </summary>
        /// <param name="message">The message to append.</param>
        /// <param name="messageType">Type of the message.</param>
        /// <param name="sender">The sender of the message.</param>
        /// <param name="messageId">The message ID of the message.</param>
        /// <returns>True on success, false otherwise.</returns>
        private bool AppendToLastGroup(ToxMessageViewModelBase message)
        {
            if (MessageGroups.Count == 0 || MessageGroups.Last().Messages.Count == 0)
                return false;

            // TODO: Implement and use simple equality operator below. It won't work for group chats like this.
            if (MessageGroups.Last().Sender.GetType() == message.Sender.GetType())
            {
                MessageGroups.Last()
                    .Messages.Add(message);
                RaiseMessageAdded(message);
                return true;
            }

            return false;
        }
Пример #6
0
        private async Task StoreMessage(ToxMessageViewModelBase message)
        {
            await _dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                var successFulAppend = AppendToLastGroup(message);
                if (successFulAppend)
                    return;

                var msgGroup = new MessageGroupViewModel(message.Sender);
                msgGroup.Messages.Add(message);
                MessageGroups.Add(msgGroup);
                RaiseMessageAdded(message);
            });
        }
Пример #7
0
 private void RaiseMessageAdded(ToxMessageViewModelBase message)
 {
     if (MessageAdded != null)
         MessageAdded(this, message);
 }
Пример #8
0
 private void StoreMessage(ToxMessageViewModelBase message)
 {
     DispatcherHelper.CheckBeginInvokeOnUI(() => { AddToMessages(message); });
 }
Пример #9
0
 private void RaiseMessageAdded(ToxMessageViewModelBase message)
 {
     MessageAdded?.Invoke(this, message);
 }