Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F32205049
D15304.1765116444.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
8 KB
Referenced Files
None
Subscribers
None
D15304.1765116444.diff
View Options
diff --git a/lib/hooks/thread-hooks.js b/lib/hooks/thread-hooks.js
--- a/lib/hooks/thread-hooks.js
+++ b/lib/hooks/thread-hooks.js
@@ -5,7 +5,6 @@
import uuid from 'uuid';
import { useChatMentionContext } from './chat-mention-hooks.js';
-import { useGetCommFCUsersForFIDs } from './user-identities-hooks.js';
import { removeUsersFromThreadActionTypes } from '../actions/thread-action-types.js';
import genesis from '../facts/genesis.js';
import { extractKeyserverIDFromID } from '../keyserver-conn/keyserver-call-utils.js';
@@ -18,8 +17,6 @@
} from '../shared/dm-ops/dm-op-types.js';
import { useProcessAndSendDMOperation } from '../shared/dm-ops/process-dm-ops.js';
import {
- useFetchFarcasterConversation,
- useFetchFarcasterMessages,
useUpdateFarcasterGroupNameAndDescription,
useModifyFarcasterMembershipInput,
} from '../shared/farcaster/farcaster-api.js';
@@ -58,7 +55,7 @@
} from '../types/thread-types.js';
import { values } from '../utils/objects.js';
import { useDispatchActionPromise } from '../utils/redux-promise-utils.js';
-import { useSelector, useDispatch } from '../utils/redux-utils.js';
+import { useSelector } from '../utils/redux-utils.js';
function useChildThreadInfosMap(): {
+[id: string]: $ReadOnlyArray<ResolvedThreadInfo>,
@@ -243,10 +240,9 @@
const keyserverCall = useKeyserverCall(changeThreadSettings);
const updateFarcasterGroupNameAndDescription =
useUpdateFarcasterGroupNameAndDescription();
- const fetchFarcasterConversation = useFetchFarcasterConversation();
- const fetchFarcasterMessages = useFetchFarcasterMessages();
- const fetchUsersByFIDs = useGetCommFCUsersForFIDs();
- const dispatch = useDispatch();
+ const modifyFarcasterMembership = useModifyFarcasterMembershipInput();
+ const refreshFarcasterConversation = useRefreshFarcasterConversation();
+ const auxUserStore = useSelector(state => state.auxUserStore);
return React.useCallback(
async (input: UseChangeThreadSettingsInput) =>
@@ -256,21 +252,19 @@
processAndSendDMOperation,
keyserverChangeThreadSettings: keyserverCall,
updateFarcasterGroupNameAndDescription,
- fetchFarcasterConversation,
- fetchFarcasterMessages,
- fetchUsersByFIDs,
- dispatch,
+ modifyFarcasterMembership,
+ refreshFarcasterConversation,
+ auxUserStore,
},
),
[
- fetchFarcasterConversation,
+ auxUserStore,
keyserverCall,
+ modifyFarcasterMembership,
processAndSendDMOperation,
+ refreshFarcasterConversation,
updateFarcasterGroupNameAndDescription,
viewerID,
- fetchFarcasterMessages,
- fetchUsersByFIDs,
- dispatch,
],
);
}
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
@@ -46,19 +46,13 @@
ThreadJoinPayload,
} from '../../../types/thread-types.js';
import { updateTypes } from '../../../types/update-types-enum.js';
-import { type ThreadUpdateInfo } from '../../../types/update-types.js';
-import { extractFarcasterIDsFromPayload } from '../../../utils/conversion-utils.js';
-import { convertFarcasterMessageToCommMessages } from '../../../utils/convert-farcaster-message-to-comm-messages.js';
-import { createFarcasterRawThreadInfo } from '../../../utils/create-farcaster-raw-thread-info.js';
import { farcasterThreadIDRegExp } from '../../../utils/validation-utils.js';
import { generatePendingThreadColor } from '../../color-utils.js';
import { type ModifyFarcasterMembershipInput } from '../../farcaster/farcaster-api.js';
-import { farcasterMessageValidator } from '../../farcaster/farcaster-messages-types.js';
import {
conversationIDFromFarcasterThreadID,
extractFIDFromUserID,
farcasterThreadIDFromConversationID,
- userIDFromFID,
} from '../../id-utils.js';
import { messageNotifyTypes } from '../../messages/message-spec.js';
import {
@@ -157,10 +151,9 @@
} = protocolInput;
const {
updateFarcasterGroupNameAndDescription,
- fetchFarcasterConversation,
- fetchFarcasterMessages,
- fetchUsersByFIDs,
- dispatch,
+ modifyFarcasterMembership,
+ refreshFarcasterConversation,
+ auxUserStore,
} = utils;
invariant(
!changes.color,
@@ -190,58 +183,40 @@
);
}
if (changes.newMemberIDs) {
- throw new Error('newMemberIDs not implemented yet');
+ const targetFids = changes.newMemberIDs
+ .map(memberID => {
+ const targetFid =
+ auxUserStore.auxUserInfos[memberID]?.fid ??
+ extractFIDFromUserID(memberID);
+ return targetFid ? parseInt(targetFid, 10) : null;
+ })
+ .filter(Boolean);
+
+ if (targetFids.length > 0) {
+ const modifyFarcasterMembershipInput: ModifyFarcasterMembershipInput = {
+ conversationId,
+ action: 'add',
+ targetFids,
+ };
+
+ promises.push(
+ modifyFarcasterMembership(modifyFarcasterMembershipInput),
+ );
+ }
}
if (changes.avatar) {
throw new Error('avatar not implemented yet');
}
- // Perform all updates before fetching updated thread
+ // Perform all updates before refreshing conversation
await Promise.all(promises);
- const updatedConversation = await fetchFarcasterConversation({
- conversationId,
- });
-
- const update = ({
- type: updateTypes.UPDATE_THREAD,
- id: threadInfo.id,
- time: Date.now(),
- threadInfo: createFarcasterRawThreadInfo(
- updatedConversation.result.conversation,
- ),
- }: ThreadUpdateInfo);
-
- const messagesResponse = await fetchFarcasterMessages({
- conversationId,
- });
- const farcasterMessages = messagesResponse.result.messages;
- const userFIDs = farcasterMessages.flatMap(message =>
- extractFarcasterIDsFromPayload(farcasterMessageValidator, message),
- );
-
- const fcUserInfos = await fetchUsersByFIDs(userFIDs);
-
- const newMessageInfos = farcasterMessages.flatMap(farcasterMessage =>
- convertFarcasterMessageToCommMessages(farcasterMessage, fcUserInfos),
- );
-
- if (fcUserInfos.size > 0) {
- const newUserIDs = Array.from(fcUserInfos.entries()).map(
- ([fid, user]) => user?.userID ?? userIDFromFID(fid),
- );
- dispatch({
- // TODO: importing processNewUserIDsActionType causes circular
- // dependencies that are hard to resolve
- type: 'PROCESS_NEW_USER_IDS',
- payload: { userIDs: newUserIDs },
- });
- }
+ await refreshFarcasterConversation(conversationId);
return ({
threadID: threadInfo.id,
- updatesResult: { newUpdates: [update] },
- newMessageInfos,
+ updatesResult: { newUpdates: [] },
+ newMessageInfos: [],
}: ChangeThreadSettingsPayload);
},
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
@@ -24,7 +24,6 @@
LeaveThreadResult,
RemoveUsersFromThreadInput,
} from '../../hooks/thread-hooks.js';
-import type { GetCommFCUsersForFIDs } from '../../hooks/user-identities-hooks.js';
import type { RolePermissionBlobs } from '../../permissions/thread-permissions.js';
import type { ProcessOutboundP2PMessagesResult } from '../../tunnelbroker/peer-to-peer-context.js';
import type { TunnelbrokerSocketState } from '../../tunnelbroker/tunnelbroker-context.js';
@@ -88,13 +87,9 @@
OutboundDMOperationSpecification,
} from '../dm-ops/dm-op-types.js';
import type {
- FetchFarcasterConversationResult,
SendFarcasterMessageResult,
SendFarcasterTextMessageInput,
UpdateFarcasterGroupNameAndDescriptionInput,
- FetchFarcasterConversationInput,
- FetchFarcasterMessageInput,
- FetchFarcasterMessageResult,
UpdateFarcasterSubscriptionInput,
StreamFarcasterDirectCastReadInput,
MarkFarcasterDirectCastUnreadInput,
@@ -167,10 +162,11 @@
+processAndSendDMOperation: OutboundDMOperationSpecification => Promise<void>,
+keyserverChangeThreadSettings: UpdateThreadRequest => Promise<ChangeThreadSettingsPayload>,
+updateFarcasterGroupNameAndDescription: UpdateFarcasterGroupNameAndDescriptionInput => Promise<void>,
- +fetchFarcasterConversation: FetchFarcasterConversationInput => Promise<FetchFarcasterConversationResult>,
- +fetchFarcasterMessages: FetchFarcasterMessageInput => Promise<FetchFarcasterMessageResult>,
- +fetchUsersByFIDs: GetCommFCUsersForFIDs,
- +dispatch: Dispatch,
+ +modifyFarcasterMembership: (
+ input: ModifyFarcasterMembershipInput,
+ ) => Promise<void>,
+ +refreshFarcasterConversation: (conversationId: string) => Promise<mixed>,
+ +auxUserStore: AuxUserStore,
};
export type ProtocolCreateEntryInput = {
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Dec 7, 2:07 PM (14 h, 16 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5844454
Default Alt Text
D15304.1765116444.diff (8 KB)
Attached To
Mode
D15304: [lib] update and simplify changing thread settings
Attached
Detach File
Event Timeline
Log In to Comment