public static void SendMessage(this IEnumerable<Channel> channels, string[] message, bool recursive)
        {
            // It's conceivable that this group could include channels from multiple different server connections
            // group by server
            foreach (var group in channels.GroupBy(a => a.Owner))
            {
                var owner = group.First().Owner;

                var msg = new TextMessage
                {
                    Actor = owner.LocalUser.Id,
                    Message = message,
                };

                if (recursive)
                    msg.TreeId = group.Select(c => c.Id).ToArray();
                else
                    msg.ChannelId = group.Select(c => c.Id).ToArray();

                owner.Connection.SendControl<TextMessage>(PacketType.TextMessage, msg);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Received a text message from the server
        /// </summary>
        /// <param name="textMessage"></param>
        public virtual void TextMessage(TextMessage textMessage)
        {
            User user;
            if (!UserDictionary.TryGetValue(textMessage.Actor, out user))   //If we don't know the user for this packet, just ignore it
                return;

            if (textMessage.ChannelId == null)
            {
                if (textMessage.TreeId == null)
                {
                    //personal message: no channel, no tree
                    PersonalMessageReceived(new PersonalMessage(user, string.Join("", textMessage.Message)));
                }
                else
                {
                    //recursive message: sent to multiple channels
                    Channel channel;
                    if (!ChannelDictionary.TryGetValue(textMessage.TreeId[0], out channel))    //If we don't know the channel for this packet, just ignore it
                        return;

                    //TODO: This is a *tree* message - trace down the entire tree (using IDs in textMessage.TreeId as roots) and call ChannelMessageReceived for every channel
                    ChannelMessageReceived(new ChannelMessage(user, string.Join("", textMessage.Message), channel, true));
                }
            }
            else
            {
                foreach (uint channelId in textMessage.ChannelId)
                {
                    Channel channel;
                    if (!ChannelDictionary.TryGetValue(channelId, out channel))
                        continue;

                    ChannelMessageReceived(new ChannelMessage(user, string.Join("", textMessage.Message), channel));
                }

            }
        }