From 54eefd3d9470365f6f75b6b584a3654bb4fddf51 Mon Sep 17 00:00:00 2001 From: ansuz Date: Fri, 25 Aug 2017 16:07:53 +0200 Subject: [PATCH 1/9] replace contacts with contacts2 --- customize.dist/pages.js | 4 -- customize.dist/template.js | 5 +- www/contacts/main.js | 17 ++--- www/{contacts2 => contacts}/messenger-ui.js | 0 www/contacts2/index.html | 30 --------- www/contacts2/inner.html | 17 ----- www/contacts2/main.js | 75 --------------------- 7 files changed, 10 insertions(+), 138 deletions(-) rename www/{contacts2 => contacts}/messenger-ui.js (100%) delete mode 100644 www/contacts2/index.html delete mode 100644 www/contacts2/inner.html delete mode 100644 www/contacts2/main.js diff --git a/customize.dist/pages.js b/customize.dist/pages.js index f9a5addc6..784fc007f 100644 --- a/customize.dist/pages.js +++ b/customize.dist/pages.js @@ -657,10 +657,6 @@ define([ return loadingScreen(); }; - Pages['/contacts2/'] = Pages['/contacts2/index.html'] = function () { - return loadingScreen(); - }; - Pages['/pad/'] = Pages['/pad/index.html'] = function () { return loadingScreen(); }; diff --git a/customize.dist/template.js b/customize.dist/template.js index a980270a3..062be4308 100644 --- a/customize.dist/template.js +++ b/customize.dist/template.js @@ -9,7 +9,7 @@ define([ $(function () { var $body = $('body'); var isMainApp = function () { - return /^\/(pad|code|slide|poll|whiteboard|file|media|contacts|contacts2|drive|settings|profile|todo)\/$/.test(location.pathname); + return /^\/(pad|code|slide|poll|whiteboard|file|media|contacts|drive|settings|profile|todo)\/$/.test(location.pathname); }; var infoPage = function () { @@ -55,9 +55,6 @@ $(function () { } else if (/^\/contacts\/$/.test(pathname)) { $('body').append(h('body', Pages[pathname]()).innerHTML); require([ '/contacts/main.js' ], ready); - } else if (/contacts2/.test(pathname)) { - $('body').append(h('body', Pages[pathname]()).innerHTML); - require([ '/contacts2/main.js' ], ready); } else if (/pad/.test(pathname)) { $('body').append(h('body', Pages[pathname]()).innerHTML); require([ '/pad/main.js' ], ready); diff --git a/www/contacts/main.js b/www/contacts/main.js index 4803a812a..f1d58029c 100644 --- a/www/contacts/main.js +++ b/www/contacts/main.js @@ -4,9 +4,12 @@ define([ '/common/toolbar2.js', '/common/cryptpad-common.js', + '/common/common-messenger.js', + '/contacts/messenger-ui.js', + 'css!/bower_components/components-font-awesome/css/font-awesome.min.css', 'less!/customize/src/less/cryptpad.less', -], function ($, Crypto, Toolbar, Cryptpad) { +], function ($, Crypto, Toolbar, Cryptpad, Messenger, UI) { var Messages = Cryptpad.Messages; var APP = window.APP = { @@ -46,14 +49,11 @@ define([ console.error('reconnecting: ', uid); Cryptpad.findOKButton().click(); - APP.messenger.cleanFriendChannels(); - APP.messenger.openFriendChannels(); - APP.messenger.setEditable(true); + //APP.messenger.cleanFriendChannels(); + //APP.messenger.openFriendChannels(); + //APP.messenger.setEditable(true); }); - var ui = APP.ui = Cryptpad.initMessagingUI(Cryptpad, $list, $messages); - APP.messenger = Cryptpad.initMessaging(Cryptpad, ui); - var $infoBlock = $('
', {'class': 'info'}).appendTo($messages); $('

').text(Messages.contacts_info1).appendTo($infoBlock); var $ul = $('
    ').appendTo($infoBlock); @@ -61,7 +61,8 @@ define([ $('
  • ').text(Messages.contacts_info3).appendTo($ul); //$('
  • ').text(Messages.contacts_info4).appendTo($ul); - Cryptpad.removeLoadingScreen(); + var messenger = window.messenger = Messenger.messenger(Cryptpad); + UI.create(messenger, $list, $messages); }; Cryptpad.ready(function () { diff --git a/www/contacts2/messenger-ui.js b/www/contacts/messenger-ui.js similarity index 100% rename from www/contacts2/messenger-ui.js rename to www/contacts/messenger-ui.js diff --git a/www/contacts2/index.html b/www/contacts2/index.html deleted file mode 100644 index a76879a6d..000000000 --- a/www/contacts2/index.html +++ /dev/null @@ -1,30 +0,0 @@ - - - - CryptPad - - - - - - - - diff --git a/www/contacts2/inner.html b/www/contacts2/inner.html deleted file mode 100644 index ebfb164c8..000000000 --- a/www/contacts2/inner.html +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - -
    -
    -
    -
    -
    - - - diff --git a/www/contacts2/main.js b/www/contacts2/main.js deleted file mode 100644 index 664ffc333..000000000 --- a/www/contacts2/main.js +++ /dev/null @@ -1,75 +0,0 @@ -define([ - 'jquery', - '/bower_components/chainpad-crypto/crypto.js', - '/common/toolbar2.js', - '/common/cryptpad-common.js', - - '/common/common-messenger.js', - '/contacts2/messenger-ui.js', - - 'css!/bower_components/components-font-awesome/css/font-awesome.min.css', - 'less!/customize/src/less/cryptpad.less', -], function ($, Crypto, Toolbar, Cryptpad, Messenger, UI) { - var Messages = Cryptpad.Messages; - - var APP = window.APP = { - Cryptpad: Cryptpad - }; - - $(function () { - - var andThen = function () { - Cryptpad.addLoadingScreen(); - - var ifrw = $('#pad-iframe')[0].contentWindow; - var $iframe = $('#pad-iframe').contents(); - //var $appContainer = $iframe.find('#app'); - var $list = $iframe.find('#friendList'); - var $messages = $iframe.find('#messaging'); - var $bar = $iframe.find('.toolbar-container'); - - var displayed = ['useradmin', 'newpad', 'limit', 'pageTitle']; - - - var configTb = { - displayed: displayed, - ifrw: ifrw, - common: Cryptpad, - $container: $bar, - network: Cryptpad.getNetwork(), - pageTitle: Messages.contacts_title, - }; - var toolbar = APP.toolbar = Toolbar.create(configTb); - toolbar.$rightside.html(''); // Remove the drawer if we don't use it to hide the toolbar - - Cryptpad.getProxy().on('disconnect', function () { - Cryptpad.alert(Messages.common_connectionLost, undefined, true); - Cryptpad.enableMessaging(false); - }); - Cryptpad.getProxy().on('reconnect', function (uid) { - console.error('reconnecting: ', uid); - Cryptpad.findOKButton().click(); - - //APP.messenger.cleanFriendChannels(); - //APP.messenger.openFriendChannels(); - //APP.messenger.setEditable(true); - }); - - var $infoBlock = $('
    ', {'class': 'info'}).appendTo($messages); - $('

    ').text(Messages.contacts_info1).appendTo($infoBlock); - var $ul = $('
      ').appendTo($infoBlock); - $('
    • ').text(Messages.contacts_info2).appendTo($ul); - $('
    • ').text(Messages.contacts_info3).appendTo($ul); - //$('
    • ').text(Messages.contacts_info4).appendTo($ul); - - var messenger = window.messenger = Messenger.messenger(Cryptpad); - UI.create(messenger, $list, $messages); - }; - - Cryptpad.ready(function () { - andThen(); - Cryptpad.reportAppUsage(); - }); - - }); -}); From 818742dd5653cde44404c65b3062af789c874cb5 Mon Sep 17 00:00:00 2001 From: Caleb James DeLisle Date: Mon, 28 Aug 2017 11:20:24 +0200 Subject: [PATCH 2/9] Add frame-src for IE/Edge compatibility --- config.example.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/config.example.js b/config.example.js index 1b28a5e89..ce38b5c3a 100644 --- a/config.example.js +++ b/config.example.js @@ -35,6 +35,8 @@ module.exports = { * domain which will serve your CryptPad instance. */ "child-src blob: *", + // IE/Edge + "frame-src blob: *", "media-src * blob:", @@ -62,7 +64,9 @@ module.exports = { /* See above under 'contentSecurity' as to how these values should be * configured for best effect. */ - "child-src *", + "child-src *", + // IE/Edge + "frame-src *", // see the comment above in the 'contentSecurity' section "connect-src 'self' ws: wss:" + domain, From abec07b1f9ae7bf660146cf3d21949788b5889b2 Mon Sep 17 00:00:00 2001 From: Caleb James DeLisle Date: Mon, 28 Aug 2017 11:21:01 +0200 Subject: [PATCH 3/9] If config.js is missing, fallback to config.example.js which is in the git repo --- server.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/server.js b/server.js index faab366f6..baf9b2e99 100644 --- a/server.js +++ b/server.js @@ -10,7 +10,13 @@ var NetfluxSrv = require('./node_modules/chainpad-server/NetfluxWebsocketSrv'); var Package = require('./package.json'); var Path = require("path"); -var config = require('./config'); +var config; +try { + config = require('./config'); +} catch (e) { + console.log("You can customize the configuration by copying config.example.js to config.js"); + config = require('./config.example'); +} var websocketPort = config.websocketPort || config.httpPort; var useSecureWebsockets = config.useSecureWebsockets || false; From e62faf7c7b544020c185ccf04d2cca8e4ee52fe2 Mon Sep 17 00:00:00 2001 From: Caleb James DeLisle Date: Mon, 28 Aug 2017 11:22:57 +0200 Subject: [PATCH 4/9] Edge fix, always use async iframe onLoad rather than invoking it manually --- www/pad2/wysiwygarea-plugin.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/www/pad2/wysiwygarea-plugin.js b/www/pad2/wysiwygarea-plugin.js index c7f827000..7a0d08788 100644 --- a/www/pad2/wysiwygarea-plugin.js +++ b/www/pad2/wysiwygarea-plugin.js @@ -55,7 +55,12 @@ define(['/api/config'], function (ApiConfig) { // Asynchronous iframe loading is only required in IE>8 and Gecko (other reasons probably). // Do not use it on WebKit as it'll break the browser-back navigation. - var useOnloadEvent = ( CKEDITOR.env.ie && !CKEDITOR.env.edge ) || CKEDITOR.env.gecko; + var useOnloadEvent = ( CKEDITOR.env.ie && !CKEDITOR.env.edge ) || CKEDITOR.env.gecko; + + // CryptPad + // This breaks Edge so lets use async all of the time + useOnloadEvent = true; + if ( useOnloadEvent ) iframe.on( 'load', onLoad ); From 91f6e3e5435b965314b1333b6bd078125d3c8acb Mon Sep 17 00:00:00 2001 From: ansuz Date: Mon, 28 Aug 2017 11:28:45 +0200 Subject: [PATCH 5/9] remove a lot of dead code --- www/common/common-messaging.js | 819 --------------------------------- www/common/cryptpad-common.js | 2 - www/contacts/main.js | 7 - www/contacts/messenger-ui.js | 7 - 4 files changed, 835 deletions(-) diff --git a/www/common/common-messaging.js b/www/common/common-messaging.js index e4f2d20e3..2dbd370ae 100644 --- a/www/common/common-messaging.js +++ b/www/common/common-messaging.js @@ -6,62 +6,16 @@ define([ '/bower_components/marked/marked.min.js', '/common/common-realtime.js', - - // displayAvatar - // whenRealtimeSyncs - // getRealtime -> removeFromFriendList - /* UI - Messages - confirm - fixHTML - displayAvatar - clearOwnedChannel - alert - - - pushMsg - removeFromFriendList - - onDirectMessage - getNetwork - getProxy - pushMsg - - Init - getNetwork - getProxy - onDirectMessage - removeFromFriendList - notify - onMessage - - */ - ], function ($, Crypto, Curve, Hash, Marked, Realtime) { var Msg = { inputs: [], }; - - var Types = { - message: 'MSG', - update: 'UPDATE', - unfriend: 'UNFRIEND', - mapId: 'MAP_ID', - mapIdAck: 'MAP_ID_ACK' - }; - // TODO // - mute a channel (hide notifications or don't open it?) - - var ready = []; var pending = {}; var pendingRequests = []; - var parseMessage = function (content) { - return Marked(content); - }; - var createData = Msg.createData = function (proxy, hash) { return { channel: hash || Hash.createChannelId(), @@ -82,13 +36,6 @@ define([ return proxy.friends ? proxy.friends[pubkey] : undefined; }; - var removeFromFriendList = function (proxy, realtime, curvePublic, cb) { - if (!proxy.friends) { return; } - var friends = proxy.friends; - delete friends[curvePublic]; - Realtime.whenRealtimeSyncs(realtime, cb); - }; - var getFriendList = Msg.getFriendList = function (proxy) { if (!proxy.friends) { proxy.friends = {}; } return proxy.friends; @@ -101,7 +48,6 @@ define([ }); }; - Msg.getFriendChannelsList = function (proxy) { var list = []; eachFriend(proxy, function (friend) { @@ -110,500 +56,9 @@ define([ return list; }; - // Messaging tools - var avatars = {}; - // TODO make this internal to the messenger var channels = Msg.channels = window.channels = {}; - var UI = Msg.UI = {}; - - UI.init = function (common, $listContainer, $msgContainer) { - var ui = { - containers: { - friendList: $listContainer, - messages: $msgContainer, - }, - }; - - ui.addToFriendList = function (data, display, remove) { - var $block = ui.containers.friendBlock; - - var $friend = $('
      ', {'class': 'friend avatar'}).appendTo($block); - $friend.data('key', data.curvePublic); - var $rightCol = $('', {'class': 'right-col'}); - $('', {'class': 'name'}).text(data.displayName).appendTo($rightCol); - var $remove = $('', {'class': 'remove fa fa-user-times'}).appendTo($rightCol); - $remove.attr('title', common.Messages.contacts_remove); - $friend.dblclick(function () { - if (data.profile) { - window.open('/profile/#' + data.profile); - } - }); - $friend.click(function () { - display(data.curvePublic); - }); - $remove.click(function (e) { - e.stopPropagation(); - common.confirm(common.Messages._getKey('contacts_confirmRemove', [ - common.fixHTML(data.displayName) - ]), function (yes) { - if (!yes) { return; } - remove(data.curvePublic); - }, null, true); - }); - if (data.avatar && avatars[data.avatar]) { - $friend.append(avatars[data.avatar]); - $friend.append($rightCol); - } else { - common.displayAvatar($friend, data.avatar, data.displayName, function ($img) { - if (data.avatar && $img) { - avatars[data.avatar] = $img[0].outerHTML; - } - $friend.append($rightCol); - }); - } - $('', {'class': 'status'}).appendTo($friend); - }; - - ui.createFriendList = function (friends, display, remove) { - var $block = ui.containers.friendBlock = $('
      '); - eachFriend(friends, function (friend) { - ui.addToFriendList(friend, display, remove); - }); - $block.appendTo($listContainer); - }; - - ui.notify = function (curvePublic) { - var $friend = $listContainer.find('.friend').filter(function (idx, el) { - return $(el).data('key') === curvePublic; - }); - $friend.addClass('notify'); - }; - - ui.unnotify = function (curvePublic) { - var $friend = $listContainer.find('.friend').filter(function (idx, el) { - return $(el).data('key') === curvePublic; - }); - $friend.removeClass('notify'); - }; - - ui.update = function (curvePublic, types) { - var proxy = common.getProxy(); - var data = getFriend(proxy, curvePublic); - var chan = channels[data.channel]; - if (!chan.ready) { - chan.updateOnReady = (chan.updateOnReady || []).concat(types); - return; - } - var $friend = $listContainer.find('.friend').filter(function (idx, el) { - return $(el).data('key') === curvePublic; - }); - if (types.indexOf('displayName') >= 0) { - $friend.find('.name').text(data.displayName); - } - if (types.indexOf('avatar') >= 0) { - $friend.find('.default').remove(); - $friend.find('media-tag').remove(); - if (data.avatar && avatars[data.avatar]) { - $friend.prepend(avatars[data.avatar]); - } else { - common.displayAvatar($friend, data.avatar, data.displayName, function ($img) { - if (data.avatar && $img) { - avatars[data.avatar] = $img[0].outerHTML; - } - }); - } - } - }; - - ui.updateStatus = function (curvePublic, online) { - ui.getFriend(curvePublic).find('.status') - .attr('class', 'status ' + (online? 'online' : 'offline')); - }; - - ui.getChannel = function (curvePublic) { - var $chat = $msgContainer.find('.chat').filter(function (idx, el) { - return $(el).data('key') === curvePublic; - }); - return $chat.length? $chat: null; - }; - - ui.hideInfo = function () { - $msgContainer.find('.info').hide(); - }; - - ui.showInfo = function () { - $msgContainer.find('.info').show(); - }; - - ui.createChat = function (curvePublic) { - return $('
      ', {'class':'chat'}) - .data('key', curvePublic).appendTo($msgContainer); - }; - - ui.hideChat = function () { - $msgContainer.find('.chat').hide(); - }; - - ui.getFriend = function (curvePublic) { - return $listContainer.find('.friend').filter(function (idx, el) { - return $(el).data('key') === curvePublic; - }); - }; - - ui.remove = function (curvePublic) { - var $friend = ui.getFriend(curvePublic); - var $chat = ui.getChannel(curvePublic); - $friend.remove(); - if ($chat) { $chat.remove(); } - ui.showInfo(); - }; - - ui.createMessage = function (msg, name) { - var $msg = $('
      ', {'class': 'message'}) - .attr('title', msg.time ? new Date(msg.time).toLocaleString(): '?'); - - if (name) { - $('
      ', {'class':'sender'}).text(name).appendTo($msg); - } - - $('
      ', {'class':'content'}).html(parseMessage(msg.text)).appendTo($msg); - return $msg; - }; - - ui.setEditable = function (bool) { - bool = !bool; - var input = ui.input; - if (!input) { return; } - - if (bool) { - input.setAttribute('disabled', bool); - } else { - input.removeAttribute('disabled'); - } - - if (common.Messages) { - // set placeholder - var placeholder = bool? - common.Messages.disconnected: - common.Messages.contacts_typeHere; - input.setAttribute('placeholder', placeholder); - } - }; - - ui.createChatBox = function (proxy, $container, curvePublic) { - var data = getFriend(proxy, curvePublic); - - // Input - var channel = channels[data.channel]; - - var $header = $('
      ', { - 'class': 'header', - }).appendTo($container); - - var $avatar = $('
      ', {'class': 'avatar'}).appendTo($header); - - // more history... - $('', { - 'class': 'more-history', - }) - .text('get more history') - .click(function () { - console.log("GETTING HISTORY"); - channel.getPreviousMessages(); - }) - .appendTo($header); - - var $removeHistory = $('', { - 'class': 'remove-history fa fa-eraser', - title: common.Messages.contacts_removeHistoryTitle - }) - .click(function () { - common.confirm(common.Messages.contacts_confirmRemoveHistory, function (yes) { - if (!yes) { return; } - common.clearOwnedChannel(data.channel, function (e) { - if (e) { - console.error(e); - common.alert(common.Messages.contacts_removeHistoryServerError); - return; - } - }); - }); - }); - $removeHistory.appendTo($header); - - $('
      ', {'class': 'messages'}).appendTo($container); - var $inputBlock = $('
      ', {'class': 'input'}).appendTo($container); - - var $input = $('