示例#1
0
        public override Widget build(BuildContext context)
        {
            if (this.message == null)
            {
                return(new Container());
            }

            var author = this.message.author != null ? this.message.author : new User();

            var messageContent =
                MessageUtils.AnalyzeMessage(this.message.content, this.message.mentions, this.message.mentionEveryone);

            return(new Container(
                       padding: EdgeInsets.symmetric(6),
                       child: new Row(
                           crossAxisAlignment: CrossAxisAlignment.start,
                           children: new List <Widget> {
                Avatar.User(this.message.author.id, this.message.author, 24),
                new Expanded(
                    child: new Container(
                        margin: EdgeInsets.only(8),
                        child: new Container(
                            child: new RichText(
                                softWrap: true,
                                text: new TextSpan(
                                    children: new List <TextSpan> {
                    new TextSpan(
                        $"{author.fullName}:".Replace(' ', '\u00a0'),
                        CTextStyle.PMediumBlue
                        ),
                    new TextSpan(
                        $" {messageContent}",
                        CTextStyle.PRegularBody
                        )
                }
                                    )
                                )
                            )
                        )
                    )
            }
                           )
                       ));
        }
示例#2
0
        IEnumerable <Widget> _buildComments(BuildContext context)
        {
            List <string> channelComments = new List <string>();

            if (this.widget.viewModel.channelMessageList.ContainsKey(this._article.channelId))
            {
                channelComments = this.widget.viewModel.channelMessageList[this._article.channelId];
            }
            var mediaQuery = MediaQuery.of(context);
            var comments   = new List <Widget> {
                new Container(
                    color: CColors.White,
                    width: mediaQuery.size.width,
                    padding: EdgeInsets.only(16, 16, 16),
                    child: new Text(
                        "评论",
                        style: CTextStyle.H5,
                        textAlign: TextAlign.left
                        )
                    )
            };

            var titleHeight = CTextUtils.CalculateTextHeight(
                "评论",
                CTextStyle.H5,
                mediaQuery.size.width - 16 * 2, // 16 is horizontal padding
                null
                ) + 16;                         // 16 is top padding

            var height = mediaQuery.size.height - navBarHeight - 44 - mediaQuery.padding.vertical;

            if (channelComments.Count == 0)
            {
                var blankView = new Container(
                    height: height - titleHeight,
                    child: new BlankView(
                        "快来写下第一条评论吧",
                        "image/default-comment"
                        )
                    );
                comments.Add(item: blankView);
                return(comments);
            }

            var   messageDict    = this.widget.viewModel.channelMessageDict[this._article.channelId];
            float contentHeights = 0;

            foreach (var commentId in channelComments)
            {
                if (!messageDict.ContainsKey(commentId))
                {
                    break;
                }

                var  message    = messageDict[commentId];
                bool isPraised  = _isPraised(message, this.widget.viewModel.loginUserId);
                var  parentName = "";
                if (message.parentMessageId.isNotEmpty())
                {
                    if (messageDict.ContainsKey(message.parentMessageId))
                    {
                        var parentMessage = messageDict[message.parentMessageId];
                        parentName = parentMessage.author.fullName;
                    }
                }

                var content = MessageUtils.AnalyzeMessage(message.content, message.mentions,
                                                          message.mentionEveryone) + (parentName.isEmpty() ? "" : $"回复@{parentName}");
                var contentHeight = CTextUtils.CalculateTextHeight(
                    content,
                    CTextStyle.PLargeBody,
                    // 16 is horizontal padding, 24 is avatar size, 8 is content left margin to avatar
                    mediaQuery.size.width - 16 * 2 - 24 - 8,
                    null
                    ) + 16 + 24 + 3 + 5 + 22 + 12;
                // 16 is top padding, 24 is avatar size, 3 is content top margin to avatar, 5 is content bottom margin to commentTime
                // 22 is commentTime height, 12 is commentTime bottom margin
                contentHeights += contentHeight;
                var card = new CommentCard(
                    message,
                    isPraised,
                    parentName,
                    () => ReportManager.showReportView(this.widget.viewModel.isLoggedIn,
                                                       commentId,
                                                       ReportType.comment, this.widget.actionModel.pushToLogin, this.widget.actionModel.pushToReport
                                                       ),
                    replyCallBack: () => {
                    if (!this.widget.viewModel.isLoggedIn)
                    {
                        this.widget.actionModel.pushToLogin();
                    }
                    else
                    {
                        AnalyticsManager.ClickComment("Article_Comment", this._article.channelId,
                                                      this._article.title, commentId);
                        ActionSheetUtils.showModalActionSheet(new CustomInput(
                                                                  message.author.fullName.isEmpty() ? "" : message.author.fullName,
                                                                  text => {
                            ActionSheetUtils.hiddenModalPopup();
                            this.widget.actionModel.sendComment(this._article.channelId,
                                                                text,
                                                                Snowflake.CreateNonce(),
                                                                commentId
                                                                );
                        })
                                                              );
                    }
                },
                    praiseCallBack: () => {
                    if (!this.widget.viewModel.isLoggedIn)
                    {
                        this.widget.actionModel.pushToLogin();
                    }
                    else
                    {
                        if (isPraised)
                        {
                            this.widget.actionModel.removeLikeComment(message);
                        }
                        else
                        {
                            this.widget.actionModel.likeComment(message);
                        }
                    }
                });
                comments.Add(card);
            }

            float endHeight = 0;

            if (!this._article.hasMore)
            {
                comments.Add(new Container(
                                 height: 52,
                                 alignment: Alignment.center,
                                 child: new Text(
                                     "一 已经全部加载完毕 一",
                                     style: CTextStyle.PRegularBody4,
                                     textAlign: TextAlign.center
                                     )
                                 ));
                endHeight = 52;
            }
            if (titleHeight + contentHeights + endHeight < height)
            {
                return(new List <Widget> {
                    new Container(
                        height: height,
                        child: new Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: comments
                            )
                        )
                });
            }
            return(comments);
        }
 string _analyzeComment(string comment)
 {
     return(comment.isNotEmpty()
         ? $" “{MessageUtils.AnalyzeMessage(content: comment, mentions: this.mentions, false)}”"
         : "");
 }
