Skip to content

Commit

Permalink
correct message sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
cpetzold committed Apr 27, 2012
1 parent ee48567 commit f17dd25
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/orca/index.coffee
Expand Up @@ -15,7 +15,14 @@ orca.get '/:channel', (page, model, params) ->
channel: params.channel
messageQuery.sort 'timestamp', 'desc'

model.subscribe "channels.#{params.channel}", messageQuery, (e, channel) ->
model.subscribe "channels.#{params.channel}", messageQuery, (e, channel, messages) ->
list = []
for id, message of messages.get()
list.push message

list.sort (a, b) -> a.timestamp - b.timestamp
model.set '_messageIds', list.map ({ id }) -> id

model.ref '_channel', channel
model.refList '_messages', 'messages', '_messageIds'
page.render()
Expand All @@ -39,5 +46,8 @@ orca.ready (model) ->
# toggleActions.innerText = 'Hide actions'
# messages.className = ''

model.on 'addDoc', (path, doc) ->
console.log path, doc

model.on 'push', '_messages', (message, len, isLocal) ->
document.body.scrollTop = messages.offsetHeight

0 comments on commit f17dd25

Please sign in to comment.