Profile refactoring with friend request
This commit is contained in:
parent
64b0a8c5e3
commit
df7a2f35fb
@ -659,6 +659,14 @@ define([
|
|||||||
};
|
};
|
||||||
mailbox.onEvent = Util.mkEvent();
|
mailbox.onEvent = Util.mkEvent();
|
||||||
|
|
||||||
|
// Universal
|
||||||
|
var universal = common.universal = {};
|
||||||
|
universal.execCommand = function (data, cb) {
|
||||||
|
postMessage("UNIVERSAL_COMMAND", data, cb);
|
||||||
|
};
|
||||||
|
universal.onEvent = Util.mkEvent();
|
||||||
|
|
||||||
|
|
||||||
// Pad RPC
|
// Pad RPC
|
||||||
var pad = common.padRpc = {};
|
var pad = common.padRpc = {};
|
||||||
pad.joinPad = function (data) {
|
pad.joinPad = function (data) {
|
||||||
@ -1097,6 +1105,8 @@ define([
|
|||||||
CURSOR_EVENT: common.cursor.onEvent.fire,
|
CURSOR_EVENT: common.cursor.onEvent.fire,
|
||||||
// Mailbox
|
// Mailbox
|
||||||
MAILBOX_EVENT: common.mailbox.onEvent.fire,
|
MAILBOX_EVENT: common.mailbox.onEvent.fire,
|
||||||
|
// Universal
|
||||||
|
UNIVERSAL_EVENT: common.universal.onEvent.fire,
|
||||||
// Pad
|
// Pad
|
||||||
PAD_READY: common.padRpc.onReadyEvent.fire,
|
PAD_READY: common.padRpc.onReadyEvent.fire,
|
||||||
PAD_MESSAGE: common.padRpc.onMessageEvent.fire,
|
PAD_MESSAGE: common.padRpc.onMessageEvent.fire,
|
||||||
|
|||||||
@ -13,6 +13,7 @@ define([
|
|||||||
'/common/outer/cursor.js',
|
'/common/outer/cursor.js',
|
||||||
'/common/outer/onlyoffice.js',
|
'/common/outer/onlyoffice.js',
|
||||||
'/common/outer/mailbox.js',
|
'/common/outer/mailbox.js',
|
||||||
|
'/common/outer/profile.js',
|
||||||
'/common/outer/network-config.js',
|
'/common/outer/network-config.js',
|
||||||
'/customize/application_config.js',
|
'/customize/application_config.js',
|
||||||
|
|
||||||
@ -23,7 +24,7 @@ define([
|
|||||||
'/bower_components/nthen/index.js',
|
'/bower_components/nthen/index.js',
|
||||||
'/bower_components/saferphore/index.js',
|
'/bower_components/saferphore/index.js',
|
||||||
], function (Sortify, UserObject, ProxyManager, Migrate, Hash, Util, Constants, Feedback, Realtime, Messaging, Messenger,
|
], function (Sortify, UserObject, ProxyManager, Migrate, Hash, Util, Constants, Feedback, Realtime, Messaging, Messenger,
|
||||||
Cursor, OnlyOffice, Mailbox, NetConfig, AppConfig,
|
Cursor, OnlyOffice, Mailbox, Profile, NetConfig, AppConfig,
|
||||||
Crypto, ChainPad, CpNetflux, Listmap, nThen, Saferphore) {
|
Crypto, ChainPad, CpNetflux, Listmap, nThen, Saferphore) {
|
||||||
|
|
||||||
var create = function () {
|
var create = function () {
|
||||||
@ -35,7 +36,9 @@ define([
|
|||||||
|
|
||||||
var storeHash;
|
var storeHash;
|
||||||
|
|
||||||
var store = window.CryptPad_AsyncStore = {};
|
var store = window.CryptPad_AsyncStore = {
|
||||||
|
modules: {}
|
||||||
|
};
|
||||||
|
|
||||||
var onSync = function (cb) {
|
var onSync = function (cb) {
|
||||||
nThen(function (waitFor) {
|
nThen(function (waitFor) {
|
||||||
@ -656,6 +659,9 @@ define([
|
|||||||
});
|
});
|
||||||
});*/
|
});*/
|
||||||
}
|
}
|
||||||
|
if (store.profile) {
|
||||||
|
store.profile.setName(value);
|
||||||
|
}
|
||||||
store.proxy[Constants.displayNameKey] = value;
|
store.proxy[Constants.displayNameKey] = value;
|
||||||
broadcast([clientId], "UPDATE_METADATA");
|
broadcast([clientId], "UPDATE_METADATA");
|
||||||
if (store.messenger) { store.messenger.updateMyData(); }
|
if (store.messenger) { store.messenger.updateMyData(); }
|
||||||
@ -994,6 +1000,39 @@ define([
|
|||||||
cb();
|
cb();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Universal
|
||||||
|
Store.universal = {
|
||||||
|
execCommand: function (clientId, obj, cb) {
|
||||||
|
var type = obj.type;
|
||||||
|
var data = obj.data;
|
||||||
|
if (store.modules[type]) {
|
||||||
|
store.modules[type].execCommand(clientId, data, cb);
|
||||||
|
} else {
|
||||||
|
return void cb({error: type + ' is disabled'});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
var loadUniversal = function (Module, type, waitFor) {
|
||||||
|
if (store.modules[type]) { return; }
|
||||||
|
store.modules[type] = Module.init({
|
||||||
|
store: store,
|
||||||
|
updateMetadata: function () {
|
||||||
|
broadcast([], "UPDATE_METADATA");
|
||||||
|
},
|
||||||
|
pinPads: function (data, cb) { Store.pinPads(null, data, cb); },
|
||||||
|
}, waitFor, function (ev, data, clients) {
|
||||||
|
clients.forEach(function (cId) {
|
||||||
|
postMessage(cId, 'UNIVERSAL_EVENT', {
|
||||||
|
type: type,
|
||||||
|
data: {
|
||||||
|
ev: ev,
|
||||||
|
data: data
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
// Messenger
|
// Messenger
|
||||||
Store.messenger = {
|
Store.messenger = {
|
||||||
execCommand: function (clientId, data, cb) {
|
execCommand: function (clientId, data, cb) {
|
||||||
@ -1394,6 +1433,11 @@ define([
|
|||||||
try {
|
try {
|
||||||
store.mailbox.removeClient(clientId);
|
store.mailbox.removeClient(clientId);
|
||||||
} catch (e) { console.error(e); }
|
} catch (e) { console.error(e); }
|
||||||
|
Object.keys(store.modules).forEach(function (key) {
|
||||||
|
try {
|
||||||
|
store.modules[key].removeClient(clientId);
|
||||||
|
} catch (e) { console.error(e); }
|
||||||
|
});
|
||||||
|
|
||||||
Object.keys(Store.channels).forEach(function (chanId) {
|
Object.keys(Store.channels).forEach(function (chanId) {
|
||||||
var chanIdx = Store.channels[chanId].clients.indexOf(clientId);
|
var chanIdx = Store.channels[chanId].clients.indexOf(clientId);
|
||||||
@ -1469,6 +1513,24 @@ define([
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
var loadProfile = function (waitFor) {
|
||||||
|
store.profile = Profile.init({
|
||||||
|
store: store,
|
||||||
|
updateMetadata: function () {
|
||||||
|
broadcast([], "UPDATE_METADATA");
|
||||||
|
},
|
||||||
|
pinPads: function (data, cb) { Store.pinPads(null, data, cb); },
|
||||||
|
}, waitFor, function (ev, data, clients) {
|
||||||
|
clients.forEach(function (cId) {
|
||||||
|
postMessage(cId, 'PROFILE_EVENT', {
|
||||||
|
ev: ev,
|
||||||
|
data: data
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
*/
|
||||||
var loadCursor = function () {
|
var loadCursor = function () {
|
||||||
store.cursor = Cursor.init(store, function (ev, data, clients) {
|
store.cursor = Cursor.init(store, function (ev, data, clients) {
|
||||||
clients.forEach(function (cId) {
|
clients.forEach(function (cId) {
|
||||||
@ -1618,6 +1680,7 @@ define([
|
|||||||
loadCursor();
|
loadCursor();
|
||||||
loadOnlyOffice();
|
loadOnlyOffice();
|
||||||
loadMailbox(waitFor);
|
loadMailbox(waitFor);
|
||||||
|
loadUniversal(Profile, 'profile', waitFor);
|
||||||
cleanFriendRequests();
|
cleanFriendRequests();
|
||||||
}).nThen(function () {
|
}).nThen(function () {
|
||||||
var requestLogin = function () {
|
var requestLogin = function () {
|
||||||
|
|||||||
@ -68,6 +68,8 @@ define([
|
|||||||
CURSOR_COMMAND: Store.cursor.execCommand,
|
CURSOR_COMMAND: Store.cursor.execCommand,
|
||||||
// Mailbox
|
// Mailbox
|
||||||
MAILBOX_COMMAND: Store.mailbox.execCommand,
|
MAILBOX_COMMAND: Store.mailbox.execCommand,
|
||||||
|
// Universal
|
||||||
|
UNIVERSAL_COMMAND: Store.universal.execCommand,
|
||||||
// Pad
|
// Pad
|
||||||
SEND_PAD_MSG: Store.sendPadMsg,
|
SEND_PAD_MSG: Store.sendPadMsg,
|
||||||
JOIN_PAD: Store.joinPad,
|
JOIN_PAD: Store.joinPad,
|
||||||
|
|||||||
@ -329,7 +329,7 @@ define([
|
|||||||
for (var k in additionalPriv) { metaObj.priv[k] = additionalPriv[k]; }
|
for (var k in additionalPriv) { metaObj.priv[k] = additionalPriv[k]; }
|
||||||
|
|
||||||
if (cfg.addData) {
|
if (cfg.addData) {
|
||||||
cfg.addData(metaObj.priv, Cryptpad);
|
cfg.addData(metaObj.priv, Cryptpad, metaObj.user);
|
||||||
}
|
}
|
||||||
|
|
||||||
sframeChan.event('EV_METADATA_UPDATE', metaObj);
|
sframeChan.event('EV_METADATA_UPDATE', metaObj);
|
||||||
@ -872,6 +872,13 @@ define([
|
|||||||
Cryptpad.cursor.execCommand(data, cb);
|
Cryptpad.cursor.execCommand(data, cb);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Cryptpad.universal.onEvent.reg(function (data) {
|
||||||
|
sframeChan.event('EV_UNIVERSAL_EVENT', data);
|
||||||
|
});
|
||||||
|
sframeChan.on('Q_UNIVERSAL_COMMAND', function (data, cb) {
|
||||||
|
Cryptpad.universal.execCommand(data, cb);
|
||||||
|
});
|
||||||
|
|
||||||
Cryptpad.mailbox.onEvent.reg(function (data) {
|
Cryptpad.mailbox.onEvent.reg(function (data) {
|
||||||
sframeChan.event('EV_MAILBOX_EVENT', data);
|
sframeChan.event('EV_MAILBOX_EVENT', data);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -168,6 +168,31 @@ define([
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Universal direct channel
|
||||||
|
var modules = {};
|
||||||
|
funcs.makeUniversal = function (type, cfg) {
|
||||||
|
if (modules[type]) { return; }
|
||||||
|
var sframeChan = funcs.getSframeChannel();
|
||||||
|
modules[type] = {
|
||||||
|
onEvent: cfg.onEvent || function () {}
|
||||||
|
};
|
||||||
|
return {
|
||||||
|
execCommand: function (cmd, data, cb) {
|
||||||
|
sframeChan.query("Q_UNIVERSAL_COMMAND", {
|
||||||
|
type: type,
|
||||||
|
data: {
|
||||||
|
cmd: cmd,
|
||||||
|
data: data
|
||||||
|
}
|
||||||
|
}, function (err, obj) {
|
||||||
|
if (err) { return void cb({error: err}); }
|
||||||
|
cb(obj);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
// Chat
|
// Chat
|
||||||
var padChatChannel;
|
var padChatChannel;
|
||||||
// common-ui-elements needs to be able to get the chat channel to put it in metadata when
|
// common-ui-elements needs to be able to get the chat channel to put it in metadata when
|
||||||
@ -575,6 +600,12 @@ define([
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ctx.sframeChan.on('EV_UNIVERSAL_EVENT', function (obj) {
|
||||||
|
var type = obj.type;
|
||||||
|
if (!type || !modules[type]) { return; }
|
||||||
|
modules[type].onEvent(obj.data);
|
||||||
|
});
|
||||||
|
|
||||||
ctx.metadataMgr.onReady(waitFor());
|
ctx.metadataMgr.onReady(waitFor());
|
||||||
|
|
||||||
funcs.addShortcuts();
|
funcs.addShortcuts();
|
||||||
|
|||||||
@ -99,10 +99,23 @@
|
|||||||
}
|
}
|
||||||
.cp-app-profile-link {
|
.cp-app-profile-link {
|
||||||
font-size: 25px;
|
font-size: 25px;
|
||||||
|
vertical-align: middle;
|
||||||
}
|
}
|
||||||
.cp-app-profile-displayname, .cp-app-profile-link {
|
.cp-app-profile-displayname, .cp-app-profile-link {
|
||||||
line-height: 40px;
|
line-height: 40px;
|
||||||
}
|
}
|
||||||
|
.cp-app-profile-link-code {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
& > button:empty {
|
||||||
|
margin-left: 25px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.cp-app-profile-friend-request {
|
||||||
|
flex: 0;
|
||||||
|
width: 400px;
|
||||||
|
margin-top: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
// I tried using flexbox but messed with how the pencil icon was displayed
|
// I tried using flexbox but messed with how the pencil icon was displayed
|
||||||
@ -116,10 +129,16 @@
|
|||||||
#cp-app-profile-description {
|
#cp-app-profile-description {
|
||||||
position: relative;
|
position: relative;
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
border: 1px solid #DDD;
|
|
||||||
margin-bottom: 20px;
|
margin-bottom: 20px;
|
||||||
|
.cp-app-profile-description-code {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
.cp-app-profile-description-rendered {
|
.cp-app-profile-description-rendered {
|
||||||
|
border: 1px solid #DDD;
|
||||||
padding: 0 15px;
|
padding: 0 15px;
|
||||||
|
&:empty {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.cp-app-profile-description-ok, .cp-app-profile-description-spin {
|
.cp-app-profile-description-ok, .cp-app-profile-description-spin {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
@ -133,7 +152,6 @@
|
|||||||
height: 300px;
|
height: 300px;
|
||||||
}
|
}
|
||||||
.CodeMirror {
|
.CodeMirror {
|
||||||
border: 1px solid #DDD;
|
|
||||||
font-family: monospace;
|
font-family: monospace;
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
line-height: initial;
|
line-height: initial;
|
||||||
@ -144,6 +162,13 @@
|
|||||||
line-height: inherit;
|
line-height: inherit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.cp-app-profile-description-edit {
|
||||||
|
& > button {
|
||||||
|
span {
|
||||||
|
margin-left: 10px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#cp-app-profile-create {
|
#cp-app-profile-create {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
|
|||||||
@ -8,6 +8,7 @@ define([
|
|||||||
'/common/common-util.js',
|
'/common/common-util.js',
|
||||||
'/common/common-interface.js',
|
'/common/common-interface.js',
|
||||||
'/common/common-realtime.js',
|
'/common/common-realtime.js',
|
||||||
|
'/common/hyperscript.js',
|
||||||
'/customize/messages.js',
|
'/customize/messages.js',
|
||||||
'/customize/application_config.js',
|
'/customize/application_config.js',
|
||||||
'/bower_components/marked/marked.min.js',
|
'/bower_components/marked/marked.min.js',
|
||||||
@ -33,6 +34,7 @@ define([
|
|||||||
Util,
|
Util,
|
||||||
UI,
|
UI,
|
||||||
Realtime,
|
Realtime,
|
||||||
|
h,
|
||||||
Messages,
|
Messages,
|
||||||
AppConfig,
|
AppConfig,
|
||||||
Marked,
|
Marked,
|
||||||
@ -75,7 +77,6 @@ define([
|
|||||||
var LINK_ID = "cp-app-profile-link";
|
var LINK_ID = "cp-app-profile-link";
|
||||||
var AVATAR_ID = "cp-app-profile-avatar";
|
var AVATAR_ID = "cp-app-profile-avatar";
|
||||||
var DESCRIPTION_ID = "cp-app-profile-description";
|
var DESCRIPTION_ID = "cp-app-profile-description";
|
||||||
var PUBKEY_ID = "cp-app-profile-pubkey";
|
|
||||||
var CREATE_ID = "cp-app-profile-create";
|
var CREATE_ID = "cp-app-profile-create";
|
||||||
var HEADER_ID = "cp-app-profile-header";
|
var HEADER_ID = "cp-app-profile-header";
|
||||||
var HEADER_RIGHT_ID = "cp-app-profile-rightside";
|
var HEADER_RIGHT_ID = "cp-app-profile-rightside";
|
||||||
@ -85,98 +86,6 @@ define([
|
|||||||
var common;
|
var common;
|
||||||
var sFrameChan;
|
var sFrameChan;
|
||||||
|
|
||||||
var createEditableInput = function ($block, name, ph, getValue, setValue, fallbackValue) {
|
|
||||||
fallbackValue = fallbackValue || ''; // don't ever display 'null' or 'undefined'
|
|
||||||
var lastVal;
|
|
||||||
getValue(function (value) {
|
|
||||||
lastVal = value;
|
|
||||||
var $input = $('<input>', {
|
|
||||||
'id': name+'Input',
|
|
||||||
placeholder: ph
|
|
||||||
}).val(value);
|
|
||||||
var editing = false;
|
|
||||||
var todo = function () {
|
|
||||||
if (editing) { return; }
|
|
||||||
editing = true;
|
|
||||||
|
|
||||||
var newVal = $input.val().trim();
|
|
||||||
|
|
||||||
if (newVal === lastVal) {
|
|
||||||
editing = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
setValue(newVal, function (err) {
|
|
||||||
if (err) { return void console.error(err); }
|
|
||||||
lastVal = newVal;
|
|
||||||
UI.log(Messages._getKey('profile_fieldSaved', [newVal || fallbackValue]));
|
|
||||||
editing = false;
|
|
||||||
});
|
|
||||||
};
|
|
||||||
$input.on('keyup', function (e) {
|
|
||||||
if (e.which === 13) { return void todo(); }
|
|
||||||
if (e.which === 27) {
|
|
||||||
$input.val(lastVal);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
$input.focus(function () {
|
|
||||||
$input.width('');
|
|
||||||
});
|
|
||||||
$input.focusout(todo);
|
|
||||||
$block.append($input);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
/* jshint ignore:start */
|
|
||||||
var isFriend = function (proxy, edKey) {
|
|
||||||
var friends = Util.find(proxy, ['friends']);
|
|
||||||
return typeof(edKey) === 'string' && friends && (edKey in friends);
|
|
||||||
};
|
|
||||||
|
|
||||||
var addCreateInviteLinkButton = function ($container) {
|
|
||||||
return;
|
|
||||||
/*var obj = APP.lm.proxy;
|
|
||||||
|
|
||||||
var proxy = Cryptpad.getProxy();
|
|
||||||
var userViewHash = Util.find(proxy, ['profile', 'view']);
|
|
||||||
|
|
||||||
var edKey = obj.edKey;
|
|
||||||
var curveKey = obj.curveKey;
|
|
||||||
|
|
||||||
if (!APP.readOnly || !curveKey || !edKey || userViewHash === window.location.hash.slice(1) || isFriend(proxy, edKey)) {
|
|
||||||
//console.log("edit mode or missing curve key, or you're viewing your own profile");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// sanitize user inputs
|
|
||||||
|
|
||||||
var unsafeName = obj.name || '';
|
|
||||||
console.log(unsafeName);
|
|
||||||
var name = Util.fixHTML(unsafeName) || Messages.anonymous;
|
|
||||||
console.log(name);
|
|
||||||
|
|
||||||
console.log("Creating invite button");
|
|
||||||
$("<button>", {
|
|
||||||
id: CREATE_INVITE_BUTTON,
|
|
||||||
title: Messages.profile_inviteButtonTitle,
|
|
||||||
})
|
|
||||||
.addClass('btn btn-success')
|
|
||||||
.text(Messages.profile_inviteButton)
|
|
||||||
.click(function () {
|
|
||||||
UI.confirm(Messages._getKey('profile_inviteExplanation', [name]), function (yes) {
|
|
||||||
if (!yes) { return; }
|
|
||||||
console.log(obj.curveKey);
|
|
||||||
UI.alert("TODO");
|
|
||||||
// TODO create a listmap object using your curve keys
|
|
||||||
// TODO fill the listmap object with your invite data
|
|
||||||
// TODO generate link to invite object
|
|
||||||
// TODO copy invite link to clipboard
|
|
||||||
}, null, true);
|
|
||||||
})
|
|
||||||
.appendTo($container);*/
|
|
||||||
};
|
|
||||||
/* jshint ignore:end */
|
|
||||||
|
|
||||||
var addViewButton = function ($container) {
|
var addViewButton = function ($container) {
|
||||||
if (APP.readOnly) {
|
if (APP.readOnly) {
|
||||||
return;
|
return;
|
||||||
@ -198,53 +107,106 @@ define([
|
|||||||
|
|
||||||
var addDisplayName = function ($container) {
|
var addDisplayName = function ($container) {
|
||||||
var $block = $('<div>', {id: DISPLAYNAME_ID}).appendTo($container);
|
var $block = $('<div>', {id: DISPLAYNAME_ID}).appendTo($container);
|
||||||
|
APP.$name = $('<span>', {'class': DISPLAYNAME_ID}).appendTo($block);
|
||||||
|
};
|
||||||
var getValue = function (cb) {
|
var refreshName = function (data) {
|
||||||
cb(APP.lm.proxy.name);
|
APP.$name.text(data.name || Messages.anonymous);
|
||||||
};
|
|
||||||
var placeholder = Messages.profile_namePlaceholder;
|
|
||||||
if (APP.readOnly) {
|
|
||||||
var $span = $('<span>', {'class': DISPLAYNAME_ID}).appendTo($block);
|
|
||||||
getValue(function (value) {
|
|
||||||
$span.text(value || Messages.anonymous);
|
|
||||||
});
|
|
||||||
|
|
||||||
//addCreateInviteLinkButton($block);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var setValue = function (value, cb) {
|
|
||||||
APP.lm.proxy.name = value;
|
|
||||||
Realtime.whenRealtimeSyncs(APP.lm.realtime, cb);
|
|
||||||
};
|
|
||||||
createEditableInput($block, DISPLAYNAME_ID, placeholder, getValue, setValue, Messages.anonymous);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var addLink = function ($container) {
|
var addLink = function ($container) {
|
||||||
var $block = $('<div>', {id: LINK_ID}).appendTo($container);
|
var $block = $('<div>', {id: LINK_ID}).appendTo($container);
|
||||||
var getValue = function (cb) {
|
|
||||||
cb(APP.lm.proxy.url);
|
APP.$link = $('<a>', {
|
||||||
};
|
'class': LINK_ID,
|
||||||
if (APP.readOnly) {
|
target: '_blank',
|
||||||
var $a = $('<a>', {
|
rel: 'noreferrer noopener'
|
||||||
'class': LINK_ID,
|
}).appendTo($block).hide();
|
||||||
target: '_blank',
|
|
||||||
rel: 'noreferrer noopener'
|
APP.$linkEdit = $();
|
||||||
}).appendTo($block);
|
if (APP.readOnly) { return; }
|
||||||
getValue(function (value) {
|
|
||||||
if (!value) {
|
var button = h('button.btn.btn-primary', {
|
||||||
return void $a.hide();
|
title: Messages.clickToEdit
|
||||||
}
|
}, Messages.profile_addLink);
|
||||||
$a.attr('href', value).text(value);
|
APP.$linkEdit = $(button);
|
||||||
|
$block.append(button);
|
||||||
|
var save = h('button.btn.btn-success', Messages.settings_save);
|
||||||
|
var text = h('input');
|
||||||
|
var code = h('div.cp-app-profile-link-code', [
|
||||||
|
text,
|
||||||
|
save
|
||||||
|
]);
|
||||||
|
var div = h('div.cp-app-profile-link-edit', [
|
||||||
|
code
|
||||||
|
]);
|
||||||
|
$block.append(div);
|
||||||
|
$(button).click(function () {
|
||||||
|
$(text).val(APP.$link.attr('href'));
|
||||||
|
$(code).show();
|
||||||
|
APP.editor.refresh();
|
||||||
|
$(button).hide();
|
||||||
|
});
|
||||||
|
$(save).click(function () {
|
||||||
|
$(save).hide();
|
||||||
|
APP.module.execCommand('SET', {
|
||||||
|
key: 'url',
|
||||||
|
value: $(text).val()
|
||||||
|
}, function (data) {
|
||||||
|
APP.updateValues(data);
|
||||||
|
$(code).hide();
|
||||||
|
$(button).show();
|
||||||
|
$(save).show();
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
var refreshLink = function (data) {
|
||||||
|
APP.$linkEdit.removeClass('fa-pencil').removeClass('fa');
|
||||||
|
if (!data.url) {
|
||||||
|
APP.$linkEdit.text(Messages.profile_addLink);
|
||||||
|
return void APP.$link.hide();
|
||||||
|
}
|
||||||
|
APP.$link.attr('href', data.url).text(data.url).show();
|
||||||
|
APP.$linkEdit.text('').addClass('fa fa-pencil');
|
||||||
|
};
|
||||||
|
|
||||||
|
var addFriendRequest = function ($container) {
|
||||||
|
if (!APP.readOnly || !APP.common.isLoggedIn()) { return; }
|
||||||
|
APP.$friend = $('<button>', {
|
||||||
|
'class': 'btn btn-success cp-app-profile-friend-request',
|
||||||
|
});
|
||||||
|
$container.append(APP.$friend);
|
||||||
|
};
|
||||||
|
var refreshFriendRequest = function (data) {
|
||||||
|
if (!APP.$friend) { return; }
|
||||||
|
|
||||||
|
var me = common.getMetadataMgr().getUserData().curvePublic;
|
||||||
|
if (data.curvePublic === me) {
|
||||||
|
APP.$friend.remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
var friends = common.getMetadataMgr().getPrivateData().friends;
|
||||||
|
if (friends[data.curvePublic]) {
|
||||||
|
$(h('p.cp-app-profile-friend', Messages.profile_friend)).insertAfter(APP.$friend);
|
||||||
|
APP.$friend.remove();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var setValue = function (value, cb) {
|
|
||||||
APP.lm.proxy.url = value;
|
var pendingFriends = APP.common.getPendingFriends(); // Friend requests sent
|
||||||
Realtime.whenRealtimeSyncs(APP.lm.realtime, cb);
|
if (pendingFriends[data.curvePublic]) {
|
||||||
};
|
APP.$friend.attr('disabled', 'disabled').text();
|
||||||
var placeholder = Messages.profile_urlPlaceholder;
|
APP.$friend.text(Messages.profile_friendRequestSent);
|
||||||
createEditableInput($block, LINK_ID, placeholder, getValue, setValue);
|
return;
|
||||||
|
}
|
||||||
|
APP.$friend.text(Messages._getKey('userlist_addAsFriendTitle', [data.name]))
|
||||||
|
.off('click')
|
||||||
|
.click(function () {
|
||||||
|
APP.common.sendFriendRequest({
|
||||||
|
curvePublic: data.curvePublic,
|
||||||
|
notifications: data.notifications
|
||||||
|
}, function () {
|
||||||
|
APP.$friend.attr('disabled', 'disabled').text();
|
||||||
|
});
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
var AVATAR_SIZE_LIMIT = 0.5;
|
var AVATAR_SIZE_LIMIT = 0.5;
|
||||||
@ -289,38 +251,44 @@ define([
|
|||||||
};
|
};
|
||||||
reader.readAsDataURL(file);
|
reader.readAsDataURL(file);
|
||||||
};
|
};
|
||||||
var addAvatar = function ($container) {
|
var displayAvatar = function (val) {
|
||||||
var $block = $('<div>', {id: AVATAR_ID}).appendTo($container);
|
|
||||||
var $span = $('<span>').appendTo($block);
|
|
||||||
var sframeChan = common.getSframeChannel();
|
var sframeChan = common.getSframeChannel();
|
||||||
var displayAvatar = function () {
|
var $span = APP.$avatar;
|
||||||
$span.html('');
|
$span.html('');
|
||||||
if (!APP.lm.proxy.avatar) {
|
if (!val) {
|
||||||
$('<img>', {
|
$('<img>', {
|
||||||
src: '/customize/images/avatar.png',
|
src: '/customize/images/avatar.png',
|
||||||
title: Messages.profile_avatar,
|
title: Messages.profile_avatar,
|
||||||
alt: 'Avatar'
|
alt: 'Avatar'
|
||||||
}).appendTo($span);
|
}).appendTo($span);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
common.displayAvatar($span, APP.lm.proxy.avatar);
|
common.displayAvatar($span, val);
|
||||||
|
|
||||||
if (APP.readOnly) { return; }
|
if (APP.readOnly) { return; }
|
||||||
|
|
||||||
var $delButton = $('<button>', {
|
var $delButton = $('<button>', {
|
||||||
'class': 'cp-app-profile-avatar-delete btn btn-danger fa fa-times',
|
'class': 'cp-app-profile-avatar-delete btn btn-danger fa fa-times',
|
||||||
title: Messages.fc_delete
|
title: Messages.fc_delete
|
||||||
});
|
});
|
||||||
$span.append($delButton);
|
$span.append($delButton);
|
||||||
$delButton.click(function () {
|
$delButton.click(function () {
|
||||||
var old = common.getMetadataMgr().getUserData().avatar;
|
var old = common.getMetadataMgr().getUserData().avatar;
|
||||||
|
APP.module.execCommand("SET", {
|
||||||
|
key: 'avatar',
|
||||||
|
value: ""
|
||||||
|
}, function () {
|
||||||
sframeChan.query("Q_PROFILE_AVATAR_REMOVE", old, function (err, err2) {
|
sframeChan.query("Q_PROFILE_AVATAR_REMOVE", old, function (err, err2) {
|
||||||
if (err || err2) { return void UI.log(err || err2); }
|
if (err || err2) { return void UI.log(err || err2); }
|
||||||
delete APP.lm.proxy.avatar;
|
|
||||||
displayAvatar();
|
displayAvatar();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
});
|
||||||
|
};
|
||||||
|
var addAvatar = function ($container) {
|
||||||
|
var $block = $('<div>', {id: AVATAR_ID}).appendTo($container);
|
||||||
|
APP.$avatar = $('<span>').appendTo($block);
|
||||||
|
var sframeChan = common.getSframeChannel();
|
||||||
displayAvatar();
|
displayAvatar();
|
||||||
if (APP.readOnly) { return; }
|
if (APP.readOnly) { return; }
|
||||||
|
|
||||||
@ -331,10 +299,14 @@ define([
|
|||||||
onUploaded: function (ev, data) {
|
onUploaded: function (ev, data) {
|
||||||
var old = common.getMetadataMgr().getUserData().avatar;
|
var old = common.getMetadataMgr().getUserData().avatar;
|
||||||
var todo = function () {
|
var todo = function () {
|
||||||
sframeChan.query("Q_PROFILE_AVATAR_ADD", data.url, function (err, err2) {
|
APP.module.execCommand("SET", {
|
||||||
if (err || err2) { return void UI.log(err || err2); }
|
key: 'avatar',
|
||||||
APP.lm.proxy.avatar = data.url;
|
value: data.url
|
||||||
displayAvatar();
|
}, function () {
|
||||||
|
sframeChan.query("Q_PROFILE_AVATAR_ADD", data.url, function (err, err2) {
|
||||||
|
if (err || err2) { return void UI.log(err || err2); }
|
||||||
|
displayAvatar(data.url);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
if (old) {
|
if (old) {
|
||||||
@ -378,30 +350,37 @@ define([
|
|||||||
$upButton.prepend($('<span>', {'class': 'fa fa-upload'}));
|
$upButton.prepend($('<span>', {'class': 'fa fa-upload'}));
|
||||||
$block.append($upButton);
|
$block.append($upButton);
|
||||||
};
|
};
|
||||||
|
var refreshAvatar = function (data) {
|
||||||
|
displayAvatar(data.avatar);
|
||||||
|
};
|
||||||
|
|
||||||
var addDescription = function ($container) {
|
var addDescription = function ($container) {
|
||||||
var $block = $('<div>', {id: DESCRIPTION_ID}).appendTo($container);
|
var $block = $('<div>', {id: DESCRIPTION_ID}).appendTo($container);
|
||||||
|
|
||||||
if (APP.readOnly) {
|
APP.$description = $('<div>', {'class': 'cp-app-profile-description-rendered'}).appendTo($block);
|
||||||
if (!(APP.lm.proxy.description || "").trim()) { return void $block.hide(); }
|
APP.$descriptionEdit = $();
|
||||||
var $div = $('<div>', {'class': 'cp-app-profile-description-rendered'}).appendTo($block);
|
if (APP.readOnly) { return; }
|
||||||
var val = Marked(APP.lm.proxy.description);
|
|
||||||
$div.html(val);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$('<h3>').text(Messages.profile_description).insertBefore($block);
|
|
||||||
|
|
||||||
var $ok = $('<span>', {
|
var button = h('button.btn.btn-primary', [
|
||||||
'class': 'cp-app-profile-description-ok fa fa-check',
|
h('i.fa.fa-pencil'),
|
||||||
title: Messages.saved
|
h('span', Messages.profile_addDescription)
|
||||||
}).appendTo($block);
|
]);
|
||||||
var $spinner = $('<span>', {
|
APP.$descriptionEdit = $(button);
|
||||||
'class': 'cp-app-profile-description-spin fa fa-spinner fa-pulse'
|
var save = h('button.btn.btn-primary', Messages.settings_save);
|
||||||
}).appendTo($block);
|
var text = h('textarea');
|
||||||
|
var code = h('div.cp-app-profile-description-code', [
|
||||||
|
text,
|
||||||
|
h('br'),
|
||||||
|
save
|
||||||
|
]);
|
||||||
|
var div = h('div.cp-app-profile-description-edit', [
|
||||||
|
h('p.cp-app-profile-info', Messages.profile_info),
|
||||||
|
button,
|
||||||
|
code
|
||||||
|
]);
|
||||||
|
$block.append(div);
|
||||||
|
|
||||||
var $textarea = $('<textarea>').val(APP.lm.proxy.description || '');
|
var editor = APP.editor = CodeMirror.fromTextArea(text, {
|
||||||
$block.append($textarea);
|
|
||||||
var editor = APP.editor = CodeMirror.fromTextArea($textarea[0], {
|
|
||||||
lineNumbers: true,
|
lineNumbers: true,
|
||||||
lineWrapping: true,
|
lineWrapping: true,
|
||||||
styleActiveLine : true,
|
styleActiveLine : true,
|
||||||
@ -409,25 +388,34 @@ define([
|
|||||||
});
|
});
|
||||||
|
|
||||||
var markdownTb = common.createMarkdownToolbar(editor);
|
var markdownTb = common.createMarkdownToolbar(editor);
|
||||||
$block.prepend(markdownTb.toolbar);
|
$(code).prepend(markdownTb.toolbar);
|
||||||
|
$(markdownTb.toolbar).show();
|
||||||
|
|
||||||
var onLocal = function () {
|
$(button).click(function () {
|
||||||
$ok.hide();
|
$(code).show();
|
||||||
$spinner.show();
|
APP.editor.refresh();
|
||||||
var val = editor.getValue();
|
$(button).hide();
|
||||||
APP.lm.proxy.description = val;
|
});
|
||||||
Realtime.whenRealtimeSyncs(APP.lm.realtime, function () {
|
$(save).click(function () {
|
||||||
$ok.show();
|
$(save).hide();
|
||||||
$spinner.hide();
|
APP.module.execCommand('SET', {
|
||||||
|
key: 'description',
|
||||||
|
value: editor.getValue()
|
||||||
|
}, function (data) {
|
||||||
|
APP.updateValues(data);
|
||||||
|
$(code).hide();
|
||||||
|
$(button).show();
|
||||||
|
$(save).show();
|
||||||
});
|
});
|
||||||
};
|
});
|
||||||
|
|
||||||
editor.on('change', onLocal);
|
|
||||||
};
|
};
|
||||||
|
var refreshDescription = function (data) {
|
||||||
var addPublicKey = function ($container) {
|
var val = Marked(data.description || "");
|
||||||
var $block = $('<div>', {id: PUBKEY_ID});
|
APP.$description.html(val);
|
||||||
$container.append($block);
|
APP.$descriptionEdit.find('span').text(val === "" ? Messages.profile_addDescription : Messages.profile_editDescription);
|
||||||
|
if (!APP.editor) { return; }
|
||||||
|
APP.editor.setValue(data.description || "");
|
||||||
|
APP.editor.save();
|
||||||
};
|
};
|
||||||
|
|
||||||
var createLeftside = function () {
|
var createLeftside = function () {
|
||||||
@ -438,7 +426,7 @@ define([
|
|||||||
$category.append(Messages.profileButton);
|
$category.append(Messages.profileButton);
|
||||||
};
|
};
|
||||||
|
|
||||||
var onReady = function () {
|
var init = function () {
|
||||||
APP.$container.find('#'+CREATE_ID).remove();
|
APP.$container.find('#'+CREATE_ID).remove();
|
||||||
|
|
||||||
if (!APP.initialized) {
|
if (!APP.initialized) {
|
||||||
@ -447,14 +435,20 @@ define([
|
|||||||
var $rightside = $('<div>', {id: HEADER_RIGHT_ID}).appendTo($header);
|
var $rightside = $('<div>', {id: HEADER_RIGHT_ID}).appendTo($header);
|
||||||
addDisplayName($rightside);
|
addDisplayName($rightside);
|
||||||
addLink($rightside);
|
addLink($rightside);
|
||||||
|
addFriendRequest($rightside);
|
||||||
addDescription(APP.$rightside);
|
addDescription(APP.$rightside);
|
||||||
addViewButton(APP.$rightside);
|
addViewButton(APP.$rightside);
|
||||||
addPublicKey(APP.$rightside);
|
|
||||||
APP.initialized = true;
|
APP.initialized = true;
|
||||||
createLeftside();
|
createLeftside();
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
UI.removeLoadingScreen();
|
var updateValues = APP.updateValues = function (data) {
|
||||||
|
refreshAvatar(data);
|
||||||
|
refreshName(data);
|
||||||
|
refreshLink(data);
|
||||||
|
refreshDescription(data);
|
||||||
|
refreshFriendRequest(data);
|
||||||
};
|
};
|
||||||
|
|
||||||
var createToolbar = function () {
|
var createToolbar = function () {
|
||||||
@ -470,6 +464,16 @@ define([
|
|||||||
APP.toolbar.$rightside.hide();
|
APP.toolbar.$rightside.hide();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var onEvent = function (obj) {
|
||||||
|
var ev = obj.ev;
|
||||||
|
var data = obj.data;
|
||||||
|
if (ev === 'UPDATE') {
|
||||||
|
console.log('Update');
|
||||||
|
updateValues(data);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
nThen(function (waitFor) {
|
nThen(function (waitFor) {
|
||||||
$(waitFor(UI.addLoadingScreen));
|
$(waitFor(UI.addLoadingScreen));
|
||||||
SFCommon.create(waitFor(function (c) { APP.common = common = c; }));
|
SFCommon.create(waitFor(function (c) { APP.common = common = c; }));
|
||||||
@ -508,6 +512,23 @@ define([
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (privateData.isOwnProfile) {
|
||||||
|
|
||||||
|
APP.module = common.makeUniversal('profile', {
|
||||||
|
onEvent: onEvent
|
||||||
|
});
|
||||||
|
var execCommand = APP.module.execCommand;
|
||||||
|
|
||||||
|
init();
|
||||||
|
|
||||||
|
console.log('POST SUBSCRIBE');
|
||||||
|
execCommand('SUBSCRIBE', null, function (obj) {
|
||||||
|
updateValues(obj);
|
||||||
|
UI.removeLoadingScreen();
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var listmapConfig = {
|
var listmapConfig = {
|
||||||
data: {},
|
data: {},
|
||||||
common: common,
|
common: common,
|
||||||
@ -517,6 +538,12 @@ define([
|
|||||||
|
|
||||||
var lm = APP.lm = Listmap.create(listmapConfig);
|
var lm = APP.lm = Listmap.create(listmapConfig);
|
||||||
|
|
||||||
lm.proxy.on('ready', onReady);
|
init();
|
||||||
|
lm.proxy.on('ready', function () {
|
||||||
|
updateValues(lm.proxy);
|
||||||
|
UI.removeLoadingScreen();
|
||||||
|
}).on('change', [], function () {
|
||||||
|
updateValues(lm.proxy);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -43,18 +43,13 @@ define([
|
|||||||
// No password for profiles
|
// No password for profiles
|
||||||
return void cb(null, Hash.getSecrets('profile', window.location.hash.slice(1)));
|
return void cb(null, Hash.getSecrets('profile', window.location.hash.slice(1)));
|
||||||
}
|
}
|
||||||
var editHash;
|
|
||||||
nThen(function (waitFor) {
|
nThen(function (waitFor) {
|
||||||
// 2nd case: visiting our own existing profile
|
// 2nd case: visiting our own existing profile
|
||||||
Cryptpad.getProfileEditUrl(waitFor(function (hash) {
|
Cryptpad.getProfileEditUrl(waitFor(function (hash) {
|
||||||
editHash = hash;
|
waitFor.abort();
|
||||||
|
return void cb(null, Hash.getSecrets('profile', hash));
|
||||||
}));
|
}));
|
||||||
}).nThen(function () {
|
}).nThen(function () {
|
||||||
if (editHash) {
|
|
||||||
// No password for profile
|
|
||||||
return void cb(null, Hash.getSecrets('profile', editHash));
|
|
||||||
}
|
|
||||||
// 3rd case: profile creation (create a new random hash, store it later if needed)
|
|
||||||
if (!Utils.LocalStore.isLoggedIn()) {
|
if (!Utils.LocalStore.isLoggedIn()) {
|
||||||
// Unregistered users can't create a profile
|
// Unregistered users can't create a profile
|
||||||
window.location.href = '/drive/';
|
window.location.href = '/drive/';
|
||||||
@ -79,6 +74,10 @@ define([
|
|||||||
cb(null, secret);
|
cb(null, secret);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
var addData = function (meta, Cryptad, user) {
|
||||||
|
meta.isOwnProfile = !window.location.hash ||
|
||||||
|
window.location.hash.slice(1) === user.profile;
|
||||||
|
};
|
||||||
var addRpc = function (sframeChan, Cryptpad, Utils) {
|
var addRpc = function (sframeChan, Cryptpad, Utils) {
|
||||||
// Adding a new avatar from the profile: pin it and store it in the object
|
// Adding a new avatar from the profile: pin it and store it in the object
|
||||||
sframeChan.on('Q_PROFILE_AVATAR_ADD', function (data, cb) {
|
sframeChan.on('Q_PROFILE_AVATAR_ADD', function (data, cb) {
|
||||||
@ -100,6 +99,7 @@ define([
|
|||||||
getSecrets: getSecrets,
|
getSecrets: getSecrets,
|
||||||
noHash: true, // Don't add the hash in the URL if it doesn't already exist
|
noHash: true, // Don't add the hash in the URL if it doesn't already exist
|
||||||
addRpc: addRpc,
|
addRpc: addRpc,
|
||||||
|
addData: addData,
|
||||||
owned: true
|
owned: true
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user