public static IEnumerable <TextSpan> messageWithMarkdownToTextSpans( string content, List <User> mentions, bool mentionEveryone, MentionTapCallback onTap, TextStyle bodyStyle = null, TextStyle linkStyle = null, string url = null, Action <string> onClickUrl = null) { bodyStyle = bodyStyle ?? CTextStyle.PLargeBody; linkStyle = linkStyle ?? CTextStyle.PLargeBlue; var textSpans = messageToTextSpans(content, mentions, mentionEveryone, onTap); List <TextSpan> result = new List <TextSpan>(); foreach (var textSpan in textSpans) { if (textSpan.recognizer != null) { result.Add(new TextSpan( text: textSpan.text, style: textSpan.style.copyWith( fontSize: bodyStyle.fontSize, color: bodyStyle.color), recognizer: textSpan.recognizer)); continue; } stripMarkdown(result, textSpan.text, bodyStyle, linkStyle, url, onClickUrl); } return(result); }
public TextMessage( ChannelMessageView message, MentionTapCallback onTap, Key key = null ) : base(key: key) { this.message = message; this.onTap = onTap; }
public EmbedMessage( ChannelMessageView message, MentionTapCallback onClickUser, Action <string> onClickUrl, Action <string> onClickImage, Dictionary <string, string> headers = null, Key key = null ) : base(key: key) { this.message = message; this.onClickUser = onClickUser; this.onClickUrl = onClickUrl; this.onClickImage = onClickImage; this.headers = headers; }
public static IEnumerable <TextSpan> messageToTextSpans(string content, List <User> mentions, bool mentionEveryone, MentionTapCallback onTap) { var userDict = StoreProvider.store.getState().userState.userDict; var textSpans = new List <TextSpan>(); if (content.isEmpty()) { return(textSpans); } var parsingContent = content; if (mentionEveryone) { parsingContent = parsingContent.Replace("@everyone", "@所有人"); } if (parsingContent.Contains("<@") && mentions != null && mentions.Count > 0) { int startIndex = 0; mentions.ForEach(mention => { var mentionId = mention.id; var mentionFullName = mention.fullName.isNotEmpty() ? mention.fullName : userDict.ContainsKey(mention.id) ? userDict[mention.id].fullName : ""; if (parsingContent.Contains($"<@{mentionId}>")) { parsingContent = parsingContent.Replace($"<@{mentionId}>", $"@{mentionFullName}"); } var index = parsingContent.IndexOf($"@{mentionFullName}", startIndex: startIndex); var length = $"@{mentionFullName}".Length; textSpans.Add(new TextSpan( parsingContent.Substring(startIndex: startIndex, index - startIndex), style: CTextStyle.PLargeBody )); textSpans.Add(new TextSpan( parsingContent.Substring(startIndex: index, length: length), style: CTextStyle.PLargeBlue, recognizer: onTap == null ? null : new TapGestureRecognizer { onTap = () => onTap(userId: mentionId) } )); startIndex = index + length; }); textSpans.Add(new TextSpan( parsingContent.Substring(startIndex: startIndex, parsingContent.Length - startIndex), style: CTextStyle.PLargeBody )); } else { textSpans.Add(new TextSpan( text: parsingContent, style: CTextStyle.PLargeBody )); } return(textSpans); }