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.

Commitd6cf9c9

Browse files
committed
refactor(comment): some action workflow debug with front
1 parent8575b26 commitd6cf9c9

File tree

7 files changed

+38
-24
lines changed

7 files changed

+38
-24
lines changed

‎lib/groupher_server/cms/delegates/comment_action.ex‎

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ defmodule GroupherServer.CMS.Delegate.CommentAction do
1515
add_participant_to_article:2,
1616
do_create_comment:4,
1717
update_comments_count:2,
18-
can_comment?:2
18+
can_comment?:2,
19+
paged_comment_replies:2
1920
]
2021

2122
importGroupherServer.CMS.Helper.Matcher
@@ -120,12 +121,6 @@ defmodule GroupherServer.CMS.Delegate.CommentAction do
120121
CommentReply
121122
|>ORM.create(%{comment_id:replyed_comment.id,reply_to_id:replying_comment.id})
122123
end)
123-
|>Multi.run(:inc_replies_count,fn_,_->
124-
ORM.inc_field(Comment,replying_comment,:replies_count)
125-
end)
126-
|>Multi.run(:add_replies_ifneed,fn_,%{create_reply_comment:replyed_comment}->
127-
add_replies_ifneed(parent_comment,replyed_comment)
128-
end)
129124
|>Multi.run(:add_participator,fn_,_->
130125
add_participant_to_article(article,user)
131126
end)
@@ -139,7 +134,18 @@ defmodule GroupherServer.CMS.Delegate.CommentAction do
139134
|>Ecto.Changeset.put_assoc(:reply_to,replying_comment)
140135
|>Repo.update()
141136
end)
142-
|>Multi.run(:after_hooks,fn_,%{create_reply_comment:replyed_comment}->
137+
|>Multi.run(:add_replies_ifneed,fn_,%{add_reply_to:replyed_comment}->
138+
add_replies_ifneed(parent_comment,replyed_comment)
139+
end)
140+
|>Multi.run(:inc_replies_count,fn_,%{add_reply_to:replyed_comment}->
141+
filter=%{page:1,size:1}
142+
143+
with{:ok,paged_replies}<-paged_comment_replies(parent_comment.id,filter),
144+
{:ok,_}<-ORM.update(parent_comment,%{replies_count:paged_replies.total_count})do
145+
{:ok,replyed_comment}
146+
end
147+
end)
148+
|>Multi.run(:after_hooks,fn_,%{add_reply_to:replyed_comment}->
143149
Later.run({Hooks.Notify,:handle,[:reply,replyed_comment,user]})
144150
Later.run({Hooks.Mention,:handle,[replyed_comment]})
145151
end)
@@ -390,18 +396,18 @@ defmodule GroupherServer.CMS.Delegate.CommentAction do
390396
end
391397

392398
defpresult({:ok,%{create_comment:result}}),do:{:ok,result}
393-
defpresult({:ok,%{add_reply_to:result}}),do:{:ok,result}
399+
defpresult({:ok,%{inc_replies_count:result}}),do:{:ok,result}
394400
defpresult({:ok,%{sync_embed_replies:result}}),do:{:ok,result}
395401
defpresult({:ok,%{update_comment_flag:result}}),do:{:ok,result}
396402
defpresult({:ok,%{delete_comment:result}}),do:{:ok,result}
397403
defpresult({:ok,%{fold_comment:result}}),do:{:ok,result}
398404

399-
defpresult({:error,:create_comment,result,_steps})do
400-
raise_error(:create_comment,result)
405+
defpresult({:error,:create_comment,_result,_steps})do
406+
raise_error(:create_comment,"create comment error")
401407
end
402408

403-
defpresult({:error,:create_comment_upvote,result,_steps})do
404-
raise_error(:comment_already_upvote,result)
409+
defpresult({:error,:create_comment_upvote,_result,_steps})do
410+
raise_error(:comment_already_upvote,"already upvoted")
405411
end
406412

407413
defpresult({:error,:add_participator,result,_steps})do

‎lib/groupher_server/cms/delegates/hooks/notify.ex‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ defmodule GroupherServer.CMS.Delegate.Hooks.Notify do
55
importGroupherServer.CMS.Delegate.Helper,
66
only:[preload_author:1,article_of:1,thread_of:1]
77

8-
aliasGroupherServer.{Accounts,CMS,Delivery}
8+
aliasGroupherServer.{Accounts,CMS,Delivery,Repo}
99

1010
aliasAccounts.Model.User
1111
aliasCMS.Model.Comment
@@ -31,6 +31,8 @@ defmodule GroupherServer.CMS.Delegate.Hooks.Notify do
3131

3232
# 回复评论是特殊情况,单独处理
3333
defhandle(:reply,%Comment{}=reply_comment,%User{}=from_user)do
34+
reply_comment=Repo.preload(reply_comment,reply_to::author)
35+
3436
{:ok,article}=article_of(reply_comment)
3537
{:ok,article}=preload_author(article)
3638
{:ok,thread}=thread_of(article)

‎lib/groupher_server/cms/models/comment.ex‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ defmodule GroupherServer.CMS.Model.Comment do
1919

2020
@required_fields~w(body author_id)a
2121
@optional_fields~w(body_html reply_to_id replies_count is_folded is_deleted floor is_article_author thread is_for_question is_solution)a
22-
@updatable_fields~w(body_html is_folded is_deleted floor upvotes_count is_pinned is_for_question is_solution)a
22+
@updatable_fields~w(body_html is_folded is_deleted floor upvotes_count is_pinned is_for_question is_solution replies_count)a
2323

2424
@article_fields@article_threads|>Enum.map(&:"#{&1}_id")
2525

‎lib/groupher_server_web/schema/Helper/fields.ex‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,7 @@ defmodule GroupherServerWeb.Schema.Helper.Fields do
166166
field(:replies_count,:integer)
167167
field(:thread,:string)
168168
field(:viewer_has_upvoted,:boolean)
169-
field(:thread,:string)
170-
field(:replies_count,:integer)
169+
field(:reply_to,:comment,resolve:dataloader(CMS,:reply_to))
171170
field(:reply_to_id,:id)
172171

173172
field(:is_deleted,:boolean)

‎lib/groupher_server_web/schema/cms/cms_types.ex‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,6 @@ defmodule GroupherServerWeb.Schema.CMS.Types do
316316

317317
object:commentdo
318318
comment_general_fields()
319-
field(:reply_to,:comment_reply)
320319

321320
field(:replies,list_of(:comment_reply))
322321
field(:article,:common_article)

‎test/groupher_server/cms/comments/post_comment_test.exs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do
157157
assertList.first(comment.upvotes).user_id==user.id
158158
end
159159

160+
@tag:wip
160161
test"user can upvote a post comment twice is fine",~m(user post)ado
161162
{:ok,comment}=CMS.create_comment(:post,post.id,mock_comment(),user)
162163

‎test/groupher_server_web/query/cms/comments/post_comment_test.exs‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do
3434
}
3535
}
3636
"""
37-
@tag:wip
3837
test"can get one comment by id",~m(guest_conn post user)ado
3938
thread=:post
4039
{:ok,comment}=CMS.create_comment(thread,post.id,mock_comment(),user)
@@ -46,7 +45,6 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do
4645
assertresults["id"]==to_string(comment.id)
4746
end
4847

49-
@tag:wip
5048
test"can get one comment by id with viewer states",~m(user_conn post user)ado
5149
thread=:post
5250
{:ok,comment}=CMS.create_comment(thread,post.id,mock_comment(),user)
@@ -156,7 +154,6 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do
156154
meta {
157155
isArticleAuthorUpvoted
158156
}
159-
replyToId
160157
replyTo {
161158
id
162159
bodyHtml
@@ -171,6 +168,14 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do
171168
replies {
172169
id
173170
bodyHtml
171+
replyTo {
172+
id
173+
author {
174+
login
175+
nickname
176+
}
177+
}
178+
repliesCount
174179
author {
175180
id
176181
login
@@ -185,9 +190,9 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do
185190
}
186191
}
187192
"""
188-
193+
@tag:wip
189194
test"list comments with default replies-mode",~m(guest_conn post user user2)ado
190-
total_count=10
195+
total_count=3
191196
page_size=20
192197
thread=:post
193198

@@ -201,7 +206,6 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do
201206
random_comment=all_comments|>Enum.at(Enum.random(0..(total_count-1)))
202207

203208
{:ok,replyed_comment_1}=CMS.reply_comment(random_comment.id,mock_comment(),user2)
204-
205209
{:ok,replyed_comment_2}=CMS.reply_comment(random_comment.id,mock_comment(),user2)
206210

207211
variables=%{id:post.id,thread:"POST",filter:%{page:1,size:page_size}}
@@ -212,12 +216,15 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do
212216
assertnotexist_in?(replyed_comment_2,results["entries"])
213217

214218
random_comment=Enum.find(results["entries"],&(&1["id"]==to_string(random_comment.id)))
219+
215220
assertrandom_comment["replies"]|>length==2
216221
assertrandom_comment["repliesCount"]==2
217222

218223
assertrandom_comment["replies"]|>List.first()|>Map.get("id")==
219224
to_string(replyed_comment_1.id)
220225

226+
assertnotis_nil(random_comment["replies"]|>List.first()|>Map.get("replyTo"))
227+
221228
assertrandom_comment["replies"]|>List.last()|>Map.get("id")==
222229
to_string(replyed_comment_2.id)
223230
end

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp