Skip to content
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commit cd519cf

Browse files
authored
refactor(article-comment): remove article prefix (#397)
* refactor(article-comment): rename to participants * refactor(article-comment): rename wip * refactor(article-comment): rename wip * refactor(article-comment): rename wip * refactor(article-comment): rename article prefix of upvotes * refactor(article-comment): rename article prefix of upvotes * refactor(article-comment): rename article prefix of pinned * refactor(article-comment): rename article prefix of emotion * refactor(article-comment): rename article prefix of emotion * refactor(article-comment): rm article prefix wip * refactor(article-comment): rm article prefix wip * refactor(article-comment): rm article prefix wip, big time * refactor(article-comment): rm article prefix wip * refactor(article-comment): rm article prefix wip * refactor(article-comment): rm article prefix wip * refactor(article-comment): rename article_comment_id, big time * chore: fix naming errors * chore: fix naming errors
1 parent fb002fc commit cd519cf

File tree

85 files changed

+1870
-1804
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

+1870
-1804
lines changed

lib/groupher_server/accounts/delegates/publish.ex

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ defmodule GroupherServer.Accounts.Delegate.Publish do
1010
import GroupherServer.CMS.Helper.Matcher
1111

1212
alias GroupherServer.Accounts.Model.{Embeds, User}
13-
alias GroupherServer.CMS.Model.ArticleComment
13+
alias GroupherServer.CMS.Model.Comment
1414

1515
alias Helper.{ORM, QueryBuilder}
1616

@@ -56,7 +56,7 @@ defmodule GroupherServer.Accounts.Delegate.Publish do
5656

5757
def paged_published_article_comments(%User{id: user_id}, %{page: page, size: size} = filter) do
5858
with {:ok, user} <- ORM.find(User, user_id) do
59-
ArticleComment
59+
Comment
6060
|> join(:inner, [comment], author in assoc(comment, :author))
6161
|> where([comment, author], author.id == ^user.id)
6262
|> QueryBuilder.filter_pack(filter)
@@ -76,7 +76,7 @@ defmodule GroupherServer.Accounts.Delegate.Publish do
7676
thread_atom = thread |> String.downcase() |> String.to_atom()
7777

7878
article_preload = Keyword.new([{thread_atom, [author: :user]}])
79-
query = from(comment in ArticleComment, preload: ^article_preload)
79+
query = from(comment in Comment, preload: ^article_preload)
8080

8181
query
8282
|> join(:inner, [comment], author in assoc(comment, :author))

lib/groupher_server/cms/cms.ex

+26-27
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ defmodule GroupherServer.CMS do
1212
ArticleCURD,
1313
ArticleCommunity,
1414
ArticleEmotion,
15-
ArticleComment,
15+
CommentCurd,
1616
ArticleCollect,
1717
ArticleUpvote,
18-
ArticleCommentAction,
19-
ArticleCommentEmotion,
18+
CommentAction,
19+
CommentEmotion,
2020
ArticleTag,
2121
CommunitySync,
2222
CommunityCURD,
@@ -125,38 +125,37 @@ defmodule GroupherServer.CMS do
125125
defdelegate undo_emotion_to_article(thread, article_id, args, user), to: ArticleEmotion
126126

127127
# Comment CURD
128-
defdelegate paged_article_comments(thread, article_id, filters, mode), to: ArticleComment
129-
defdelegate paged_article_comments(thread, article_id, filters, mode, user), to: ArticleComment
128+
defdelegate paged_comments(thread, article_id, filters, mode), to: CommentCurd
129+
defdelegate paged_comments(thread, article_id, filters, mode, user), to: CommentCurd
130130

131-
defdelegate paged_folded_article_comments(thread, article_id, filters), to: ArticleComment
132-
defdelegate paged_folded_article_comments(thread, article_id, filters, user), to: ArticleComment
131+
defdelegate paged_folded_article_comments(thread, article_id, filters), to: CommentCurd
132+
defdelegate paged_folded_article_comments(thread, article_id, filters, user), to: CommentCurd
133133

134-
defdelegate paged_comment_replies(comment_id, filters), to: ArticleComment
135-
defdelegate paged_comment_replies(comment_id, filters, user), to: ArticleComment
134+
defdelegate paged_comment_replies(comment_id, filters), to: CommentCurd
135+
defdelegate paged_comment_replies(comment_id, filters, user), to: CommentCurd
136136

137-
defdelegate paged_article_comments_participators(thread, content_id, filters),
138-
to: ArticleComment
137+
defdelegate paged_comments_participants(thread, content_id, filters), to: CommentCurd
139138

140-
defdelegate create_article_comment(thread, article_id, args, user), to: ArticleComment
141-
defdelegate update_article_comment(comment, content), to: ArticleComment
142-
defdelegate delete_article_comment(comment), to: ArticleComment
143-
defdelegate mark_comment_solution(comment, user), to: ArticleComment
144-
defdelegate undo_mark_comment_solution(comment, user), to: ArticleComment
139+
defdelegate create_comment(thread, article_id, args, user), to: CommentCurd
140+
defdelegate update_comment(comment, content), to: CommentCurd
141+
defdelegate delete_comment(comment), to: CommentCurd
142+
defdelegate mark_comment_solution(comment, user), to: CommentCurd
143+
defdelegate undo_mark_comment_solution(comment, user), to: CommentCurd
145144

146-
defdelegate upvote_article_comment(comment_id, user), to: ArticleCommentAction
147-
defdelegate undo_upvote_article_comment(comment_id, user), to: ArticleCommentAction
148-
defdelegate reply_article_comment(comment_id, args, user), to: ArticleCommentAction
149-
defdelegate lock_article_comment(thread, article_id), to: ArticleCommentAction
150-
defdelegate undo_lock_article_comment(thread, article_id), to: ArticleCommentAction
145+
defdelegate upvote_comment(comment_id, user), to: CommentAction
146+
defdelegate undo_upvote_comment(comment_id, user), to: CommentAction
147+
defdelegate reply_comment(comment_id, args, user), to: CommentAction
148+
defdelegate lock_article_comment(thread, article_id), to: CommentAction
149+
defdelegate undo_lock_article_comment(thread, article_id), to: CommentAction
151150

152-
defdelegate pin_article_comment(comment_id), to: ArticleCommentAction
153-
defdelegate undo_pin_article_comment(comment_id), to: ArticleCommentAction
151+
defdelegate pin_comment(comment_id), to: CommentAction
152+
defdelegate undo_pin_comment(comment_id), to: CommentAction
154153

155-
defdelegate fold_article_comment(comment_id, user), to: ArticleCommentAction
156-
defdelegate unfold_article_comment(comment_id, user), to: ArticleCommentAction
154+
defdelegate fold_article_comment(comment_id, user), to: CommentAction
155+
defdelegate unfold_article_comment(comment_id, user), to: CommentAction
157156

158-
defdelegate emotion_to_comment(comment_id, args, user), to: ArticleCommentEmotion
159-
defdelegate undo_emotion_to_comment(comment_id, args, user), to: ArticleCommentEmotion
157+
defdelegate emotion_to_comment(comment_id, args, user), to: CommentEmotion
158+
defdelegate undo_emotion_to_comment(comment_id, args, user), to: CommentEmotion
160159
###################
161160
###################
162161
###################

lib/groupher_server/cms/delegates/abuse_report.ex

+20-20
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do
1313
alias GroupherServer.{Accounts, CMS, Repo}
1414

1515
alias Accounts.Model.User
16-
alias CMS.Model.{AbuseReport, ArticleComment, Embeds}
16+
alias CMS.Model.{AbuseReport, Comment, Embeds}
1717

1818
alias Ecto.Multi
1919

2020
@article_threads get_config(:article, :threads)
21-
@report_threshold_for_fold ArticleComment.report_threshold_for_fold()
21+
@report_threshold_for_fold Comment.report_threshold_for_fold()
2222

2323
@export_author_keys [:id, :login, :nickname, :avatar]
2424
@export_article_keys [:id, :title, :digest, :upvotes_count, :views]
@@ -50,16 +50,16 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do
5050
@doc """
5151
list paged reports for article comemnts
5252
"""
53-
def paged_reports(%{content_type: :article_comment, content_id: content_id} = filter) do
54-
with {:ok, info} <- match(:article_comment) do
53+
def paged_reports(%{content_type: :comment, content_id: content_id} = filter) do
54+
with {:ok, info} <- match(:comment) do
5555
query =
5656
from(r in AbuseReport,
5757
where: field(r, ^info.foreign_key) == ^content_id,
58-
preload: [article_comment: ^@article_threads],
59-
preload: [article_comment: :author]
58+
preload: [comment: ^@article_threads],
59+
preload: [comment: :author]
6060
)
6161

62-
do_paged_reports(query, :article_comment, filter)
62+
do_paged_reports(query, :comment, filter)
6363
end
6464
end
6565

@@ -86,7 +86,7 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do
8686
from(r in AbuseReport,
8787
where: not is_nil(field(r, ^info.foreign_key)),
8888
preload: [^thread, :operate_user],
89-
preload: [article_comment: :author]
89+
preload: [comment: :author]
9090
)
9191

9292
do_paged_reports(query, thread, filter)
@@ -173,13 +173,13 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do
173173

174174
@doc "report a comment"
175175
def report_article_comment(comment_id, reason, attr, %User{} = user) do
176-
with {:ok, comment} <- ORM.find(ArticleComment, comment_id) do
176+
with {:ok, comment} <- ORM.find(Comment, comment_id) do
177177
Multi.new()
178178
|> Multi.run(:create_abuse_report, fn _, _ ->
179-
create_report(:article_comment, comment_id, reason, attr, user)
179+
create_report(:comment, comment_id, reason, attr, user)
180180
end)
181181
|> Multi.run(:update_report_meta, fn _, _ ->
182-
{:ok, info} = match(:article_comment)
182+
{:ok, info} = match(:comment)
183183
update_report_meta(info, comment)
184184
end)
185185
|> Multi.run(:fold_comment_report_too_many, fn _, %{create_abuse_report: abuse_report} ->
@@ -193,7 +193,7 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do
193193
end
194194

195195
def undo_report_article_comment(comment_id, %User{} = user) do
196-
undo_report_article(:article_comment, comment_id, user)
196+
undo_report_article(:comment, comment_id, user)
197197
end
198198

199199
defp do_paged_reports(query, thread, filter) do
@@ -320,13 +320,13 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do
320320
)
321321
end
322322

323-
defp reports_formater(%{entries: entries} = paged_reports, :article_comment) do
323+
defp reports_formater(%{entries: entries} = paged_reports, :comment) do
324324
paged_reports
325325
|> Map.put(
326326
:entries,
327327
Enum.map(entries, fn report ->
328328
basic_report = report |> Map.take(@export_report_keys)
329-
basic_report |> Map.put(:article_comment, extract_article_comment_info(report))
329+
basic_report |> Map.put(:comment, extract_article_comment_info(report))
330330
end)
331331
)
332332
end
@@ -357,23 +357,23 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do
357357

358358
def extract_article_comment_info(%AbuseReport{} = report) do
359359
keys = [:id, :upvotes_count, :body_html]
360-
author = Map.take(report.article_comment.author, @export_author_keys)
360+
author = Map.take(report.comment.author, @export_author_keys)
361361

362-
comment = Map.take(report.article_comment, keys)
362+
comment = Map.take(report.comment, keys)
363363
comment = Map.merge(comment, %{author: author})
364364

365-
article = extract_article_in_comment(report.article_comment)
365+
article = extract_article_in_comment(report.comment)
366366
Map.merge(comment, %{article: article})
367367
end
368368

369-
defp extract_article_in_comment(%ArticleComment{} = article_comment) do
369+
defp extract_article_in_comment(%Comment{} = comment) do
370370
article_thread =
371371
Enum.filter(@article_threads, fn thread ->
372-
not is_nil(Map.get(article_comment, :"#{thread}_id"))
372+
not is_nil(Map.get(comment, :"#{thread}_id"))
373373
end)
374374
|> List.first()
375375

376-
article_comment
376+
comment
377377
|> Map.get(article_thread)
378378
|> Map.take(@export_article_keys)
379379
|> Map.merge(%{thread: article_thread})

lib/groupher_server/cms/delegates/article_curd.ex

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do
1818

1919
alias Accounts.Model.User
2020
alias CMS.Model.{Author, Community, PinnedArticle, Embeds}
21-
alias CMS.Delegate.{ArticleCommunity, ArticleComment, ArticleTag, CommunityCURD, CiteTasks}
21+
alias CMS.Delegate.{ArticleCommunity, CommentCurd, ArticleTag, CommunityCURD, CiteTasks}
2222

2323
alias Ecto.Multi
2424

@@ -216,7 +216,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do
216216
|> Multi.run(:update_comment_question_flag_if_need, fn _, %{update_article: update_article} ->
217217
# 如果帖子的类型变了,那么 update 所有的 flag
218218
case Map.has_key?(args, :is_question) do
219-
true -> ArticleComment.batch_update_question_flag(update_article)
219+
true -> CommentCurd.batch_update_question_flag(update_article)
220220
false -> {:ok, :pass}
221221
end
222222
end)

lib/groupher_server/cms/delegates/article_emotion.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleEmotion do
7777
end
7878
end
7979

80-
# @spec query_emotion_status(ArticleComment.t(), Atom.t()) :: {:ok, t_mention_status}
80+
# @spec query_emotion_status(Comment.t(), Atom.t()) :: {:ok, t_mention_status}
8181
defp query_emotion_status(thread, article_id, emotion) do
8282
with {:ok, info} <- match(thread) do
8383
# 每次被 emotion 动作触发后重新查询,主要原因

0 commit comments

Comments
 (0)