mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-06-28 06:46:27 +00:00
Fix and improved hasher routing
This commit is contained in:
@@ -78,7 +78,7 @@ class AppUser extends AbstractApp {
|
||||
const currentTime = Date.now();
|
||||
if (currentTime > (lastTime + interval + 1000)) {
|
||||
Remote.request('Version',
|
||||
iError => (100 < iError) && this.reload(),
|
||||
iError => (100 < iError) && (Settings.app('inIframe') ? parent : window).location.reload(),
|
||||
{ Version: Settings.app('version') }
|
||||
);
|
||||
}
|
||||
@@ -91,10 +91,6 @@ class AppUser extends AbstractApp {
|
||||
shortcuts.add('escape,enter', '', () => rl.Dropdowns.detectVisibility());
|
||||
}
|
||||
|
||||
reload() {
|
||||
(Settings.app('inIframe') ? parent : window).location.reload();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {number} iDeleteType
|
||||
* @param {string} sFromFolderFullName
|
||||
|
||||
@@ -2,7 +2,6 @@ import { pString, pInt } from 'Common/Utils';
|
||||
import { Settings } from 'Common/Globals';
|
||||
|
||||
const
|
||||
ROOT = './',
|
||||
HASH_PREFIX = '#/',
|
||||
SERVER_PREFIX = './?',
|
||||
VERSION = Settings.app('version'),
|
||||
@@ -24,7 +23,7 @@ export const
|
||||
/**
|
||||
* @returns {string}
|
||||
*/
|
||||
logoutLink = () => adminPath() ? prefix() : ROOT,
|
||||
logoutLink = () => adminPath() ? prefix() : './',
|
||||
|
||||
/**
|
||||
* @param {string} type
|
||||
|
||||
@@ -173,7 +173,7 @@ const
|
||||
|
||||
// Close all popups
|
||||
for (let vm of visiblePopups) {
|
||||
vm.closeCommand();
|
||||
false === vm.onClose() || vm.closeCommand();
|
||||
}
|
||||
|
||||
if (screenName) {
|
||||
|
||||
@@ -85,7 +85,7 @@ export class AbstractSettingsScreen extends AbstractScreen {
|
||||
}, 1);
|
||||
}
|
||||
} else {
|
||||
rl.route.setHash(settings(), false, true);
|
||||
hasher.replaceHash(settings());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,12 @@ import { SettingsUserStore } from 'Stores/User/Settings';
|
||||
import Remote from 'Remote/User/Fetch';
|
||||
|
||||
const
|
||||
isChecked = item => item.checked();
|
||||
isChecked = item => item.checked(),
|
||||
replaceHash = hash => {
|
||||
rl.route.off();
|
||||
hasher.replaceHash(hash);
|
||||
rl.route.on();
|
||||
}
|
||||
|
||||
export const MessagelistUserStore = ko.observableArray().extend({ debounce: 0 });
|
||||
|
||||
@@ -69,7 +74,7 @@ addComputablesTo(MessagelistUserStore, {
|
||||
|
||||
mainSearch: {
|
||||
read: MessagelistUserStore.listSearch,
|
||||
write: value => rl.route.setHash(
|
||||
write: value => hasher.setHash(
|
||||
mailBox(FolderUserStore.currentFolderFullNameHash(), 1,
|
||||
value.toString().trim(), MessagelistUserStore.threadUid())
|
||||
)
|
||||
@@ -156,15 +161,13 @@ MessagelistUserStore.reload = (bDropPagePosition = false, bDropCurrenFolderCache
|
||||
MessagelistUserStore.pageBeforeThread(1);
|
||||
iOffset = 0;
|
||||
|
||||
rl.route.setHash(
|
||||
replaceHash(
|
||||
mailBox(
|
||||
FolderUserStore.currentFolderFullNameHash(),
|
||||
MessagelistUserStore.page(),
|
||||
MessagelistUserStore.listSearch(),
|
||||
MessagelistUserStore.threadUid()
|
||||
),
|
||||
true,
|
||||
true
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -400,14 +403,12 @@ MessagelistUserStore.removeMessagesFromList = (
|
||||
setHash = 1;
|
||||
} else {
|
||||
MessagelistUserStore.threadUid(0);
|
||||
rl.route.setHash(
|
||||
replaceHash(
|
||||
mailBox(
|
||||
FolderUserStore.currentFolderFullNameHash(),
|
||||
MessagelistUserStore.pageBeforeThread(),
|
||||
MessagelistUserStore.listSearch()
|
||||
),
|
||||
true,
|
||||
true
|
||||
)
|
||||
);
|
||||
}
|
||||
} else if (MessagelistUserStore.threadUid() != message.uid) {
|
||||
@@ -415,15 +416,13 @@ MessagelistUserStore.removeMessagesFromList = (
|
||||
setHash = 1;
|
||||
}
|
||||
if (setHash) {
|
||||
rl.route.setHash(
|
||||
replaceHash(
|
||||
mailBox(
|
||||
FolderUserStore.currentFolderFullNameHash(),
|
||||
MessagelistUserStore.page(),
|
||||
MessagelistUserStore.listSearch(),
|
||||
MessagelistUserStore.threadUid()
|
||||
),
|
||||
true,
|
||||
true
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ const HTML5Notification = window.Notification,
|
||||
if (data.Folder && data.Uid) {
|
||||
fireEvent('mailbox.message.show', data);
|
||||
} else if (data.Url) {
|
||||
rl.route.setHash(data.Url);
|
||||
hasher.setHash(data.Url);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -766,8 +766,6 @@ export class ComposePopupView extends AbstractViewPopup {
|
||||
|
||||
this.to.focused(false);
|
||||
|
||||
rl.route.on();
|
||||
|
||||
(getFullscreenElement() === this.oContent) && exitFullscreen();
|
||||
}
|
||||
|
||||
@@ -830,8 +828,6 @@ export class ComposePopupView extends AbstractViewPopup {
|
||||
* @param {string=} sCustomPlainText = null
|
||||
*/
|
||||
onShow(type, oMessageOrArray, aToEmails, aCcEmails, aBccEmails, sCustomSubject, sCustomPlainText) {
|
||||
rl.route.off();
|
||||
|
||||
this.autosaveStart();
|
||||
|
||||
this.viewModelDom.dataset.wysiwyg = SettingsUserStore.editorDefaultType();
|
||||
|
||||
@@ -494,14 +494,10 @@ export class ContactsPopupView extends AbstractViewPopup {
|
||||
onShow(bBackToCompose, sLastComposeFocusedField) {
|
||||
this.bBackToCompose = !!bBackToCompose;
|
||||
this.sLastComposeFocusedField = sLastComposeFocusedField;
|
||||
|
||||
rl.route.off();
|
||||
this.reloadContactList(true);
|
||||
}
|
||||
|
||||
onHide() {
|
||||
rl.route.on();
|
||||
|
||||
this.currentContact(null);
|
||||
this.emptySelection(true);
|
||||
this.search('');
|
||||
|
||||
@@ -115,7 +115,6 @@ export class LoginUserView extends AbstractViewLogin {
|
||||
this.submitErrorAddidional((oData && oData.ErrorMessageAdditional) || '');
|
||||
} else {
|
||||
rl.setData(oData.Result);
|
||||
// rl.route.reload();
|
||||
}
|
||||
},
|
||||
data
|
||||
|
||||
@@ -105,7 +105,7 @@ export class MailFolderList extends AbstractViewLeft {
|
||||
setFolderHash(folder.fullName, '');
|
||||
}
|
||||
|
||||
rl.route.setHash(
|
||||
hasher.setHash(
|
||||
mailBox(folder.fullNameHash, 1,
|
||||
(event.target.matches('.flag-icon') && !folder.isFlagged()) ? 'flagged' : ''
|
||||
)
|
||||
@@ -206,7 +206,7 @@ export class MailFolderList extends AbstractViewLeft {
|
||||
}
|
||||
|
||||
configureFolders() {
|
||||
rl.route.setHash(settings('folders'));
|
||||
hasher.setHash(settings('folders'));
|
||||
}
|
||||
|
||||
contactsClick() {
|
||||
|
||||
@@ -230,14 +230,14 @@ export class MailMessageList extends AbstractViewRight {
|
||||
);
|
||||
|
||||
if ('INBOX' === sFolder) {
|
||||
rl.route.setHash(mailBox(sFolder));
|
||||
hasher.setHash(mailBox(sFolder));
|
||||
}
|
||||
|
||||
if (message) {
|
||||
this.selector.selectMessageItem(message);
|
||||
} else {
|
||||
if ('INBOX' !== sFolder) {
|
||||
rl.route.setHash(mailBox(sFolder));
|
||||
hasher.setHash(mailBox(sFolder));
|
||||
}
|
||||
if (sFolder && iUid) {
|
||||
MessageUserStore.message(MessageModel.fromMessageListItem(null));
|
||||
@@ -420,7 +420,7 @@ export class MailMessageList extends AbstractViewRight {
|
||||
|
||||
cancelThreadUid() {
|
||||
// history.go(-1) better?
|
||||
rl.route.setHash(
|
||||
hasher.setHash(
|
||||
mailBox(
|
||||
FolderUserStore.currentFolderFullNameHash(),
|
||||
MessagelistUserStore.pageBeforeThread(),
|
||||
@@ -590,7 +590,7 @@ export class MailMessageList extends AbstractViewRight {
|
||||
}
|
||||
|
||||
gotoPage(page) {
|
||||
page && rl.route.setHash(
|
||||
page && hasher.setHash(
|
||||
mailBox(
|
||||
FolderUserStore.currentFolderFullNameHash(),
|
||||
page.value,
|
||||
@@ -604,7 +604,7 @@ export class MailMessageList extends AbstractViewRight {
|
||||
if (message && 0 < message.threadsLen()) {
|
||||
MessagelistUserStore.pageBeforeThread(MessagelistUserStore.page());
|
||||
|
||||
rl.route.setHash(
|
||||
hasher.setHash(
|
||||
mailBox(FolderUserStore.currentFolderFullNameHash(), 1, MessagelistUserStore.listSearch(), message.uid)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -18,6 +18,6 @@ export class MenuSettingsUserView extends AbstractViewLeft {
|
||||
}
|
||||
|
||||
backToMailBoxClick() {
|
||||
rl.route.setHash(mailbox(getFolderInboxName()));
|
||||
hasher.setHash(mailbox(getFolderInboxName()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,6 @@ export class PaneSettingsUserView extends AbstractViewRight {
|
||||
}
|
||||
|
||||
backToMailBoxClick() {
|
||||
rl.route.setHash(mailbox(getFolderInboxName()));
|
||||
hasher.setHash(mailbox(getFolderInboxName()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import { MessageUserStore } from 'Stores/User/Message';
|
||||
//import { FolderUserStore } from 'Stores/User/Folder';
|
||||
|
||||
import { Capa, Scope } from 'Common/Enums';
|
||||
import { root, settings } from 'Common/Links';
|
||||
import { settings } from 'Common/Links';
|
||||
|
||||
import { showScreenPopup } from 'Knoin/Knoin';
|
||||
import { AbstractViewRight } from 'Knoin/AbstractViews';
|
||||
@@ -82,9 +82,7 @@ export class SystemDropDownUserView extends AbstractViewRight {
|
||||
});
|
||||
AccountUserStore.loading(false);
|
||||
*/
|
||||
// rl.route.reload();
|
||||
location.href = root();
|
||||
location.reload();
|
||||
rl.route.reload();
|
||||
}
|
||||
}, {Email:account.email}
|
||||
);
|
||||
@@ -97,7 +95,7 @@ export class SystemDropDownUserView extends AbstractViewRight {
|
||||
}
|
||||
|
||||
settingsClick() {
|
||||
rl.route.setHash(settings());
|
||||
hasher.setHash(settings());
|
||||
}
|
||||
|
||||
settingsHelp() {
|
||||
|
||||
20
dev/bootstrap.js
vendored
20
dev/bootstrap.js
vendored
@@ -27,31 +27,15 @@ export default App => {
|
||||
|
||||
rl.route = {
|
||||
root: () => {
|
||||
rl.route.setHash(root(), true);
|
||||
rl.route.off();
|
||||
hasher.setHash(root());
|
||||
},
|
||||
reload: () => {
|
||||
rl.route.root();
|
||||
setTimeout(() => (Settings.app('inIframe') ? parent : window).location.reload(), 100);
|
||||
},
|
||||
off: () => hasher.active = false,
|
||||
on: () => hasher.active = true,
|
||||
/**
|
||||
* @param {string} sHash
|
||||
* @param {boolean=} silence = false
|
||||
* @param {boolean=} replace = false
|
||||
* @returns {void}
|
||||
*/
|
||||
setHash: (hash, silence = false, replace = false) => {
|
||||
hash = hash.replace(/^[#/]+/, '');
|
||||
hasher.active = !silence;
|
||||
hasher[replace ? 'replaceHash' : 'setHash'](hash);
|
||||
if (silence) {
|
||||
hasher.active = true;
|
||||
} else {
|
||||
hasher.setHash(hash);
|
||||
}
|
||||
}
|
||||
on: () => hasher.active = true
|
||||
};
|
||||
|
||||
rl.fetch = (resource, init, postData) => {
|
||||
|
||||
27
vendors/routes/hasher.js
vendored
27
vendors/routes/hasher.js
vendored
@@ -13,12 +13,11 @@
|
||||
|
||||
const
|
||||
_hashValRegexp = /#(.*)$/,
|
||||
_hashRegexp = /^#/,
|
||||
_hashRegexp = /^[#/]+/,
|
||||
_hashTrim = /^\/|\$/g,
|
||||
_trimHash = hash => hash ? hash.replace(_hashTrim, '') : '',
|
||||
_getWindowHash = () => {
|
||||
//parsed full URL instead of getting window.location.hash because Firefox decode hash value (and all the other browsers don't)
|
||||
//also because of IE8 bug with hash query in local file [issue #6]
|
||||
var result = _hashValRegexp.exec( location.href );
|
||||
return (result && result[1]) ? decodeURIComponent(result[1]) : '';
|
||||
},
|
||||
@@ -26,17 +25,10 @@
|
||||
if (_hash !== newHash) {
|
||||
var oldHash = _hash;
|
||||
_hash = newHash; //should come before event dispatch to make sure user can get proper value inside event handler
|
||||
hasher.dispatch(_trimHash(newHash), _trimHash(oldHash));
|
||||
}
|
||||
},
|
||||
_checkHistory = () => {
|
||||
var windowHash = _getWindowHash();
|
||||
if (windowHash !== _hash) {
|
||||
_registerChange(windowHash);
|
||||
_dispatch(_trimHash(newHash), _trimHash(oldHash));
|
||||
}
|
||||
},
|
||||
_setHash = (path, replace) => {
|
||||
path = path.join('/');
|
||||
path = path ? '/' + path.replace(_hashRegexp, '') : path;
|
||||
if (path !== _hash){
|
||||
// we should store raw value
|
||||
@@ -51,6 +43,7 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
_dispatch = (...args) => hasher.active && _bindings.forEach(callback => callback(...args)),
|
||||
|
||||
//--------------------------------------------------------------------------------------
|
||||
// Public (API)
|
||||
@@ -69,7 +62,6 @@
|
||||
*/
|
||||
active : true,
|
||||
add : callback => _bindings.push(callback),
|
||||
dispatch : (...args) => hasher.active && _bindings.forEach(callback => callback(...args)),
|
||||
|
||||
/**
|
||||
* Start listening/dispatching changes in the hash/history.
|
||||
@@ -77,28 +69,27 @@
|
||||
* <li>hasher won't dispatch CHANGE events by manually typing a new value or pressing the back/forward buttons before calling this method.</li>
|
||||
* </ul>
|
||||
*/
|
||||
init : () => hasher.dispatch(_trimHash(_hash)),
|
||||
init : () => _dispatch(_trimHash(_hash)),
|
||||
|
||||
/**
|
||||
* Set Hash value, generating a new history record.
|
||||
* @param {...string} path Hash value without '#'.
|
||||
* @example hasher.setHash('lorem', 'ipsum', 'dolor') -> '#/lorem/ipsum/dolor'
|
||||
* @example hasher.setHash('lorem/ipsum/dolor') -> '#/lorem/ipsum/dolor'
|
||||
*/
|
||||
setHash : (...path) => _setHash(path),
|
||||
setHash : path => _setHash(path),
|
||||
|
||||
/**
|
||||
* Set Hash value without keeping previous hash on the history record.
|
||||
* Similar to calling `window.location.replace("#/hash")` but will also work on IE6-7.
|
||||
* @param {...string} path Hash value without '#'.
|
||||
* @example hasher.replaceHash('lorem', 'ipsum', 'dolor') -> '#/lorem/ipsum/dolor'
|
||||
* @example hasher.replaceHash('lorem/ipsum/dolor') -> '#/lorem/ipsum/dolor'
|
||||
*/
|
||||
replaceHash : (...path) => _setHash(path, true)
|
||||
replaceHash : path => _setHash(path, true)
|
||||
};
|
||||
|
||||
var _hash = _getWindowHash(),
|
||||
_bindings = [];
|
||||
|
||||
addEventListener('hashchange', _checkHistory);
|
||||
addEventListener('hashchange', () => _registerChange(_getWindowHash()));
|
||||
|
||||
global.hasher = hasher;
|
||||
})(this);
|
||||
|
||||
Reference in New Issue
Block a user