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

refactor(article-comment): remove article prefix #397

Merged
merged 18 commits into from
Jun 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/groupher_server/accounts/delegates/publish.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ defmodule GroupherServer.Accounts.Delegate.Publish do
import GroupherServer.CMS.Helper.Matcher

alias GroupherServer.Accounts.Model.{Embeds, User}
alias GroupherServer.CMS.Model.ArticleComment
alias GroupherServer.CMS.Model.Comment

alias Helper.{ORM, QueryBuilder}

Expand Down Expand Up @@ -56,7 +56,7 @@ defmodule GroupherServer.Accounts.Delegate.Publish do

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

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

query
|> join(:inner, [comment], author in assoc(comment, :author))
Expand Down
53 changes: 26 additions & 27 deletions lib/groupher_server/cms/cms.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ defmodule GroupherServer.CMS do
ArticleCURD,
ArticleCommunity,
ArticleEmotion,
ArticleComment,
CommentCurd,
ArticleCollect,
ArticleUpvote,
ArticleCommentAction,
ArticleCommentEmotion,
CommentAction,
CommentEmotion,
ArticleTag,
CommunitySync,
CommunityCURD,
Expand Down Expand Up @@ -125,38 +125,37 @@ defmodule GroupherServer.CMS do
defdelegate undo_emotion_to_article(thread, article_id, args, user), to: ArticleEmotion

# Comment CURD
defdelegate paged_article_comments(thread, article_id, filters, mode), to: ArticleComment
defdelegate paged_article_comments(thread, article_id, filters, mode, user), to: ArticleComment
defdelegate paged_comments(thread, article_id, filters, mode), to: CommentCurd
defdelegate paged_comments(thread, article_id, filters, mode, user), to: CommentCurd

defdelegate paged_folded_article_comments(thread, article_id, filters), to: ArticleComment
defdelegate paged_folded_article_comments(thread, article_id, filters, user), to: ArticleComment
defdelegate paged_folded_article_comments(thread, article_id, filters), to: CommentCurd
defdelegate paged_folded_article_comments(thread, article_id, filters, user), to: CommentCurd

defdelegate paged_comment_replies(comment_id, filters), to: ArticleComment
defdelegate paged_comment_replies(comment_id, filters, user), to: ArticleComment
defdelegate paged_comment_replies(comment_id, filters), to: CommentCurd
defdelegate paged_comment_replies(comment_id, filters, user), to: CommentCurd

defdelegate paged_article_comments_participators(thread, content_id, filters),
to: ArticleComment
defdelegate paged_comments_participants(thread, content_id, filters), to: CommentCurd

defdelegate create_article_comment(thread, article_id, args, user), to: ArticleComment
defdelegate update_article_comment(comment, content), to: ArticleComment
defdelegate delete_article_comment(comment), to: ArticleComment
defdelegate mark_comment_solution(comment, user), to: ArticleComment
defdelegate undo_mark_comment_solution(comment, user), to: ArticleComment
defdelegate create_comment(thread, article_id, args, user), to: CommentCurd
defdelegate update_comment(comment, content), to: CommentCurd
defdelegate delete_comment(comment), to: CommentCurd
defdelegate mark_comment_solution(comment, user), to: CommentCurd
defdelegate undo_mark_comment_solution(comment, user), to: CommentCurd

defdelegate upvote_article_comment(comment_id, user), to: ArticleCommentAction
defdelegate undo_upvote_article_comment(comment_id, user), to: ArticleCommentAction
defdelegate reply_article_comment(comment_id, args, user), to: ArticleCommentAction
defdelegate lock_article_comment(thread, article_id), to: ArticleCommentAction
defdelegate undo_lock_article_comment(thread, article_id), to: ArticleCommentAction
defdelegate upvote_comment(comment_id, user), to: CommentAction
defdelegate undo_upvote_comment(comment_id, user), to: CommentAction
defdelegate reply_comment(comment_id, args, user), to: CommentAction
defdelegate lock_article_comment(thread, article_id), to: CommentAction
defdelegate undo_lock_article_comment(thread, article_id), to: CommentAction

defdelegate pin_article_comment(comment_id), to: ArticleCommentAction
defdelegate undo_pin_article_comment(comment_id), to: ArticleCommentAction
defdelegate pin_comment(comment_id), to: CommentAction
defdelegate undo_pin_comment(comment_id), to: CommentAction

defdelegate fold_article_comment(comment_id, user), to: ArticleCommentAction
defdelegate unfold_article_comment(comment_id, user), to: ArticleCommentAction
defdelegate fold_article_comment(comment_id, user), to: CommentAction
defdelegate unfold_article_comment(comment_id, user), to: CommentAction

