Пример #1
0
        /// <summary>
        /// Handle new reply in conversation.
        /// </summary>
        /// <param name="user">user.</param>
        /// <param name="interlocutor">interlocutor.</param>
        /// <param name="text">text of reply.</param>
        /// <exception cref="ConnectionInterruptedException"></exception>
        private void HandleReply(OnlineUser user, string interlocutor, string text)
        {
            int interlocutorId = DBoperations.GetUserId(interlocutor);

            if (interlocutorId == 0)
            {
                return;
            }

            // time of reply
            DateTime time = DateTime.Now;

            if (DBoperations.AddNewReply(user.Id, interlocutorId, text, time))
            {
                // send reply to user one
                user.Client.SendMessage(new NewReplyMessage
                {
                    Interlocutor = interlocutor,
                    Author       = user.Login,
                    Time         = time,
                    Text         = text
                });

                // send reply to user two if online
                OnlineUser friend = GetOnlineUser(interlocutor);

                if (friend != null)
                {
                    friend.Client.SendMessage(new NewReplyMessage
                    {
                        Interlocutor = user.Login,
                        Author       = user.Login,
                        Time         = time,
                        Text         = text
                    });
                }
                // write notification to db
                else
                {
                    DBoperations.AddNotification(interlocutorId, user.Id, UserActions.MessageSended, DateTime.Now);
                }
            }
        }