easier mailBox() link generator

This commit is contained in:
djmaze 2021-12-07 16:52:05 +01:00
parent df293960d0
commit c41adf35f5
2 changed files with 9 additions and 7 deletions

View file

@ -118,23 +118,23 @@ export const
* @param {number=} threadUid = 0
* @returns {string}
*/
mailBox = (folder, page = 1, search = '', threadUid = 0) => {
mailBox = (folder, page, search, threadUid) => {
page = pInt(page, 1);
search = pString(search);
let result = HASH_PREFIX + 'mailbox/';
let result = [HASH_PREFIX + 'mailbox'];
if (folder) {
result += encodeURI(folder) + (threadUid ? '~' + threadUid : '');
result.push(folder + (threadUid ? '~' + threadUid : ''));
}
if (1 < page) {
result = result.replace(/\/+$/, '') + '/p' + page;
result.push('p' + page);
}
if (search) {
result = result.replace(/\/+$/, '') + '/' + encodeURI(search);
result.push(encodeURI(search));
}
return result;
return result.join('/');
};

View file

@ -134,11 +134,13 @@ export class MailBoxUserScreen extends AbstractScreen {
fNormS = (request, vals) => [folder(request, vals), request ? pInt(vals[1]) : 1, decodeURI(pString(vals[2]))];
return [
// Folder: INBOX | INBOX.sub | Sent | fullNameHash
[/^([^/]*)$/, { normalize_: fNormS }],
// Regex the fullNameHash
// Search: {folder}/{string}
[/^([a-zA-Z0-9.~_-]+)\/(.+)\/?$/, { normalize_: (request, vals) =>
[folder(request, vals), 1, decodeURI(pString(vals[1]))]
}],
// Page: {folder}/p{int}(/{search})?
[/^([a-zA-Z0-9.~_-]+)\/p([1-9][0-9]*)(?:\/(.+)\/?)?$/, { normalize_: fNormS }]
];
}