Пример #1
0
        /// <summary>
        /// Set the user as active in the chat room
        /// </summary>
        /// <param name="roomId"></param>
        /// <returns>The last message id</returns>
        public int EnterRoom(int roomId)
        {
            RoomId = roomId;
            CurrentRoom.ValidateUsers(ChatUsersMaxInterval);
            CurrentRoom.EnterRoom(CurrentSession.User.UserId, CurrentSession.User.UserName);

            //TODO (?): Send a message
            if (LastMessageId != null)
                return (int) LastMessageId;

            var da = new ChatDataAccess();
            LastMessageId = da.GetLastMessage();
            return (int) LastMessageId;
        }
Пример #2
0
        public Response SendMessage(string message, int lastMessageId)
        {
            SetLastActivity();

            //Save message in the db
            var da = new ChatDataAccess();
            da.MessageInsert(RoomId, message, DateTime.Now, CurrentSession.User.UserId, false);

            //Validate users
            CurrentRoom.ValidateUsers(ChatUsersMaxInterval);

            return CheckMessages(lastMessageId);
        }
Пример #3
0
        public Response CheckMessages(int lastMessage)
        {
            var response = new Response();
            SetLastActivity();

            //Get messages from the db
            var da = new ChatDataAccess();
            var messages = da.GetRoomMessages(lastMessage, RoomId);

            if (messages.Count <= 0)
                return response;

            response.Messages.AddRange(messages);
            response.LastMessageId = messages[messages.Count - 1].Id;

            CheckUsers(response);

            return response;
        }