This repository was archived by the owner on Nov 8, 2022. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork20
refactor(comments-redesign): rewrite, enhance#319
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
48 commits Select commitHold shift + click to select a range
775cd1c
refactor(article-comments): basic write & upvote impl
mydearxymf18a4d1
refactor(article-comments): wip
mydearxymb6911fd
refactor(article-comments): test embed association workflow
mydearxym7048f0c
refactor(article-comments): comment_participators workflow test, WOW!
mydearxym9ad0cd1
refactor(article-comments): add participators after comment created
mydearxym5c06ab0
refactor(article-comments): add gq test
mydearxym69de473
refactor(article-comments): clean up
mydearxymb4fff1a
refactor(article-comments): fix test err/warings
mydearxym1b034b1
refactor(article-comments): nested reply wip
mydearxyme2d4382
refactor(article-comments): more test on reply
mydearxym3c34d83
refactor(article-comments): replies basic logic done
mydearxymc661ef4
refactor(article-comments): replies count logic
mydearxymf60e436
refactor(article-comments): paged replies logic
mydearxymfa06c78
refactor(article-comments): basic emotion setup
mydearxymc5a830a
refactor(post-meta): emotions wip
mydearxymb858bb9
refactor(article-comments): basic emotion wip
mydearxymd8bf2c3
refactor(article-comments): emotion curd done
mydearxym6b5bfa6
refactor(article-comments): viewer_has_emotioned wip
mydearxym9150348
refactor(article-comments): re-org wip
mydearxymf76cbd0
refactor(article-comments): re-org wip
mydearxym62f2265
refactor(article-comments): re-org wip
mydearxym586373f
refactor(article-comments): naming re-org
mydearxym52c1349
refactor(article-comments): clean up
mydearxym1b98ba9
refactor(article-comments): make emotion dynamicly
mydearxym46d6250
refactor(article-comments): fold/unfold done
mydearxym2904cdd
refactor(article-comments): paged fold/unfold done
mydearxym9838245
refactor(article-comments): paged report/unreport done
mydearxym5da19b3
refactor(article-comments): floor done
mydearxym325b834
refactor(article-comments): write_comment -> create_article_comment
mydearxym8bf2fe9
refactor(article-comments): upvote_comment -> upvote_article_comment
mydearxymb033be8
refactor(article-comments): delete comment logic
mydearxym9e639c9
refactor(article-comments): is_article_author flag
mydearxymaf627c9
refactor(article-comments): upvotes_count logic
mydearxymc40fd00
refactor(article-comments): rm old job comments & logic
mydearxym14ed577
refactor(article-comments): rm old repo comments & logic
mydearxymc232ec8
refactor(article-comments): rm job/repo GQ comments test
mydearxymbef5f32
Merge branch 'dev' into comments-redesign
mydearxymbb7baca
refactor(article-comments): rm post comment dislike
mydearxym3b51f03
refactor(article-comments): add meta embeds
mydearxymad7814e
refactor(article-comments): abuse_reports setup
mydearxymf523b9d
refactor(article-comments): abuse_reports wip
mydearxym2794e01
refactor(article-comments): abuse_reports wip
mydearxyme22113a
refactor(article-comments): abuse_reports re-org wip
mydearxymba52fac
refactor(article-comments): clean up unused var in tests
mydearxym7e57070
refactor(article-comments): @report_threshold_for_fold logic
mydearxyma0ac4be
refactor(article-comments): wip
mydearxymea2598f
refactor(article-comments): fix broken tests
mydearxymd772a78
refactor(post-meta): fix ci tests & warnings
mydearxymFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
45 changes: 45 additions & 0 deletionslib/groupher_server/cms/abuse_report.ex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
defmodule GroupherServer.CMS.AbuseReport do | ||
@moduledoc false | ||
alias __MODULE__ | ||
use Ecto.Schema | ||
import Ecto.Changeset | ||
alias GroupherServer.{Accounts, CMS} | ||
alias CMS.{ArticleComment, Embeds, Post, Job} | ||
# @required_fields ~w(article_comment_id user_id recived_user_id)a | ||
@optional_fields ~w(article_comment_id post_id job_id account_id operate_user_id deal_with is_closed report_cases_count)a | ||
@update_fields ~w(operate_user_id deal_with is_closed report_cases_count)a | ||
@type t :: %AbuseReport{} | ||
schema "abuse_reports" do | ||
belongs_to(:article_comment, ArticleComment, foreign_key: :article_comment_id) | ||
belongs_to(:post, Post, foreign_key: :post_id) | ||
belongs_to(:job, Job, foreign_key: :job_id) | ||
belongs_to(:account, Accounts.User, foreign_key: :account_id) | ||
embeds_many(:report_cases, Embeds.AbuseReportCase, on_replace: :delete) | ||
field(:report_cases_count, :integer, default: 0) | ||
belongs_to(:operate_user, Accounts.User, foreign_key: :operate_user_id) | ||
field(:deal_with, :string) | ||
field(:is_closed, :boolean, default: false) | ||
timestamps(type: :utc_datetime) | ||
end | ||
@doc false | ||
def changeset(%AbuseReport{} = struct, attrs) do | ||
struct | ||
|> cast(attrs, @optional_fields) | ||
|> cast_embed(:report_cases, required: true, with: &Embeds.AbuseReportCase.changeset/2) | ||
end | ||
def update_changeset(%AbuseReport{} = struct, attrs) do | ||
struct | ||
|> cast(attrs, @update_fields) | ||
|> cast_embed(:report_cases, required: true, with: &Embeds.AbuseReportCase.changeset/2) | ||
end | ||
end |
104 changes: 104 additions & 0 deletionslib/groupher_server/cms/article_comment.ex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
defmodule GroupherServer.CMS.ArticleComment do | ||
@moduledoc false | ||
alias __MODULE__ | ||
use Ecto.Schema | ||
use Accessible | ||
import Ecto.Changeset | ||
alias GroupherServer.{Accounts, CMS} | ||
alias CMS.{ | ||
Post, | ||
Job, | ||
Embeds, | ||
ArticleCommentUpvote | ||
} | ||
# alias Helper.HTML | ||
@required_fields ~w(body_html author_id)a | ||
@optional_fields ~w(post_id job_id reply_to_id replies_count is_folded is_reported is_deleted floor is_article_author)a | ||
@updatable_fields ~w(is_folded is_reported is_deleted floor upvotes_count)a | ||
@max_participator_count 5 | ||
@max_parent_replies_count 3 | ||
@supported_emotions [:downvote, :beer, :heart, :biceps, :orz, :confused, :pill] | ||
@max_latest_emotion_users_count 5 | ||
@delete_hint "this comment is deleted" | ||
# 举报超过此数评论会被自动折叠 | ||
@report_threshold_for_fold 5 | ||
@doc "latest participators stores in article comment_participators field" | ||
def max_participator_count(), do: @max_participator_count | ||
@doc "latest replies stores in article_comment replies field, used for frontend display" | ||
def max_parent_replies_count(), do: @max_parent_replies_count | ||
@doc "操作某 emotion 的最近用户" | ||
def max_latest_emotion_users_count(), do: @max_latest_emotion_users_count | ||
def supported_emotions(), do: @supported_emotions | ||
def delete_hint(), do: @delete_hint | ||
def report_threshold_for_fold, do: @report_threshold_for_fold | ||
@type t :: %ArticleComment{} | ||
schema "articles_comments" do | ||
field(:body_html, :string) | ||
field(:replies_count, :integer, default: 0) | ||
# 是否被折叠 | ||
field(:is_folded, :boolean, default: false) | ||
# 是否被举报 | ||
field(:is_reported, :boolean, default: false) | ||
# 是否被删除 | ||
field(:is_deleted, :boolean, default: false) | ||
# 楼层 | ||
field(:floor, :integer, default: 0) | ||
# 是否是评论文章的作者 | ||
field(:is_article_author, :boolean, default: false) | ||
field(:upvotes_count, :integer, default: 0) | ||
belongs_to(:author, Accounts.User, foreign_key: :author_id) | ||
belongs_to(:post, Post, foreign_key: :post_id) | ||
belongs_to(:job, Job, foreign_key: :job_id) | ||
belongs_to(:reply_to, ArticleComment, foreign_key: :reply_to_id) | ||
embeds_many(:replies, ArticleComment, on_replace: :delete) | ||
embeds_one(:emotions, Embeds.ArticleCommentEmotion, on_replace: :update) | ||
embeds_one(:meta, Embeds.ArticleCommentMeta, on_replace: :update) | ||
has_many(:upvotes, {"articles_comments_upvotes", ArticleCommentUpvote}) | ||
timestamps(type: :utc_datetime) | ||
end | ||
@doc false | ||
def changeset(%ArticleComment{} = article_comment, attrs) do | ||
article_comment | ||
|> cast(attrs, @required_fields ++ @optional_fields) | ||
|> cast_embed(:emotions, required: true, with: &Embeds.ArticleCommentEmotion.changeset/2) | ||
|> validate_required(@required_fields) | ||
|> generl_changeset | ||
end | ||
# @doc false | ||
def update_changeset(%ArticleComment{} = article_comment, attrs) do | ||
article_comment | ||
|> cast(attrs, @required_fields ++ @updatable_fields) | ||
# |> cast_embed(:emotions, required: false, with: &Embeds.ArticleCommentEmotion.changeset/2) | ||
|> generl_changeset | ||
end | ||
defp generl_changeset(content) do | ||
content | ||
|> foreign_key_constraint(:author_id) | ||
# |> validate_length(:body_html, min: 3, max: 2000) | ||
# |> HTML.safe_string(:body_html) | ||
end | ||
end |
24 changes: 24 additions & 0 deletionslib/groupher_server/cms/article_comment_participator.ex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
defmodule GroupherServer.CMS.ArticleCommentParticipator do | ||
@moduledoc false | ||
use Ecto.Schema | ||
alias GroupherServer.Accounts.User | ||
# alias CMS.{ | ||
# Post, | ||
# Job, | ||
# ArticleCommentUpvote | ||
# } | ||
# alias Helper.HTML | ||
# @required_fields ~w(user_id)a | ||
# @optional_fields ~w(post_id job_id)a | ||
embedded_schema do | ||
# field(:reply_time, :string) | ||
belongs_to(:user, User) | ||
end | ||
end |
29 changes: 29 additions & 0 deletionslib/groupher_server/cms/article_comment_reply.ex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
defmodule GroupherServer.CMS.ArticleCommentReply do | ||
@moduledoc false | ||
alias __MODULE__ | ||
use Ecto.Schema | ||
import Ecto.Changeset | ||
alias GroupherServer.CMS | ||
alias CMS.ArticleComment | ||
@required_fields ~w(article_comment_id reply_to_id)a | ||
@type t :: %ArticleCommentReply{} | ||
schema "articles_comments_replies" do | ||
belongs_to(:article_comment, ArticleComment, foreign_key: :article_comment_id) | ||
belongs_to(:reply_to, ArticleComment, foreign_key: :reply_to_id) | ||
timestamps(type: :utc_datetime) | ||
end | ||
@doc false | ||
def changeset(%ArticleCommentReply{} = article_comment_reply, attrs) do | ||
article_comment_reply | ||
|> cast(attrs, @required_fields) | ||
|> validate_required(@required_fields) | ||
|> foreign_key_constraint(:article_comment_id) | ||
|> foreign_key_constraint(:reply_to_id) | ||
end | ||
end |
32 changes: 32 additions & 0 deletionslib/groupher_server/cms/article_comment_upvote.ex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
defmodule GroupherServer.CMS.ArticleCommentUpvote do | ||
@moduledoc false | ||
alias __MODULE__ | ||
use Ecto.Schema | ||
import Ecto.Changeset | ||
alias GroupherServer.{Accounts, CMS} | ||
alias CMS.ArticleComment | ||
@required_fields ~w(article_comment_id user_id)a | ||
@type t :: %ArticleCommentUpvote{} | ||
schema "articles_comments_upvotes" do | ||
belongs_to(:user, Accounts.User, foreign_key: :user_id) | ||
belongs_to(:article_comment, ArticleComment, foreign_key: :article_comment_id) | ||
timestamps(type: :utc_datetime) | ||
end | ||
@doc false | ||
def changeset(%ArticleCommentUpvote{} = article_comment_upvote, attrs) do | ||
article_comment_upvote | ||
|> cast(attrs, @required_fields) | ||
|> validate_required(@required_fields) | ||
|> foreign_key_constraint(:article_comment_id) | ||
|> foreign_key_constraint(:user_id) | ||
|> unique_constraint(:user_id, | ||
name: :articles_comments_upvotes_user_id_article_comment_id_index | ||
) | ||
end | ||
end |
40 changes: 40 additions & 0 deletionslib/groupher_server/cms/article_comment_user_emotion.ex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
defmodule GroupherServer.CMS.ArticleCommentUserEmotion do | ||
@moduledoc false | ||
alias __MODULE__ | ||
use Ecto.Schema | ||
import Ecto.Changeset | ||
alias GroupherServer.{Accounts, CMS} | ||
alias CMS.ArticleComment | ||
@required_fields ~w(article_comment_id user_id recived_user_id)a | ||
@optional_fields ~w(downvote beer heart biceps orz confused pill)a | ||
@type t :: %ArticleCommentUserEmotion{} | ||
schema "articles_comments_users_emotions" do | ||
belongs_to(:article_comment, ArticleComment, foreign_key: :article_comment_id) | ||
belongs_to(:recived_user, Accounts.User, foreign_key: :recived_user_id) | ||
belongs_to(:user, Accounts.User, foreign_key: :user_id) | ||
field(:downvote, :boolean, default: false) | ||
field(:beer, :boolean, default: false) | ||
field(:heart, :boolean, default: false) | ||
field(:biceps, :boolean, default: false) | ||
field(:orz, :boolean, default: false) | ||
field(:confused, :boolean, default: false) | ||
field(:pill, :boolean, default: false) | ||
timestamps(type: :utc_datetime) | ||
end | ||
@doc false | ||
def changeset(%ArticleCommentUserEmotion{} = struct, attrs) do | ||
struct | ||
|> cast(attrs, @required_fields ++ @optional_fields) | ||
|> validate_required(@required_fields) | ||
|> foreign_key_constraint(:article_comment_id) | ||
|> foreign_key_constraint(:user_id) | ||
|> foreign_key_constraint(:recived_user_id) | ||
end | ||
end |
30 changes: 27 additions & 3 deletionslib/groupher_server/cms/cms.ex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletionlib/groupher_server/cms/community.ex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -10,7 +10,6 @@ defmodule GroupherServer.CMS.Community do | ||
alias CMS.{ | ||
Category, | ||
Post, | ||
Repo, | ||
Job, | ||
CommunityThread, | ||
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.