Feature: Search support for before: and after: dates (#252)

This commit is contained in:
Ralph Slooten
2024-04-12 14:44:14 +12:00
parent 186f8b1829
commit a7dfbf4af0
11 changed files with 79 additions and 17 deletions

View File

@@ -109,6 +109,11 @@ func Search(w http.ResponseWriter, r *http.Request) {
// required: false
// type: integer
// default: 50
// + name: tz
// in: query
// description: Timezone for `before:` & `after:` queries, eg: "Pacific/Auckland"
// required: false
// type: string
//
// Responses:
// 200: MessagesSummaryResponse
@@ -121,7 +126,7 @@ func Search(w http.ResponseWriter, r *http.Request) {
start, limit := getStartLimit(r)
messages, results, err := storage.Search(search, start, limit)
messages, results, err := storage.Search(search, r.URL.Query().Get("tz"), start, limit)
if err != nil {
httpError(w, err.Error())
return
@@ -173,7 +178,7 @@ func DeleteSearch(w http.ResponseWriter, r *http.Request) {
return
}
if err := storage.DeleteSearch(search); err != nil {
if err := storage.DeleteSearch(search, r.URL.Query().Get("tz")); err != nil {
httpError(w, err.Error())
return
}

View File

@@ -19,7 +19,7 @@ func RedirectToLatestMessage(w http.ResponseWriter, r *http.Request) {
search := strings.TrimSpace(r.URL.Query().Get("query"))
if search != "" {
messages, _, err = storage.Search(search, 0, 1)
messages, _, err = storage.Search(search, "", 0, 1)
if err != nil {
httpError(w, err.Error())
return

View File

@@ -16,6 +16,7 @@ export default {
beforeMount() {
document.title = document.title + ' - ' + location.hostname
mailbox.showTagColors = !localStorage.getItem('hideTagColors') == '1'
mailbox.timeZone = localStorage.getItem('timezone') ? localStorage.getItem('timezone') : Intl.DateTimeFormat().resolvedOptions().timeZone;
// load global config
this.get(this.resolve('/api/v1/webui'), false, function (response) {

View File

@@ -19,6 +19,7 @@ export const mailbox = reactive({
appInfo: {}, // application information
uiConfig: {}, // configuration for UI
lastMessage: false, // return scrolling
timeZone: '', // browser timezone
})
watch(

View File

@@ -59,6 +59,9 @@ export default {
}
this.apiURI = this.resolve(`/api/v1/search`) + '?query=' + encodeURIComponent(s)
if (mailbox.timeZone != '' && (s.indexOf('after:') != -1 || s.indexOf('before:') != -1)) {
this.apiURI += '&tz=' + encodeURIComponent(mailbox.timeZone)
}
this.loadMessages()
}
}

View File

@@ -550,6 +550,12 @@
"description": "Limit results",
"name": "limit",
"in": "query"
},
{
"type": "string",
"description": "Timezone for `before:` \u0026 `after:` queries, eg: \"Pacific/Auckland\"",
"name": "tz",
"in": "query"
}
],
"responses": {