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
b9a7db7e
Commit
b9a7db7e
authored
Sep 19, 2012
by
Arjun Singh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor / rename a couple tiny things
parent
50a06762
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
17 additions
and
14 deletions
+17
-14
api/users.rb
+3
-3
lib/helpers.rb
+0
-4
models/comment_thread.rb
+13
-6
models/user.rb
+1
-1
No files found.
api/users.rb
View file @
b9a7db7e
...
...
@@ -48,11 +48,11 @@ put "#{APIPREFIX}/users/:user_id/read_states" do |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_time
=
read_state
.
last_read_time
.
with_indifferent_access
.
merge
({
read_state
.
last_read_time
s
=
read_state
.
last_read_times
.
with_indifferent_access
.
merge
({
params
[
"thread_id"
]
=>
params
[
"last_read_time"
]
})
elsif
params
[
"
read_stat
es"
]
read_state
.
last_read_time
=
read_state
.
last_read_time
.
with_indifferent_access
.
merge
(
params
[
"read_stat
es"
])
elsif
params
[
"
last_read_tim
es"
]
read_state
.
last_read_time
s
=
read_state
.
last_read_times
.
with_indifferent_access
.
merge
(
params
[
"last_read_tim
es"
])
end
read_state
.
save
if
read_state
.
errors
.
any?
...
...
lib/helpers.rb
View file @
b9a7db7e
...
...
@@ -16,10 +16,6 @@ helpers do
@comment
||=
Comment
.
find
(
params
[
:comment_id
])
end
def
profile
@profile
||=
user
.
profiles
.
find_or_create_by
(
course_id:
params
[
"course_id"
])
end
def
source
@source
||=
case
params
[
"source_type"
]
when
"user"
...
...
models/comment_thread.rb
View file @
b9a7db7e
...
...
@@ -165,10 +165,13 @@ class CommentThread < Content
if
params
[
:recursive
]
doc
=
doc
.
merge
(
"children"
=>
root_comments
.
map
{
|
c
|
c
.
to_hash
(
recursive:
true
)})
end
comments_count
=
comments
.
count
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_time
[
self
.
id
.
to_s
])
if
read_state
last_read_time
=
Time
.
parse
(
read_state
.
last_read_time
s
[
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,
...
...
@@ -187,14 +190,18 @@ class CommentThread < Content
unread_count
=
self
.
comments
.
where
(
:author_id
=>
{:
$ne
=>
params
[
:user_id
]}).
count
viewed
=
false
end
doc
=
doc
.
merge
(
"unread_comments_count"
=>
unread_count
)
.
merge
(
"viewed"
=>
viewed
)
else
doc
=
doc
.
merge
(
"unread_comments_count"
=>
comments
.
count
)
.
merge
(
"viewed"
=>
false
)
# If there's no user, say it's not viewed and all comments are unread
unread_count
=
comments_count
viewed
=
false
end
doc
=
doc
.
merge
(
"comments_count"
=>
comments
.
count
)
doc
=
doc
.
merge
(
"unread_comments_count"
=>
unread_count
)
.
merge
(
"viewed"
=>
viewed
)
.
merge
(
"comments_count"
=>
comments_count
)
doc
end
def
self
.
tag_name_valid?
(
tag
)
...
...
models/user.rb
View file @
b9a7db7e
...
...
@@ -107,7 +107,7 @@ end
class
ReadState
include
Mongoid
::
Document
field
:course_id
,
type:
String
field
:last_read_time
,
type:
Hash
,
default:
{}
field
:last_read_time
s
,
type:
Hash
,
default:
{}
embedded_in
:user
validates
:course_id
,
uniqueness:
true
,
presence:
true
...
...
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