Anton Shestakov <av6@dwimlabs.net>, Thu, 14 Apr 2016 02:05:24 +0800
index: remove offline contacts only when they change to being offline
Since new contacts are currently added while they still have the default
presence of 'unavailable', add event sees them as offline and throws them away
immediately, before their presence could change to something else.
coffee/messages.coffee
Permissions: -rw-r--r--
class Tram.Message extends Backbone.Model @on 'add change:stamp', -> @set('d/mstamp', moment(@get('stamp'))) class Tram.Messages extends Backbone.Collection splitThreshold: 30 * 60 * 1000 model.get('stamp').valueOf() @_splitOrFold(prev, model) @_splitOrFold(model, next) _splitOrFold: (m1, m2) -> Math.abs(m1.get('stamp').valueOf() - m2.get('stamp').valueOf()) > @splitThreshold m1.get('from') is m2.get('from') and Math.abs(m1.get('stamp').valueOf() - m2.get('stamp').valueOf()) < @foldThreshold class Tram.MessageView extends Backbone.View template: $('#message-template').html() @$el.attr('data-id', @model.get('id')) @$avatarColumn = @$('.avatar-column') @listenTo(@model, 'change:contact', @updateContact) if not @model.previous('contact')? and @model.get('contact')? av = new Tram.AvatarView(model: contact) @$avatarColumn.prepend(av.render().el) @model.get('contact')?.get('d/handle') or @model.get('from') @rivet = rivets.bind(@el, model: @model, view: this) contact = @model.get('contact') av = new Tram.AvatarView(model: contact) @$avatarColumn.prepend(av.render().el) class Tram.LogApp extends Backbone.View @listenTo(@collection, 'add', @onAdd) onAdd: (model, collection) -> mi = collection.indexOf(model) view = new Tram.MessageView(model: model) @$el.children().eq(mi - 1).after(el) @$el.scrollTop() + @$el.height() == @$el.get(0).scrollHeight @$el.scrollTop(@$el.get(0).scrollHeight)