Inheritance: Packet
Exemplo n.º 1
0
        public async void HandleMessage(Room room, Message message)
        {
            var chatLine = message.Line as ChatLine;
            if (chatLine == null || chatLine.SenderId == "0")
                return;

            await Task.Yield();

            var senderId = long.Parse(chatLine.SenderId);

            var recipientDevices = Notifications
                .Where(n => n.UserId != senderId && !room.IsBanned(n.Name) && n.Rooms.Contains(chatLine.Chat))
                .Where(n => IsMatch(n.Regex, chatLine.Content))
                .Select(n => n.DeviceToken)
                .ToList();

            if (recipientDevices.Count > 0)
            {
                var content = $"[{chatLine.Chat}] {WebUtility.HtmlDecode(chatLine.Sender)}: {WebUtility.HtmlDecode(chatLine.Content)}";
                await Notify(recipientDevices, content);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Called when a message is being sent to the room. Should call base.
        /// </summary>
        public virtual void SendLine(HistoryLine line)
        {
            line = Util.EmoticonReplace(line);

            var chatLine = line as ChatLine;
            if (chatLine != null && _showLinkTitles && chatLine.SenderId != "0")
            {
                Action checkTitles = async () =>
                {
                    var titles = await LinkTitles.Lookup(chatLine.Content);
                    if (!string.IsNullOrWhiteSpace(titles))
                        Send(titles);
                };

                checkTitles();
            }

            var message = new Message();
            message.Line = line;

            Func<Session, bool> filter = session =>
            {
                if (session.Account == null)
                    return false;

                if (IsPrivate && IsBanned(session.Account.Name))
                    return false;

                return session.IsInRoom(RoomInfo.ShortName);
            };

            var sessions = Program.SessionManager.List.Where(filter);
            sessions = SendLineFilter(line, sessions);

            Program.SessionManager.Send(message, sessions);

            AddHistory(line);
        }