コード例 #1
0
 void _sendComment(string type, string parentMessageId = "", string upperMessageId = "", string replyUserName = null)
 {
     if (!this.widget.viewModel.isLoggedIn)
     {
         this.widget.actionModel.pushToLogin();
     }
     else
     {
         AnalyticsManager.ClickComment(
             type: type,
             channelId: this._article.channelId,
             title: this._article.title,
             commentId: parentMessageId
             );
         ActionSheetUtils.showModalActionSheet(new CustomInput(
                                                   replyUserName: replyUserName,
                                                   text => {
             ActionSheetUtils.hiddenModalPopup();
             this.widget.actionModel.sendComment(
                 arg1: this._article.channelId,
                 arg2: text,
                 Snowflake.CreateNonce(),
                 arg4: parentMessageId,
                 arg5: upperMessageId
                 );
         })
                                               );
     }
 }
コード例 #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);
        }
コード例 #3
0
        public override Widget build(BuildContext context)
        {
            this.widget.viewModel.articleDict.TryGetValue(this.widget.viewModel.articleId, out this._article);
            if (this.widget.viewModel.articleDetailLoading && (this._article == null || !this._article.isNotFirst))
            {
                return(new Container(
                           color: CColors.White,
                           child: new CustomSafeArea(
                               child: new Column(
                                   children: new List <Widget> {
                    this._buildNavigationBar(false),
                    new ArticleDetailLoading()
                }
                                   )
                               )
                           ));
            }

            if (this._article == null || this._article.channelId == null)
            {
                return(new Container());
            }

            if (this._article.ownerType == "user")
            {
                if (this._article.userId != null &&
                    this.widget.viewModel.userDict.TryGetValue(this._article.userId, out this._user))
                {
                    this._user = this.widget.viewModel.userDict[this._article.userId];
                }
            }

            if (this._article.ownerType == "team")
            {
                if (this._article.teamId != null &&
                    this.widget.viewModel.teamDict.TryGetValue(this._article.teamId, out this._team))
                {
                    this._team = this.widget.viewModel.teamDict[this._article.teamId];
                }
            }

            if (this._titleHeight == 0f && this._article.title.isNotEmpty())
            {
                this._titleHeight = CTextUtils.CalculateTextHeight(
                    text: this._article.title,
                    textStyle: CTextStyle.H3,
                    MediaQuery.of(context).size.width - 16 * 2, // 16 is horizontal padding
                    null
                    ) + 16;                                     // 16 is top padding
                this.setState(() => { });
            }

            var commentIndex = 0;
            var originItems  = this._article == null ? new List <Widget>() : this._buildItems(context, out commentIndex);

            commentIndex    = this._jumpState == _ArticleJumpToCommentState.active ? commentIndex : 0;
            this._jumpState = _ArticleJumpToCommentState.Inactive;

            var child = new Container(
                color: CColors.Background,
                child: new Column(
                    children: new List <Widget> {
                this._buildNavigationBar(),
                new Expanded(
                    child: new CustomScrollbar(
                        new CenteredRefresher(
                            controller: this._refreshController,
                            enablePullDown: false,
                            enablePullUp: this._article.hasMore,
                            onRefresh: this._onRefresh,
                            onNotification: this._onNotification,
                            children: originItems,
                            centerIndex: commentIndex
                            )
                        )
                    ),
                new ArticleTabBar(this._article.like,
                                  () => {
                    if (!this.widget.viewModel.isLoggedIn)
                    {
                        this.widget.actionModel.pushToLogin();
                    }
                    else
                    {
                        AnalyticsManager.ClickComment("Article", this._article.channelId,
                                                      this._article.title);
                        ActionSheetUtils.showModalActionSheet(new CustomInput(
                                                                  doneCallBack: text => {
                            ActionSheetUtils.hiddenModalPopup();
                            this.widget.actionModel.sendComment(this._article.channelId,
                                                                text,
                                                                Snowflake.CreateNonce(),
                                                                null
                                                                );
                        })
                                                              );
                    }
                },
                                  () => {
                    if (!this.widget.viewModel.isLoggedIn)
                    {
                        this.widget.actionModel.pushToLogin();
                    }
                    else
                    {
                        AnalyticsManager.ClickComment("Article", this._article.channelId,
                                                      this._article.title);
                        ActionSheetUtils.showModalActionSheet(new CustomInput(
                                                                  doneCallBack: text => {
                            ActionSheetUtils.hiddenModalPopup();
                            this.widget.actionModel.sendComment(this._article.channelId,
                                                                text,
                                                                Snowflake.CreateNonce(),
                                                                null
                                                                );
                        })
                                                              );
                    }
                },
                                  () => {
                    if (!this.widget.viewModel.isLoggedIn)
                    {
                        this.widget.actionModel.pushToLogin();
                    }
                    else
                    {
                        if (!this._article.like)
                        {
                            this.widget.actionModel.likeArticle(this._article.id);
                        }
                    }
                },
                                  shareCallback: this.share
                                  )
            }
                    )
                );

            return(new Container(
                       color: CColors.White,
                       child: new CustomSafeArea(
                           child: child
                           )
                       ));
        }
