set uid in cursor object in outer scope

rather than within each app that uses cursors
This commit is contained in:
ansuz 2021-08-27 18:23:07 +05:30
parent 1e1890dbe4
commit c416303e1d
8 changed files with 9 additions and 21 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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();

View File

@ -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;
};

View File

@ -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) {

View File

@ -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

View File

@ -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;

View File

@ -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);