diff --git a/lib/types/messages/update-relationship.js b/lib/types/messages/update-relationship.js index 6de1bb9ac..cf7461038 100644 --- a/lib/types/messages/update-relationship.js +++ b/lib/types/messages/update-relationship.js @@ -1,67 +1,82 @@ // @flow -import t, { type TInterface } from 'tcomb'; +import t, { type TInterface, type TUnion } from 'tcomb'; -import { tID, tNumber, tShape } from '../../utils/validation-utils.js'; +import { tID, tNumber, tShape, tString } from '../../utils/validation-utils.js'; import { messageTypes } from '../message-types-enum.js'; import type { RelativeUserInfo } from '../user-types.js'; export type TraditionalRelationshipOperation = | 'request_sent' | 'request_accepted'; export type FarcasterRelationshipOperation = 'farcaster_mutual'; export type UpdateTraditionalRelationshipMessageData = { +type: 22, +threadID: string, +creatorID: string, +targetID: string, +time: number, +operation: TraditionalRelationshipOperation, }; export type UpdateFarcasterRelationshipMessageData = { +type: 22, +threadID: string, +creatorID: string, +creatorFID: string, +targetID: string, +targetFID: string, +time: number, +operation: FarcasterRelationshipOperation, }; export type UpdateRelationshipMessageData = | UpdateTraditionalRelationshipMessageData | UpdateFarcasterRelationshipMessageData; export type RawUpdateRelationshipMessageInfo = { ...UpdateRelationshipMessageData, id: string, }; -export const rawUpdateRelationshipMessageInfoValidator: TInterface = +export const rawUpdateTraditionalRelationshipMessageInfoValidator: TInterface = tShape({ + id: tID, type: tNumber(messageTypes.UPDATE_RELATIONSHIP), threadID: tID, creatorID: t.String, targetID: t.String, time: t.Number, - operation: t.enums.of([ - 'request_sent', - 'request_accepted', - 'farcaster_mutual', - ]), + operation: t.enums.of(['request_sent', 'request_accepted']), + }); + +export const rawUpdateFarcasterRelationshipMessageInfoValidator: TInterface = + tShape({ id: tID, + type: tNumber(messageTypes.UPDATE_RELATIONSHIP), + threadID: tID, + creatorID: t.String, + creatorFID: t.String, + targetID: t.String, + targetFID: t.String, + time: t.Number, + operation: tString('farcaster_mutual'), }); +export const rawUpdateRelationshipMessageInfoValidator: TUnion = + t.union([ + rawUpdateTraditionalRelationshipMessageInfoValidator, + rawUpdateFarcasterRelationshipMessageInfoValidator, + ]); + export type UpdateRelationshipMessageInfo = { +type: 22, +id: string, +threadID: string, +creator: RelativeUserInfo, +target: RelativeUserInfo, +time: number, +operation: 'request_sent' | 'request_accepted' | 'farcaster_mutual', };