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>(); }
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); }
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)); }