defdelegate emotion_to_comment(comment_id, args, user), to: ArticleCommentEmotion
defdelegate undo_emotion_to_comment(comment_id, args, user), to: ArticleCommentEmotion
defdelegate emotion_to_comment(comment_id, args, user), to: CommentEmotion
defdelegate undo_emotion_to_comment(comment_id, args, user), to: CommentEmotion
###################
###################
###################
Expand Down
40 changes: 20 additions & 20 deletions lib/groupher_server/cms/delegates/abuse_report.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do
alias GroupherServer.{Accounts, CMS, Repo}

alias Accounts.Model.User
alias CMS.Model.{AbuseReport, ArticleComment, Embeds}
alias CMS.Model.{AbuseReport, Comment, Embeds}

alias Ecto.Multi

@article_threads get_config(:article, :threads)
@report_threshold_for_fold ArticleComment.report_threshold_for_fold()
@report_threshold_for_fold Comment.report_threshold_for_fold()

@export_author_keys [:id, :login, :nickname, :avatar]
@export_article_keys [:id, :title, :digest, :upvotes_count, :views]
Expand Down Expand Up @@ -50,16 +50,16 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do
@doc """
list paged reports for article comemnts
"""
def paged_reports(%{content_type: :article_comment, content_id: content_id} = filter) do
with {:ok, info} <- match(:article_comment) do
def paged_reports(%{content_type: :comment, content_id: content_id} = filter) do
with {:ok, info} <- match(:comment) do
query =
from(r in AbuseReport,
where: field(r, ^info.foreign_key) == ^content_id,
preload: [article_comment: ^@article_threads],
preload: [article_comment: :author]
preload: [comment: ^@article_threads],
preload: [comment: :author]
)

do_paged_reports(query, :article_comment, filter)
do_paged_reports(query, :comment, filter)
end
end

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

do_paged_reports(query, thread, filter)
Expand Down Expand Up @@ -173,13 +173,13 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do

@doc "report a comment"
def report_article_comment(comment_id, reason, attr, %User{} = user) do
with {:ok, comment} <- ORM.find(ArticleComment, comment_id) do
with {:ok, comment} <- ORM.find(Comment, comment_id) do
Multi.new()
|> Multi.run(:create_abuse_report, fn _, _ ->
create_report(:article_comment, comment_id, reason, attr, user)
create_report(:comment, comment_id, reason, attr, user)
end)
|> Multi.run(:update_report_meta, fn _, _ ->
{:ok, info} = match(:article_comment)
{:ok, info} = match(:comment)
update_report_meta(info, comment)
end)
|> Multi.run(:fold_comment_report_too_many, fn _, %{create_abuse_report: abuse_report} ->
Expand All @@ -193,7 +193,7 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do
end

def undo_report_article_comment(comment_id, %User{} = user) do
undo_report_article(:article_comment, comment_id, user)
undo_report_article(:comment, comment_id, user)
end

defp do_paged_reports(query, thread, filter) do
Expand Down Expand Up @@ -320,13 +320,13 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do
)
end

defp reports_formater(%{entries: entries} = paged_reports, :article_comment) do
defp reports_formater(%{entries: entries} = paged_reports, :comment) do
paged_reports
|> Map.put(
:entries,
Enum.map(entries, fn report ->
basic_report = report |> Map.take(@export_report_keys)
basic_report |> Map.put(:article_comment, extract_article_comment_info(report))
basic_report |> Map.put(:comment, extract_article_comment_info(report))
end)
)
end
Expand Down Expand Up @@ -357,23 +357,23 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do

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

comment = Map.take(report.article_comment, keys)
comment = Map.take(report.comment, keys)
comment = Map.merge(comment, %{author: author})

article = extract_article_in_comment(report.article_comment)
article = extract_article_in_comment(report.comment)
Map.merge(comment, %{article: article})
end

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

article_comment
comment
|> Map.get(article_thread)
|> Map.take(@export_article_keys)
|> Map.merge(%{thread: article_thread})
Expand Down
4 changes: 2 additions & 2 deletions lib/groupher_server/cms/delegates/article_curd.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do

alias Accounts.Model.User
alias CMS.Model.{Author, Community, PinnedArticle, Embeds}
alias CMS.Delegate.{ArticleCommunity, ArticleComment, ArticleTag, CommunityCURD, CiteTasks}
alias CMS.Delegate.{ArticleCommunity, CommentCurd, ArticleTag, CommunityCURD, CiteTasks}

alias Ecto.Multi

Expand Down Expand Up @@ -216,7 +216,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do
|> Multi.run(:update_comment_question_flag_if_need, fn _, %{update_article: update_article} ->
# 如果帖子的类型变了,那么 update 所有的 flag
case Map.has_key?(args, :is_question) do
true -> ArticleComment.batch_update_question_flag(update_article)
true -> CommentCurd.batch_update_question_flag(update_article)
false -> {:ok, :pass}
end
end)
Expand Down
2 changes: 1 addition & 1 deletion lib/groupher_server/cms/delegates/article_emotion.ex
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleEmotion do
end
end

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