From 096b0fb44aba3687b45068cfedf58114de229824 Mon Sep 17 00:00:00 2001 From: ansuz Date: Thu, 5 Sep 2019 12:22:30 +0200 Subject: [PATCH] move 'getDefaultName' out of 'common-hash' --- www/common/common-hash.js | 17 +---------------- www/common/cryptpad-common.js | 1 - www/common/outer/async-store.js | 4 +++- www/common/outer/userObject.js | 2 +- www/common/sframe-common-outer.js | 8 +++++--- www/common/userObject.js | 16 ++++++++++++++++ 6 files changed, 26 insertions(+), 22 deletions(-) diff --git a/www/common/common-hash.js b/www/common/common-hash.js index e49b0e217..756877857 100644 --- a/www/common/common-hash.js +++ b/www/common/common-hash.js @@ -1,9 +1,8 @@ define([ '/common/common-util.js', - '/customize/messages.js', '/bower_components/chainpad-crypto/crypto.js', '/bower_components/tweetnacl/nacl-fast.min.js' -], function (Util, Messages, Crypto) { +], function (Util, Crypto) { var Nacl = window.nacl; var Hash = window.CryptPad_Hash = {}; @@ -515,20 +514,6 @@ Version 1 '/' + curvePublic.replace(/\//g, '-') + '/'; }; - // Create untitled documents when no name is given - var getLocaleDate = function () { - if (window.Intl && window.Intl.DateTimeFormat) { - var options = {weekday: "short", year: "numeric", month: "long", day: "numeric"}; - return new window.Intl.DateTimeFormat(undefined, options).format(new Date()); - } - return new Date().toString().split(' ').slice(0,4).join(' '); - }; - Hash.getDefaultName = function (parsed) { - var type = parsed.type; - var name = (Messages.type)[type] + ' - ' + getLocaleDate(); - return name; - }; - Hash.isValidHref = function (href) { // Non-empty href? if (!href) { return; } diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index f8c3f1545..0c4ccb3a3 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -648,7 +648,6 @@ define([ data.href = parsed.getUrl({present: parsed.present}); if (typeof (data.title) !== "string") { return cb('Missing title'); } - if (data.title.trim() === "") { data.title = Hash.getDefaultName(parsed); } if (common.initialPath) { if (!data.path) { diff --git a/www/common/outer/async-store.js b/www/common/outer/async-store.js index 4a7696749..928978574 100644 --- a/www/common/outer/async-store.js +++ b/www/common/outer/async-store.js @@ -507,7 +507,7 @@ define([ roHref: roHref, atime: now, ctime: now, - title: title || Hash.getDefaultName(Hash.parsePadUrl(href)), + title: title || UserObject.getDefaultName(Hash.parsePadUrl(href)), }; }; @@ -805,6 +805,8 @@ define([ var p = Hash.parsePadUrl(href); var h = p.hashData; + if (title.trim() === "") { title = UserObject.getDefaultName(p); } + if (AppConfig.disableAnonymousStore && !store.loggedIn) { return void cb(); } if (p.type === "debug") { return void cb(); } diff --git a/www/common/outer/userObject.js b/www/common/outer/userObject.js index 4f235366a..64673c882 100644 --- a/www/common/outer/userObject.js +++ b/www/common/outer/userObject.js @@ -694,7 +694,7 @@ define([ // Fix creation time if (!el.ctime) { el.ctime = el.atime; } // Fix title - if (!el.title) { el.title = Hash.getDefaultName(parsed); } + if (!el.title) { el.title = exp.getDefaultName(parsed); } // Fix channel if (!el.channel) { try { diff --git a/www/common/sframe-common-outer.js b/www/common/sframe-common-outer.js index 3c13e0e8e..71282114b 100644 --- a/www/common/sframe-common-outer.js +++ b/www/common/sframe-common-outer.js @@ -50,9 +50,10 @@ define([ '/common/outer/local-store.js', '/customize/application_config.js', '/common/test.js', + '/common/userObject.js', ], waitFor(function (_CpNfOuter, _Cryptpad, _Crypto, _Cryptget, _SFrameChannel, _FilePicker, _Share, _Messaging, _Notifier, _Hash, _Util, _Realtime, - _Constants, _Feedback, _LocalStore, _AppConfig, _Test) { + _Constants, _Feedback, _LocalStore, _AppConfig, _Test, _UserObject) { CpNfOuter = _CpNfOuter; Cryptpad = _Cryptpad; Crypto = Utils.Crypto = _Crypto; @@ -68,6 +69,7 @@ define([ Utils.Constants = _Constants; Utils.Feedback = _Feedback; Utils.LocalStore = _LocalStore; + Utils.UserObject = _UserObject; AppConfig = _AppConfig; Test = _Test; @@ -271,7 +273,7 @@ define([ Utils.crypto = Utils.Crypto.createEncryptor(Utils.secret.keys); var parsed = Utils.Hash.parsePadUrl(window.location.href); if (!parsed.type) { throw new Error(); } - var defaultTitle = Utils.Hash.getDefaultName(parsed); + var defaultTitle = Utils.UserObject.getDefaultName(parsed); var edPublic, curvePublic, notifications, isTemplate; var forceCreationScreen = cfg.useCreationScreen && sessionStorage[Utils.Constants.displayPadCreationScreen]; @@ -1176,7 +1178,7 @@ define([ // Update metadata values and send new metadata inside parsed = Utils.Hash.parsePadUrl(window.location.href); - defaultTitle = Utils.Hash.getDefaultName(parsed); + defaultTitle = Utils.UserObject.getDefaultName(parsed); hashes = Utils.Hash.getHashes(secret); readOnly = false; updateMeta(); diff --git a/www/common/userObject.js b/www/common/userObject.js index 38372e880..48c74746b 100644 --- a/www/common/userObject.js +++ b/www/common/userObject.js @@ -15,8 +15,24 @@ define([ var TEMPLATE = module.TEMPLATE = "template"; var SHARED_FOLDERS = module.SHARED_FOLDERS = "sharedFolders"; + // Create untitled documents when no name is given + var getLocaleDate = function () { + if (window.Intl && window.Intl.DateTimeFormat) { + var options = {weekday: "short", year: "numeric", month: "long", day: "numeric"}; + return new window.Intl.DateTimeFormat(undefined, options).format(new Date()); + } + return new Date().toString().split(' ').slice(0,4).join(' '); + }; + module.getDefaultName = function (parsed) { + var type = parsed.type; + var name = (Messages.type)[type] + ' - ' + getLocaleDate(); + return name; + }; + module.init = function (files, config) { var exp = {}; + exp.getDefaultName = module.getDefaultName; + var sframeChan = config.sframeChan; var FILES_DATA = module.FILES_DATA = exp.FILES_DATA = Constants.storageKey;