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
1f5684a7
Commit
1f5684a7
authored
Jul 31, 2013
by
Kevin Chugh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
restore notifications api post-merge-rollback
parent
d2bf94ef
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
82 additions
and
0 deletions
+82
-0
app.rb
+1
-0
lib/helpers.rb
+62
-0
models/comment.rb
+8
-0
models/content.rb
+11
-0
No files found.
app.rb
View file @
1f5684a7
...
...
@@ -72,6 +72,7 @@ require './api/votes'
require
'./api/flags'
require
'./api/pins'
require
'./api/notifications_and_subscriptions'
require
'./api/notifications'
if
RACK_ENV
.
to_s
==
"development"
get
"
#{
APIPREFIX
}
/clean"
do
...
...
lib/helpers.rb
View file @
1f5684a7
...
...
@@ -203,4 +203,66 @@ helpers do
end
.
compact
end
def
notifications_by_date_range_and_user_ids
start_date_time
,
end_date_time
,
user_ids
#given a date range and a user, find all of the notifiable content
#key by thread id, and return notification messages for each user
#first, find the subscriptions for the users
subscriptions
=
Subscription
.
where
(
:subscriber_id
.
in
=>
user_ids
)
#get the thhread ids
thread_ids
=
subscriptions
.
collect
{
|
t
|
t
.
source_id
}.
uniq
#find all the comments
comments
=
Comment
.
by_date_range_and_thread_ids
start_date_time
,
end_date_time
,
thread_ids
#and get the threads too, b/c we'll need them for the title
thread_map
=
Hash
[
CommentThread
.
where
(
:_id
.
in
=>
thread_ids
).
all
.
map
{
|
t
|
[
t
.
id
,
t
]
}]
#now build a thread to users subscription map
subscriptions_map
=
{}
subscriptions
.
each
do
|
s
|
if
not
subscriptions_map
.
keys
.
include?
s
.
source_id
.
to_s
subscriptions_map
[
s
.
source_id
.
to_s
]
=
[]
end
subscriptions_map
[
s
.
source_id
]
<<
s
.
subscriber_id
end
#notification map will be user => course => thread => [comment bodies]
notification_map
=
{}
comments
.
each
do
|
c
|
user_ids
=
subscriptions_map
[
c
.
comment_thread_id
.
to_s
]
user_ids
.
each
do
|
u
|
if
not
notification_map
.
keys
.
include?
u
notification_map
[
u
]
=
{}
end
if
not
notification_map
[
u
].
keys
.
include?
c
.
course_id
notification_map
[
u
][
c
.
course_id
]
=
{}
end
if
not
notification_map
[
u
][
c
.
course_id
].
include?
c
.
comment_thread_id
.
to_s
t
=
notification_map
[
u
][
c
.
course_id
][
c
.
comment_thread_id
.
to_s
]
=
{}
t
[
"content"
]
=
[]
t
[
"title"
]
=
thread_map
[
c
.
comment_thread_id
].
title
t
[
"commentable_id"
]
=
thread_map
[
c
.
comment_thread_id
].
commentable_id
else
t
=
notification_map
[
u
][
c
.
course_id
][
c
.
comment_thread_id
.
to_s
]
end
content_obj
=
{}
content_obj
[
"username"
]
=
c
.
author_with_anonymity
(
:username
,
"(anonymous)"
)
content_obj
[
"updated_at"
]
=
c
.
updated_at
content_obj
[
"body"
]
=
c
.
body
t
[
"content"
]
<<
content_obj
end
end
notification_map
.
to_json
end
end
models/comment.rb
View file @
1f5684a7
...
...
@@ -97,6 +97,14 @@ class Comment < Content
end
end
end
def
self
.
by_date_range_and_thread_ids
from_when
,
to_when
,
thread_ids
#return all content between from_when and to_when
self
.
where
(
:created_at
.
gte
=>
(
from_when
)).
where
(
:created_at
.
lte
=>
(
to_when
)).
where
(
:comment_thread_id
.
in
=>
thread_ids
)
end
private
def
set_thread_last_activity_at
...
...
models/content.rb
View file @
1f5684a7
...
...
@@ -84,4 +84,15 @@ class Content
answer
end
def
self
.
by_date_range
from_when
,
to_when
#return all content between from_when and to_when
Content
.
where
(
:created_at
.
gte
=>
(
from_when
)).
where
(
:created_at
.
lte
=>
(
to_when
))
end
def
self
.
by_date_range_and_thread_ids
from_when
,
to_when
,
thread_ids
#return all content between from_when and to_when
Content
.
where
(
:created_at
.
gte
=>
(
from_when
)).
where
(
:created_at
.
lte
=>
(
to_when
)).
where
(
:comment_thread_id
.
in
=>
thread_ids
)
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