<commit_before>fetched = (obj) ->
  obj.fetch()
  obj

class window.Channel extends Backbone.Model
  initialize: (opts) ->
    @on "activate", @setActive
    @on "deactivate", @setNotActive

  setActive: ->
    @isActive = true

  setNotActive: ->
    @isActive = false

  user: -> new User(@get("created_by"))

  cached: (field, retrieval) ->
    @cache ||= {}
    @cache[field] = (@cache[field] || retrieval())

  subchannels: ->
    @cached 'subchannels', => fetched(new SubchannelList(channel: this))

  relatedChannels: ->
    @cached 'relatedchannels', => fetched(new RelatedChannels [], forChannel: this)

  lastAddedFactAsActivity: ->
    @cached 'lastFactAsActivity', =>
      console.info('creating new lastfactactivity')
      new LastFactActivity(channel: this)

  topic: ->
    new Topic
      slug_title: @get 'slug_title'
      title: @get 'title'

  facts: ->
    new ChannelFacts [],
      channel: this

  topicUrl: -> "/t/#{@get('slug_title')}"

  getOwnContainingChannels: ->
    containingChannels = @get("containing_channel_ids")
    ret = []
    currentUser.channels.each (ch) ->
      if _.indexOf(containingChannels, ch.id) isnt -1
        ret.push ch.clone()

    new OwnChannelCollection ret

  urlRoot: "/facts/"

  url: ->
    if @collection
      Backbone.Model::url.apply this, arguments
    else
      @normal_url()

  normal_url: ->
    "/" + @getUsername() + "/channels/" + @get("id")

  getUsername: ->
    @get("created_by")?.username ? @get("username")<commit_msg>Reverted copy paste error<commit_after>fetched = (obj) ->
  obj.fetch()
  obj

class window.Channel extends Backbone.Model
  initialize: (opts) ->
    @on "activate", @setActive
    @on "deactivate", @setNotActive

  setActive: ->
    @isActive = true

  setNotActive: ->
    @isActive = false

  user: -> new User(@get("created_by"))

  cached: (field, retrieval) ->
    @cache ||= {}
    @cache[field] = (@cache[field] || retrieval())

  subchannels: ->
    @cached 'subchannels', => fetched(new SubchannelList(channel: this))

  relatedChannels: ->
    @cached 'relatedchannels', => fetched(new RelatedChannels [], forChannel: this)

  lastAddedFactAsActivity: ->
    @cached 'lastFactAsActivity', =>
      console.info('creating new lastfactactivity')
      new LastFactActivity(channel: this)

  topic: ->
    new Topic
      slug_title: @get 'slug_title'
      title: @get 'title'

  facts: ->
    new ChannelFacts [],
      channel: this

  topicUrl: -> "/t/#{@get('slug_title')}"

  getOwnContainingChannels: ->
    containingChannels = @get("containing_channel_ids")
    ret = []
    currentUser.channels.each (ch) ->
      if _.indexOf(containingChannels, ch.id) isnt -1
        ret.push ch.clone()

    new OwnChannelCollection ret

  url: ->
    if @collection
      Backbone.Model::url.apply this, arguments
    else
      @normal_url()

  normal_url: ->
    "/" + @getUsername() + "/channels/" + @get("id")

  getUsername: ->
    @get("created_by")?.username ? @get("username")
{'fraction_non_alphanumeric': 0.15474598930481284, 'fraction_numerical': 0.0006684491978609625, 'mean_word_length': 3.1511789181692094, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 43, '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': '3210405', 'n_tokens_mistral': 986, 'n_tokens_neox': 949, 'n_words': 206}