Compare commits

..
3 Commits
Author SHA1 Message Date
Mikescher 1ecc5d7ebd [Server] Fix FTS search
Build Docker and Deploy / Build Docker Container (push) Successful in 2m35s
Build Docker and Deploy / Run Unit-Tests (push) Successful in 4m54s
Build Docker and Deploy / Deploy to Server (push) Successful in 18s
2026-07-09 18:19:40 +02:00
Mikescher 0282bc0f0a show message timestamp in local tz
Build Docker and Deploy / Build Docker Container (push) Successful in 2m18s
Build Docker and Deploy / Run Unit-Tests (push) Successful in 7m46s
Build Docker and Deploy / Deploy to Server (push) Successful in 14s
2026-06-26 09:20:07 +02:00
Mikescher bff8257f34 More flutter upgrades
Build Docker and Deploy / Build Docker Container (push) Successful in 1m4s
Build Docker and Deploy / Run Unit-Tests (push) Successful in 7m40s
Build Docker and Deploy / Deploy to Server (push) Successful in 7s
2026-05-31 04:49:17 +02:00
6 changed files with 72 additions and 13 deletions
+9 -5
View File
@@ -3,7 +3,9 @@ plugins {
// START: FlutterFire Configuration
id 'com.google.gms.google-services'
// END: FlutterFire Configuration
id "kotlin-android"
// Kotlin is provided by Flutter's built-in Kotlin support (the flutter-gradle-plugin
// auto-applies kotlin-android). KGP stays declared in settings.gradle so it remains
// on the classpath. See https://docs.flutter.dev/release/breaking-changes/migrate-to-built-in-kotlin/for-app-developers
id "dev.flutter.flutter-gradle-plugin"
}
@@ -42,10 +44,6 @@ android {
targetCompatibility JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = '17'
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
@@ -75,6 +73,12 @@ android {
}
}
kotlin {
compilerOptions {
jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17
}
}
flutter {
source '../..'
}
+4
View File
@@ -1,3 +1,7 @@
org.gradle.jvmargs=-Xmx4G
android.useAndroidX=true
android.enableJetifier=true
# This builtInKotlin flag was added automatically by Flutter migrator
android.builtInKotlin=false
# This newDsl flag was added automatically by Flutter migrator
android.newDsl=false
@@ -140,6 +140,7 @@ class _MessageViewPageState extends State<MessageViewPage> {
Widget _buildMessageView(BuildContext context, SCNMessage message, ChannelPreview? channel, KeyTokenPreview? token, UserPreview? user) {
final userAccUserID = context.select<AppAuth, String?>((v) => v.userID);
final dateFormat = context.select<AppSettings, AppSettingsDateFormat>((v) => v.dateFormat).dateFormat();
var cfg = AppSettings();
@@ -229,7 +230,7 @@ class _MessageViewPageState extends State<MessageViewPage> {
}
: null,
),
UI.metaCard(context: context, icon: FontAwesomeIcons.solidTimer, title: 'Timestamp', values: [message.timestamp]),
UI.metaCard(context: context, icon: FontAwesomeIcons.solidTimer, title: 'Timestamp', values: [dateFormat.format(DateTime.parse(message.timestamp).toLocal())]),
if (cfg.showExtendedAttributes)
UI.metaCard(
context: context,
@@ -319,7 +320,7 @@ class _MessageViewPageState extends State<MessageViewPage> {
children: [
UI.channelChip(context: context, text: _resolveChannelName(channel, message), margin: const EdgeInsets.fromLTRB(0, 0, 4, 0), fontSize: 16),
Expanded(child: SizedBox()),
Text(dateFormat.format(DateTime.parse(message.timestamp)), style: const TextStyle(fontSize: 14)),
Text(dateFormat.format(DateTime.parse(message.timestamp).toLocal()), style: const TextStyle(fontSize: 14)),
],
),
SizedBox(height: 8),
+8 -2
View File
@@ -119,11 +119,17 @@ func (h APIHandler) ListMessages(pctx ginext.PreContext) ginext.HTTPResponse {
}
if len(q.Search) != 0 {
filter.SearchStringFTS = langext.Ptr(langext.ArrMap(q.Search, func(v string) string { return strings.TrimSpace(v) }))
searchTerms := langext.ArrFilter(langext.ArrMap(q.Search, func(v string) string { return strings.TrimSpace(v) }), func(v string) bool { return v != "" })
if len(searchTerms) != 0 {
filter.SearchStringFTS = langext.Ptr(searchTerms)
}
}
if len(q.StringSearch) != 0 {
filter.SearchStringPlain = langext.Ptr(langext.ArrMap(q.StringSearch, func(v string) string { return strings.TrimSpace(v) }))
searchTerms := langext.ArrFilter(langext.ArrMap(q.StringSearch, func(v string) string { return strings.TrimSpace(v) }), func(v string) bool { return v != "" })
if len(searchTerms) != 0 {
filter.SearchStringPlain = langext.Ptr(searchTerms)
}
}
if len(q.Channels) != 0 {
+43 -4
View File
@@ -4,13 +4,15 @@ import (
"crypto/sha512"
"encoding/hex"
"fmt"
"strconv"
"strings"
"time"
"unicode"
"git.blackforestbytes.com/BlackForestBytes/goext/dataext"
"git.blackforestbytes.com/BlackForestBytes/goext/langext"
"git.blackforestbytes.com/BlackForestBytes/goext/mathext"
"git.blackforestbytes.com/BlackForestBytes/goext/sq"
"strconv"
"strings"
"time"
)
type MessageFilter struct {
@@ -219,7 +221,7 @@ func (f MessageFilter) SQL() (string, string, sq.PP, error) {
if f.SearchStringFTS != nil {
filter := make([]string, 0)
for _, v := range *f.SearchStringFTS {
filter = append(filter, fmt.Sprintf("(messages_fts match :%s)", params.Add(v)))
filter = append(filter, fmt.Sprintf("(messages_fts match :%s)", params.Add(sanitizeFTSMatchQuery(v))))
}
sqlClauses = append(sqlClauses, "("+strings.Join(filter, " OR ")+")")
}
@@ -246,6 +248,43 @@ func (f MessageFilter) SQL() (string, string, sq.PP, error) {
return sqlClause, joinClause, params, nil
}
// sanitizeFTSMatchQuery converts an arbitrary user-provided search string into a valid FTS5 MATCH query.
// It preserves explicit "quoted phrases" typed by the user and wraps every other whitespace-separated word
// in double-quotes, so that FTS5 special characters ( - : * ^ ( ) AND OR NOT NEAR ... ) inside plain search
// terms are treated as literal text instead of query operators.
func sanitizeFTSMatchQuery(s string) string {
out := make([]string, 0)
buf := strings.Builder{}
inQuote := false
flush := func() {
if buf.Len() > 0 {
out = append(out, `"`+strings.ReplaceAll(buf.String(), `"`, `""`)+`"`)
buf.Reset()
}
}
for _, r := range s {
switch {
case r == '"':
// a double-quote opens or closes an explicit phrase; flush the pending word either way
flush()
inQuote = !inQuote
case !inQuote && unicode.IsSpace(r):
flush()
default:
buf.WriteRune(r)
}
}
flush() // trailing word or an unterminated phrase
if len(out) == 0 {
return `""` // valid FTS5 query that simply matches nothing
}
return strings.Join(out, " ")
}
func (f MessageFilter) Hash() string {
bh, err := dataext.StructHash(f, dataext.StructHashOptions{HashAlgo: sha512.New()})
if err != nil {
+5
View File
@@ -830,6 +830,11 @@ func TestListMessagesSearch(t *testing.T) {
{"search=the(2)", 17, fmt.Sprintf("/api/v2/messages?search=%s", url.QueryEscape("THE"))},
{"search=please", 9, fmt.Sprintf("/api/v2/messages?search=%s", url.QueryEscape("please"))},
{"search=11pm", 2, fmt.Sprintf("/api/v2/messages?search=%s", url.QueryEscape("\"11:00pm\""))},
{"search=hyphen", 0, fmt.Sprintf("/api/v2/messages?search=%s", url.QueryEscape("yt-backup"))},
{"search=colon", 0, fmt.Sprintf("/api/v2/messages?search=%s", url.QueryEscape("foo:bar"))},
{"search=NOT", 0, fmt.Sprintf("/api/v2/messages?search=%s", url.QueryEscape("NOT"))},
{"search=empty", 22, fmt.Sprintf("/api/v2/messages?search=%s", url.QueryEscape(""))},
}
for _, testdata := range filterTests {