Add local timeline
This commit is contained in:
parent
5630c6160f
commit
8694516180
4 changed files with 30 additions and 3 deletions
|
@ -356,5 +356,14 @@ fn ApiConn(comptime DbConn: type) type {
|
||||||
const result = try services.notes.query(self.db, .{}, self.arena.allocator());
|
const result = try services.notes.query(self.db, .{}, self.arena.allocator());
|
||||||
return result.items;
|
return result.items;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn localTimeline(self: *Self) ![]services.notes.Note {
|
||||||
|
const result = try services.notes.query(
|
||||||
|
self.db,
|
||||||
|
.{ .community_id = self.community.id },
|
||||||
|
self.arena.allocator(),
|
||||||
|
);
|
||||||
|
return result.items;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ const selectStarFromNote = std.fmt.comptimePrint(
|
||||||
\\SELECT {s}
|
\\SELECT {s}
|
||||||
\\FROM note
|
\\FROM note
|
||||||
\\
|
\\
|
||||||
, .{util.comptimeJoin(",", std.meta.fieldNames(Note))});
|
, .{util.comptimeJoinWithPrefix(",", "note.", std.meta.fieldNames(Note))});
|
||||||
pub fn get(db: anytype, id: Uuid, alloc: std.mem.Allocator) GetError!Note {
|
pub fn get(db: anytype, id: Uuid, alloc: std.mem.Allocator) GetError!Note {
|
||||||
return db.queryRow(
|
return db.queryRow(
|
||||||
Note,
|
Note,
|
||||||
|
@ -69,6 +69,7 @@ pub const QueryArgs = struct {
|
||||||
|
|
||||||
created_before: ?DateTime = null,
|
created_before: ?DateTime = null,
|
||||||
created_after: ?DateTime = null,
|
created_after: ?DateTime = null,
|
||||||
|
community_id: ?Uuid = null,
|
||||||
|
|
||||||
prev: ?struct {
|
prev: ?struct {
|
||||||
id: Uuid,
|
id: Uuid,
|
||||||
|
@ -89,7 +90,10 @@ pub fn query(db: anytype, args: QueryArgs, alloc: std.mem.Allocator) !QueryResul
|
||||||
var builder = sql.QueryBuilder.init(alloc);
|
var builder = sql.QueryBuilder.init(alloc);
|
||||||
defer builder.deinit();
|
defer builder.deinit();
|
||||||
|
|
||||||
try builder.appendSlice(selectStarFromNote);
|
try builder.appendSlice(selectStarFromNote ++
|
||||||
|
\\ JOIN actor ON actor.id = note.author_id
|
||||||
|
\\
|
||||||
|
);
|
||||||
|
|
||||||
if (args.created_before != null) try builder.andWhere("note.created_at < $1");
|
if (args.created_before != null) try builder.andWhere("note.created_at < $1");
|
||||||
if (args.created_after != null) try builder.andWhere("note.created_at > $2");
|
if (args.created_after != null) try builder.andWhere("note.created_at > $2");
|
||||||
|
@ -102,11 +106,12 @@ pub fn query(db: anytype, args: QueryArgs, alloc: std.mem.Allocator) !QueryResul
|
||||||
}
|
}
|
||||||
try builder.appendSlice("($3, $4)");
|
try builder.appendSlice("($3, $4)");
|
||||||
}
|
}
|
||||||
|
if (args.community_id != null) try builder.andWhere("actor.community_id = $5");
|
||||||
|
|
||||||
try builder.appendSlice(
|
try builder.appendSlice(
|
||||||
\\
|
\\
|
||||||
\\ORDER BY note.created_at DESC
|
\\ORDER BY note.created_at DESC
|
||||||
\\LIMIT $5
|
\\LIMIT $6
|
||||||
\\
|
\\
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -121,6 +126,7 @@ pub fn query(db: anytype, args: QueryArgs, alloc: std.mem.Allocator) !QueryResul
|
||||||
args.created_after,
|
args.created_after,
|
||||||
prev_created_at,
|
prev_created_at,
|
||||||
prev_id,
|
prev_id,
|
||||||
|
args.community_id,
|
||||||
max_items,
|
max_items,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -44,6 +44,7 @@ const routes = .{
|
||||||
notes.get,
|
notes.get,
|
||||||
streaming.streaming,
|
streaming.streaming,
|
||||||
timelines.global,
|
timelines.global,
|
||||||
|
timelines.local,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn Context(comptime Route: type) type {
|
pub fn Context(comptime Route: type) type {
|
||||||
|
|
|
@ -8,3 +8,14 @@ pub const global = struct {
|
||||||
try res.json(.ok, results);
|
try res.json(.ok, results);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub const local = struct {
|
||||||
|
pub const method = .GET;
|
||||||
|
pub const path = "/timelines/local";
|
||||||
|
|
||||||
|
pub fn handler(_: anytype, res: anytype, srv: anytype) !void {
|
||||||
|
const results = try srv.localTimeline();
|
||||||
|
|
||||||
|
try res.json(.ok, results);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue