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.

Commit96583cd

Browse files
committed
fix(emotion): set viewer status after emontion to comment & re-org
1 parent0028ffb commit96583cd

File tree

5 files changed

+73
-35
lines changed

5 files changed

+73
-35
lines changed

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

Lines changed: 3 additions & 3 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:3,article_of:1,thread_of:1]
10+
only:[mark_viewer_emotion_states:2,article_of:1,thread_of:1]
1111

1212
importGroupherServer.CMS.Helper.Matcher
1313
importShortMaps
@@ -387,7 +387,7 @@ defmodule GroupherServer.CMS.Delegate.CommentCurd do
387387
|>QueryBuilder.filter_pack(Map.merge(filters,%{sort:sort}))
388388
|>ORM.paginator(~m(page size)a)
389389
|>add_pinned_comments_ifneed(thread,article_id,filters)
390-
|>mark_viewer_emotion_states(user,:comment)
390+
|>mark_viewer_emotion_states(user)
391391
|>mark_viewer_has_upvoted(user)
392392
|>done()
393393
end
@@ -403,7 +403,7 @@ defmodule GroupherServer.CMS.Delegate.CommentCurd do
403403
|>where(^where_query)
404404
|>QueryBuilder.filter_pack(filters)
405405
|>ORM.paginator(~m(page size)a)
406-
|>mark_viewer_emotion_states(user,:comment)
406+
|>mark_viewer_emotion_states(user)
407407
|>mark_viewer_has_upvoted(user)
408408
|>done()
409409
end

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

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ defmodule GroupherServer.CMS.Delegate.CommentEmotion do
44
"""
55
importEcto.Query,warn:false
66

7-
importGroupherServer.CMS.Delegate.Helper,only:[update_emotions_field:4]
7+
importHelper.Utils,only:[done:1]
8+
9+
importGroupherServer.CMS.Delegate.Helper,
10+
only:[update_emotions_field:4,mark_viewer_emotion_states:2]
811

912
aliasHelper.ORM
1013
aliasGroupherServer.{Accounts,CMS,Repo}
@@ -36,13 +39,16 @@ defmodule GroupherServer.CMS.Delegate.CommentEmotion do
3639
end
3740
end)
3841
|>Multi.run(:query_emotion_states,fn_,_->
42+
# query_emotion_states2(comment)
3943
query_emotion_states(comment,emotion)
4044
end)
4145
|>Multi.run(:update_emotions_field,fn_,%{query_emotion_states:status}->
42-
update_emotions_field(comment,emotion,status,user)
46+
with{:ok,comment}<-update_emotions_field(comment,emotion,status,user)do
47+
mark_viewer_emotion_states(comment,user)|>done
48+
end
4349
end)
4450
|>Repo.transaction()
45-
|>update_emotions_field_result
51+
|>result
4652
end
4753
end
4854

@@ -69,10 +75,12 @@ defmodule GroupherServer.CMS.Delegate.CommentEmotion do
6975
query_emotion_states(comment,emotion)
7076
end)
7177
|>Multi.run(:update_emotions_field,fn_,%{query_emotion_states:status}->
72-
update_emotions_field(comment,emotion,status,user)
78+
with{:ok,comment}<-update_emotions_field(comment,emotion,status,user)do
79+
mark_viewer_emotion_states(comment,user)|>done
80+
end
7381
end)
7482
|>Repo.transaction()
75-
|>update_emotions_field_result
83+
|>result
7684
end
7785
end
7886

@@ -96,9 +104,9 @@ defmodule GroupherServer.CMS.Delegate.CommentEmotion do
96104
{:ok,%{user_list:emotioned_user_info_list,user_count:emotioned_user_count}}
97105
end
98106

99-
defpupdate_emotions_field_result({:ok,%{update_emotions_field:result}}),do:{:ok,result}
107+
defpresult({:ok,%{update_emotions_field:result}}),do:{:ok,result}
100108

101-
defpupdate_emotions_field_result({:error,_,result,_steps})do
109+
defpresult({:error,_,result,_steps})do
102110
{:error,result}
103111
end
104112
end

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

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -70,44 +70,44 @@ defmodule GroupherServer.CMS.Delegate.Helper do
7070
#######
7171
# emotion related
7272
#######
73-
defpget_supported_mentions(:comment),do:@supported_comment_emotions
74-
defpget_supported_mentions(_),do:@supported_emotions
7573

7674
defmark_viewer_emotion_states(paged_artiments,nil),do:paged_artiments
7775
defmark_viewer_emotion_states(%{entries:[]}=paged_artiments,_),do:paged_artiments
78-
defmark_viewer_emotion_states(paged_artiments,nil,:comment),do:paged_artiments
7976

8077
@doc"""
8178
mark viewer emotions status for article or comment
8279
"""
83-
defmark_viewer_emotion_states(
84-
%{entries:entries}=paged_artiments,
85-
%User{}=user,
86-
type\\:article
87-
)do
88-
supported_emotions=get_supported_mentions(type)
89-
90-
new_entries=
91-
Enum.map(entries,fnarticle->
92-
update_viewed_status=
93-
supported_emotions
94-
|>Enum.reduce([],fnemotion,acc->
95-
already_emotioned=user_in_logins?(article.emotions[:"#{emotion}_user_logins"],user)
96-
acc++["viewer_has_#{emotion}ed":already_emotioned]
97-
end)
98-
|>Enum.into(%{})
99-
100-
updated_emotions=Map.merge(article.emotions,update_viewed_status)
101-
Map.put(article,:emotions,updated_emotions)
80+
defmark_viewer_emotion_states(%{entries:entries}=artiments,%User{}=user)do
81+
new_entries=Enum.map(entries,&mark_viewer_emotion_states(&1,user))
82+
%{artiments|entries:new_entries}
83+
end
84+
85+
defmark_viewer_emotion_states(%Comment{}=comment,%User{}=user)do
86+
do_mark_viewer_emotion_states(comment,user,@supported_comment_emotions)
87+
end
88+
89+
defmark_viewer_emotion_states(article,%User{}=user)do
90+
do_mark_viewer_emotion_states(article,user,@supported_emotions)
91+
end
92+
93+
defpdo_mark_viewer_emotion_states(artiment,%User{}=user,emotions)do
94+
update_viewed_status=
95+
emotions
96+
|>Enum.reduce([],fnemotion,acc->
97+
already_emotioned=user_in_logins?(artiment.emotions[:"#{emotion}_user_logins"],user)
98+
acc++["viewer_has_#{emotion}ed":already_emotioned]
10299
end)
100+
|>Enum.into(%{})
101+
102+
updated_emotions=Map.merge(artiment.emotions,update_viewed_status)
103103

104-
%{paged_artiments|entries:new_entries}
104+
%{artiment|emotions:updated_emotions}
105105
end
106106

107107
@doc"""
108108
update emotions field for boty article and comment
109109
"""
110-
defupdate_emotions_field(content,emotion,status,user)do
110+
defupdate_emotions_field(artiment,emotion,status,user)do
111111
%{user_count:user_count,user_list:user_list}=status
112112

113113
emotions=
@@ -122,7 +122,7 @@ defmodule GroupherServer.CMS.Delegate.Helper do
122122
viewer_has_emotioned=user.logininMap.get(emotions,:"#{emotion}_user_logins")
123123
emotions=emotions|>Map.put(:"viewer_has_#{emotion}ed",viewer_has_emotioned)
124124

125-
content
125+
artiment
126126
|>ORM.update_embed(:emotions,emotions)
127127
# virtual field can not be updated
128128
|>add_viewer_emotioned_ifneed(emotions)

‎test/groupher_server/cms/comments/post_comment_emotions_test.exs‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,26 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentEmotions do
2121
end
2222

2323
describe"[emotion in paged article comment]"do
24+
@tag:wip
25+
test"emotioned comment should return valid viewer_has status",~m(post user user2)ado
26+
total_count=3
27+
28+
all_comment=
29+
Enum.reduce(0..total_count,[],fn_,acc->
30+
{:ok,comment}=CMS.create_comment(:post,post.id,mock_comment(),user)
31+
acc++[comment]
32+
end)
33+
34+
first_comment=List.first(all_comment)
35+
36+
{:ok,_}=CMS.emotion_to_comment(first_comment.id,:downvote,user)
37+
{:ok,_}=CMS.emotion_to_comment(first_comment.id,:beer,user2)
38+
{:ok,comment}=CMS.emotion_to_comment(first_comment.id,:beer,user)
39+
40+
assertcomment.emotions.viewer_has_downvoteed==true
41+
assertcomment.emotions.viewer_has_beered==true
42+
end
43+
2444
test"login user should got viewer has emotioned status",~m(post user)ado
2545
total_count=0
2646
page_number=10

‎test/groupher_server/cms/comments/post_comment_test.exs‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,16 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do
157157
assertList.first(comment.upvotes).user_id==user.id
158158
end
159159

160+
test"user can upvote a post comment twice is fine",~m(user post)ado
161+
{:ok,comment}=CMS.create_comment(:post,post.id,mock_comment(),user)
162+
163+
{:ok,_}=CMS.upvote_comment(comment.id,user)
164+
{:error,_}=CMS.upvote_comment(comment.id,user)
165+
166+
{:ok,comment}=ORM.find(Comment,comment.id,preload::upvotes)
167+
assert1==length(comment.upvotes)
168+
end
169+
160170
test"article author upvote post comment will have flag",~m(post user)ado
161171
{:ok,comment}=CMS.create_comment(:post,post.id,mock_comment(),user)
162172
{:ok,author_user}=ORM.find(User,post.author.user.id)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp