mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-27 09:22:44 +00:00
Merge pull request #9 from sharelatex/as-decode-ranges
Decode comments & track changes from real-time
This commit is contained in:
commit
2d3bae2f7b
1 changed files with 16 additions and 3 deletions
|
@ -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 )
|
||||||
@_catchUpRanges( ranges?.changes, ranges?.comments )
|
@_decodeRanges(ranges)
|
||||||
|
@_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) =>
|
||||||
|
|
Loading…
Reference in a new issue