Page MenuHomePhorge

D15248.1765078416.diff
No OneTemporary

Size
4 KB
Referenced Files
None
Subscribers
None

D15248.1765078416.diff

diff --git a/lib/actions/user-actions.js b/lib/actions/user-actions.js
--- a/lib/actions/user-actions.js
+++ b/lib/actions/user-actions.js
@@ -32,6 +32,7 @@
} from '../shared/crypto-utils.js';
import { fetchLatestDeviceList } from '../shared/device-list-utils.js';
import { useProcessAndSendDMOperation } from '../shared/dm-ops/process-dm-ops.js';
+import { useUpdateFarcasterSubscription } from '../shared/farcaster/farcaster-api.js';
import type { AuthMetadata } from '../shared/identity-client-context';
import { IdentityClientContext } from '../shared/identity-client-context.js';
import threadWatcher from '../shared/thread-watcher.js';
@@ -1384,6 +1385,7 @@
state => state.currentUserInfo && state.currentUserInfo.id,
);
const keyserverCall = useKeyserverCall(updateSubscription);
+ const updateFarcasterSubscription = useUpdateFarcasterSubscription();
return React.useCallback(
async (input: UseUpdateSubscriptionInput) =>
@@ -1392,9 +1394,15 @@
{
processAndSendDMOperation,
keyserverUpdateSubscription: keyserverCall,
+ updateFarcasterSubscription,
},
),
- [keyserverCall, processAndSendDMOperation, viewerID],
+ [
+ keyserverCall,
+ processAndSendDMOperation,
+ updateFarcasterSubscription,
+ viewerID,
+ ],
);
}
diff --git a/lib/shared/farcaster/farcaster-api.js b/lib/shared/farcaster/farcaster-api.js
--- a/lib/shared/farcaster/farcaster-api.js
+++ b/lib/shared/farcaster/farcaster-api.js
@@ -295,10 +295,33 @@
);
}
+export type UpdateFarcasterSubscriptionInput = {
+ +conversationId: string,
+ +muted: boolean,
+};
+
+function useUpdateFarcasterSubscription(): (
+ input: UpdateFarcasterSubscriptionInput,
+) => Promise<void> {
+ const { sendFarcasterRequest } = useTunnelbroker();
+ return React.useCallback(
+ async (input: UpdateFarcasterSubscriptionInput) => {
+ await sendFarcasterRequest({
+ apiVersion: 'v2',
+ endpoint: 'direct-cast-conversation-notifications',
+ method: { type: 'POST' },
+ payload: JSON.stringify(input),
+ });
+ },
+ [sendFarcasterRequest],
+ );
+}
+
export {
useSendFarcasterTextMessage,
useFetchFarcasterMessages,
useFetchFarcasterConversation,
useFetchFarcasterInbox,
useUpdateFarcasterGroupNameAndDescription,
+ useUpdateFarcasterSubscription,
};
diff --git a/lib/shared/threads/protocols/farcaster-thread-protocol.js b/lib/shared/threads/protocols/farcaster-thread-protocol.js
--- a/lib/shared/threads/protocols/farcaster-thread-protocol.js
+++ b/lib/shared/threads/protocols/farcaster-thread-protocol.js
@@ -49,10 +49,12 @@
FetchMessageUtils,
ProtocolFetchMessageInput,
ProtocolSendTextMessageInput,
+ ProtocolUpdateSubscriptionInput,
SendTextMessageUtils,
ThreadProtocol,
OnOpenThreadUtils,
ProtocolOnOpenThreadInput,
+ UpdateSubscriptionUtils,
} from '../thread-spec.js';
const farcasterThreadProtocol: ThreadProtocol<MemberInfoSansPermissions> = {
@@ -216,8 +218,32 @@
throw new Error('addThreadMembers method is not yet implemented');
},
- updateSubscription: async (): Promise<SubscriptionUpdateResult> => {
- throw new Error('updateSubscription method is not yet implemented');
+ updateSubscription: async (
+ protocolInput: ProtocolUpdateSubscriptionInput,
+ utils: UpdateSubscriptionUtils,
+ ): Promise<SubscriptionUpdateResult> => {
+ const { input } = protocolInput;
+ const { threadInfo, updatedFields } = input;
+ const { home, pushNotifs } = updatedFields;
+ const { updateFarcasterSubscription } = utils;
+
+ invariant(
+ home === pushNotifs,
+ 'background notifs are not supported for Farcaster',
+ );
+
+ const muted = !home && !pushNotifs;
+ const conversationId = conversationIDFromFarcasterThreadID(threadInfo.id);
+
+ await updateFarcasterSubscription({ conversationId, muted });
+
+ return {
+ threadID: threadInfo.id,
+ subscription: {
+ ...threadInfo.currentUser.subscription,
+ ...updatedFields,
+ },
+ };
},
leaveThread: async () => {
diff --git a/lib/shared/threads/thread-spec.js b/lib/shared/threads/thread-spec.js
--- a/lib/shared/threads/thread-spec.js
+++ b/lib/shared/threads/thread-spec.js
@@ -92,6 +92,7 @@
FetchFarcasterConversationInput,
FetchFarcasterMessageInput,
FetchFarcasterMessageResult,
+ UpdateFarcasterSubscriptionInput,
} from '../farcaster/farcaster-api.js';
import type { FetchMessagesFromDBType } from '../message-utils.js';
import type {
@@ -233,6 +234,7 @@
export type UpdateSubscriptionUtils = {
+processAndSendDMOperation: OutboundDMOperationSpecification => Promise<void>,
+keyserverUpdateSubscription: SubscriptionUpdateRequest => Promise<SubscriptionUpdateResult>,
+ +updateFarcasterSubscription: UpdateFarcasterSubscriptionInput => Promise<void>,
};
export type ProtocolLeaveThreadInput = {

File Metadata

Mime Type
text/plain
Expires
Sun, Dec 7, 3:33 AM (13 h, 31 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5842344
Default Alt Text
D15248.1765078416.diff (4 KB)

Event Timeline