From afbd987ca34242c4362458376717f00ddaeb99b5 Mon Sep 17 00:00:00 2001 From: Peter Stuifzand Date: Tue, 11 May 2021 20:48:58 +0200 Subject: [PATCH] Fetch items from channel with channelID --- pkg/timeline/postgres.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/pkg/timeline/postgres.go b/pkg/timeline/postgres.go index b39ac84..0336a94 100644 --- a/pkg/timeline/postgres.go +++ b/pkg/timeline/postgres.go @@ -80,7 +80,7 @@ CREATE TABLE IF NOT EXISTS "items" ( // Items func (p *postgresStream) Items(before, after string) (microsub.Timeline, error) { - rows, err := p.database.Query(`SELECT "id", "uid", "data", "created_at", "is_read" FROM "items" WHERE "channel_id" = $1`, p.channel) + rows, err := p.database.Query(`SELECT "id", "uid", "data", "created_at", "is_read" FROM "items" WHERE "channel_id" = $1 ORDER BY "published_at"`, p.channelID) if err != nil { return microsub.Timeline{}, fmt.Errorf("while query: %w", err) } @@ -96,13 +96,23 @@ func (p *postgresStream) Items(before, after string) (microsub.Timeline, error) err = rows.Scan(&id, &uid, &item, &createdAt, &isRead) if err != nil { - return microsub.Timeline{}, fmt.Errorf("while scanning: %w", err) + break } + item.Read = isRead == 1 item.ID = uid tl.Items = append(tl.Items, item) } + if closeErr := rows.Close(); closeErr != nil { + return tl, err + } + if err != nil { + return tl, err + } + if err = rows.Err(); err != nil { + return tl, err + } return tl, nil }