Merge pull request '[PR]:' (#10302) from PrivateGER/calckey:fix/search-filter-behavior into develop
Reviewed-on: https://codeberg.org/calckey/calckey/pulls/10302
This commit is contained in:
commit
5d627d56aa
1 changed files with 50 additions and 10 deletions
|
@ -135,6 +135,24 @@ export type MeilisearchNote = {
|
||||||
createdAt: number;
|
createdAt: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function timestampToUnix(timestamp: string) {
|
||||||
|
let unix = 0;
|
||||||
|
|
||||||
|
// Only contains numbers => UNIX timestamp
|
||||||
|
if (/^\d+$/.test(timestamp)) {
|
||||||
|
unix = Number.parseInt(timestamp);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (unix === 0) {
|
||||||
|
// Try to parse the timestamp as JavaScript Date
|
||||||
|
const date = Date.parse(timestamp);
|
||||||
|
if (isNaN(date)) return 0;
|
||||||
|
unix = date / 1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
return unix;
|
||||||
|
}
|
||||||
|
|
||||||
export default hasConfig
|
export default hasConfig
|
||||||
? {
|
? {
|
||||||
search: async (
|
search: async (
|
||||||
|
@ -166,8 +184,29 @@ export default hasConfig
|
||||||
constructedFilters.push(`mediaAttachment = "${fileType}"`);
|
constructedFilters.push(`mediaAttachment = "${fileType}"`);
|
||||||
return null;
|
return null;
|
||||||
} else if (term.startsWith("from:")) {
|
} else if (term.startsWith("from:")) {
|
||||||
const user = term.slice(5);
|
let user = term.slice(5);
|
||||||
constructedFilters.push(`userName = ${user}`);
|
|
||||||
|
if (user.length === 0) return null;
|
||||||
|
|
||||||
|
// Cut off leading @, those aren't saved in the DB
|
||||||
|
if (user.charAt(0) === "@") {
|
||||||
|
user = user.slice(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Determine if we got a webfinger address or a single username
|
||||||
|
if (user.split("@").length > 1) {
|
||||||
|
let splitUser = user.split("@");
|
||||||
|
|
||||||
|
let domain = splitUser.pop();
|
||||||
|
user = splitUser.join("@");
|
||||||
|
|
||||||
|
constructedFilters.push(
|
||||||
|
`userName = ${user} AND userHost = ${domain}`,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
constructedFilters.push(`userName = ${user}`);
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
} else if (term.startsWith("domain:")) {
|
} else if (term.startsWith("domain:")) {
|
||||||
const domain = term.slice(7);
|
const domain = term.slice(7);
|
||||||
|
@ -175,17 +214,18 @@ export default hasConfig
|
||||||
return null;
|
return null;
|
||||||
} else if (term.startsWith("after:")) {
|
} else if (term.startsWith("after:")) {
|
||||||
const timestamp = term.slice(6);
|
const timestamp = term.slice(6);
|
||||||
// Try to parse the timestamp as JavaScript Date
|
|
||||||
const date = Date.parse(timestamp);
|
let unix = timestampToUnix(timestamp);
|
||||||
if (isNaN(date)) return null;
|
|
||||||
constructedFilters.push(`createdAt > ${date / 1000}`);
|
if (unix !== 0) constructedFilters.push(`createdAt > ${unix}`);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
} else if (term.startsWith("before:")) {
|
} else if (term.startsWith("before:")) {
|
||||||
const timestamp = term.slice(7);
|
const timestamp = term.slice(7);
|
||||||
// Try to parse the timestamp as JavaScript Date
|
|
||||||
const date = Date.parse(timestamp);
|
let unix = timestampToUnix(timestamp);
|
||||||
if (isNaN(date)) return null;
|
if (unix !== 0) constructedFilters.push(`createdAt < ${unix}`);
|
||||||
constructedFilters.push(`createdAt < ${date / 1000}`);
|
|
||||||
return null;
|
return null;
|
||||||
} else if (term.startsWith("filter:following")) {
|
} else if (term.startsWith("filter:following")) {
|
||||||
// Check if we got a context user
|
// Check if we got a context user
|
||||||
|
|
Loading…
Reference in a new issue