Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commita3ae8ce

Browse files
authored
refactor(comments-redesign): rewrite, enhance (#319)
* refactor(article-comments): basic write & upvote impl* refactor(article-comments): wip* refactor(article-comments): test embed association workflow* refactor(article-comments): comment_participators workflow test, WOW!* refactor(article-comments): add participators after comment created* refactor(article-comments): add gq test* refactor(article-comments): clean up* refactor(article-comments): fix test err/warings* refactor(article-comments): nested reply wip* refactor(article-comments): more test on reply* refactor(article-comments): replies basic logic done* refactor(article-comments): replies count logic* refactor(article-comments): paged replies logic* refactor(article-comments): basic emotion setup* refactor(post-meta): emotions wip* refactor(article-comments): basic emotion wip* refactor(article-comments): emotion curd done* refactor(article-comments): viewer_has_emotioned wip* refactor(article-comments): re-org wip* refactor(article-comments): re-org wip* refactor(article-comments): re-org wip* refactor(article-comments): naming re-org* refactor(article-comments): clean up* refactor(article-comments): make emotion dynamicly* refactor(article-comments): fold/unfold done* refactor(article-comments): paged fold/unfold done* refactor(article-comments): paged report/unreport done* refactor(article-comments): floor done* refactor(article-comments): write_comment -> create_article_comment* refactor(article-comments): upvote_comment -> upvote_article_comment* refactor(article-comments): delete comment logic* refactor(article-comments): is_article_author flag* refactor(article-comments): upvotes_count logic* refactor(article-comments): rm old job comments & logic* refactor(article-comments): rm old repo comments & logic* refactor(article-comments): rm job/repo GQ comments test* refactor(article-comments): rm post comment dislike* refactor(article-comments): add meta embeds* refactor(article-comments): abuse_reports setup* refactor(article-comments): abuse_reports wip* refactor(article-comments): abuse_reports wip* refactor(article-comments): abuse_reports re-org wip* refactor(article-comments): clean up unused var in tests* refactor(article-comments): @report_threshold_for_fold logic* refactor(article-comments): wip* refactor(article-comments): fix broken tests* refactor(post-meta): fix ci tests & warnings
1 parent8a15031 commita3ae8ce

File tree

85 files changed

+2349
-2860
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+2349
-2860
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
defmoduleGroupherServer.CMS.AbuseReportdo
2+
@moduledocfalse
3+
alias__MODULE__
4+
5+
useEcto.Schema
6+
importEcto.Changeset
7+
8+
aliasGroupherServer.{Accounts,CMS}
9+
aliasCMS.{ArticleComment,Embeds,Post,Job}
10+
11+
# @required_fields ~w(article_comment_id user_id recived_user_id)a
12+
@optional_fields~w(article_comment_id post_id job_id account_id operate_user_id deal_with is_closed report_cases_count)a
13+
@update_fields~w(operate_user_id deal_with is_closed report_cases_count)a
14+
15+
@typet::%AbuseReport{}
16+
schema"abuse_reports"do
17+
belongs_to(:article_comment,ArticleComment,foreign_key::article_comment_id)
18+
belongs_to(:post,Post,foreign_key::post_id)
19+
belongs_to(:job,Job,foreign_key::job_id)
20+
belongs_to(:account,Accounts.User,foreign_key::account_id)
21+
22+
embeds_many(:report_cases,Embeds.AbuseReportCase,on_replace::delete)
23+
field(:report_cases_count,:integer,default:0)
24+
25+
belongs_to(:operate_user,Accounts.User,foreign_key::operate_user_id)
26+
27+
field(:deal_with,:string)
28+
field(:is_closed,:boolean,default:false)
29+
30+
timestamps(type::utc_datetime)
31+
end
32+
33+
@docfalse
34+
defchangeset(%AbuseReport{}=struct,attrs)do
35+
struct
36+
|>cast(attrs,@optional_fields)
37+
|>cast_embed(:report_cases,required:true,with:&Embeds.AbuseReportCase.changeset/2)
38+
end
39+
40+
defupdate_changeset(%AbuseReport{}=struct,attrs)do
41+
struct
42+
|>cast(attrs,@update_fields)
43+
|>cast_embed(:report_cases,required:true,with:&Embeds.AbuseReportCase.changeset/2)
44+
end
45+
end
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
defmoduleGroupherServer.CMS.ArticleCommentdo
2+
@moduledocfalse
3+
alias__MODULE__
4+
5+
useEcto.Schema
6+
useAccessible
7+
8+
importEcto.Changeset
9+
10+
aliasGroupherServer.{Accounts,CMS}
11+
12+
aliasCMS.{
13+
Post,
14+
Job,
15+
Embeds,
16+
ArticleCommentUpvote
17+
}
18+
19+
# alias Helper.HTML
20+
21+
@required_fields~w(body_html author_id)a
22+
@optional_fields~w(post_id job_id reply_to_id replies_count is_folded is_reported is_deleted floor is_article_author)a
23+
@updatable_fields~w(is_folded is_reported is_deleted floor upvotes_count)a
24+
25+
@max_participator_count5
26+
@max_parent_replies_count3
27+
28+
@supported_emotions[:downvote,:beer,:heart,:biceps,:orz,:confused,:pill]
29+
@max_latest_emotion_users_count5
30+
31+
@delete_hint"this comment is deleted"
32+
# 举报超过此数评论会被自动折叠
33+
@report_threshold_for_fold5
34+
35+
@doc"latest participators stores in article comment_participators field"
36+
defmax_participator_count(),do:@max_participator_count
37+
@doc"latest replies stores in article_comment replies field, used for frontend display"
38+
defmax_parent_replies_count(),do:@max_parent_replies_count
39+
40+
@doc"操作某 emotion 的最近用户"
41+
defmax_latest_emotion_users_count(),do:@max_latest_emotion_users_count
42+
43+
defsupported_emotions(),do:@supported_emotions
44+
defdelete_hint(),do:@delete_hint
45+
46+
defreport_threshold_for_fold,do:@report_threshold_for_fold
47+
48+
@typet::%ArticleComment{}
49+
schema"articles_comments"do
50+
field(:body_html,:string)
51+
field(:replies_count,:integer,default:0)
52+
53+
# 是否被折叠
54+
field(:is_folded,:boolean,default:false)
55+
# 是否被举报
56+
field(:is_reported,:boolean,default:false)
57+
# 是否被删除
58+
field(:is_deleted,:boolean,default:false)
59+
# 楼层
60+
field(:floor,:integer,default:0)
61+
62+
# 是否是评论文章的作者
63+
field(:is_article_author,:boolean,default:false)
64+
field(:upvotes_count,:integer,default:0)
65+
66+
belongs_to(:author,Accounts.User,foreign_key::author_id)
67+
belongs_to(:post,Post,foreign_key::post_id)
68+
belongs_to(:job,Job,foreign_key::job_id)
69+
belongs_to(:reply_to,ArticleComment,foreign_key::reply_to_id)
70+
71+
embeds_many(:replies,ArticleComment,on_replace::delete)
72+
embeds_one(:emotions,Embeds.ArticleCommentEmotion,on_replace::update)
73+
embeds_one(:meta,Embeds.ArticleCommentMeta,on_replace::update)
74+
75+
has_many(:upvotes,{"articles_comments_upvotes",ArticleCommentUpvote})
76+
77+
timestamps(type::utc_datetime)
78+
end
79+
80+
@docfalse
81+
defchangeset(%ArticleComment{}=article_comment,attrs)do
82+
article_comment
83+
|>cast(attrs,@required_fields++@optional_fields)
84+
|>cast_embed(:emotions,required:true,with:&Embeds.ArticleCommentEmotion.changeset/2)
85+
|>validate_required(@required_fields)
86+
|>generl_changeset
87+
end
88+
89+
# @doc false
90+
defupdate_changeset(%ArticleComment{}=article_comment,attrs)do
91+
article_comment
92+
|>cast(attrs,@required_fields++@updatable_fields)
93+
# |> cast_embed(:emotions, required: false, with: &Embeds.ArticleCommentEmotion.changeset/2)
94+
|>generl_changeset
95+
end
96+
97+
defpgenerl_changeset(content)do
98+
content
99+
|>foreign_key_constraint(:author_id)
100+
101+
# |> validate_length(:body_html, min: 3, max: 2000)
102+
# |> HTML.safe_string(:body_html)
103+
end
104+
end
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
defmoduleGroupherServer.CMS.ArticleCommentParticipatordo
2+
@moduledocfalse
3+
4+
useEcto.Schema
5+
6+
aliasGroupherServer.Accounts.User
7+
8+
# alias CMS.{
9+
# Post,
10+
# Job,
11+
# ArticleCommentUpvote
12+
# }
13+
14+
# alias Helper.HTML
15+
16+
# @required_fields ~w(user_id)a
17+
# @optional_fields ~w(post_id job_id)a
18+
19+
embedded_schemado
20+
# field(:reply_time, :string)
21+
22+
belongs_to(:user,User)
23+
end
24+
end
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
defmoduleGroupherServer.CMS.ArticleCommentReplydo
2+
@moduledocfalse
3+
alias__MODULE__
4+
5+
useEcto.Schema
6+
importEcto.Changeset
7+
8+
aliasGroupherServer.CMS
9+
aliasCMS.ArticleComment
10+
11+
@required_fields~w(article_comment_id reply_to_id)a
12+
13+
@typet::%ArticleCommentReply{}
14+
schema"articles_comments_replies"do
15+
belongs_to(:article_comment,ArticleComment,foreign_key::article_comment_id)
16+
belongs_to(:reply_to,ArticleComment,foreign_key::reply_to_id)
17+
18+
timestamps(type::utc_datetime)
19+
end
20+
21+
@docfalse
22+
defchangeset(%ArticleCommentReply{}=article_comment_reply,attrs)do
23+
article_comment_reply
24+
|>cast(attrs,@required_fields)
25+
|>validate_required(@required_fields)
26+
|>foreign_key_constraint(:article_comment_id)
27+
|>foreign_key_constraint(:reply_to_id)
28+
end
29+
end
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
defmoduleGroupherServer.CMS.ArticleCommentUpvotedo
2+
@moduledocfalse
3+
alias__MODULE__
4+
5+
useEcto.Schema
6+
importEcto.Changeset
7+
8+
aliasGroupherServer.{Accounts,CMS}
9+
aliasCMS.ArticleComment
10+
11+
@required_fields~w(article_comment_id user_id)a
12+
13+
@typet::%ArticleCommentUpvote{}
14+
schema"articles_comments_upvotes"do
15+
belongs_to(:user,Accounts.User,foreign_key::user_id)
16+
belongs_to(:article_comment,ArticleComment,foreign_key::article_comment_id)
17+
18+
timestamps(type::utc_datetime)
19+
end
20+
21+
@docfalse
22+
defchangeset(%ArticleCommentUpvote{}=article_comment_upvote,attrs)do
23+
article_comment_upvote
24+
|>cast(attrs,@required_fields)
25+
|>validate_required(@required_fields)
26+
|>foreign_key_constraint(:article_comment_id)
27+
|>foreign_key_constraint(:user_id)
28+
|>unique_constraint(:user_id,
29+
name::articles_comments_upvotes_user_id_article_comment_id_index
30+
)
31+
end
32+
end
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
defmoduleGroupherServer.CMS.ArticleCommentUserEmotiondo
2+
@moduledocfalse
3+
alias__MODULE__
4+
5+
useEcto.Schema
6+
importEcto.Changeset
7+
8+
aliasGroupherServer.{Accounts,CMS}
9+
aliasCMS.ArticleComment
10+
11+
@required_fields~w(article_comment_id user_id recived_user_id)a
12+
@optional_fields~w(downvote beer heart biceps orz confused pill)a
13+
14+
@typet::%ArticleCommentUserEmotion{}
15+
schema"articles_comments_users_emotions"do
16+
belongs_to(:article_comment,ArticleComment,foreign_key::article_comment_id)
17+
belongs_to(:recived_user,Accounts.User,foreign_key::recived_user_id)
18+
belongs_to(:user,Accounts.User,foreign_key::user_id)
19+
20+
field(:downvote,:boolean,default:false)
21+
field(:beer,:boolean,default:false)
22+
field(:heart,:boolean,default:false)
23+
field(:biceps,:boolean,default:false)
24+
field(:orz,:boolean,default:false)
25+
field(:confused,:boolean,default:false)
26+
field(:pill,:boolean,default:false)
27+
28+
timestamps(type::utc_datetime)
29+
end
30+
31+
@docfalse
32+
defchangeset(%ArticleCommentUserEmotion{}=struct,attrs)do
33+
struct
34+
|>cast(attrs,@required_fields++@optional_fields)
35+
|>validate_required(@required_fields)
36+
|>foreign_key_constraint(:article_comment_id)
37+
|>foreign_key_constraint(:user_id)
38+
|>foreign_key_constraint(:recived_user_id)
39+
end
40+
end

‎lib/groupher_server/cms/cms.ex‎

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ defmodule GroupherServer.CMS do
88
aliasGroupherServer.CMS.Delegate
99

1010
aliasDelegate.{
11+
AbuseReport,
1112
ArticleCURD,
1213
ArticleOperation,
1314
ArticleReaction,
1415
FavoritedContents,
16+
ArticleComment,
1517
CommentCURD,
1618
CommunitySync,
1719
CommentReaction,
@@ -106,22 +108,44 @@ defmodule GroupherServer.CMS do
106108
defdelegateunset_community(community,thread,content_id),to:ArticleOperation
107109

108110
# Comment CURD
111+
defdelegatelist_article_comments(thread,article_id,filters),to:ArticleComment
112+
defdelegatelist_article_comments(thread,article_id,filters,user),to:ArticleComment
113+
defdelegatelist_folded_article_comments(thread,article_id,filters),to:ArticleComment
114+
defdelegatelist_folded_article_comments(thread,article_id,filters,user),to:ArticleComment
115+
defdelegatelist_reported_article_comments(thread,article_id,filters),to:ArticleComment
116+
117+
defdelegatelist_reported_article_comments(thread,article_id,filters,user),
118+
to:ArticleComment
119+
120+
defdelegatelist_comment_replies(comment_id,filters),to:ArticleComment
121+
109122
defdelegatelist_comments(thread,content_id,filters),to:CommentCURD
110123
defdelegatelist_comments_participators(thread,content_id,filters),to:CommentCURD
111124

125+
defdelegatecreate_article_comment(thread,article_id,args,user),to:ArticleComment
126+
defdelegateupvote_article_comment(comment_id,user),to:ArticleComment
127+
defdelegatedelete_article_comment(comment_id,user),to:ArticleComment
128+
defdelegatereply_article_comment(comment_id,args,user),to:ArticleComment
129+
130+
defdelegatemake_emotion(comment_id,args,user),to:ArticleComment
131+
defdelegatefold_article_comment(comment_id,user),to:ArticleComment
132+
defdelegateunfold_article_comment(comment_id,user),to:ArticleComment
133+
defdelegatereport_article_comment(comment_id,user),to:ArticleComment
134+
defdelegateunreport_article_comment(comment_id,user),to:ArticleComment
135+
112136
defdelegatecreate_comment(thread,content_id,args,user),to:CommentCURD
113137
defdelegateupdate_comment(thread,id,args,user),to:CommentCURD
114138
defdelegatedelete_comment(thread,content_id),to:CommentCURD
115139
defdelegatelist_replies(thread,comment,user),to:CommentCURD
116140
defdelegatereply_comment(thread,comment,args,user),to:CommentCURD
117141

142+
# report
143+
defdelegatecreate_report(type,content_id,args,user),to:AbuseReport
144+
118145
# Comment Reaction
119146
# >> like / undo like
120147
defdelegatelike_comment(thread,comment,user),to:CommentReaction
121148
defdelegateundo_like_comment(thread,comment,user),to:CommentReaction
122-
# >> dislike / undo dislike
123-
defdelegatedislike_comment(thread,comment,user),to:CommentReaction
124-
defdelegateundo_dislike_comment(thread,comment,user),to:CommentReaction
125149

126150
# Passport CURD
127151
defdelegatestamp_passport(rules,user),to:PassportCURD

‎lib/groupher_server/cms/community.ex‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ defmodule GroupherServer.CMS.Community do
1010
aliasCMS.{
1111
Category,
1212
Post,
13-
Video,
1413
Repo,
1514
Job,
1615
CommunityThread,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp