Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support location user data type #514

Merged
merged 5 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/cool-ties-accept.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"frames.js": patch
---

feat: support location user data type
213 changes: 207 additions & 6 deletions packages/frames.js/src/farcaster/generated/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ export enum MessageType {
USERNAME_PROOF = 12,
/** FRAME_ACTION - A Farcaster Frame action */
FRAME_ACTION = 13,
/** LINK_COMPACT_STATE - Link Compaction State Message */
LINK_COMPACT_STATE = 14,
}

export function messageTypeFromJSON(object: any): MessageType {
Expand Down Expand Up @@ -150,6 +152,9 @@ export function messageTypeFromJSON(object: any): MessageType {
case 13:
case "MESSAGE_TYPE_FRAME_ACTION":
return MessageType.FRAME_ACTION;
case 14:
case "MESSAGE_TYPE_LINK_COMPACT_STATE":
return MessageType.LINK_COMPACT_STATE;
default:
throw new tsProtoGlobalThis.Error(
"Unrecognized enum value " + object + " for enum MessageType"
Expand Down Expand Up @@ -183,6 +188,8 @@ export function messageTypeToJSON(object: MessageType): string {
return "MESSAGE_TYPE_USERNAME_PROOF";
case MessageType.FRAME_ACTION:
return "MESSAGE_TYPE_FRAME_ACTION";
case MessageType.LINK_COMPACT_STATE:
return "MESSAGE_TYPE_LINK_COMPACT_STATE";
default:
throw new tsProtoGlobalThis.Error(
"Unrecognized enum value " + object + " for enum MessageType"
Expand Down Expand Up @@ -252,6 +259,8 @@ export enum UserDataType {
URL = 5,
/** USERNAME - Preferred Name for the user */
USERNAME = 6,
/** LOCATION - Current location for the user */
LOCATION = 7,
}

export function userDataTypeFromJSON(object: any): UserDataType {
Expand All @@ -274,6 +283,9 @@ export function userDataTypeFromJSON(object: any): UserDataType {
case 6:
case "USER_DATA_TYPE_USERNAME":
return UserDataType.USERNAME;
case 7:
case "USER_DATA_TYPE_LOCATION":
return UserDataType.LOCATION;
default:
throw new tsProtoGlobalThis.Error(
"Unrecognized enum value " + object + " for enum UserDataType"
Expand All @@ -295,13 +307,49 @@ export function userDataTypeToJSON(object: UserDataType): string {
return "USER_DATA_TYPE_URL";
case UserDataType.USERNAME:
return "USER_DATA_TYPE_USERNAME";
case UserDataType.LOCATION:
return "USER_DATA_TYPE_LOCATION";
default:
throw new tsProtoGlobalThis.Error(
"Unrecognized enum value " + object + " for enum UserDataType"
);
}
}

/** Type of cast */
export enum CastType {
CAST = 0,
LONG_CAST = 1,
}

export function castTypeFromJSON(object: any): CastType {
switch (object) {
case 0:
case "CAST":
return CastType.CAST;
case 1:
case "LONG_CAST":
return CastType.LONG_CAST;
default:
throw new tsProtoGlobalThis.Error(
"Unrecognized enum value " + object + " for enum CastType"
);
}
}

export function castTypeToJSON(object: CastType): string {
switch (object) {
case CastType.CAST:
return "CAST";
case CastType.LONG_CAST:
return "LONG_CAST";
default:
throw new tsProtoGlobalThis.Error(
"Unrecognized enum value " + object + " for enum CastType"
);
}
}

/** Type of Reaction */
export enum ReactionType {
NONE = 0,
Expand Down Expand Up @@ -423,6 +471,8 @@ export interface MessageData {
linkBody?: LinkBody | undefined;
usernameProofBody?: UserNameProof | undefined;
frameActionBody?: FrameActionBody | undefined;
/** Compaction messages */
linkCompactStateBody?: LinkCompactStateBody | undefined;
}

/** Adds metadata about a user */
Expand Down Expand Up @@ -454,6 +504,8 @@ export interface CastAddBody {
mentionsPositions: number[];
/** URLs or cast ids to be embedded in the cast */
embeds: Embed[];
/** Type of cast */
type: CastType;
}

/** Removes an existing Cast */
Expand Down Expand Up @@ -514,6 +566,13 @@ export interface LinkBody {
targetFid?: number | undefined;
}

/** A Compaction message for the Link Store */
export interface LinkCompactStateBody {
/** Type of link, <= 8 characters */
type: string;
targetFids: number[];
}

/** A Farcaster Frame action */
export interface FrameActionBody {
/** URL of the Frame triggering the action */
Expand Down Expand Up @@ -726,6 +785,7 @@ function createBaseMessageData(): MessageData {
linkBody: undefined,
usernameProofBody: undefined,
frameActionBody: undefined,
linkCompactStateBody: undefined,
};
}

Expand Down Expand Up @@ -797,6 +857,12 @@ export const MessageData = {
writer.uint32(130).fork()
).ldelim();
}
if (message.linkCompactStateBody !== undefined) {
LinkCompactStateBody.encode(
message.linkCompactStateBody,
writer.uint32(138).fork()
).ldelim();
}
return writer;
},

Expand Down Expand Up @@ -912,6 +978,16 @@ export const MessageData = {
reader.uint32()
);
continue;
case 17:
if (tag != 138) {
break;
}

message.linkCompactStateBody = LinkCompactStateBody.decode(
reader,
reader.uint32()
);
continue;
}
if ((tag & 7) == 4 || tag == 0) {
break;
Expand Down Expand Up @@ -956,6 +1032,9 @@ export const MessageData = {
frameActionBody: isSet(object.frameActionBody)
? FrameActionBody.fromJSON(object.frameActionBody)
: undefined,
linkCompactStateBody: isSet(object.linkCompactStateBody)
? LinkCompactStateBody.fromJSON(object.linkCompactStateBody)
: undefined,
};
},

Expand Down Expand Up @@ -1003,6 +1082,10 @@ export const MessageData = {
(obj.frameActionBody = message.frameActionBody
? FrameActionBody.toJSON(message.frameActionBody)
: undefined);
message.linkCompactStateBody !== undefined &&
(obj.linkCompactStateBody = message.linkCompactStateBody
? LinkCompactStateBody.toJSON(message.linkCompactStateBody)
: undefined);
return obj;
},

Expand Down Expand Up @@ -1059,6 +1142,11 @@ export const MessageData = {
object.frameActionBody !== undefined && object.frameActionBody !== null
? FrameActionBody.fromPartial(object.frameActionBody)
: undefined;
message.linkCompactStateBody =
object.linkCompactStateBody !== undefined &&
object.linkCompactStateBody !== null
? LinkCompactStateBody.fromPartial(object.linkCompactStateBody)
: undefined;
return message;
},
};
Expand Down Expand Up @@ -1227,6 +1315,7 @@ function createBaseCastAddBody(): CastAddBody {
text: "",
mentionsPositions: [],
embeds: [],
type: 0,
};
}

Expand Down Expand Up @@ -1260,6 +1349,9 @@ export const CastAddBody = {
for (const v of message.embeds) {
Embed.encode(v!, writer.uint32(50).fork()).ldelim();
}
if (message.type !== 0) {
writer.uint32(64).int32(message.type);
}
return writer;
},

Expand Down Expand Up @@ -1338,6 +1430,13 @@ export const CastAddBody = {

message.embeds.push(Embed.decode(reader, reader.uint32()));
continue;
case 8:
if (tag != 64) {
break;
}

message.type = reader.int32() as any;
continue;
}
if ((tag & 7) == 4 || tag == 0) {
break;
Expand Down Expand Up @@ -1366,6 +1465,7 @@ export const CastAddBody = {
embeds: Array.isArray(object?.embeds)
? object.embeds.map((e: any) => Embed.fromJSON(e))
: [],
type: isSet(object.type) ? castTypeFromJSON(object.type) : 0,
};
},

Expand Down Expand Up @@ -1399,6 +1499,7 @@ export const CastAddBody = {
} else {
obj.embeds = [];
}
message.type !== undefined && (obj.type = castTypeToJSON(message.type));
return obj;
},

Expand All @@ -1420,6 +1521,7 @@ export const CastAddBody = {
message.text = object.text ?? "";
message.mentionsPositions = object.mentionsPositions?.map((e) => e) || [];
message.embeds = object.embeds?.map((e) => Embed.fromPartial(e)) || [];
message.type = object.type ?? 0;
return message;
},
};
Expand Down Expand Up @@ -2018,6 +2120,105 @@ export const LinkBody = {
},
};

