Merge pull request #735 from MITx/feature/arjun/unread_count
Unread counts + tracking for discussion
This commit is contained in:
@@ -43,6 +43,7 @@ def get_threads(request, course_id, discussion_id=None, per_page=THREADS_PER_PAG
|
||||
'tags': '',
|
||||
'commentable_id': discussion_id,
|
||||
'course_id': course_id,
|
||||
'user_id': request.user.id,
|
||||
}
|
||||
|
||||
if not request.GET.get('sort_key'):
|
||||
@@ -81,6 +82,7 @@ def inline_discussion(request, course_id, discussion_id):
|
||||
# TODO (vshnayder): since none of this code seems to be aware of the fact that
|
||||
# sometimes things go wrong, I suspect that the js client is also not
|
||||
# checking for errors on request. Check and fix as needed.
|
||||
log.error("Error loading inline discussion threads.")
|
||||
raise Http404
|
||||
|
||||
def infogetter(thread):
|
||||
@@ -114,6 +116,7 @@ def forum_form_discussion(request, course_id):
|
||||
unsafethreads, query_params = get_threads(request, course_id) # This might process a search query
|
||||
threads = [utils.safe_content(thread) for thread in unsafethreads]
|
||||
except (cc.utils.CommentClientError, cc.utils.CommentClientUnknownError) as err:
|
||||
log.error("Error loading forum discussion threads: %s" % str(err))
|
||||
raise Http404
|
||||
|
||||
user_info = cc.User.from_django_user(request.user).to_dict()
|
||||
@@ -164,14 +167,18 @@ def forum_form_discussion(request, course_id):
|
||||
@login_required
|
||||
def single_thread(request, course_id, discussion_id, thread_id):
|
||||
|
||||
if request.is_ajax():
|
||||
course = get_course_with_access(request.user, course_id, 'load')
|
||||
user_info = cc.User.from_django_user(request.user).to_dict()
|
||||
course = get_course_with_access(request.user, course_id, 'load')
|
||||
cc_user = cc.User.from_django_user(request.user)
|
||||
user_info = cc_user.to_dict()
|
||||
|
||||
try:
|
||||
thread = cc.Thread.find(thread_id).retrieve(recursive=True, user_id=request.user.id)
|
||||
except (cc.utils.CommentClientError, cc.utils.CommentClientUnknownError) as err:
|
||||
log.error("Error loading single thread.")
|
||||
raise Http404
|
||||
|
||||
if request.is_ajax():
|
||||
|
||||
try:
|
||||
thread = cc.Thread.find(thread_id).retrieve(recursive=True)
|
||||
except (cc.utils.CommentClientError, cc.utils.CommentClientUnknownError) as err:
|
||||
raise Http404
|
||||
courseware_context = get_courseware_context(thread, course)
|
||||
|
||||
annotated_content_info = utils.get_annotated_content_infos(course_id, thread, request.user, user_info=user_info)
|
||||
@@ -188,13 +195,13 @@ def single_thread(request, course_id, discussion_id, thread_id):
|
||||
})
|
||||
|
||||
else:
|
||||
course = get_course_with_access(request.user, course_id, 'load')
|
||||
category_map = utils.get_discussion_category_map(course)
|
||||
|
||||
try:
|
||||
threads, query_params = get_threads(request, course_id)
|
||||
thread = cc.Thread.find(thread_id).retrieve(recursive=True)
|
||||
threads.append(thread.to_dict())
|
||||
except (cc.utils.CommentClientError, cc.utils.CommentClientUnknownError) as err:
|
||||
log.error("Error loading single thread.")
|
||||
raise Http404
|
||||
|
||||
course = get_course_with_access(request.user, course_id, 'load')
|
||||
@@ -216,8 +223,7 @@ def single_thread(request, course_id, discussion_id, thread_id):
|
||||
# course_id,
|
||||
#)
|
||||
|
||||
user_info = cc.User.from_django_user(request.user).to_dict()
|
||||
|
||||
|
||||
def infogetter(thread):
|
||||
return utils.get_annotated_content_infos(course_id, thread, request.user, user_info)
|
||||
|
||||
|
||||
@@ -336,7 +336,8 @@ def safe_content(content):
|
||||
'endorsed', 'parent_id', 'thread_id', 'votes', 'closed', 'created_at',
|
||||
'updated_at', 'depth', 'type', 'commentable_id', 'comments_count',
|
||||
'at_position_list', 'children', 'highlighted_title', 'highlighted_body',
|
||||
'courseware_title', 'courseware_url', 'tags'
|
||||
'courseware_title', 'courseware_url', 'tags', 'unread_comments_count',
|
||||
'read',
|
||||
]
|
||||
|
||||
if (content.get('anonymous') is False) and (content.get('anonymous_to_peers') is False):
|
||||
|
||||
@@ -60,7 +60,21 @@ class Thread(models.Model):
|
||||
else:
|
||||
return super(Thread, cls).url(action, params)
|
||||
|
||||
# TODO: This is currently overriding Model._retrieve only to add parameters
|
||||
# for the request. Model._retrieve should be modified to handle this such
|
||||
# that subclasses don't need to override for this.
|
||||
def _retrieve(self, *args, **kwargs):
|
||||
url = self.url(action='get', params=self.attributes)
|
||||
response = perform_request('get', url, {'recursive': kwargs.get('recursive')})
|
||||
|
||||
request_params = {
|
||||
'recursive': kwargs.get('recursive'),
|
||||
'user_id': kwargs.get('user_id'),
|
||||
'mark_as_read': kwargs.get('mark_as_read', True),
|
||||
}
|
||||
|
||||
# user_id may be none, in which case it shouldn't be part of the
|
||||
# request.
|
||||
request_params = strip_none(request_params)
|
||||
|
||||
response = perform_request('get', url, request_params)
|
||||
self.update_attributes(**response)
|
||||
|
||||
@@ -27,6 +27,8 @@ if Backbone?
|
||||
|
||||
showThread: (forum_name, thread_id) ->
|
||||
@thread = @discussion.get(thread_id)
|
||||
@thread.set("unread_comments_count", 0)
|
||||
@thread.set("read", true)
|
||||
@setActiveThread()
|
||||
if(@main)
|
||||
@main.cleanup()
|
||||
|
||||
@@ -130,6 +130,8 @@ if Backbone?
|
||||
content.addClass("followed")
|
||||
if thread.get('endorsed')
|
||||
content.addClass("resolved")
|
||||
if thread.get('read')
|
||||
content.addClass("read")
|
||||
@highlight(content)
|
||||
|
||||
|
||||
|
||||
@@ -1018,6 +1018,7 @@ body.discussion {
|
||||
text-shadow: 0 -1px 0 rgba(0, 0, 0, .3);
|
||||
box-shadow: 0 1px 0 rgba(255, 255, 255, 0.2), 0 1px 1px rgba(0, 0, 0, .2) inset;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1204,12 +1205,13 @@ body.discussion {
|
||||
background-position: 0 -5px;
|
||||
}
|
||||
|
||||
&.new {
|
||||
@include linear-gradient(top, #84d7fe, #99e0fe);
|
||||
&.unread {
|
||||
@include linear-gradient(top, #84d7fe, #60a8d6);
|
||||
color: #333;
|
||||
|
||||
&:after {
|
||||
color: #99e0fe;
|
||||
background-position: 0 0px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,5 +128,13 @@
|
||||
</script>
|
||||
|
||||
<script type="text/template" id="thread-list-item-template">
|
||||
<a href="${'<%- id %>'}" data-id="${'<%- id %>'}"><span class="title">${"<%- title %>"}</span> <span class="comments-count">${"<%- comments_count %>"}</span><span class="votes-count">+${"<%- votes['up_count'] %>"}</span></a>
|
||||
<a href="${'<%- id %>'}" data-id="${'<%- id %>'}">
|
||||
<span class="title">${"<%- title %>"}</span>
|
||||
${"<% if (unread_comments_count > 0) { %>"}
|
||||
<span class="comments-count unread">${"<%- unread_comments_count %>"}</span>
|
||||
${"<% } else { %>"}
|
||||
<span class="comments-count">${"<%- comments_count %>"}</span>
|
||||
${"<% } %>"}
|
||||
<span class="votes-count">+${"<%- votes['up_count'] %>"}</span>
|
||||
</a>
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user