Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
cs_comments_service
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
cs_comments_service
Commits
9250057d
Commit
9250057d
authored
Jul 25, 2012
by
Rocky Duan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
no subscription to oneself
parent
b495fba3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
2 deletions
+35
-2
models/user.rb
+35
-2
No files found.
models/user.rb
View file @
9250057d
...
...
@@ -20,8 +20,37 @@ class User
Subscription
.
where
(
subscriber_id:
id
.
to_s
)
end
def
subscribed_thread_ids
subscriptions_as_subscriber
.
where
(
source_type:
"CommentThread"
).
map
(
&
:source_id
)
end
def
subscribed_commentable_ids
subscriptions_as_subscriber
.
where
(
source_type:
"Commentable"
).
map
(
&
:source_id
)
end
def
subscribed_user_ids
subscriptions_as_subscriber
.
where
(
source_type:
"User"
).
map
(
&
:source_id
)
end
def
to_hash
(
params
=
{})
as_document
.
slice
(
*
%w[_id external_id]
)
hash
=
as_document
.
slice
(
*
%w[_id external_id]
)
if
params
[
:complete
]
hash
=
hash
.
merge
(
"subscribed_thread_ids"
=>
subscribed_thread_ids
,
"subscribed_commentable_ids"
=>
subscribed_commentable_ids
,
"subscribed_user_ids"
=>
subscribed_user_ids
,
"follower_ids"
=>
subscriptions_as_source
.
map
(
&
:subscriber_id
),
"upvoted_ids"
=>
upvoted_ids
,
"downvoted_ids"
=>
downvoted_ids
)
end
hash
end
def
upvoted_ids
Comment
.
up_voted_by
(
self
).
map
(
&
:id
)
+
CommentThread
.
up_voted_by
(
self
).
map
(
&
:id
)
end
def
downvoted_ids
Comment
.
down_voted_by
(
self
).
map
(
&
:id
)
+
CommentThread
.
down_voted_by
(
self
).
map
(
&
:id
)
end
def
followers
...
...
@@ -29,7 +58,11 @@ class User
end
def
subscribe
(
source
)
Subscription
.
find_or_create_by
(
subscriber_id:
self
.
_id
.
to_s
,
source_id:
source
.
_id
.
to_s
,
source_type:
source
.
class
.
to_s
)
if
source
.
_id
==
self
.
_id
and
source
.
class
==
self
.
class
nil
else
Subscription
.
find_or_create_by
(
subscriber_id:
self
.
_id
.
to_s
,
source_id:
source
.
_id
.
to_s
,
source_type:
source
.
class
.
to_s
)
end
end
def
unsubscribe
(
source
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment