Exemple #1
0
        /// <summary>
        ///     Adds a new message to this <see cref="Channel"/> and transmits it to all the current members.
        /// </summary>
        /// <param name="sender">The sender of the message.</param>
        /// <param name="message">The content of the message.</param>
        public void AddMessage(User sender, string message)
        {
            var received = MessagePackageContent.GetReceivedMessage(sender.InternalId, sender.Identity, message, InternalId);
            var sent     = MessagePackageContent.GetSentMessage(sender.InternalId, sender.Identity, message, InternalId);

            if (message.Contains('@'))
            {
                var mentions = message.Split(' ').ToList().Where(s => s.StartsWith('@') && Pool.Server.Users.Any(u => u.Identity.Id == s.Substring(1))).Select(s => s.Substring(1)).Distinct().ToList();
                new Target().AddMany(Pool.Server.Users.FindAll(u => mentions.Contains(u.Identity.Id)).ToArray()).SendPackage(new Package(PackageType.Mention, received));
            }

            new Target().AddMany(this).Remove(sender).SendPackage(new Package(PackageType.Message, received));

            if (sender.ActiveChannel == this)
            {
                new Target(sender).SendPackage(new Package(PackageType.Message, sent));
            }

            SaveMessage(received);
        }
Exemple #2
0
        public override void OnBeforeInput(Before <InputEventArgs> args)
        {
            if (args.Event.Sender.ActiveChannel.Attributes.ContainsKey("neo.channeltype") && args.Event.Sender.ActiveChannel.Attributes["neo.channeltype"].ToString() == "conversation")
            {
                args.Cancel = true;

                var conversation = conversations.Find(_ => _.Channel.InternalId.Equals(args.Event.Sender.ActiveChannel.InternalId));
                var received     = MessagePackageContent.GetReceivedMessage(args.Event.Sender.InternalId, args.Event.Sender.Identity, args.Event.Input, conversation.Channel.InternalId);
                var sent         = MessagePackageContent.GetSentMessage(args.Event.Sender.InternalId, args.Event.Sender.Identity, args.Event.Input, conversation.Channel.InternalId);

                conversation.Channel.SaveMessage(received);

                args.Event.Sender.ToTarget().SendPackage(new Package(PackageType.Message, sent));
                args.Event.Sender.ToTarget().SendPackage(new Package(PackageType.CustomEvent, new CustomEventArgs($"{Namespace}.update", InternalId, conversations.FindAll(_ => _.Users.Contains(args.Event.Sender.InternalId)))));

                var targetUser = Pool.Server.Users.Find(_ => _.InternalId.Equals(conversation.Users.Find(u => !u.Equals(args.Event.Sender.InternalId))));
                if (targetUser != null)
                {
                    targetUser.ToTarget().SendPackage(new Package(PackageType.Message, received));
                    targetUser.ToTarget().SendPackage(new Package(PackageType.CustomEvent, new CustomEventArgs($"{Namespace}.update", InternalId, conversations.FindAll(_ => _.Users.Contains(targetUser.InternalId)))));
                }
            }
        }