Skip to content

Commit

Permalink
Possible fix for "Unknown Author"
Browse files Browse the repository at this point in the history
This is a back port from instructure instructure/canvas-lms@8e9ee5a

if an entry hasn't been added to the materialized view in the database
yet, still find its author from among the participants, rather than
showing "Unknown Author".
  • Loading branch information
ogg committed Oct 21, 2013
1 parent 007cef0 commit 063432d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
4 changes: 2 additions & 2 deletions app/coffeescripts/bundles/discussion.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ require [
router = new Backbone.Router

@data = if ENV.DISCUSSION.THREADED
new MaterializedDiscussionTopic
new MaterializedDiscussionTopic root_url: ENV.DISCUSSION.ROOT_URL
else
new SideCommentDiscussionTopic
new SideCommentDiscussionTopic root_url: ENV.DISCUSSION.ROOT_URL

entries = new EntryCollection null, {perPage}

Expand Down
23 changes: 15 additions & 8 deletions app/coffeescripts/models/Topic.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ define [
'compiled/arr/erase'
], (I18n, {each}, Backbone, BackoffPoller, walk, erase) ->

UNKOWN_AUTHOR =
UNKNOWN_AUTHOR =
avatar_image_url: null
display_name: I18n.t 'uknown_author', 'Unknown Author'
id: null
Expand All @@ -24,10 +24,11 @@ define [
new_entries: []
unread_entries: []

url: ENV.DISCUSSION.ROOT_URL + '?include_new_entries=1'
url: ->
"#{@get 'root_url'}?include_new_entries=1"

fetch: (options = {}) ->
loader = new BackoffPoller @url, (data, xhr) =>
loader = new BackoffPoller @url(), (data, xhr) =>
return 'continue' if xhr.status is 503
return 'abort' if xhr.status isnt 200
@set(@parse(data, 200, xhr))
Expand Down Expand Up @@ -65,19 +66,22 @@ define [
for participant in @data.participants
@participants[participant.id] = participant

setEntryAuthor: (entry) ->
if entry.user_id?
entry.author = @participants[entry.user_id]
else
entry.author = UNKNOWN_AUTHOR

parseEntry: (entry) =>
@flattened[entry.id] = entry
parent = @flattened[entry.parent_id]
entry.parent = parent
entry.read_state = 'unread' if entry.id in @data.unread_entries

if entry.user_id?
entry.author = @participants[entry.user_id]
else
entry.author = UNKOWN_AUTHOR
@setEntryAuthor(entry)

if entry.editor_id?
entry.editor = @participants[entry.user_id]
entry.editor = @participants[entry.editor_id]

if entry.parent_id?
entry.root_entry = @lastRoot
Expand All @@ -92,6 +96,9 @@ define [
parseNewEntry: (entry) =>
@flattened[entry.id] = entry
parent = @flattened[entry.parent_id]

@setEntryAuthor(entry)

if parent?
(parent.replies ?= []).push entry
entry.parent = parent
Expand Down

0 comments on commit 063432d

Please sign in to comment.