From c416303e1d3f9d9fb74821abedf23141e23b8b44 Mon Sep 17 00:00:00 2001 From: ansuz Date: Fri, 27 Aug 2021 18:23:07 +0530 Subject: [PATCH] set uid in cursor object in outer scope rather than within each app that uses cursors --- www/code/inner.js | 4 +--- www/code/markers.js | 5 +++-- www/common/outer/cursor.js | 1 + www/common/sframe-common-codemirror.js | 1 - www/kanban/inner.js | 2 -- www/pad/cursor.js | 8 +------- www/pad/inner.js | 3 +-- www/slide/inner.js | 6 ++---- 8 files changed, 9 insertions(+), 21 deletions(-) diff --git a/www/code/inner.js b/www/code/inner.js index 4328f0d8f..4f6c0308e 100644 --- a/www/code/inner.js +++ b/www/code/inner.js @@ -388,9 +388,7 @@ define([ var andThen2 = function (editor, CodeMirror, framework, isPresentMode) { var common = framework._.sfCommon; - var metadataMgr = common.getMetadataMgr(); - var privateData = metadataMgr.getPrivateData(); - CodeMirror.uid = metadataMgr.getUserData().uid; + var privateData = common.getMetadataMgr().getPrivateData(); var previewPane = mkPreviewPane(editor, CodeMirror, framework, isPresentMode); var markdownTb = mkMarkdownTb(editor, framework); diff --git a/www/code/markers.js b/www/code/markers.js index b8a53bdd9..48e5a25fb 100644 --- a/www/code/markers.js +++ b/www/code/markers.js @@ -4,7 +4,8 @@ define([ '/customize/messages.js', '/bower_components/chainpad/chainpad.dist.js', '/common/inner/common-mediatag.js', -], function (Util, SFCodeMirror, Messages, ChainPad, MT) { + '/common/common-interface.js', +], function (Util, SFCodeMirror, Messages, ChainPad, MT, UI) { var Markers = {}; /* TODO Known Issues @@ -39,7 +40,7 @@ define([ }); } uid = Number(uid); - var name = Util.fixHTML((author.name || "").trim()); + var name = Util.fixHTML(UI.getDisplayName(author.name)); var animal; if ((!name || name === Messages.anonymous) && typeof(author.uid) === 'string') { animal = MT.getPseudorandomAnimal(author.uid); diff --git a/www/common/outer/cursor.js b/www/common/outer/cursor.js index 95b2b34c6..b1a5e7cd0 100644 --- a/www/common/outer/cursor.js +++ b/www/common/outer/cursor.js @@ -187,6 +187,7 @@ define([ data.color = Util.find(proxy, ['settings', 'general', 'cursor', 'color']); data.name = proxy[Constants.displayNameKey] || ctx.store.noDriveName || Messages.anonymous; data.avatar = Util.find(proxy, ['profile', 'avatar']); + data.uid = Util.find(proxy, ['uid']) || ctx.store.noDriveUid; c.cursor = data; sendMyCursor(ctx, client); cb(); diff --git a/www/common/sframe-common-codemirror.js b/www/common/sframe-common-codemirror.js index 4e490288d..58475bbed 100644 --- a/www/common/sframe-common-codemirror.js +++ b/www/common/sframe-common-codemirror.js @@ -509,7 +509,6 @@ define([ var cursor = {}; cursor.selectionStart = cursorToPos(editor.getCursor('from'), doc); cursor.selectionEnd = cursorToPos(editor.getCursor('to'), doc); - cursor.uid = exp.uid; // FIXME this is inefficient for the network but it's unlikely to trigger errors return cursor; }; diff --git a/www/kanban/inner.js b/www/kanban/inner.js index 6934dd210..368d18139 100644 --- a/www/kanban/inner.js +++ b/www/kanban/inner.js @@ -1272,9 +1272,7 @@ define([ var myCursor = {}; onCursorUpdate.reg(function (data) { - console.log('onCursorUpdate', data); myCursor = data; - myCursor.uid = myData.uid; framework.updateCursor(); }); framework.onCursorUpdate(function (data) { diff --git a/www/pad/cursor.js b/www/pad/cursor.js index fbca1a9cf..5b4c60ad7 100644 --- a/www/pad/cursor.js +++ b/www/pad/cursor.js @@ -37,7 +37,7 @@ define([ $(el).remove(); }; - Cursor.create = function (inner, hjsonToDom, cursorModule, uid) { + Cursor.create = function (inner, hjsonToDom, cursorModule) { var exp = {}; var cursors = {}; @@ -147,12 +147,6 @@ define([ var cursorObj = data.cursor; if (!cursorObj.selectionStart) { return; } - if (cursorObj.name === Messages.anonymous) { - // save a little bit of data from going over the wire... - // remote clients will interpret this as Messages.anonymous (in their UI language) - cursorObj.name = ''; - cursorObj.uid = uid; - } // 1. Transform the cursor to get the offset relative to our doc // 2. Turn it into a range diff --git a/www/pad/inner.js b/www/pad/inner.js index e89cd9a0a..95e7c1bff 100644 --- a/www/pad/inner.js +++ b/www/pad/inner.js @@ -678,7 +678,6 @@ define([ var metadataMgr = framework._.sfCommon.getMetadataMgr(); var privateData = metadataMgr.getPrivateData(); - var myData = metadataMgr.getUserData(); var common = framework._.sfCommon; var APP = window.APP; @@ -705,7 +704,7 @@ define([ var cursor = module.cursor = Cursor(inner); // Display other users cursor - var cursors = Cursors.create(inner, hjsonToDom, cursor, myData.uid); + var cursors = Cursors.create(inner, hjsonToDom, cursor); var openLink = function(e) { var el = e.currentTarget; diff --git a/www/slide/inner.js b/www/slide/inner.js index 9bbfc6e4d..9c9b9c70b 100644 --- a/www/slide/inner.js +++ b/www/slide/inner.js @@ -459,9 +459,7 @@ define([ var andThen2 = function (editor, CodeMirror, framework, isPresentMode) { var common = framework._.sfCommon; - var metadataMgr = common.getMetadataMgr(); - var privateData = metadataMgr.getPrivateData(); - CodeMirror.uid = metadataMgr.getUserData().uid; + var privateData = common.getMetadataMgr().getPrivateData(); var $contentContainer = $('#cp-app-slide-editor'); var $modal = $('#cp-app-slide-modal'); @@ -513,7 +511,7 @@ define([ framework.updateCursor(); }, 500); // 500ms to make sure it is sent after chainpad sync }; - framework.onCursorUpdate(CodeMirror.setRemoteCursor); // XXX + framework.onCursorUpdate(CodeMirror.setRemoteCursor); framework.setCursorGetter(CodeMirror.getCursor); editor.on('cursorActivity', updateCursor);