fixed one last fight

pull/1/head
Caleb James DeLisle 7 years ago
parent 9c0b0cc6a8
commit 33e73dd5e5

@ -2,7 +2,6 @@ define([], function () {
var UNINIT = 'uninitialized'; var UNINIT = 'uninitialized';
var create = function (sframeChan) { var create = function (sframeChan) {
var meta = UNINIT; var meta = UNINIT;
var myID = UNINIT;
var members = []; var members = [];
var metadataObj = UNINIT; var metadataObj = UNINIT;
var dirty = true; var dirty = true;
@ -11,27 +10,27 @@ define([], function () {
var checkUpdate = function () { var checkUpdate = function () {
if (!dirty) { return; } if (!dirty) { return; }
if (meta === UNINIT) { throw new Error(); } if (meta === UNINIT) { throw new Error(); }
if (myID === UNINIT) { myID = meta.myID; }
if (metadataObj === UNINIT) { if (metadataObj === UNINIT) {
metadataObj = { metadataObj = {
defaultTitle: meta.doc.defaultTitle, defaultTitle: meta.doc.defaultTitle,
title: meta.doc.defaultTitle, title: meta.doc.defaultTitle,
type: meta.doc.type,
users: {} users: {}
}; };
} }
var mdo = {}; var mdo = {};
// We don't want to add our user data to the object multiple times. // We don't want to add our user data to the object multiple times.
var containsYou = false; var containsYou = false;
console.log(metadataObj); //console.log(metadataObj);
Object.keys(metadataObj.users).forEach(function (x) { Object.keys(metadataObj.users).forEach(function (x) {
if (members.indexOf(x) === -1) { return; } if (members.indexOf(x) === -1) { return; }
mdo[x] = metadataObj.users[x]; mdo[x] = metadataObj.users[x];
if (metadataObj.users[x].uid === meta.user.uid) { if (metadataObj.users[x].uid === meta.user.uid) {
console.log('document already contains you'); //console.log('document already contains you');
containsYou = true; containsYou = true;
} }
}); });
if (!containsYou) { mdo[myID] = meta.user; } if (!containsYou) { mdo[meta.user.netfluxId] = meta.user; }
metadataObj.users = mdo; metadataObj.users = mdo;
dirty = false; dirty = false;
changeHandlers.forEach(function (f) { f(); }); changeHandlers.forEach(function (f) { f(); });
@ -46,7 +45,7 @@ define([], function () {
change(); change();
}); });
sframeChan.on('EV_RT_CONNECT', function (ev) { sframeChan.on('EV_RT_CONNECT', function (ev) {
myID = ev.myID; meta.user.netfluxId = ev.myID;
members = ev.members; members = ev.members;
change(); change();
}); });

@ -622,6 +622,10 @@ define([
// Update the user list (metadata) from the hyperjson // Update the user list (metadata) from the hyperjson
// XXX Metadata.update(shjson); // XXX Metadata.update(shjson);
var parsed = JSON.parse(shjson);
if (parsed[3] && parsed[3].metadata) {
cpNfInner.metadataMgr.updateMetadata(parsed[3].metadata);
}
if (!readOnly) { if (!readOnly) {
var shjson2 = stringifyDOM(inner); var shjson2 = stringifyDOM(inner);

@ -19,10 +19,11 @@ define([
Cryptpad.ready(waitFor()); Cryptpad.ready(waitFor());
}).nThen(function (waitFor) { }).nThen(function (waitFor) {
var parsed = Cryptpad.parsePadUrl(window.location.href); var parsed = Cryptpad.parsePadUrl(window.location.href);
parsed.type = parsed.type.replace('pad2', 'pad');
if (!parsed.type) { throw new Error(); } if (!parsed.type) { throw new Error(); }
var defaultTitle = Cryptpad.getDefaultName(parsed); var defaultTitle = Cryptpad.getDefaultName(parsed);
var updateMeta = function () { var updateMeta = function () {
console.log('EV_METADATA_UPDATE'); //console.log('EV_METADATA_UPDATE');
var name; var name;
nThen(function (waitFor) { nThen(function (waitFor) {
Cryptpad.getLastName(waitFor(function (n) { name = n })); Cryptpad.getLastName(waitFor(function (n) { name = n }));
@ -32,13 +33,13 @@ define([
defaultTitle: defaultTitle, defaultTitle: defaultTitle,
type: parsed.type type: parsed.type
}, },
myID: Cryptpad.getNetwork().webChannels[0].myID,
user: { user: {
name: name, name: name,
uid: Cryptpad.getUid(), uid: Cryptpad.getUid(),
avatar: Cryptpad.getAvatarUrl(), avatar: Cryptpad.getAvatarUrl(),
profile: Cryptpad.getProfileUrl(), profile: Cryptpad.getProfileUrl(),
curvePublic: Cryptpad.getProxy().curvePublic curvePublic: Cryptpad.getProxy().curvePublic,
netfluxId: Cryptpad.getNetwork().webChannels[0].myID,
} }
}); });
}); });

Loading…
Cancel
Save