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