示例#1
0
        public static PollMessage FromString(string text)
        {
            PollMessage message = new PollMessage();

            string[] values = text.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);

            for (int i = 0; i < values.Length; i++)
            {
                if (i == 0)
                {
                    message.Text = values[i];
                }
                else
                {
                    message.AddChoice(values[i]);
                }
            }

            return(message);
        }
示例#2
0
        private static ChatUserMessage Parse(ChatUser fromUser, string text, IList <ChatUser> allUsers, bool ignoreTagAndUsers)
        {
            List <string>   tags    = new List <string>();
            List <ChatUser> toUsers = new List <ChatUser>();

            if (!ignoreTagAndUsers)
            {
                // If the message is tagged, send to all users, don't even parse usernames
                if (TryGetTags(text, out tags, out text))
                {
                }
                else
                {
                    toUsers = GetWhisperUsers(text, allUsers, out text);
                }
            }

            ChatUserMessage message = null;

            if (MatchesCommand(text, Commands.IMAGEURL))
            {
                string imageUrl = RemoveCommand(text, Commands.IMAGEURL);
                message = new ImageUrlChatMessage {
                    ImageUrl = imageUrl
                };
            }
            else if (MatchesCommand(text, Commands.WEB))
            {
                string url = RemoveCommand(text, Commands.WEB);
                message = new WebUrlChatMessage {
                    Url = url
                };
            }
            else if (MatchesCommand(text, Commands.STATUS_UPDATE))
            {
                string status = RemoveCommand(text, Commands.STATUS_UPDATE);
                message = new UserStatusMessage {
                    Text = status
                };
            }
            else if (MatchesCommand(text, Commands.ASCII))
            {
                string asciiText = RemoveCommand(text, Commands.ASCII);
                message = new ASCIIChatMessage {
                    Text = asciiText
                };
            }
            else if (MatchesCommand(text, Commands.XAML))
            {
                string xaml = RemoveCommand(text, Commands.XAML);
                message = new XamlChatMessage {
                    Xaml = xaml
                };
            }
            else if (MatchesCommand(text, Commands.MEME))
            {
                string memeText = RemoveCommand(text, Commands.MEME);
                message = MemeChatMessage.FromString(memeText);
            }
            else if (MatchesCommand(text, Commands.POLL))
            {
                string pollText = RemoveCommand(text, Commands.POLL);
                message = PollMessage.FromString(pollText);
            }
            else if (MatchesCommand(text, Commands.LINK) || HyperlinkUtility.IsHyperlink(text))
            {
                string url = RemoveCommand(text, Commands.LINK);
                message = new HyperlinkChatMessage(url);
            }
            else if (MatchesCommand(text, Commands.VIDEOURL))
            {
                string url = RemoveCommand(text, Commands.VIDEOURL);

                if (url.Contains("https://"))
                {
                    url = url.Replace("https://", "http://");
                }
                message = new VideoUrlChatMessage {
                    VideoUrl = url
                };
            }
            else if (MatchesCommand(text, Commands.WHITEBOARD) || text == "/" + Commands.WHITEBOARD)
            {
                if (text == "/" + Commands.WHITEBOARD)
                {
                    text += " ";
                }
                string url = RemoveCommand(text, Commands.WHITEBOARD);
                message = new WhiteboardChatMessage {
                    ImageUrl = url
                };
            }
            else
            {
                message = new NormalChatUserMessage {
                    Text = text
                };
            }

            message.ToUsers  = toUsers;
            message.FromUser = fromUser;
            message.Tags     = tags;

            return(message);
        }
示例#3
0
 public UserVotedEventArgs(ChatUser user, PollMessage poll, PollChoice choice)
 {
     User   = user;
     Choice = choice;
     Poll   = poll;
 }
示例#4
0
 public PollClosedEventArgs(PollMessage message)
 {
     Message = message;
 }
示例#5
0
 /// <summary>
 /// Occurs when a poll is closed
 /// </summary>
 /// <param name="message"></param>
 protected virtual void OnPollClosed(PollMessage message)
 {
 }
示例#6
0
 /// <summary>
 /// Occurs when a user votes on a poll
 /// </summary>
 /// <param name="user">The user that voted</param>
 /// <param name="poll">The poll that the user voted on</param>
 /// <param name="choice">The choice that the user voted for</param>
 protected virtual void OnUserVoted(ChatUser user, PollMessage poll, PollChoice choice)
 {
     //Debug.WriteLine( "User: {0}, Voted on: '{1}', Answered: {2}", user, poll.Text, choice.Text );
 }
示例#7
0
 /// <summary>
 /// Occurs when a poll message is received from another user (this occurs after the OnMessageReceived)
 /// </summary>
 /// <param name="message"></param>
 protected virtual void OnPollReceived(PollMessage message)
 {
     //Debug.WriteLine( "Poll received: {0}", message );
 }