tangled
alpha
login
or
join now
leaflet.pub
/
leaflet
289
fork
atom
a tool for shared writing and social publishing
289
fork
atom
overview
issues
27
pulls
pipelines
don't getpreferences on subscribe
awarm.space
1 month ago
e023d527
856e0c8f
+10
-13
1 changed file
expand all
collapse all
unified
split
app
lish
subscribeToPublication.ts
+10
-13
app/lish/subscribeToPublication.ts
···
3
import { AtpBaseClient } from "lexicons/api";
4
import { AppBskyActorDefs, Agent as BskyAgent } from "@atproto/api";
5
import { getIdentityData } from "actions/getIdentityData";
6
-
import {
7
-
restoreOAuthSession,
8
-
OAuthSessionError,
9
-
} from "src/atproto-oauth";
10
import { TID } from "@atproto/common";
11
import { supabaseServerClient } from "supabase/serverClient";
12
import { revalidatePath } from "next/cache";
···
79
}
80
81
let bsky = new BskyAgent(credentialSession);
82
-
let [prefs, profile, resolveDid] = await Promise.all([
83
-
bsky.app.bsky.actor.getPreferences(),
84
bsky.app.bsky.actor.profile
85
.get({
86
repo: credentialSession.did!,
···
96
handle: resolveDid?.alsoKnownAs?.[0]?.slice(5),
97
});
98
}
99
-
let savedFeeds = prefs.data.preferences.find(
100
-
(pref) => pref.$type === "app.bsky.actor.defs#savedFeedsPrefV2",
101
-
) as AppBskyActorDefs.SavedFeedsPrefV2;
102
revalidatePath("/lish/[did]/[publication]", "layout");
103
return {
104
success: true,
105
-
hasFeed: !!savedFeeds.items.find((feed) => feed.value === leafletFeedURI),
106
};
107
}
108
···
111
| { success: false; error: OAuthSessionError };
112
113
export async function unsubscribeToPublication(
114
-
publication: string
115
): Promise<UnsubscribeResult> {
116
let identity = await getIdentityData();
117
if (!identity || !identity.atp_did) {
···
144
// Delete from both collections (old and new schema) - one or both may exist
145
let rkey = new AtUri(existingSubscription.uri).rkey;
146
await Promise.all([
147
-
agent.pub.leaflet.graph.subscription.delete({ repo: credentialSession.did!, rkey }).catch(() => {}),
148
-
agent.site.standard.graph.subscription.delete({ repo: credentialSession.did!, rkey }).catch(() => {}),
0
0
0
0
149
]);
150
151
await supabaseServerClient
···
3
import { AtpBaseClient } from "lexicons/api";
4
import { AppBskyActorDefs, Agent as BskyAgent } from "@atproto/api";
5
import { getIdentityData } from "actions/getIdentityData";
6
+
import { restoreOAuthSession, OAuthSessionError } from "src/atproto-oauth";
0
0
0
7
import { TID } from "@atproto/common";
8
import { supabaseServerClient } from "supabase/serverClient";
9
import { revalidatePath } from "next/cache";
···
76
}
77
78
let bsky = new BskyAgent(credentialSession);
79
+
let [profile, resolveDid] = await Promise.all([
0
80
bsky.app.bsky.actor.profile
81
.get({
82
repo: credentialSession.did!,
···
92
handle: resolveDid?.alsoKnownAs?.[0]?.slice(5),
93
});
94
}
0
0
0
95
revalidatePath("/lish/[did]/[publication]", "layout");
96
return {
97
success: true,
98
+
hasFeed: true,
99
};
100
}
101
···
104
| { success: false; error: OAuthSessionError };
105
106
export async function unsubscribeToPublication(
107
+
publication: string,
108
): Promise<UnsubscribeResult> {
109
let identity = await getIdentityData();
110
if (!identity || !identity.atp_did) {
···
137
// Delete from both collections (old and new schema) - one or both may exist
138
let rkey = new AtUri(existingSubscription.uri).rkey;
139
await Promise.all([
140
+
agent.pub.leaflet.graph.subscription
141
+
.delete({ repo: credentialSession.did!, rkey })
142
+
.catch(() => {}),
143
+
agent.site.standard.graph.subscription
144
+
.delete({ repo: credentialSession.did!, rkey })
145
+
.catch(() => {}),
146
]);
147
148
await supabaseServerClient