set uid in cursor object in outer scope

rather than within each app that uses cursors
pull/1/head
ansuz 3 years ago
parent 1e1890dbe4
commit c416303e1d

@ -388,9 +388,7 @@ define([
var andThen2 = function (editor, CodeMirror, framework, isPresentMode) { var andThen2 = function (editor, CodeMirror, framework, isPresentMode) {
var common = framework._.sfCommon; var common = framework._.sfCommon;
var metadataMgr = common.getMetadataMgr(); var privateData = common.getMetadataMgr().getPrivateData();
var privateData = metadataMgr.getPrivateData();
CodeMirror.uid = metadataMgr.getUserData().uid;
var previewPane = mkPreviewPane(editor, CodeMirror, framework, isPresentMode); var previewPane = mkPreviewPane(editor, CodeMirror, framework, isPresentMode);
var markdownTb = mkMarkdownTb(editor, framework); var markdownTb = mkMarkdownTb(editor, framework);

@ -4,7 +4,8 @@ define([
'/customize/messages.js', '/customize/messages.js',
'/bower_components/chainpad/chainpad.dist.js', '/bower_components/chainpad/chainpad.dist.js',
'/common/inner/common-mediatag.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 = {}; var Markers = {};
/* TODO Known Issues /* TODO Known Issues
@ -39,7 +40,7 @@ define([
}); });
} }
uid = Number(uid); uid = Number(uid);
var name = Util.fixHTML((author.name || "").trim()); var name = Util.fixHTML(UI.getDisplayName(author.name));
var animal; var animal;
if ((!name || name === Messages.anonymous) && typeof(author.uid) === 'string') { if ((!name || name === Messages.anonymous) && typeof(author.uid) === 'string') {
animal = MT.getPseudorandomAnimal(author.uid); animal = MT.getPseudorandomAnimal(author.uid);

@ -187,6 +187,7 @@ define([
data.color = Util.find(proxy, ['settings', 'general', 'cursor', 'color']); data.color = Util.find(proxy, ['settings', 'general', 'cursor', 'color']);
data.name = proxy[Constants.displayNameKey] || ctx.store.noDriveName || Messages.anonymous; data.name = proxy[Constants.displayNameKey] || ctx.store.noDriveName || Messages.anonymous;
data.avatar = Util.find(proxy, ['profile', 'avatar']); data.avatar = Util.find(proxy, ['profile', 'avatar']);
data.uid = Util.find(proxy, ['uid']) || ctx.store.noDriveUid;
c.cursor = data; c.cursor = data;
sendMyCursor(ctx, client); sendMyCursor(ctx, client);
cb(); cb();

@ -509,7 +509,6 @@ define([
var cursor = {}; var cursor = {};
cursor.selectionStart = cursorToPos(editor.getCursor('from'), doc); cursor.selectionStart = cursorToPos(editor.getCursor('from'), doc);
cursor.selectionEnd = cursorToPos(editor.getCursor('to'), 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; return cursor;
}; };

@ -1272,9 +1272,7 @@ define([
var myCursor = {}; var myCursor = {};
onCursorUpdate.reg(function (data) { onCursorUpdate.reg(function (data) {
console.log('onCursorUpdate', data);
myCursor = data; myCursor = data;
myCursor.uid = myData.uid;
framework.updateCursor(); framework.updateCursor();
}); });
framework.onCursorUpdate(function (data) { framework.onCursorUpdate(function (data) {

@ -37,7 +37,7 @@ define([
$(el).remove(); $(el).remove();
}; };
Cursor.create = function (inner, hjsonToDom, cursorModule, uid) { Cursor.create = function (inner, hjsonToDom, cursorModule) {
var exp = {}; var exp = {};
var cursors = {}; var cursors = {};
@ -147,12 +147,6 @@ define([
var cursorObj = data.cursor; var cursorObj = data.cursor;
if (!cursorObj.selectionStart) { return; } 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 // 1. Transform the cursor to get the offset relative to our doc
// 2. Turn it into a range // 2. Turn it into a range

@ -678,7 +678,6 @@ define([
var metadataMgr = framework._.sfCommon.getMetadataMgr(); var metadataMgr = framework._.sfCommon.getMetadataMgr();
var privateData = metadataMgr.getPrivateData(); var privateData = metadataMgr.getPrivateData();
var myData = metadataMgr.getUserData();
var common = framework._.sfCommon; var common = framework._.sfCommon;
var APP = window.APP; var APP = window.APP;
@ -705,7 +704,7 @@ define([
var cursor = module.cursor = Cursor(inner); var cursor = module.cursor = Cursor(inner);
// Display other users cursor // 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 openLink = function(e) {
var el = e.currentTarget; var el = e.currentTarget;

@ -459,9 +459,7 @@ define([
var andThen2 = function (editor, CodeMirror, framework, isPresentMode) { var andThen2 = function (editor, CodeMirror, framework, isPresentMode) {
var common = framework._.sfCommon; var common = framework._.sfCommon;
var metadataMgr = common.getMetadataMgr(); var privateData = common.getMetadataMgr().getPrivateData();
var privateData = metadataMgr.getPrivateData();
CodeMirror.uid = metadataMgr.getUserData().uid;
var $contentContainer = $('#cp-app-slide-editor'); var $contentContainer = $('#cp-app-slide-editor');
var $modal = $('#cp-app-slide-modal'); var $modal = $('#cp-app-slide-modal');
@ -513,7 +511,7 @@ define([
framework.updateCursor(); framework.updateCursor();
}, 500); // 500ms to make sure it is sent after chainpad sync }, 500); // 500ms to make sure it is sent after chainpad sync
}; };
framework.onCursorUpdate(CodeMirror.setRemoteCursor); // XXX framework.onCursorUpdate(CodeMirror.setRemoteCursor);
framework.setCursorGetter(CodeMirror.getCursor); framework.setCursorGetter(CodeMirror.getCursor);
editor.on('cursorActivity', updateCursor); editor.on('cursorActivity', updateCursor);

Loading…
Cancel
Save