Skip to content

Commit f9445cb

Browse files
committed
Show the latest view when a notification is already the newest message and release v0.1.6.
1 parent 231f1da commit f9445cb

7 files changed

Lines changed: 36 additions & 9 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
The section of each version is the release notes that the update window shows.
44

5+
## 0.1.6
6+
7+
- Opening a notification for the newest message stays on the latest messages, so "Viewing older messages" only appears when newer ones exist.
8+
- Notification bodies are no longer cut off at 300 characters.
9+
510
## 0.1.5
611

712
- Hide the default browser context menu outside text fields in production builds, while keeping native editing commands and message actions.

‎frontend/src/MessagesPage.tsx‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ export function MessagesPage({ state, serverId, appId, onRelogin, onError }: Mes
225225
// refresh the loaded window using bounded cursor queries.
226226
const reuse = !target && previous?.scope === scope && previous.gen === state.msgGen;
227227
let result = reuse ? previous.page : await Desktop.messages({ serverId, appId, search: target ? "" : query, limit: pageSize, include: anchor, before: null });
228+
const hasNewer = result.hasNewer;
228229
const all = [...result.messages];
229230
while (live && result.hasMore && result.next && all.length < limit) {
230231
result = await Desktop.messages({ serverId, appId, search: target ? "" : query, limit: pageSize, include: null, before: result.next });
@@ -233,8 +234,9 @@ export function MessagesPage({ state, serverId, appId, onRelogin, onError }: Mes
233234
if (!live) return;
234235
// A message can move into a refreshed page while queries are in flight.
235236
const unique = [...new Map(all.map((m) => [keyOf(m), m])).values()];
236-
const p = { ...result, messages: unique };
237-
const effectiveAnchor = anchor && unique.some((m) => keyOf(m) === keyOf(anchor)) ? anchor : null;
237+
const p = { ...result, hasNewer, messages: unique };
238+
// A target that is the newest message leaves the list at the latest, where new messages show.
239+
const effectiveAnchor = anchor && hasNewer && unique.some((m) => keyOf(m) === keyOf(anchor)) ? anchor : null;
238240
loaded.current = { scope, gen: state.msgGen, page: p, anchor: effectiveAnchor };
239241
setHistorical(effectiveAnchor !== null);
240242
setPage((prev) => ({ ...p, messages: reconcile(prev?.messages ?? [], p.messages) }));

‎frontend/src/mygo.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ export interface MessagePage {
6666
messages: Message[];
6767
/** HasMore is true when Next can load another page. */
6868
hasMore: boolean;
69+
/**
70+
* HasNewer is true when the page starts at Query.Include and newer messages
71+
* match the query.
72+
*/
73+
hasNewer: boolean;
6974
/** MsgGen is the State.MsgGen the page was read at. */
7075
msgGen: number;
7176
}

‎internal/api/api.go‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,9 @@ type MessagePage struct {
204204
Messages []Message `json:"messages"`
205205
// HasMore is true when Next can load another page.
206206
HasMore bool `json:"hasMore"`
207+
// HasNewer is true when the page starts at Query.Include and newer messages
208+
// match the query.
209+
HasNewer bool `json:"hasNewer"`
207210
// MsgGen is the State.MsgGen the page was read at.
208211
MsgGen uint64 `json:"msgGen"`
209212
}
@@ -444,15 +447,23 @@ func (d *Desktop) Messages(q Query) (MessagePage, error) {
444447
limit = pageSize
445448
}
446449
query := store.MessageQuery{ServerID: q.ServerID, AppID: q.AppID, Search: strings.TrimSpace(q.Search), Limit: limit + 1, Before: q.Before}
450+
hasNewer := false
447451
if q.Include != nil && q.Include.ServerID > 0 && q.Include.ID > 0 && (q.ServerID == 0 || q.ServerID == q.Include.ServerID) {
448452
target, err := d.be.Messages(store.MessageQuery{ServerID: q.Include.ServerID, ID: q.Include.ID, AppID: q.AppID, Search: query.Search, Limit: 1})
449453
if err != nil {
450454
return MessagePage{}, err
451455
}
452456
if len(target) > 0 {
453457
m := target[0]
454-
query.Before = &store.MessageCursor{Date: m.Date, ID: m.ID, ServerID: m.ServerID}
455-
query.Inclusive = true
458+
newest, err := d.be.Messages(store.MessageQuery{ServerID: q.ServerID, AppID: q.AppID, Search: query.Search, Limit: 1})
459+
if err != nil {
460+
return MessagePage{}, err
461+
}
462+
if len(newest) > 0 && (newest[0].ServerID != m.ServerID || newest[0].ID != m.ID) {
463+
hasNewer = true
464+
query.Before = &store.MessageCursor{Date: m.Date, ID: m.ID, ServerID: m.ServerID}
465+
query.Inclusive = true
466+
}
456467
}
457468
}
458469
msgs, err := d.be.Messages(query)
@@ -463,7 +474,7 @@ func (d *Desktop) Messages(q Query) (MessagePage, error) {
463474
if more {
464475
msgs = msgs[:limit]
465476
}
466-
page := MessagePage{HasMore: more, MsgGen: gen, Messages: make([]Message, 0, len(msgs))}
477+
page := MessagePage{HasMore: more, HasNewer: hasNewer, MsgGen: gen, Messages: make([]Message, 0, len(msgs))}
467478
for _, m := range msgs {
468479
img := notify.BigImageURL(m.Extras)
469480
src := ""

‎internal/api/api_test.go‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,12 @@ func TestMessagesPagesAndGrowToInclude(t *testing.T) {
143143
t.Fatalf("page: %d, more %v", len(p.Messages), p.HasMore)
144144
}
145145
p, _ = d.Messages(Query{Limit: 100, Include: &MessageRef{ServerID: 1, ID: 120}})
146-
if len(p.Messages) != 100 || !p.HasMore || p.Messages[0].ID != 120 {
147-
t.Fatalf("the bounded page should start at message 120: %d, more %v", len(p.Messages), p.HasMore)
146+
if len(p.Messages) != 100 || !p.HasMore || !p.HasNewer || p.Messages[0].ID != 120 {
147+
t.Fatalf("the bounded page should start at message 120: %d, more %v, newer %v", len(p.Messages), p.HasMore, p.HasNewer)
148+
}
149+
p, _ = d.Messages(Query{Limit: 100, Include: &MessageRef{ServerID: 1, ID: 250}})
150+
if len(p.Messages) != 100 || p.HasNewer || p.Messages[0].ID != 250 {
151+
t.Fatalf("the newest message is not an older page: %d, newer %v", len(p.Messages), p.HasNewer)
148152
}
149153
p, _ = d.Messages(Query{Limit: 100, Include: &MessageRef{ServerID: 2, ID: 30}})
150154
if len(p.Messages) != 100 {

‎internal/api/reliability_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func TestDeepAndMissingTargetsUseBoundedQueries(t *testing.T) {
3636
if err != nil {
3737
t.Fatal(err)
3838
}
39-
if b.queries > 2 || len(p.Messages) > 100 {
39+
if b.queries > 3 || len(p.Messages) > 100 {
4040
t.Fatalf("unbounded target lookup: queries=%d rows=%d", b.queries, len(p.Messages))
4141
}
4242
}

‎mygo.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "Gotify Desktop",
33
"identifier": "com.austin.gotifydesktop",
4-
"version": "0.1.5",
4+
"version": "0.1.6",
55
"copyright": "Copyright © 2026 RedwindA",
66
"devUrl": "http://localhost:5173",
77
"devCommand": "bun run --cwd frontend dev",

0 commit comments

Comments
 (0)