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.

Commitc23a8cf

Browse files
committed
refactor(comment): sync_embed_replies if need
1 parentd16d227 commitc23a8cf

File tree

4 files changed

+39
-12
lines changed

4 files changed

+39
-12
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do
55
importEcto.Query,warn:false
66
importHelper.Utils,only:[done:1,strip_struct:1,get_config:2]
77

8+
importGroupherServer.CMS.Delegate.Helper,only:[sync_embed_replies:1]
9+
810
importGroupherServer.CMS.Helper.Matcher
911
importShortMaps
1012

@@ -166,6 +168,9 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do
166168
|>Multi.run(:update_report_meta,fn_,_->
167169
update_report_meta(info,article)
168170
end)
171+
|>Multi.run(:sync_embed_replies,fn_,%{update_report_meta:comment}->
172+
sync_embed_replies(comment)
173+
end)
169174
|>Repo.transaction()
170175
|>result()
171176
end
@@ -187,6 +192,9 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do
187192
do:CMS.fold_comment(comment,user),
188193
else:{:ok,comment}
189194
end)
195+
|>Multi.run(:sync_embed_replies,fn_,%{update_report_meta:comment}->
196+
sync_embed_replies(comment)
197+
end)
190198
|>Repo.transaction()
191199
|>result()
192200
end
@@ -379,7 +387,7 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do
379387
|>Map.merge(%{thread:article_thread})
380388
end
381389

382-
defpresult({:ok,%{update_report_meta:result}}),do:result|>done()
390+
defpresult({:ok,%{sync_embed_replies:result}}),do:result|>done()
383391
defpresult({:ok,%{update_content_reported_flag:result}}),do:result|>done()
384392

385393
defpresult({:error,_,result,_steps})do

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ defmodule GroupherServer.CMS.Delegate.CommentAction do
180180
|>Map.merge(%{viewer_has_reported:viewer_has_reported})
181181
|>done
182182
end)
183-
|>Multi.run(:upvote_comment_done,fn_,%{viewer_states:comment}->
183+
|>Multi.run(:sync_embed_replies,fn_,%{viewer_states:comment}->
184184
sync_embed_replies(comment)
185185
end)
186186
|>Multi.run(:after_hooks,fn_,_->
@@ -223,7 +223,7 @@ defmodule GroupherServer.CMS.Delegate.CommentAction do
223223
|>Map.merge(%{viewer_has_reported:viewer_has_reported})
224224
|>done
225225
end)
226-
|>Multi.run(:upvote_comment_done,fn_,%{viewer_states:comment}->
226+
|>Multi.run(:sync_embed_replies,fn_,%{viewer_states:comment}->
227227
sync_embed_replies(comment)
228228
end)
229229
|>Multi.run(:after_hooks,fn_,_->
@@ -390,7 +390,7 @@ defmodule GroupherServer.CMS.Delegate.CommentAction do
390390

391391
defpresult({:ok,%{create_comment:result}}),do:{:ok,result}
392392
defpresult({:ok,%{add_reply_to:result}}),do:{:ok,result}
393-
defpresult({:ok,%{upvote_comment_done:result}}),do:{:ok,result}
393+
defpresult({:ok,%{sync_embed_replies:result}}),do:{:ok,result}
394394
defpresult({:ok,%{update_comment_flag:result}}),do:{:ok,result}
395395
defpresult({:ok,%{delete_comment:result}}),do:{:ok,result}
396396
defpresult({:ok,%{fold_comment:result}}),do:{:ok,result}

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

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ defmodule GroupherServer.CMS.Delegate.CommentCurd do
77
importHelper.ErrorCode
88

99
importGroupherServer.CMS.Delegate.Helper,
10-
only:[mark_viewer_emotion_states:2,article_of:1,thread_of:1]
10+
only:[mark_viewer_emotion_states:2,article_of:1,thread_of:1,sync_embed_replies:1]
1111

1212
importGroupherServer.CMS.Helper.Matcher
1313
importShortMaps
@@ -209,15 +209,33 @@ defmodule GroupherServer.CMS.Delegate.CommentCurd do
209209
with{:ok,post}<-ORM.find(Post,comment.post_id),
210210
{:ok,parsed}<-Converter.Article.parse_body(body),
211211
{:ok,digest}<-Converter.Article.parse_digest(parsed.body_map)do
212-
%{body:body,body_html:body_html}=parsed
213-
post|>ORM.update(%{solution_digest:digest})
214-
comment|>ORM.update(%{body:body,body_html:body_html})
212+
Multi.new()
213+
|>Multi.run(:update_parent_post,fn_,_->
214+
ORM.update(post,%{solution_digest:digest})
215+
end)
216+
|>Multi.run(:update_comment,fn_,_->
217+
%{body:body,body_html:body_html}=parsed
218+
comment|>ORM.update(%{body:body,body_html:body_html})
219+
end)
220+
|>Multi.run(:sync_embed_replies,fn_,%{update_comment:comment}->
221+
sync_embed_replies(comment)
222+
end)
223+
|>Repo.transaction()
224+
|>result()
215225
end
216226
end
217227

218228
defupdate_comment(%Comment{}=comment,body)do
219229
with{:ok,%{body:body,body_html:body_html}}<-Converter.Article.parse_body(body)do
220-
comment|>ORM.update(%{body:body,body_html:body_html})
230+
Multi.new()
231+
|>Multi.run(:update_comment,fn_,_->
232+
ORM.update(comment,%{body:body,body_html:body_html})
233+
end)
234+
|>Multi.run(:sync_embed_replies,fn_,%{update_comment:comment}->
235+
sync_embed_replies(comment)
236+
end)
237+
|>Repo.transaction()
238+
|>result()
221239
end
222240
end
223241

@@ -254,6 +272,9 @@ defmodule GroupherServer.CMS.Delegate.CommentCurd do
254272
|>Multi.run(:update_post_state,fn_,_->
255273
ORM.update(post,%{is_solved:is_solution,solution_digest:comment.body_html})
256274
end)
275+
|>Multi.run(:sync_embed_replies,fn_,%{mark_solution:comment}->
276+
sync_embed_replies(comment)
277+
end)
257278
|>Repo.transaction()
258279
|>result()
259280
else
@@ -513,6 +534,7 @@ defmodule GroupherServer.CMS.Delegate.CommentCurd do
513534
defpresult({:ok,%{set_question_flag_ifneed:result}}),do:{:ok,result}
514535
defpresult({:ok,%{delete_comment:result}}),do:{:ok,result}
515536
defpresult({:ok,%{mark_solution:result}}),do:{:ok,result}
537+
defpresult({:ok,%{sync_embed_replies:result}}),do:{:ok,result}
516538

517539
defpresult({:error,:create_comment,result,_steps})do
518540
raise_error(:create_comment,result)

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,6 @@ defmodule GroupherServer.CMS.Delegate.Helper do
153153
end
154154

155155
# replies(embed_many) 不会自定更新,需要手动更新,否则在 replies 模式下数据会不同步。
156-
# TODO: CURD comment in replies list
157-
# TODO: report / emotion / upvote comment in replies list
158-
# ...
159156
defsync_embed_replies(%Comment{reply_to_id:reply_to_id}=comment)do
160157
with{:ok,parent_comment}<-ORM.find(Comment,reply_to_id),
161158
embed_index<-Enum.find_index(parent_comment.replies,&(&1.id==comment.id))do

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp