Ejemplo 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);
        }
Ejemplo n.º 2
0
        public static void UpdateAction(LoginUser loginUser, int chatID)
        {
            Chat chat = Chats.GetChat(loginUser, chatID);

            if (chat == null || chat.ActionID == null)
            {
                return;
            }

            Action action = Actions.GetAction(loginUser, (int)chat.ActionID);

            if (action == null)
            {
                return;
            }

            action.Description = chat.GetHtml(true, loginUser.OrganizationCulture);
            action.Collection.Save();
        }