Example #1
0
        /// <summary>
        /// Send conversation to user.
        /// </summary>
        /// <param name="user">user.</param>
        /// <param name="interlocutor">interlocutor of user in conversation.</param>
        /// <exception cref="ConnectionInterruptedException"></exception>
        private void SendConversation(OnlineUser user, string interlocutor)
        {
            int interlocutorId = DBoperations.GetUserId(interlocutor);

            if (interlocutorId == 0)
            {
                return;
            }

            // get replies from db
            ConversationReply[] replies = DBoperations.GetConversation(user.Id, interlocutorId);

            if (replies != null)
            {
                foreach (var r in replies)
                {
                    user.Client.SendMessage(new OldReplyMessage
                    {
                        Interlocutor = interlocutor,
                        Author       = DBoperations.GetUserLogin(r.user_id),
                        Time         = r.time,
                        Text         = r.reply
                    });
                }
            }
        }
Example #2
0
        /// <summary>
        /// Send array all notifications to user.
        /// </summary>
        /// <param name="user">user.</param>
        /// <exception cref="ConnectionInterruptedException"></exception>
        private void SendNotifications(OnlineUser user)
        {
            Notification[] notifications = DBoperations.GetNotifications(user.Id);
            foreach (var notification in notifications)
            {
                if (notification.accept_friendship)
                {
                    user.Client.SendMessage(new UserActionMessage
                    {
                        UserLogin = DBoperations.GetUserLogin(notification.user_two),
                        Time      = notification.time,
                        Action    = UserActions.AcceptFriendship
                    });
                }
                else if (notification.reject_friendship)
                {
                    user.Client.SendMessage(new UserActionMessage
                    {
                        UserLogin = DBoperations.GetUserLogin(notification.user_two),
                        Time      = notification.time,
                        Action    = UserActions.RejectFriendship
                    });
                }
                else if (notification.send_friendship)
                {
                    user.Client.SendMessage(new UserActionMessage
                    {
                        UserLogin = DBoperations.GetUserLogin(notification.user_two),
                        Time      = notification.time,
                        Action    = UserActions.SendFriendshipRequest
                    });
                }
                else if (notification.cancel_friendship)
                {
                    user.Client.SendMessage(new UserActionMessage
                    {
                        UserLogin = DBoperations.GetUserLogin(notification.user_two),
                        Time      = notification.time,
                        Action    = UserActions.CancelFriendshipRequest
                    });
                }
                else if (notification.remove_friend)
                {
                    user.Client.SendMessage(new UserActionMessage
                    {
                        UserLogin = DBoperations.GetUserLogin(notification.user_two),
                        Time      = notification.time,
                        Action    = UserActions.RemoveFromFriends
                    });
                }
                else
                {
                    user.Client.SendMessage(new UserActionMessage
                    {
                        UserLogin = DBoperations.GetUserLogin(notification.user_two),
                        Time      = notification.time,
                        Action    = UserActions.MessageSended
                    });
                }
            }

            // delete notifications from db
            DBoperations.RemoveNotifications(user.Id);
        }