示例#4
0
        IEnumerable <Widget> _buildComments(BuildContext context)
        {
            List <string> channelComments = new List <string>();

            if (this.widget.viewModel.channelMessageList.ContainsKey(key: this._article.channelId))
            {
                channelComments = this.widget.viewModel.channelMessageList[key : this._article.channelId];
            }

            var mediaQuery = MediaQuery.of(context);
            var comments   = new List <Widget> {
                new Container(
                    color: CColors.White,
                    width: mediaQuery.size.width,
                    padding: EdgeInsets.only(16, 16, 16),
                    child: new Text(
                        "评论",
                        style: CTextStyle.H5,
                        textAlign: TextAlign.left
                        )
                    )
            };

            var titleHeight = CTextUtils.CalculateTextHeight(
                "评论",
                CTextStyle.H5,
                mediaQuery.size.width - 16 * 2, // 16 is horizontal padding
                null
                ) + 16;                         // 16 is top padding

            float safeAreaPadding = 0;

            if (Application.platform != RuntimePlatform.Android)
            {
                safeAreaPadding = mediaQuery.padding.vertical;
            }

            var height = mediaQuery.size.height - navBarHeight - 44 - safeAreaPadding;

            if (channelComments.Count == 0)
            {
                var blankView = new Container(
                    height: height - titleHeight,
                    child: new BlankView(
                        "快来写下第一条评论吧",
                        "image/default-comment"
                        )
                    );
                comments.Add(item: blankView);
                return(comments);
            }

            var   messageDict    = this.widget.viewModel.channelMessageDict[key : this._article.channelId];
            float contentHeights = 0;

            foreach (var commentId in channelComments)
            {
                if (!messageDict.ContainsKey(key: commentId))
                {
                    break;
                }

                var  message        = messageDict[key : commentId];
                bool isPraised      = _isPraised(message: message, loginUserId: this.widget.viewModel.loginUserId);
                var  parentName     = "";
                var  parentAuthorId = "";
                if (message.upperMessageId.isNotEmpty())
                {
                    if (messageDict.ContainsKey(key: message.upperMessageId))
                    {
                        var parentMessage = messageDict[key : message.upperMessageId];
                        parentName     = parentMessage.author.fullName;
                        parentAuthorId = parentMessage.author.id;
                    }
                }
                else if (message.parentMessageId.isNotEmpty())
                {
                    if (messageDict.ContainsKey(key: message.parentMessageId))
                    {
                        var parentMessage = messageDict[key : message.parentMessageId];
                        parentName     = parentMessage.author.fullName;
                        parentAuthorId = parentMessage.author.id;
                    }
                }

                var content = MessageUtils.AnalyzeMessage(message.content, message.mentions,
                                                          message.mentionEveryone) + (parentName.isEmpty() ? "" : $"回复@{parentName}");
                var contentHeight = CTextUtils.CalculateTextHeight(
                    content,
                    CTextStyle.PLargeBody,
                    // 16 is horizontal padding, 24 is avatar size, 8 is content left margin to avatar
                    mediaQuery.size.width - 16 * 2 - 24 - 8,
                    null
                    ) + 16 + 24 + 3 + 5 + 22 + 12;
                // 16 is top padding, 24 is avatar size, 3 is content top margin to avatar, 5 is content bottom margin to commentTime
                // 22 is commentTime height, 12 is commentTime bottom margin
                contentHeights += contentHeight;
                var card = new CommentCard(
                    message: message,
                    isPraised: isPraised,
                    parentName: parentName,
                    parentAuthorId: parentAuthorId,
                    () => ReportManager.showReportView(
                        isLoggedIn: this.widget.viewModel.isLoggedIn,
                        reportType: ReportType.comment,
                        () => this.widget.actionModel.pushToLogin(),
                        () => this.widget.actionModel.pushToReport(arg1: commentId, arg2: ReportType.comment)
                        ),
                    replyCallBack: () => this._sendComment(
                        "Article_Comment",
                        message.parentMessageId.isNotEmpty() ? message.parentMessageId : commentId,
                        message.parentMessageId.isNotEmpty() ? commentId : "",
                        message.author.fullName.isEmpty() ? "" : message.author.fullName
                        ),
                    praiseCallBack: () => {
                    if (!this.widget.viewModel.isLoggedIn)
                    {
                        this.widget.actionModel.pushToLogin();
                    }
                    else
                    {
                        if (isPraised)
                        {
                            this.widget.actionModel.removeLikeComment(arg: message);
                        }
                        else
                        {
                            this.widget.actionModel.likeComment(arg: message);
                        }
                    }
                },
                    pushToUserDetail: this.widget.actionModel.pushToUserDetail
                    );
                comments.Add(item: card);
            }

            float endHeight = 0;

            if (!this._article.hasMore)
            {
                comments.Add(new EndView());
                endHeight = 52;
            }

            if (titleHeight + contentHeights + endHeight < height)
            {
                return(new List <Widget> {
                    new Container(
                        height: height,
                        child: new Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: comments
                            )
                        )
                });
            }

            return(comments);
        }
