summaryrefslogtreecommitdiff
path: root/front/src/logic/requests
diff options
context:
space:
mode:
Diffstat (limited to 'front/src/logic/requests')
-rw-r--r--front/src/logic/requests/nostrill.ts62
1 files changed, 51 insertions, 11 deletions
diff --git a/front/src/logic/requests/nostrill.ts b/front/src/logic/requests/nostrill.ts
index 4147e35..e35b939 100644
--- a/front/src/logic/requests/nostrill.ts
+++ b/front/src/logic/requests/nostrill.ts
@@ -1,5 +1,5 @@
import type Urbit from "urbit-api";
-import type { Cursor, FC, PostID } from "@/types/trill";
+import type { Cursor, FC, FullNode, PID, PostID } from "@/types/trill";
import type { Ship } from "@/types/urbit";
import { FeedPostCount } from "../constants";
import type { UserProfile, UserType } from "@/types/nostrill";
@@ -57,25 +57,39 @@ export default class IO {
}
// scries
- async scryFeed(start: Cursor, end: Cursor, desc = true) {
- const order = desc ? 1 : 0;
- const term = "feed";
-
- const path = `/j/feed/${term}/${start}/${end}/${FeedPostCount}/${order}`;
- return await this.scry(path);
- }
- async scryPost(
+ async scryFeed(
host: Ship,
- id: PostID,
start: Cursor,
end: Cursor,
desc = true,
+
+ replies = false,
) {
const order = desc ? 1 : 0;
+ const rp = replies ? 1 : 0;
- const path = `/j/post/${host}/${id}/${start}/${end}/${FeedPostCount}/${order}`;
+ const path = `/j/feed/${host}/${start}/${end}/${FeedPostCount}/${order}/${rp}`;
return await this.scry(path);
}
+ async scryThread(
+ host: Ship,
+ id: PostID,
+ // start: Cursor,
+ // end: Cursor,
+ // desc = true,
+ ): AsyncRes<FullNode> {
+ // const order = desc ? 1 : 0;
+
+ // const path = `/j/thread/${host}/${id}/${start}/${end}/${FeedPostCount}/${order}`;
+ const path = `/j/thread/${host}/${id}`;
+ const res = await this.scry(path);
+ if (!("begs" in res)) return { error: "wrong result" };
+ if ("ng" in res.begs) return { error: res.begs.ng };
+ if ("ok" in res.begs) {
+ if (!("thread" in res.begs.ok)) return { error: "wrong result" };
+ else return { ok: res.begs.ok.thread };
+ } else return { error: "wrong result" };
+ }
// pokes
async pokeAlive() {
@@ -85,6 +99,19 @@ export default class IO {
const json = { add: { content } };
return this.poke({ post: json });
}
+ async addReply(content: string, host: string, id: string, thread: string) {
+ const json = { reply: { content, host, id, thread } };
+ return this.poke({ post: json });
+ }
+ async addQuote(content: string, pid: PID) {
+ const json = { quote: { content, host: pid.ship, id: pid.id } };
+ return this.poke({ post: json });
+ }
+ async addRP(pid: PID) {
+ const json = { quote: { host: pid.ship, id: pid.id } };
+ return this.poke({ post: json });
+ }
+
// async addPost(post: SentPoast, gossip: boolean) {
// const json = {
// "new-post": {
@@ -177,6 +204,19 @@ export default class IO {
return { error: `${e}` };
}
}
+ async peekThread(host: string, id: string): AsyncRes<FullNode> {
+ try {
+ const json = { begs: { thread: { host, id } } };
+ const res: any = await this.thread("beg", json);
+ console.log("peeking feed", res);
+ if (!("begs" in res)) return { error: "wrong request" };
+ if ("ng" in res.begs) return { error: res.begs.ng };
+ if (!("thread" in res.begs.ok)) return { error: "wrong request" };
+ else return { ok: res.begs.ok.thread };
+ } catch (e) {
+ return { error: `${e}` };
+ }
+ }
}
// notifications