Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3516354
D13392.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
D13392.diff
View Options
diff --git a/lib/shared/dm-ops/dm-op-specs.js b/lib/shared/dm-ops/dm-op-specs.js
--- a/lib/shared/dm-ops/dm-op-specs.js
+++ b/lib/shared/dm-ops/dm-op-specs.js
@@ -18,6 +18,7 @@
import { sendMultimediaMessageSpec } from './send-multimedia-message-spec.js';
import { sendReactionMessageSpec } from './send-reaction-message-spec.js';
import { sendTextMessageSpec } from './send-text-message-spec.js';
+import { updateRelationshipSpec } from './update-relationship-spec.js';
import { type DMOperationType, dmOperationTypes } from '../../types/dm-ops.js';
export const dmOpSpecs: {
@@ -40,4 +41,5 @@
[dmOperationTypes.CREATE_ENTRY]: createEntrySpec,
[dmOperationTypes.DELETE_ENTRY]: deleteEntrySpec,
[dmOperationTypes.EDIT_ENTRY]: editEntrySpec,
+ [dmOperationTypes.UPDATE_RELATIONSHIP]: updateRelationshipSpec,
});
diff --git a/lib/shared/dm-ops/update-relationship-spec.js b/lib/shared/dm-ops/update-relationship-spec.js
new file mode 100644
--- /dev/null
+++ b/lib/shared/dm-ops/update-relationship-spec.js
@@ -0,0 +1,110 @@
+// @flow
+
+import type {
+ DMOperationSpec,
+ ProcessDMOperationUtilities,
+} from './dm-op-spec.js';
+import type { DMUpdateRelationshipOperation } from '../../types/dm-ops.js';
+import { messageTypes } from '../../types/message-types-enum.js';
+import { rawMessageInfoFromMessageData } from '../message-utils.js';
+
+async function createMessageDataFromDMOperation(
+ dmOperation: DMUpdateRelationshipOperation,
+ viewerID: string,
+ utilities: ProcessDMOperationUtilities,
+) {
+ const { threadID, creatorID, time, operation } = dmOperation;
+ if (operation !== 'farcaster_mutual') {
+ return {
+ type: messageTypes.UPDATE_RELATIONSHIP,
+ threadID,
+ creatorID,
+ targetID: viewerID,
+ time,
+ operation,
+ };
+ }
+ const { findUserIdentities } = utilities;
+ const { identities: userIdentities } = await findUserIdentities([
+ creatorID,
+ viewerID,
+ ]);
+ const creatorFID = userIdentities[creatorID]?.farcasterID;
+ const targetFID = userIdentities[viewerID]?.farcasterID;
+ if (!creatorFID || !targetFID) {
+ const errorMap = { creatorID: creatorFID, viewerID: targetFID };
+ throw new Error(
+ 'could not fetch FID for either creator or target: ' +
+ JSON.stringify(errorMap),
+ );
+ }
+ return {
+ type: messageTypes.UPDATE_RELATIONSHIP,
+ threadID,
+ creatorID,
+ creatorFID,
+ targetID: viewerID,
+ targetFID,
+ time,
+ operation,
+ };
+}
+
+const updateRelationshipSpec: DMOperationSpec<DMUpdateRelationshipOperation> =
+ Object.freeze({
+ notificationsCreationData: async (
+ dmOperation: DMUpdateRelationshipOperation,
+ viewerID: string,
+ utilities: ProcessDMOperationUtilities,
+ ) => {
+ const messageData = await createMessageDataFromDMOperation(
+ dmOperation,
+ viewerID,
+ utilities,
+ );
+ return { messageDatas: [messageData] };
+ },
+ processDMOperation: async (
+ dmOperation: DMUpdateRelationshipOperation,
+ viewerID: string,
+ utilities: ProcessDMOperationUtilities,
+ ) => {
+ const { messageID } = dmOperation;
+ const messageData = await createMessageDataFromDMOperation(
+ dmOperation,
+ viewerID,
+ utilities,
+ );
+ const rawMessageInfos = [
+ rawMessageInfoFromMessageData(messageData, messageID),
+ ];
+ return {
+ rawMessageInfos,
+ updateInfos: [],
+ };
+ },
+ canBeProcessed: async (
+ dmOperation: DMUpdateRelationshipOperation,
+ viewerID: string,
+ utilities: ProcessDMOperationUtilities,
+ ) => {
+ try {
+ await createMessageDataFromDMOperation(
+ dmOperation,
+ viewerID,
+ utilities,
+ );
+ return {
+ isProcessingPossible: true,
+ };
+ } catch (e) {
+ return {
+ isProcessingPossible: false,
+ reason: { type: 'invalid' },
+ };
+ }
+ },
+ supportsAutoRetry: true,
+ });
+
+export { updateRelationshipSpec };
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Dec 23, 2:04 PM (18 h, 31 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2694831
Default Alt Text
D13392.diff (4 KB)
Attached To
Mode
D13392: [lib] Introduce updateRelationshipSpec
Attached
Detach File
Event Timeline
Log In to Comment