コード例 #4
0
        List <Widget> _buildComments()
        {
            if (this._channelComments.Count == 0)
            {
                return(new List <Widget>());
            }

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

            var messageDict = this.widget.viewModel.channelMessageDict[this._channelId];

            foreach (var commentId in this._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 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._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);
            }

            return(comments);
        }
コード例 #5
0
        public override Widget build(BuildContext context)
        {
            this.widget.viewModel.articleDict.TryGetValue(this.widget.viewModel.articleId, out this._article);
            if (this.widget.viewModel.articleDetailLoading && (this._article == null || !this._article.isNotFirst))
            {
                return(new Container(
                           color: CColors.White,
                           child: new CustomSafeArea(
                               child: new Column(
                                   children: new List <Widget> {
                    this._buildNavigationBar(),
                    new ArticleDetailLoading()
                }
                                   )
                               )
                           ));
            }

            if (this._article == null || this._article.channelId == null)
            {
                return(new Container());
            }

            if (this._article.ownerType == "user")
            {
                if (this._article.userId != null &&
                    this.widget.viewModel.userDict.TryGetValue(this._article.userId, out this._user))
                {
                    this._user = this.widget.viewModel.userDict[this._article.userId];
                }
            }

            if (this._article.ownerType == "team")
            {
                if (this._article.teamId != null &&
                    this.widget.viewModel.teamDict.TryGetValue(this._article.teamId, out this._team))
                {
                    this._team = this.widget.viewModel.teamDict[this._article.teamId];
                }
            }

            this._channelId   = this._article.channelId;
            this._relArticles = this._article.projects.FindAll(item => item.type == "article");
            if (this.widget.viewModel.channelMessageList.ContainsKey(this._article.channelId))
            {
                this._channelComments = this.widget.viewModel.channelMessageList[this._article.channelId];
            }

            this._contentMap    = this._article.contentMap;
            this._lastCommentId = this._article.currOldestMessageId ?? "";
            this._hasMore       = this._article.hasMore;

            var originItems = this._article == null ? new List <Widget>() : this._buildItems(context);

            var child = new Container(
                color: CColors.Background,
                child: new Column(
                    children: new List <Widget> {
                this._buildNavigationBar(),
                new Expanded(
                    child: new CustomScrollbar(
                        new SmartRefresher(
                            controller: this._refreshController,
                            enablePullDown: false,
                            enablePullUp: this._hasMore,
                            onRefresh: this._onRefresh,
                            onNotification: this._onNotification,
                            child: ListView.builder(
                                physics: new AlwaysScrollableScrollPhysics(),
                                itemCount: originItems.Count,
                                itemBuilder: (cxt, index) => originItems[index]
                                )
                            )
                        )
                    ),
                new ArticleTabBar(this._article.like,
                                  () => {
                    if (!this.widget.viewModel.isLoggedIn)
                    {
                        this.widget.actionModel.pushToLogin();
                    }
                    else
                    {
                        AnalyticsManager.ClickComment("Article", this._article.channelId,
                                                      this._article.title);
                        ActionSheetUtils.showModalActionSheet(new CustomInput(
                                                                  doneCallBack: text => {
                            ActionSheetUtils.hiddenModalPopup();
                            this.widget.actionModel.sendComment(this._article.channelId,
                                                                text,
                                                                Snowflake.CreateNonce(),
                                                                null
                                                                );
                        })
                                                              );
                    }
                },
                                  () => {
                    if (!this.widget.viewModel.isLoggedIn)
                    {
                        this.widget.actionModel.pushToLogin();
                    }
                    else
                    {
                        AnalyticsManager.ClickComment("Article", this._article.channelId,
                                                      this._article.title);
                        ActionSheetUtils.showModalActionSheet(new CustomInput(
                                                                  doneCallBack: text => {
                            ActionSheetUtils.hiddenModalPopup();
                            this.widget.actionModel.sendComment(this._article.channelId,
                                                                text,
                                                                Snowflake.CreateNonce(),
                                                                null
                                                                );
                        })
                                                              );
                    }
                },
                                  () => {
                    if (!this.widget.viewModel.isLoggedIn)
                    {
                        this.widget.actionModel.pushToLogin();
                    }
                    else
                    {
                        if (!this._article.like)
                        {
                            this.widget.actionModel.likeArticle(this._article.id);
                        }
                    }
                },
                                  shareCallback: this.share
                                  )
            }
                    )
                );

            return(new Container(
                       color: CColors.White,
                       child: new CustomSafeArea(
                           child: child
                           )
                       ));
        }