예제 #1
0
        public static void Init()
        {
            chatRooms = UniChatModule.mainInstance.database.GetCollection <Chat>("chats").Query().ToList().ConvertAll(chat => {
                if (chat.key == null)
                {
                    chat.key = UniChatModule.GenerateKey(CHAT_KEY_LENGTH);
                }

                return(new ChatRoom(chat, true));
            }) ?? new List <ChatRoom>();
        }
예제 #2
0
        private static Chat CreateChat(string name = "", string description = "", string password = null, Banner banner = null)
        {
            Chat chat = new Chat(UniChatModule.GenerateKey(CHAT_KEY_LENGTH))
            {
                name        = name,
                description = description,
                password    = password,
                banner      = banner
            };

            return(chat);
        }
예제 #3
0
        public void AddMessage(string text, string type, string userName = null, List <ChatFile> files = null)
        {
            ChatMessage message = new ChatMessage(UniChatModule.GenerateKey(ChatRoomsController.CHAT_KEY_LENGTH))
            {
                text    = text,
                type    = type,
                creator = userName,
                files   = files?.Select(file => new ChatFile()
                {
                    key     = file.key,
                    chatKey = file.chatKey
                })?.ToList(),
                timestamp = (long)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds
            };

            Chat.messages.Add(message);

            ConnectedUsers.ForEach(user => user.NewMessage(message, Chat.key));
        }