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.

Commitf529bff

Browse files
committed
fix(article): comments_participants_count logic
1 parent66f7004 commitf529bff

File tree

4 files changed

+12
-6
lines changed

4 files changed

+12
-6
lines changed

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ defmodule GroupherServer.CMS.Delegate.CommentCurd do
33
CURD and operations for article comments
44
"""
55
importEcto.Query,warn:false
6-
importHelper.Utils,only:[done:1,ensure:2,get_config:2]
6+
importHelper.Utils,only:[done:1,ensure:2,strip_struct:1,get_config:2]
77
importHelper.ErrorCode
88

99
importGroupherServer.CMS.Delegate.Helper,
@@ -291,13 +291,17 @@ defmodule GroupherServer.CMS.Delegate.CommentCurd do
291291
defadd_participant_to_article(%{comments_participants:participants}=article,%User{}=user)do
292292
cur_participants=participants|>List.insert_at(0,user)|>Enum.uniq_by(&&1.id)
293293

294+
meta=article.meta|>strip_struct
295+
cur_participants_ids=(meta.comments_participant_user_ids++[user.id])|>Enum.uniq()
296+
meta=Map.merge(meta,%{comments_participant_user_ids:cur_participants_ids})
297+
294298
latest_participants=cur_participants|>Enum.slice(0,@max_participator_count)
295-
total_participants_count=article.comments_participants_count+1
296299

297300
article
298301
|>Ecto.Changeset.change()
299-
|>Ecto.Changeset.put_change(:comments_participants_count,total_participants_count)
302+
|>Ecto.Changeset.put_change(:comments_participants_count,cur_participants_ids|>length)
300303
|>Ecto.Changeset.put_embed(:comments_participants,latest_participants)
304+
|>Ecto.Changeset.put_embed(:meta,meta)
301305
|>Repo.update()
302306
end
303307

‎lib/groupher_server/cms/models/embeds/article_meta.ex‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ defmodule GroupherServer.CMS.Model.Embeds.ArticleMeta do
88

99
aliasGroupherServer.CMS.Model.Embeds
1010

11-
@optional_fields~w(thread is_edited is_comment_locked upvoted_user_ids collected_user_ids viewed_user_ids reported_user_ids reported_count is_sinked can_undo_sink last_active_at)a
11+
@optional_fields~w(thread is_edited is_comment_locked upvoted_user_ids collected_user_ids viewed_user_idscomments_participant_user_idsreported_user_ids reported_count is_sinked can_undo_sink last_active_at)a
1212

1313
@doc"for test usage"
1414
defdefault_meta()do
@@ -21,6 +21,7 @@ defmodule GroupherServer.CMS.Model.Embeds.ArticleMeta do
2121
collected_user_ids:[],
2222
viewed_user_ids:[],
2323
reported_user_ids:[],
24+
comments_participant_user_ids:[],
2425
reported_count:0,
2526
is_sinked:false,
2627
can_undo_sink:true,
@@ -44,6 +45,8 @@ defmodule GroupherServer.CMS.Model.Embeds.ArticleMeta do
4445
field(:reported_user_ids,{:array,:integer},default:[])
4546
field(:reported_count,:integer,default:0)
4647

48+
field(:comments_participant_user_ids,{:array,:integer},default:[])
49+
4750
field(:is_sinked,:boolean,default:false)
4851
field(:can_undo_sink,:boolean,default:false)
4952
# if undo_sink, can recover last active_at from here

‎test/groupher_server/seeds/articles_seed_test.exs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ defmodule GroupherServer.Test.Seeds.Articles do
1111
aliasHelper.ORM
1212

1313
describe"[posts seed]"do
14-
@tag:wip
1514
test"can seed posts"do
1615
{:ok,community}=CMS.seed_community(:home)
1716
CMS.seed_articles(community,:post,5)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ defmodule GroupherServer.Test.Query.Comments.GuideComment do
3030
}
3131
}
3232
"""
33-
33+
@tag:wip
3434
test"guest user can get comment participants after comment created",
3535
~m(guest_conn guide user user2)ado
3636
total_count=5

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp