   getShareIdentifier: ->
     @shareIdentifier
 
+  attachDecoration: (userSnapshot) ->
+    # reset markers
+    @markers?.forEach (marker) =>
+      marker.destroy()
+    @markers = []
+
+    # attach decorations
+    users = userSnapshot.val()
+    for uid, user of users
+      # uncomment below if you want to hide the cursor of self
+      # continue if user.userId is @userId
+      marker = @editor.markBufferRange([
+        [user.pos.row, 0]
+        [user.pos.row, 0]
+      ], invalidate: 'never')
+      @markers.push marker
+      decoration = @editor.decorateMarker marker,
+        type: 'overlay',
+        item: @getCursorElement user
+
+  getCursorElement: (user) ->
+    element = document.createElement('div')
+    element.setAttribute 'class', 'popover-list'
+    element.setAttribute 'style',
+      """
+      background-color: #{user.color};
+      display: block;
+      padding: 3px;
+      font-size: 12px;
+      color: white;
+      """
+    element.textContent = user.displayName
+    element
+
+  updateCursorPosition: (event) ->
+    @firebaseCursor.set(event.newBufferPosition)
+
   remove: ->
     # @firepad.dispose() # Won't work #4
     # @subscriptions.dispose()
     # @emitter.emit 'did-destroy'
+    @firebaseUserSelf.remove()
     atom.notifications.addWarning('The "unshare" function is due dependencies buggy, and wont work. Please close the pane, to stop sharing!')
 
   onDidDestroy: (callback) ->

    @handleEditorEvents()

    hash = Crypto.createHash('sha256').update(@shareIdentifier).digest('base64')
    @firebase = new Firebase(atom.config.get('firepad.firebaseUrl')).child(hash)

    @firebase.once 'value', (snapshot) =>
      options = {sv_: Firebase.ServerValue.TIMESTAMP}
      if not snapshot.val() and @editor.getText() isnt ''
        options.overwrite = true
      else
        @editor.setText ''
      @firepad = Firepad.fromAtom @firebase, @editor, options
    #   @shareview.show(@shareIdentifier)

  handleEditorEvents: ->
    @subscriptions.add @editor.onDidDestroy =>
      @remove()


{CompositeDisposable} = require 'atom'
{Emitter} = require 'event-kit'
Crypto = require 'crypto'
os = require 'os'
Firebase = require 'firebase'
Firepad = require './firepad-lib'