示例#5
0
        public override Widget build(BuildContext context)
        {
            if (this.message == null)
            {
                return(new Container());
            }

            var content = MessageUtils.AnalyzeMessage(this.message.content, this.message.mentions,
                                                      this.message.mentionEveryone);
            Widget _content = this.parentName.isEmpty()
                ? new Container(
                child: new Text(
                    content,
                    style: CTextStyle.PLargeBody
                    ),
                alignment: Alignment.centerLeft
                )
                : new Container(alignment: Alignment.centerLeft, child: new RichText(text: new TextSpan(
                                                                                         "回复@",
                                                                                         children: new List <TextSpan> {
                new TextSpan(
                    $"{this.parentName}",
                    children: new List <TextSpan> {
                    new TextSpan(
                        $": {content}",
                        CTextStyle.PLargeBody
                        )
                },
                    style: CTextStyle.PLargeBlue)
            },
                                                                                         style: CTextStyle.PLargeBody4
                                                                                         )
                                                                                     )
                                );
            var reply = this.message.parentMessageId.isEmpty()
                ? new GestureDetector(
                onTap: this.replyCallBack,
                child: new Container(
                    margin: EdgeInsets.only(left: 10),
                    child: new Text(
                        $"回复 {this.message.replyMessageIds.Count}",
                        style: CTextStyle.PRegularBody4
                        ))
                )
                : new GestureDetector(
                child: new Container()
                );

            return(new Container(
                       color: CColors.White,
                       padding: EdgeInsets.only(16, 16, 16),
                       child: new Row(
                           crossAxisAlignment: CrossAxisAlignment.start,
                           children: new List <Widget> {
                new Container(
                    height: 24,
                    margin: EdgeInsets.only(right: 8),
                    child: Avatar.User(this.message.author.id, this.message.author, 24)
                    ),
                new Expanded(
                    child: new Container(
                        child: new Column(
                            children: new List <Widget> {
                    new Container(
                        height: 24,
                        child: new Row(
                            children: new List <Widget> {
                        new Expanded(
                            child: new Container(
                                alignment: Alignment.centerLeft,
                                child: new Text(this.message.author.fullName,
                                                style: CTextStyle.PMediumBody3))),

                        new CustomButton(
                            padding: EdgeInsets.only(8, 0, 0, 8),
                            onPressed: this.moreCallBack,
                            child: new Icon(Icons.ellipsis, size: 20,
                                            color: CColors.BrownGrey)
                            )
                    }
                            )
                        ),

                    new Container(
                        margin: EdgeInsets.only(top: 3, bottom: 5),
                        child: _content
                        ),

                    new Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: new List <Widget> {
                        new Text($"{DateConvert.DateStringFromNonce(this.message.nonce)}",
                                 style: CTextStyle.PSmallBody4),
                        new Container(
                            child: new Row(
                                children: new List <Widget> {
                            new GestureDetector(
                                onTap: this.praiseCallBack,
                                child: new Container(
                                    color: CColors.White,
                                    child: new Text(
                                        $"点赞 {this.message.reactions.Count}",
                                        style: this.isPraised
                                                                            ? CTextStyle.PRegularBlue
                                                                            : CTextStyle.PRegularBody4
                                        )
                                    )),
                            reply
                        }
                                )
                            )
                    }
                        ),
                    new Container(
                        margin: EdgeInsets.only(top: 12),
                        height: 1,
                        color: CColors.Separator2
                        )
                }
                            )
                        )
                    )
            }
                           )
                       ));
        }