function createBaseLinkCompactStateBody(): LinkCompactStateBody {
return { type: "", targetFids: [] };
}

export const LinkCompactStateBody = {
encode(
message: LinkCompactStateBody,
writer: _m0.Writer = _m0.Writer.create()
): _m0.Writer {
if (message.type !== "") {
writer.uint32(10).string(message.type);
}
writer.uint32(18).fork();
for (const v of message.targetFids) {
writer.uint64(v);
}
writer.ldelim();
return writer;
},

decode(
input: _m0.Reader | Uint8Array,
length?: number
): LinkCompactStateBody {
const reader =
input instanceof _m0.Reader ? input : _m0.Reader.create(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = createBaseLinkCompactStateBody();
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
case 1:
if (tag != 10) {
break;
}

message.type = reader.string();
continue;
case 2:
if (tag == 16) {
message.targetFids.push(longToNumber(reader.uint64() as Long));
continue;
}

if (tag == 18) {
const end2 = reader.uint32() + reader.pos;
while (reader.pos < end2) {
message.targetFids.push(longToNumber(reader.uint64() as Long));
}

continue;
}

break;
}
if ((tag & 7) == 4 || tag == 0) {
break;
}
reader.skipType(tag & 7);
}
return message;
},

fromJSON(object: any): LinkCompactStateBody {
return {
type: isSet(object.type) ? String(object.type) : "",
targetFids: Array.isArray(object?.targetFids)
? object.targetFids.map((e: any) => Number(e))
: [],
};
},

