public virtual bool SendMessage(ChatMessage message) { if (IsAnonymous) { return(false); } lock ( channelsLock) { this.With(x => ChatChannels.FirstOrDefault(channel => channel.ChannelName.Equals(message.Channel, StringComparison.InvariantCultureIgnoreCase))) .Do(x => { if (String.IsNullOrWhiteSpace(message.FromUserName)) { message.FromUserName = NickName; } Task.Factory.StartNew(() => x.SendMessage(message)); if (ReceiveOwnMessages) { ReadMessage(message); } }); } return(true); }
public void StartAllChats() { steamChat = (SteamChat)GetChat(SettingsRegistry.ChatTitleSteam); if (historyService.Config.Enabled) { historyService.Start(); } //Accumulate messages and update ViewModel periodically receiveTimer.Interval = TimeSpan.FromMilliseconds(1500); receiveTimer.Tick += receiveTimer_Tick; receiveTimer.Start(); timerUpdateDatabase = new Timer((o) => { UpdateDatabase(); }, this, 0, 60000); int waitChatStatus = 5000; Chats.ForEach(chat => { chat.MessageReceived += chat_MessageReceived; chat.AddChannel = (channel, fromChat) => { lock ( channelsLock ) { UI.Dispatch(() => { lock (channelsLock) { if (!ChatChannels.Any(c => c.ChannelName == channel && c.ChatName == fromChat.ChatName)) { ChatChannels.Add(new ChatChannel() { ChatName = fromChat.ChatName, ChannelName = channel, ChatIconURL = fromChat.IconURL }); } } }); } }; chat.RemoveChannel = (channel, fromChat) => { UI.Dispatch(() => { lock (channelsLock) { var searchItem = ChatChannels.FirstOrDefault(item => item.ChatName == fromChat.ChatName && item.ChannelName == channel && item.ChatIconURL == fromChat.IconURL); if (searchItem != null) { ChatChannels.Remove(searchItem); } if (ChatChannels.Count <= 0) { if (!chat.Status.IsStopping) { chat.Status.IsConnected = false; chat.Status.IsLoggedIn = false; chat.Restart(); } } } }); }; if (chat.Enabled) { Task.Factory.StartNew(() => { var c = chat; c.Start(); while (ChatStatusHandler == null && waitChatStatus > 0) { waitChatStatus -= 50; Thread.Sleep(100); } if (ChatStatusHandler != null) { ChatStatusHandler(c); } }); } }); }