Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F32156123
D15502.1765035790.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
5 KB
Referenced Files
None
Subscribers
None
D15502.1765035790.diff
View Options
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
@@ -955,15 +955,42 @@
utils: PinMessageUtils,
): Promise<void> => {
const { messageID, threadInfo, action } = input;
- const { farcasterPinMessage } = utils;
+ const { farcasterPinMessage, dispatch, viewerID } = utils;
+ invariant(viewerID, 'Viewer ID should be present');
const conversationId = conversationIDFromFarcasterThreadID(threadInfo.id);
+ const time = Date.now();
await farcasterPinMessage({
conversationId,
messageId: messageID,
action,
});
+
+ const currentPinnedMessageIDs = threadInfo.pinnedMessageIDs ?? [];
+ // Farcaster supports only one pinned message at a time
+ const updatedPinnedMessageIDs =
+ action === 'pin'
+ ? [messageID]
+ : currentPinnedMessageIDs.filter(id => id !== messageID);
+
+ const updateInfos = [
+ {
+ type: updateTypes.UPDATE_THREAD,
+ id: uuid.v4(),
+ time,
+ threadInfo: {
+ ...threadInfo,
+ pinnedMessageIDs: updatedPinnedMessageIDs,
+ pinnedCount: updatedPinnedMessageIDs.length,
+ },
+ },
+ ];
+
+ dispatch({
+ type: processFarcasterOpsActionType,
+ payload: { rawMessageInfos: [], updateInfos },
+ });
},
fetchPinnedMessages: 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
@@ -380,13 +380,15 @@
export type ProtocolPinMessageInput = {
+messageID: string,
- +threadInfo: ThreadInfo,
+ +threadInfo: RawThreadInfo,
+action: 'pin' | 'unpin',
};
export type PinMessageUtils = {
+keyserverToggleMessagePin: ToggleMessagePinRequest => Promise<ToggleMessagePinResult>,
+farcasterPinMessage: PinMessageInput => Promise<void>,
+dispatchActionPromise: DispatchActionPromise,
+ +dispatch: Dispatch,
+ +viewerID: ?string,
};
export type ProtocolFetchPinnedMessagesInput = {
diff --git a/lib/utils/pin-message-utils.js b/lib/utils/pin-message-utils.js
--- a/lib/utils/pin-message-utils.js
+++ b/lib/utils/pin-message-utils.js
@@ -3,6 +3,7 @@
import * as React from 'react';
import { useDispatchActionPromise } from './redux-promise-utils.js';
+import { useDispatch, useSelector } from './redux-utils.js';
import { useGetLatestMessageEdit } from '../hooks/latest-message-edit.js';
import {
useFetchPinnedMessages,
@@ -15,29 +16,40 @@
function usePinMessageAction(): (
messageID: string,
- threadInfo: ThreadInfo,
+ threadID: string,
action: 'pin' | 'unpin',
) => Promise<void> {
const keyserverToggleMessagePin = useToggleMessagePin();
const farcasterPinMessage = usePinMessage();
const dispatchActionPromise = useDispatchActionPromise();
+ const dispatch = useDispatch();
+ const viewerID = useSelector(
+ state => state.currentUserInfo && state.currentUserInfo.id,
+ );
+ const threadInfos = useSelector(state => state.threadStore.threadInfos);
return React.useCallback(
- async (
- messageID: string,
- threadInfo: ThreadInfo,
- action: 'pin' | 'unpin',
- ) => {
+ async (messageID: string, threadID: string, action: 'pin' | 'unpin') => {
+ const threadInfo = threadInfos[threadID];
await threadSpecs[threadInfo.type].protocol().pinMessage(
{ messageID, threadInfo, action },
{
keyserverToggleMessagePin,
farcasterPinMessage,
dispatchActionPromise,
+ dispatch,
+ viewerID,
},
);
},
- [keyserverToggleMessagePin, farcasterPinMessage, dispatchActionPromise],
+ [
+ keyserverToggleMessagePin,
+ farcasterPinMessage,
+ dispatchActionPromise,
+ dispatch,
+ viewerID,
+ threadInfos,
+ ],
);
}
diff --git a/native/chat/toggle-pin-modal.react.js b/native/chat/toggle-pin-modal.react.js
--- a/native/chat/toggle-pin-modal.react.js
+++ b/native/chat/toggle-pin-modal.react.js
@@ -59,12 +59,12 @@
const onPress = React.useCallback(() => {
invariant(messageInfo.id, 'messageInfo.id should be defined');
- void pinMessageAction(messageInfo.id, threadInfo, modalInfo.action);
+ void pinMessageAction(messageInfo.id, threadInfo.id, modalInfo.action);
navigation.goBack();
}, [
pinMessageAction,
messageInfo.id,
- threadInfo,
+ threadInfo.id,
modalInfo.action,
navigation,
]);
diff --git a/web/modals/chat/toggle-pin-modal.react.js b/web/modals/chat/toggle-pin-modal.react.js
--- a/web/modals/chat/toggle-pin-modal.react.js
+++ b/web/modals/chat/toggle-pin-modal.react.js
@@ -76,15 +76,15 @@
);
void pinMessageAction(
engagementTargetMessageID,
- threadInfo,
+ threadInfo.id,
modalInfo.action,
);
popModal();
}, [
+ threadInfo.id,
modalInfo.action,
pinMessageAction,
engagementTargetMessageID,
- threadInfo,
popModal,
]);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Dec 6, 3:43 PM (20 h, 28 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5837367
Default Alt Text
D15502.1765035790.diff (5 KB)
Attached To
Mode
D15502: [lib] Optimistically update after pinning
Attached
Detach File
Event Timeline
Log In to Comment