summaryrefslogtreecommitdiff
path: root/front/src/logic/requests/nostrill.ts
diff options
context:
space:
mode:
authorpolwex <polwex@sortug.com>2025-09-17 15:56:00 +0700
committerpolwex <polwex@sortug.com>2025-09-17 15:56:00 +0700
commitf0df4c7297a05bd592d8717b8997284c80fd0500 (patch)
tree2d38e079e971a2e98e78a0f7a3104f2bd3c5daeb /front/src/logic/requests/nostrill.ts
parent387af8fc1603805b02ce03f8adba4fa73a954f7c (diff)
argh
Diffstat (limited to 'front/src/logic/requests/nostrill.ts')
-rw-r--r--front/src/logic/requests/nostrill.ts139
1 files changed, 139 insertions, 0 deletions
diff --git a/front/src/logic/requests/nostrill.ts b/front/src/logic/requests/nostrill.ts
new file mode 100644
index 0000000..6334c34
--- /dev/null
+++ b/front/src/logic/requests/nostrill.ts
@@ -0,0 +1,139 @@
+import type Urbit from "urbit-api";
+import type { Cursor, PostID } from "@/types/trill";
+import type { Ship } from "@/types/urbit";
+import { FeedPostCount } from "../constants";
+import type { UserProfile } from "@/types/nostrill";
+
+// Subscribe
+type Handler = (date: any) => void;
+export default class IO {
+ airlock;
+ constructor(airlock: Urbit) {
+ this.airlock = airlock;
+ }
+ private async poke(json: any) {
+ return this.airlock.poke({ app: "nostrill", mark: "json", json });
+ }
+ private async scry(path: string) {
+ return this.airlock.scry({ app: "nostrill", path });
+ }
+ private async sub(path: string, handler: Handler) {
+ const err = (err: any, _id: string) =>
+ console.log(err, "error on nostrill subscription");
+ const quit = (data: any) =>
+ console.log(data, "nostrill subscription kicked");
+ const res = await this.airlock.subscribe({
+ app: "nostrill",
+ path,
+ event: handler,
+ err,
+ quit,
+ });
+ console.log(res, "subscribed to nostrill agent");
+ }
+ async unsub(sub: number) {
+ return await this.airlock.unsubscribe(sub);
+ }
+ // subs
+ async subscribeStore(handler: Handler) {
+ const res = await this.sub("/ui", handler);
+ return res;
+ }
+ // 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(
+ host: Ship,
+ id: PostID,
+ start: Cursor,
+ end: Cursor,
+ desc = true,
+ ) {
+ const order = desc ? 1 : 0;
+
+ const path = `/j/post/${host}/${id}/${start}/${end}/${FeedPostCount}/${order}`;
+ return await this.scry(path);
+ }
+ // pokes
+
+ async pokeAlive() {
+ return await this.poke({ alive: true });
+ }
+ async addPost(content: string) {
+ const json = { add: { content } };
+ return this.poke({ post: json });
+ }
+ // async addPost(post: SentPoast, gossip: boolean) {
+ // const json = {
+ // "new-post": {
+ // "sent-post": post,
+ // gossip,
+ // },
+ // };
+ // return this.poke(json);
+ // }
+
+ async deletePost(id: string) {
+ const host = `~${this.airlock.ship}`;
+ const json = {
+ "del-post": {
+ ship: host,
+ id: id,
+ },
+ };
+ return this.poke(json);
+ }
+
+ async addReact(ship: Ship, id: PostID, reaction: string) {
+ const json = {
+ "new-react": {
+ react: reaction,
+ pid: {
+ id: id,
+ ship: ship,
+ },
+ },
+ };
+
+ return this.poke(json);
+ }
+
+ // follows
+ async follow(ship: Ship) {
+ const json = { add: ship };
+ return this.poke({ fols: json });
+ }
+
+ async unfollow(ship: Ship) {
+ const json = { del: ship };
+ return await this.poke({ fols: json });
+ }
+ // profiles
+ async createProfile(pubkey: string, profile: UserProfile) {
+ const json = { add: { pubkey, profile } };
+ return await this.poke({ prof: json });
+ }
+ async createKey() {
+ const json = { add: null };
+ return await this.poke({ keys: json });
+ }
+ async removeKey(pubkey: string) {
+ const json = { del: pubkey };
+ return await this.poke({ keys: json });
+ }
+ // relaying
+ async relayPost(host: string, id: string, relays: string[]) {
+ const json = { send: { host, id, relays } };
+ return await this.poke({ rela: json });
+ }
+}
+
+// notifications
+
+// mark as read