示例#6
0
        Widget _buildNotificationTitle()
        {
            var    type         = this.notification.type;
            var    data         = this.notification.data;
            var    subTitle     = new TextSpan();
            Widget projectTitle = new Container();
            var    content      = "";

            if (type == "project_liked")
            {
                subTitle = new TextSpan(
                    " 赞了你的文章",
                    style: CTextStyle.PLargeBody2
                    );
            }

            if (type == "project_message_commented")
            {
                if (data.parentComment.isNotEmpty())
                {
                    content  = $" “{MessageUtils.AnalyzeMessage(data.parentComment, this.mentions, false)}”";
                    subTitle = new TextSpan(
                        " 回复了你的评论" + content,
                        style: CTextStyle.PLargeBody2
                        );
                }
                else
                {
                    subTitle = new TextSpan(
                        " 评论了你的文章",
                        style: CTextStyle.PLargeBody2
                        );
                }
            }

            if (type == "project_participate_comment")
            {
                if (data.parentComment.isNotEmpty())
                {
                    content = $" “{MessageUtils.AnalyzeMessage(data.parentComment, this.mentions, false)}”";
                }

                subTitle = new TextSpan(
                    " 回复了你的评论" + content,
                    style: CTextStyle.PLargeBody2
                    );
            }

            if (type == "project_message_liked")
            {
                if (data.comment.isNotEmpty())
                {
                    content = $" “{MessageUtils.AnalyzeMessage(data.comment, this.mentions, false)}”";
                }

                subTitle = new TextSpan(
                    " 赞了你的评论" + content,
                    style: CTextStyle.PLargeBody2
                    );
            }

            if (type == "project_message_participate_liked")
            {
                if (data.comment.isNotEmpty())
                {
                    content = $" “{MessageUtils.AnalyzeMessage(data.comment, this.mentions, false)}”";
                }

                subTitle = new TextSpan(
                    " 赞了你的评论" + content,
                    style: CTextStyle.PLargeBody2
                    );
            }

            if (type == "followed")
            {
                subTitle = new TextSpan(
                    " 关注了你",
                    style: CTextStyle.PLargeBody2
                    );
            }

            if (type == "team_followed")
            {
                subTitle = new TextSpan(
                    children: new List <TextSpan> {
                    new TextSpan(" 关注了 "),
                    new TextSpan(data.teamName, recognizer: new TapGestureRecognizer {
                        onTap = () => { this.pushToTeamDetail(data.teamId); }
                    }, style: CTextStyle.PLargeBlue)
                },
                    style: CTextStyle.PLargeBody2
                    );
            }

            if (data.projectTitle.isNotEmpty())
            {
                projectTitle = new Text(
                    data: data.projectTitle,
                    maxLines: 1,
                    style: CTextStyle.PLargeMedium,
                    overflow: TextOverflow.ellipsis
                    );
            }

            return(new Column(
                       crossAxisAlignment: CrossAxisAlignment.start,
                       children: new List <Widget> {
                new RichText(
                    maxLines: 2,
                    text: new TextSpan(
                        children: new List <TextSpan> {
                    new TextSpan(
                        text: data.fullname,
                        style: CTextStyle.PLargeMedium,
                        recognizer: new TapGestureRecognizer {
                        onTap = () => this.pushToUserDetail(obj: data.userId)
                    }
                        ),
                    subTitle
                }
                        ),
                    overflow: TextOverflow.ellipsis
                    ),
                projectTitle
            }
                       ));
        }
        Widget _buildNotificationTitle()
        {
            var type     = this.notification.type;
            var data     = this.notification.data;
            var subTitle = new TextSpan();
            var content  = "";

            if (type == "project_liked")
            {
                subTitle = new TextSpan(
                    " 赞了你的文章",
                    CTextStyle.PLargeBody2
                    );
            }

            if (type == "project_message_commented")
            {
                if (data.parentComment.isNotEmpty())
                {
                    content  = $" “{MessageUtils.AnalyzeMessage(data.parentComment, this.mentions, false)}”";
                    subTitle = new TextSpan(
                        " 回复了你的评论" + content,
                        CTextStyle.PLargeBody2
                        );
                }
                else
                {
                    subTitle = new TextSpan(
                        " 评论了你的文章",
                        CTextStyle.PLargeBody2
                        );
                }
            }

            if (type == "project_participate_comment")
            {
                if (data.parentComment.isNotEmpty())
                {
                    content = $" “{MessageUtils.AnalyzeMessage(data.parentComment, this.mentions, false)}”";
                }

                subTitle = new TextSpan(
                    " 回复了你的评论" + content,
                    CTextStyle.PLargeBody2
                    );
            }

            if (type == "project_message_liked")
            {
                if (data.comment.isNotEmpty())
                {
                    content = $" “{MessageUtils.AnalyzeMessage(data.comment, this.mentions, false)}”";
                }

                subTitle = new TextSpan(
                    " 赞了你的评论" + content,
                    CTextStyle.PLargeBody2
                    );
            }

            if (type == "project_message_participate_liked")
            {
                if (data.comment.isNotEmpty())
                {
                    content = $" “{MessageUtils.AnalyzeMessage(data.comment, this.mentions, false)}”";
                }

                subTitle = new TextSpan(
                    " 赞了你的评论" + content,
                    CTextStyle.PLargeBody2
                    );
            }

            return(new Column(
                       crossAxisAlignment: CrossAxisAlignment.start,
                       children: new List <Widget> {
                new RichText(
                    maxLines: 2,
                    text: new TextSpan(
                        children: new List <TextSpan> {
                    new TextSpan(
                        data.fullname,
                        CTextStyle.PLargeMedium
                        ),
                    subTitle
                }
                        ),
                    overflow: TextOverflow.ellipsis
                    ),
                new Text(
                    data.projectTitle,
                    maxLines: 1,
                    style: CTextStyle.PLargeMedium,
                    overflow: TextOverflow.ellipsis
                    )
            }
                       ));
        }