 class window.ActivitiesGroupView extends Backbone.Marionette.CompositeView
+  className: 'activity-group'
+  itemView: Backbone.View
+  itemViewContainer: ".js-region-activities"
+
   @new: (options)->
     new (@classForModel(options.model))(options)
 


  actions: -> []

  appendable: (model) -> model.get('action') in @actions()

  tryAppend: (model) ->
    return false unless @appendable(model)
    @append model
    true

  append: (model) ->
    unless @lastView?.tryAppend(model)
      @collection.add model

class UserActivitiesGroupView extends ActivitiesGroupView
  className: 'activity-group'
  itemView: Backbone.View
  itemViewContainer: ".js-region-activities"

  constructor: ->
    super
    @on 'render', @makeUserTooltip

  itemViewOptions: ->
    $offsetParent: @$el

  sameUser: (model) -> @model.user().get('username') == model.user().get('username')

  appendable: (model) -> super(model) and @sameUser(model)

  buildItemView: (item, ItemView, itemViewOptions) ->
    options = _.extend({model: item}, itemViewOptions)
    @lastView = ActivityItemView.for(options)

  activityMadeRedundantBy: (newActivity, oldActivity) -> false
  newActivityIsRedundant: (newActivity) ->
    return false unless @collection.models.length > 1
    @activityMadeRedundantBy newActivity,
      @collection.models[@collection.length - 2]

  appendHtml: (collectionView, itemView, index) ->
    return if @newActivityIsRedundant(itemView.model)
    super

class UserFactActivitiesGroupView extends UserActivitiesGroupView
  template: 'activities/user_fact_activities_group'

  @actions: ["created_comment", "created_sub_comment", "believes", "disbelieves", "doubts"]
  actions: -> UserFactActivitiesGroupView.actions

  onRender: ->
    @$('.js-region-fact').html @factView().render().el

      if action in group_view.actions
        return group_view

    return ActivitiesGroupView

  templateHelpers: ->
    user: @user?.toJSON()
