<commit_before>class App.Conversation extends Spine.Model
  @configure 'Conversation', 'read', 'received_at', 'to_users'
  @extend Spine.Model.Ajax
  @extend Spine.Timestamps
  
  @hasOne 'user', 'App.User'
  @hasMany 'messages', 'App.Message'
  
  # TODO - refactor
  to_users: (users) ->
    if users?
      @_to_users = []
      for user in users
        unless user instanceof App.User
          user = App.User.create(user)
        @_to_users.push(user)
    @_to_users or= []
    
  preview: ->
    messages = @messages().all().sort(App.Message.sentAtAsc)
    
    from_user = (msg.from_user() for msg in messages when not msg.isMe())[0]
    from_user or= @to_users()[0]
    
    message = (msg for msg in messages when not msg.isMe())[0]
    message or= messages[0] or {}
    
    {
      avatar_url: from_user?.avatar_url
      handle:     from_user?.toString() or App.user.handle
      body:       message.body
      timestamp:  new Date(message.sent_at).formatAgo()
    }
    
  open: ->
    # TODO - renable
    # return if @read
    @read = true
    @save()
  
  @sort: (a, b) ->
    earlier = Date.parse(a.updated_at) > Date.parse(b.updated_at)
    if earlier then -1 else 1
    
  @unreadCount: ->
    @select((c)-> not c.read).length<commit_msg>renable<commit_after>class App.Conversation extends Spine.Model
  @configure 'Conversation', 'read', 'received_at', 'to_users'
  @extend Spine.Model.Ajax
  @extend Spine.Timestamps
  
  @hasOne 'user', 'App.User'
  @hasMany 'messages', 'App.Message'
  
  # TODO - refactor
  to_users: (users) ->
    if users?
      @_to_users = []
      for user in users
        unless user instanceof App.User
          user = App.User.create(user)
        @_to_users.push(user)
    @_to_users or= []
    
  preview: ->
    messages = @messages().all().sort(App.Message.sentAtAsc)
    
    from_user = (msg.from_user() for msg in messages when not msg.isMe())[0]
    from_user or= @to_users()[0]
    
    message = (msg for msg in messages when not msg.isMe())[0]
    message or= messages[0] or {}
    
    {
      avatar_url: from_user?.avatar_url
      handle:     from_user?.toString() or App.user.handle
      body:       message.body
      timestamp:  new Date(message.sent_at).formatAgo()
    }
    
  open: ->
    return if @read
    @read = true
    @save()
  
  @sort: (a, b) ->
    earlier = Date.parse(a.updated_at) > Date.parse(b.updated_at)
    if earlier then -1 else 1
    
  @unreadCount: ->
    @select((c)-> not c.read).length
{'fraction_non_alphanumeric': 0.1361992768179992, 'fraction_numerical': 0.004821213338690237, 'mean_word_length': 2.4728033472803346, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4260806', 'n_tokens_mistral': 876, 'n_tokens_neox': 873, 'n_words': 203}