Exemplo n.º 1
0
        public static ChatMessageProxy LeaveChat(LoginUser loginUser, int id, ChatParticipantType type, int chatID)
        {
            Chat            chat = Chats.GetChat(loginUser, chatID);
            ChatParticipant self = ChatParticipants.GetChatParticipant(loginUser, id, type, chatID);

            if (self == null || self.DateLeft != null)
            {
                return(null);
            }

            self.DateLeft = DateTime.UtcNow;
            self.Collection.Save();

            ChatMessageProxy message = AddNotification(loginUser, chatID, id, type, string.Format("{0} {1} has left the chat.", self.FirstName, self.LastName));

            if (self.ParticipantType != ChatParticipantType.User)
            {
                return(message);
            }

            ChatParticipants participants = new ChatParticipants(loginUser);

            participants.LoadByChatID(chatID);

            bool allUsersGone = true;

            foreach (ChatParticipant item in participants)
            {
                if (item.DateLeft == null && item.ParticipantType == ChatParticipantType.User)
                {
                    allUsersGone = false;
                    break;
                }
            }

            if (allUsersGone)
            {
                foreach (ChatParticipant item in participants)
                {
                    if (item.DateLeft == null)
                    {
                        LeaveChat(loginUser, item.ParticipantID, item.ParticipantType, chatID);
                    }
                }
            }

            return(message);
        }
Exemplo n.º 2
0
        public static ChatMessageProxy AbandonedChatRequest(LoginUser loginUser, Chat chat, int id, ChatParticipantType type, int chatID)
        {
            ChatParticipant self = ChatParticipants.GetChatParticipant(loginUser, id, type, chatID);

            if (self == null || self.DateLeft != null)
            {
                return(null);
            }

            self.DateLeft = DateTime.UtcNow;
            self.Collection.Save();

            ChatMessageProxy message = AddNotification(loginUser, chatID, id, type, string.Format("{0} {1} has abandoned the chat request.", self.FirstName, self.LastName));

            return(message);
        }
        public ChatMessageProxy GetProxy()
        {
            ChatMessageProxy result = new ChatMessageProxy();

            result.PosterType     = this.PosterType;
            result.PosterID       = this.PosterID;
            result.Message        = this.Message;
            result.IsNotification = this.IsNotification;
            result.ChatID         = this.ChatID;
            result.ChatMessageID  = this.ChatMessageID;

            result.DateCreated = DateTime.SpecifyKind(this.DateCreatedUtc, DateTimeKind.Utc);


            return(result);
        }