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
96fb9e26
Commit
96fb9e26
authored
Sep 20, 2012
by
Arjun Singh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Alter service to allow marking as read when a thread is fetched
parent
6f61a891
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
19 additions
and
21 deletions
+19
-21
api/comment_threads.rb
+8
-1
api/users.rb
+0
-19
lib/helpers.rb
+4
-0
models/comment_thread.rb
+1
-1
models/user.rb
+6
-0
No files found.
api/comment_threads.rb
View file @
96fb9e26
...
...
@@ -3,7 +3,14 @@ get "#{APIPREFIX}/threads" do # retrieve threads by course
end
get
"
#{
APIPREFIX
}
/threads/:thread_id"
do
|
thread_id
|
CommentThread
.
find
(
thread_id
).
to_hash
(
recursive:
bool_recursive
,
user_id:
params
[
"user_id"
]).
to_json
thread
=
CommentThread
.
find
(
thread_id
)
if
params
[
"user_id"
]
and
bool_mark_as_read
user
=
User
.
only
([
:id
,
:read_states
]).
find_or_create_by
(
external_id:
params
[
"user_id"
])
user
.
mark_as_read
(
thread
)
end
thread
.
to_hash
(
recursive:
bool_recursive
,
user_id:
params
[
"user_id"
]).
to_json
end
put
"
#{
APIPREFIX
}
/threads/:thread_id"
do
|
thread_id
|
...
...
api/users.rb
View file @
96fb9e26
...
...
@@ -43,25 +43,6 @@ get "#{APIPREFIX}/users/:user_id/active_threads" do |user_id|
end
put
"
#{
APIPREFIX
}
/users/:user_id/read_states"
do
|
user_id
|
user
=
User
.
find_or_create_by
(
external_id:
user_id
)
read_state
=
user
.
read_states
.
find_or_create_by
(
course_id:
params
[
"course_id"
])
# support updating single thread data or bulk update
if
params
[
"last_read_time"
]
and
params
[
"thread_id"
]
read_state
.
last_read_times
=
read_state
.
last_read_times
.
with_indifferent_access
.
merge
({
params
[
"thread_id"
]
=>
params
[
"last_read_time"
]
})
elsif
params
[
"last_read_times"
]
read_state
.
last_read_times
=
read_state
.
last_read_times
.
with_indifferent_access
.
merge
(
params
[
"last_read_times"
])
end
read_state
.
save
if
read_state
.
errors
.
any?
error
400
,
read_state
.
errors
.
full_messages
.
to_json
else
read_state
.
to_hash
.
to_json
end
end
put
"
#{
APIPREFIX
}
/users/:user_id"
do
|
user_id
|
user
=
User
.
find_or_create_by
(
external_id:
user_id
)
user
.
update_attributes
(
params
.
slice
(
*
%w[username email default_sort_key]
))
...
...
lib/helpers.rb
View file @
96fb9e26
...
...
@@ -51,6 +51,10 @@ helpers do
value_to_boolean
params
[
"recursive"
]
end
def
bool_mark_as_read
value_to_boolean
params
[
"mark_as_read"
]
end
def
bool_complete
value_to_boolean
params
[
"complete"
]
end
...
...
models/comment_thread.rb
View file @
96fb9e26
...
...
@@ -171,7 +171,7 @@ class CommentThread < Content
if
params
[
:user_id
]
user
=
User
.
find_or_create_by
(
external_id:
params
[
:user_id
])
read_state
=
user
.
read_states
.
where
(
course_id:
self
.
course_id
).
first
last_read_time
=
Time
.
parse
(
read_state
.
last_read_times
[
self
.
id
.
to_s
])
if
read_state
last_read_time
=
read_state
.
last_read_times
[
self
.
id
.
to_s
]
if
read_state
# comments created by the user are excluded in the count
# this is rather like a hack but it avoids the following situation:
# when you reply to a thread and while you are editing,
...
...
models/user.rb
View file @
96fb9e26
...
...
@@ -102,6 +102,12 @@ class User
subscription
end
def
mark_as_read
(
thread
)
read_state
=
read_states
.
find_or_create_by
(
course_id:
thread
.
course_id
)
read_state
.
last_read_times
[
thread
.
id
]
=
Time
.
now
.
utc
read_state
.
save
end
end
class
ReadState
...
...
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