toJSON(message: LinkCompactStateBody): unknown {
const obj: any = {};
message.type !== undefined && (obj.type = message.type);
if (message.targetFids) {
obj.targetFids = message.targetFids.map((e) => Math.round(e));
} else {
obj.targetFids = [];
}
return obj;
},

create<I extends Exact<DeepPartial<LinkCompactStateBody>, I>>(
base?: I
): LinkCompactStateBody {
return LinkCompactStateBody.fromPartial(base ?? {});
},

fromPartial<I extends Exact<DeepPartial<LinkCompactStateBody>, I>>(
object: I
): LinkCompactStateBody {
const message = createBaseLinkCompactStateBody();
message.type = object.type ?? "";
message.targetFids = object.targetFids?.map((e) => e) || [];
return message;
},
};

function createBaseFrameActionBody(): FrameActionBody {
return {
url: new Uint8Array(),
Expand Down Expand Up @@ -2256,12 +2457,12 @@ type Builtin =
type DeepPartial<T> = T extends Builtin
? T
: T extends Array<infer U>
? Array<DeepPartial<U>>
: T extends ReadonlyArray<infer U>
? ReadonlyArray<DeepPartial<U>>
: T extends {}
? { [K in keyof T]?: DeepPartial<T[K]> }
: Partial<T>;
? Array<DeepPartial<U>>
: T extends ReadonlyArray<infer U>
? ReadonlyArray<DeepPartial<U>>
: T extends {}
? { [K in keyof T]?: DeepPartial<T[K]> }
: Partial<T>;

type KeysOfUnion<T> = T extends T ? keyof T : never;
type Exact<P, I extends P> = P extends Builtin
Expand Down
Loading
Loading