Merge pull request #9 from sharelatex/as-decode-ranges

Decode comments & track changes from real-time
This commit is contained in:
Alasdair Smith 2017-09-22 13:50:37 +01:00 committed by GitHub
commit 2d3bae2f7b

View file

@ -252,21 +252,34 @@ define [
_joinDoc: (callback = (error) ->) -> _joinDoc: (callback = (error) ->) ->
if @doc? if @doc?
@ide.socket.emit 'joinDoc', @doc_id, @doc.getVersion(), (error, docLines, version, updates, ranges) => @ide.socket.emit 'joinDoc', @doc_id, @doc.getVersion(), { encodeRanges: true }, (error, docLines, version, updates, ranges) =>
return callback(error) if error? return callback(error) if error?
@joined = true @joined = true
@doc.catchUp( updates ) @doc.catchUp( updates )
@_decodeRanges(ranges)
@_catchUpRanges(ranges?.changes, ranges?.comments) @_catchUpRanges(ranges?.changes, ranges?.comments)
callback() callback()
else else
@ide.socket.emit 'joinDoc', @doc_id, (error, docLines, version, updates, ranges) => @ide.socket.emit 'joinDoc', @doc_id, { encodeRanges: true }, (error, docLines, version, updates, ranges) =>
return callback(error) if error? return callback(error) if error?
@joined = true @joined = true
@doc = new ShareJsDoc @doc_id, docLines, version, @ide.socket @doc = new ShareJsDoc @doc_id, docLines, version, @ide.socket
@_decodeRanges(ranges)
@ranges = new RangesTracker(ranges?.changes, ranges?.comments) @ranges = new RangesTracker(ranges?.changes, ranges?.comments)
@_bindToShareJsDocEvents() @_bindToShareJsDocEvents()
callback() callback()
_decodeRanges: (ranges) ->
decodeFromWebsockets = (text) -> decodeURIComponent(escape(text))
try
for change in ranges.changes or []
change.op.i = decodeFromWebsockets(change.op.i) if change.op.i?
change.op.d = decodeFromWebsockets(change.op.d) if change.op.d?
for comment in ranges.comments or []
comment.op.c = decodeFromWebsockets(comment.op.c) if comment.op.c?
catch err
console.log(err)
_leaveDoc: (callback = (error) ->) -> _leaveDoc: (callback = (error) ->) ->
sl_console.log '[_leaveDoc] Sending leaveDoc request' sl_console.log '[_leaveDoc] Sending leaveDoc request'
@ide.socket.emit 'leaveDoc', @doc_id, (error) => @ide.socket.emit 'leaveDoc', @doc_id, (error) =>