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
4fd9756b
Commit
4fd9756b
authored
Aug 05, 2012
by
Rocky Duan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add last_updated_at field
parent
a6798555
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
20 deletions
+37
-20
models/comment.rb
+10
-13
models/comment_thread.rb
+13
-4
models/observers/at_user_observer.rb
+14
-3
No files found.
models/comment.rb
View file @
4fd9756b
...
...
@@ -27,21 +27,12 @@ class Comment < Content
counter_cache
:comment_thread
before_destroy
:delete_descendants
# TODO async
def
self
.
hash_tree
(
nodes
)
nodes
.
map
{
|
node
,
sub_nodes
|
node
.
to_hash
.
merge
(
"children"
=>
hash_tree
(
sub_nodes
).
compact
)}
end
def
thread_title
comment_thread
.
title
end
def
commentable
comment_thread
.
commentable
end
before_create
:set_thread_last_activity_at
before_update
:set_thread_last_activity_at
def
commentable_id
comment_thread
.
commentable_id
def
self
.
hash_tree
(
nodes
)
nodes
.
map
{
|
node
,
sub_nodes
|
node
.
to_hash
.
merge
(
"children"
=>
hash_tree
(
sub_nodes
).
compact
)}
end
def
to_hash
(
params
=
{})
...
...
@@ -66,4 +57,10 @@ class Comment < Content
end
end
private
def
set_thread_last_activity_at
self
.
comment_thread
.
update_attributes!
(
last_activity_at:
Time
.
now
.
utc
)
end
end
models/comment_thread.rb
View file @
4fd9756b
...
...
@@ -14,14 +14,19 @@ class CommentThread < Content
field
:commentable_id
,
type:
String
field
:anonymous
,
type:
Boolean
,
default:
false
field
:at_position_list
,
type:
Array
,
default:
[]
field
:last_activity_at
,
type:
Time
include
Sunspot
::
Mongoid
searchable
do
text
:title
,
boost:
5.0
,
stored:
true
,
more_like_this:
true
text
:body
,
stored:
true
,
more_like_this:
true
text
:tags
do
tags_array
.
join
" "
end
time
:created_at
time
:updated_at
time
:last_activity_at
integer
:comment_count
integer
:votes_point
do
votes_point
...
...
@@ -48,6 +53,10 @@ class CommentThread < Content
validate
:tag_names_valid
validate
:tag_names_unique
before_create
:set_last_activity_at
before_update
:set_last_activity_at
def
self
.
new_dumb_thread
(
options
=
{})
c
=
self
.
new
c
.
title
=
options
[
:title
]
||
"title"
...
...
@@ -105,10 +114,6 @@ class CommentThread < Content
!!
(
tag
=~
RE_TAG
)
end
def
thread_title
title
end
private
RE_HEADCHAR
=
/[a-z0-9]/
...
...
@@ -131,4 +136,8 @@ private
errors
.
add
:tags
,
"must be unique"
end
end
def
set_last_activity_at
self
.
last_activity_at
=
Time
.
now
.
utc
unless
last_activity_at_changed?
end
end
models/observers/at_user_observer.rb
View file @
4fd9756b
...
...
@@ -23,16 +23,27 @@ class AtUserObserver < Mongoid::Observer
new_user_ids
=
current_user_ids
-
prev_user_ids
if
content_type
==
:thread
thread_title
=
content
.
title
thread_id
=
content
.
id
commentable_id
=
content
.
commentable_id
else
thread_title
=
content
.
comment_thread
.
title
thread_id
=
content
.
comment_thread
.
id
commentable_id
=
content
.
comment_thread
.
commentable_id
end
unless
new_user_ids
.
empty?
notification
=
Notification
.
new
(
notification_type:
"at_user"
,
info:
{
co
ntent_id:
content
.
id
,
co
mment_id:
(
content
.
id
if
content_type
==
:comment
)
,
content_type:
content_type
,
thread_title:
content
.
thread_title
,
thread_title:
thread_title
,
thread_id:
thread_id
,
actor_username:
content
.
author_with_anonymity
(
:username
),
commentable_id:
co
ntent
.
co
mmentable_id
,
commentable_id:
commentable_id
,
}
)
notification
.
actor
=
content
.
author_with_anonymity
...
...
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