export default Ember.Component.extend({

  tagName: 'li',
  topicVersion: 0,

  topic: Ember.computed('topicVersion', function() { return Discourse.Babble && Discourse.Babble.topic }),
  unreadCount: Ember.computed('topicVersion', function() {
    var topic = this.get('topic')
    if (!topic) { return 0 }
    return topic.highest_post_number - topic.last_read_post_number
  }),

  _init: function() {
    const self = this
    const messageBus = Discourse.__container__.lookup('message-bus:main')

    if (!Discourse.Babble) {
      Discourse.Babble = {}
      Discourse.Babble.refresh = function(data) {
        if (!data.id) {
          self.set('noTopicAvailable', true)
          return
        }

        var topic = Discourse.Topic.create(data)
        var postStream = Discourse.PostStream.create(topic.post_stream)

        postStream.posts = topic.post_stream.posts
        postStream.topic = topic

        Discourse.Babble.topic = topic
        Discourse.Babble.postStream = postStream

        var updateIfGiven = function(field, data) {
          Discourse.Babble.topic[field] = data[field] || Discourse.Babble.topic[field]
        }

        updateIfGiven('last_read_post_number', data)
        updateIfGiven('highest_post_number', data)

        self.set('topicVersion', self.get('topicVersion') + 1)
      }
    }

    Discourse.ajax('/babble/topic.json').then(Discourse.Babble.refresh)
    messageBus.subscribe('/babble/topic', Discourse.Babble.refresh)
  }.on('init')
});

@@ -742,24 +742,245 @@
 reate(data)%0A
+        topic.last_read_post_number = data.last_read_post_number %7C%7C Discourse.Babble.topic.last_read_post_number%0A        topic.highest_post_number = data.highest_post_number %7C%7C Discourse.Babble.topic.highest_post_number%0A%0A
         var 
@@ -1039,17 +1039,16 @@
 stream)%0A
-%0A
         
@@ -1217,263 +1217,8 @@
 am%0A%0A
-        var updateIfGiven = function(field, data) %7B%0A          Discourse.Babble.topic%5Bfield%5D = data%5Bfield%5D %7C%7C Discourse.Babble.topic%5Bfield%5D%0A        %7D%0A%0A        updateIfGiven('last_read_post_number', data)%0A        updateIfGiven('highest_post_number', data)%0A%0A
     

Fix live updating unread count