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
890c5c0c
Commit
890c5c0c
authored
Jul 15, 2012
by
Rocky Duan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
async callback to generate feeds
parent
463bb4de
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
2 deletions
+46
-2
models/comment.rb
+23
-1
models/comment_thread.rb
+19
-1
models/feed.rb
+4
-0
No files found.
models/comment.rb
View file @
890c5c0c
...
@@ -20,12 +20,16 @@ class Comment
...
@@ -20,12 +20,16 @@ class Comment
#validates_presence_of :author # allow anonymity?
#validates_presence_of :author # allow anonymity?
before_destroy
:delete_descendants
before_destroy
:delete_descendants
#after_create :cre
ate_feeds
after_create
:gener
ate_feeds
def
self
.
hash_tree
(
nodes
)
def
self
.
hash_tree
(
nodes
)
nodes
.
map
{
|
node
,
sub_nodes
|
node
.
to_hash
.
merge
(
"children"
=>
hash_tree
(
sub_nodes
).
compact
)}
nodes
.
map
{
|
node
,
sub_nodes
|
node
.
to_hash
.
merge
(
"children"
=>
hash_tree
(
sub_nodes
).
compact
)}
end
end
def
comment_thread
comment_thread
||
root
.
comment_thread
end
def
to_hash
(
params
=
{})
def
to_hash
(
params
=
{})
if
params
[
:recursive
]
if
params
[
:recursive
]
self
.
class
.
hash_tree
(
subtree
(
order_by:
[[
:parent_ids
,
:asc
],
[
:created_at
,
:asc
]]))
self
.
class
.
hash_tree
(
subtree
(
order_by:
[[
:parent_ids
,
:asc
],
[
:created_at
,
:asc
]]))
...
@@ -36,4 +40,22 @@ class Comment
...
@@ -36,4 +40,22 @@ class Comment
end
end
end
end
def
generate_feeds
feed
=
Feed
.
new
(
feed_type:
"post_reply"
,
info:
{
comment_thread_id:
comment_thread
.
id
,
comment_thread_title:
comment_thread
.
title
,
comment_id:
id
,
},
)
feed
.
actor
=
author
feed
.
target
=
self
feed
.
subscribers
<<
comment_thread
.
watchers
feed
.
subscribers
<<
author
.
followers
feed
.
save!
end
handle_asynchronously
:generate_feeds
end
end
models/comment_thread.rb
View file @
890c5c0c
...
@@ -21,7 +21,7 @@ class CommentThread
...
@@ -21,7 +21,7 @@ class CommentThread
validates_presence_of
:course_id
# do we really need this?
validates_presence_of
:course_id
# do we really need this?
#validates_presence_of :author #allow anonymity?
#validates_presence_of :author #allow anonymity?
#after_create :cre
ate_feeds
after_create
:gener
ate_feeds
def
to_hash
(
params
=
{})
def
to_hash
(
params
=
{})
doc
=
as_document
.
slice
(
*
%w[title body course_id _id]
).
doc
=
as_document
.
slice
(
*
%w[title body course_id _id]
).
...
@@ -33,4 +33,22 @@ class CommentThread
...
@@ -33,4 +33,22 @@ class CommentThread
doc
doc
end
end
def
generate_feeds
feed
=
Feed
.
new
(
feed_type:
"post_topic"
,
info:
{
commentable_id:
commentable
.
id
,
commentable_type:
commentable
.
type
,
comment_thread_id:
comment_thread
.
id
,
comment_thread_title:
comment_thread
.
title
,
},
)
feed
.
actor
=
author
feed
.
target
=
self
feed
.
subscribers
<<
commentable
.
watchers
feed
.
subscribers
<<
author
.
followers
feed
.
save!
end
handle_asynchronously
:generate_feeds
end
end
models/feed.rb
View file @
890c5c0c
...
@@ -10,5 +10,9 @@ class Feed
...
@@ -10,5 +10,9 @@ class Feed
attr_accessible
:feed_type
,
:info
attr_accessible
:feed_type
,
:info
validates_presence_of
:feed_type
validates_presence_of
:actor
validates_presence_of
:target
has_and_belongs_to_many
:subscribers
,
class_name:
"User"
,
inverse_of: :subscribed_feeds
has_and_belongs_to_many
:subscribers
,
class_name:
"User"
,
inverse_of: :subscribed_feeds
end
end
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