Skip to content

Commit

Permalink
Add created_by to invite list items
Browse files Browse the repository at this point in the history
  • Loading branch information
vxgmichel committed Jan 21, 2025
1 parent 67d1d70 commit d1dd3b3
Show file tree
Hide file tree
Showing 14 changed files with 511 additions and 58 deletions.
18 changes: 18 additions & 0 deletions bindings/electron/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1617,19 +1617,36 @@ export type ImportRecoveryDeviceError =
| ImportRecoveryDeviceErrorTimestampOutOfBallpark


// InviteListInvitationCreatedBy
export interface InviteListInvitationCreatedByExternalService {
tag: "ExternalService"
service_name: string
}
export interface InviteListInvitationCreatedByUser {
tag: "User"
user_id: string
human_handle: HumanHandle
}
export type InviteListInvitationCreatedBy =
| InviteListInvitationCreatedByExternalService
| InviteListInvitationCreatedByUser


// InviteListItem
export interface InviteListItemDevice {
tag: "Device"
addr: string
token: string
created_on: number
created_by: InviteListInvitationCreatedBy
status: InvitationStatus
}
export interface InviteListItemShamirRecovery {
tag: "ShamirRecovery"
addr: string
token: string
created_on: number
created_by: InviteListInvitationCreatedBy
claimer_user_id: string
shamir_recovery_created_on: number
status: InvitationStatus
Expand All @@ -1639,6 +1656,7 @@ export interface InviteListItemUser {
addr: string
token: string
created_on: number
created_by: InviteListInvitationCreatedBy
claimer_email: string
status: InvitationStatus
}
Expand Down
104 changes: 104 additions & 0 deletions bindings/electron/src/meths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6668,6 +6668,86 @@ fn variant_import_recovery_device_error_rs_to_js<'a>(
Ok(js_obj)
}

// InviteListInvitationCreatedBy

#[allow(dead_code)]
fn variant_invite_list_invitation_created_by_js_to_rs<'a>(
cx: &mut impl Context<'a>,
obj: Handle<'a, JsObject>,
) -> NeonResult<libparsec::InviteListInvitationCreatedBy> {
let tag = obj.get::<JsString, _, _>(cx, "tag")?.value(cx);
match tag.as_str() {
"InviteListInvitationCreatedByExternalService" => {
let service_name = {
let js_val: Handle<JsString> = obj.get(cx, "serviceName")?;
js_val.value(cx)
};
Ok(libparsec::InviteListInvitationCreatedBy::ExternalService { service_name })
}
"InviteListInvitationCreatedByUser" => {
let user_id = {
let js_val: Handle<JsString> = obj.get(cx, "userId")?;
{
let custom_from_rs_string = |s: String| -> Result<libparsec::UserID, _> {
libparsec::UserID::from_hex(s.as_str()).map_err(|e| e.to_string())
};
match custom_from_rs_string(js_val.value(cx)) {
Ok(val) => val,
Err(err) => return cx.throw_type_error(err),
}
}
};
let human_handle = {
let js_val: Handle<JsObject> = obj.get(cx, "humanHandle")?;
struct_human_handle_js_to_rs(cx, js_val)?
};
Ok(libparsec::InviteListInvitationCreatedBy::User {
user_id,
human_handle,
})
}
_ => cx.throw_type_error("Object is not a InviteListInvitationCreatedBy"),
}
}

#[allow(dead_code)]
fn variant_invite_list_invitation_created_by_rs_to_js<'a>(
cx: &mut impl Context<'a>,
rs_obj: libparsec::InviteListInvitationCreatedBy,
) -> NeonResult<Handle<'a, JsObject>> {
let js_obj = cx.empty_object();
match rs_obj {
libparsec::InviteListInvitationCreatedBy::ExternalService { service_name, .. } => {
let js_tag = JsString::try_new(cx, "InviteListInvitationCreatedByExternalService")
.or_throw(cx)?;
js_obj.set(cx, "tag", js_tag)?;
let js_service_name = JsString::try_new(cx, service_name).or_throw(cx)?;
js_obj.set(cx, "serviceName", js_service_name)?;
}
libparsec::InviteListInvitationCreatedBy::User {
user_id,
human_handle,
..
} => {
let js_tag = JsString::try_new(cx, "InviteListInvitationCreatedByUser").or_throw(cx)?;
js_obj.set(cx, "tag", js_tag)?;
let js_user_id = JsString::try_new(cx, {
let custom_to_rs_string =
|x: libparsec::UserID| -> Result<String, &'static str> { Ok(x.hex()) };
match custom_to_rs_string(user_id) {
Ok(ok) => ok,
Err(err) => return cx.throw_type_error(err),
}
})
.or_throw(cx)?;
js_obj.set(cx, "userId", js_user_id)?;
let js_human_handle = struct_human_handle_rs_to_js(cx, human_handle)?;
js_obj.set(cx, "humanHandle", js_human_handle)?;
}
}
Ok(js_obj)
}

// InviteListItem

#[allow(dead_code)]
Expand Down Expand Up @@ -6718,6 +6798,10 @@ fn variant_invite_list_item_js_to_rs<'a>(
}
}
};
let created_by = {
let js_val: Handle<JsObject> = obj.get(cx, "createdBy")?;
variant_invite_list_invitation_created_by_js_to_rs(cx, js_val)?
};
let status = {
let js_val: Handle<JsString> = obj.get(cx, "status")?;
{
Expand All @@ -6729,6 +6813,7 @@ fn variant_invite_list_item_js_to_rs<'a>(
addr,
token,
created_on,
created_by,
status,
})
}
Expand Down Expand Up @@ -6773,6 +6858,10 @@ fn variant_invite_list_item_js_to_rs<'a>(
}
}
};
let created_by = {
let js_val: Handle<JsObject> = obj.get(cx, "createdBy")?;
variant_invite_list_invitation_created_by_js_to_rs(cx, js_val)?
};
let claimer_user_id = {
let js_val: Handle<JsString> = obj.get(cx, "claimerUserId")?;
{
Expand Down Expand Up @@ -6810,6 +6899,7 @@ fn variant_invite_list_item_js_to_rs<'a>(
addr,
token,
created_on,
created_by,
claimer_user_id,
shamir_recovery_created_on,
status,
Expand Down Expand Up @@ -6856,6 +6946,10 @@ fn variant_invite_list_item_js_to_rs<'a>(
}
}
};
let created_by = {
let js_val: Handle<JsObject> = obj.get(cx, "createdBy")?;
variant_invite_list_invitation_created_by_js_to_rs(cx, js_val)?
};
let claimer_email = {
let js_val: Handle<JsString> = obj.get(cx, "claimerEmail")?;
js_val.value(cx)
Expand All @@ -6871,6 +6965,7 @@ fn variant_invite_list_item_js_to_rs<'a>(
addr,
token,
created_on,
created_by,
claimer_email,
status,
})
Expand All @@ -6890,6 +6985,7 @@ fn variant_invite_list_item_rs_to_js<'a>(
addr,
token,
created_on,
created_by,
status,
..
} => {
Expand Down Expand Up @@ -6927,6 +7023,8 @@ fn variant_invite_list_item_rs_to_js<'a>(
}
});
js_obj.set(cx, "createdOn", js_created_on)?;
let js_created_by = variant_invite_list_invitation_created_by_rs_to_js(cx, created_by)?;
js_obj.set(cx, "createdBy", js_created_by)?;
let js_status =
JsString::try_new(cx, enum_invitation_status_rs_to_js(status)).or_throw(cx)?;
js_obj.set(cx, "status", js_status)?;
Expand All @@ -6935,6 +7033,7 @@ fn variant_invite_list_item_rs_to_js<'a>(
addr,
token,
created_on,
created_by,
claimer_user_id,
shamir_recovery_created_on,
status,
Expand Down Expand Up @@ -6974,6 +7073,8 @@ fn variant_invite_list_item_rs_to_js<'a>(
}
});
js_obj.set(cx, "createdOn", js_created_on)?;
let js_created_by = variant_invite_list_invitation_created_by_rs_to_js(cx, created_by)?;
js_obj.set(cx, "createdBy", js_created_by)?;
let js_claimer_user_id = JsString::try_new(cx, {
let custom_to_rs_string =
|x: libparsec::UserID| -> Result<String, &'static str> { Ok(x.hex()) };
Expand Down Expand Up @@ -7002,6 +7103,7 @@ fn variant_invite_list_item_rs_to_js<'a>(
addr,
token,
created_on,
created_by,
claimer_email,
status,
..
Expand Down Expand Up @@ -7040,6 +7142,8 @@ fn variant_invite_list_item_rs_to_js<'a>(
}
});
js_obj.set(cx, "createdOn", js_created_on)?;
let js_created_by = variant_invite_list_invitation_created_by_rs_to_js(cx, created_by)?;
js_obj.set(cx, "createdBy", js_created_by)?;
let js_claimer_email = JsString::try_new(cx, claimer_email).or_throw(cx)?;
js_obj.set(cx, "claimerEmail", js_claimer_email)?;
let js_status =
Expand Down
12 changes: 12 additions & 0 deletions bindings/generator/api/invite.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,24 +591,36 @@ async def client_cancel_invitation(
raise NotImplementedError


class InviteListInvitationCreatedBy(Variant):
class User:
user_id: UserID
human_handle: HumanHandle

class ExternalService:
service_name: str


class InviteListItem(Variant):
class User:
addr: ParsecInvitationAddr
token: InvitationToken
created_on: DateTime
created_by: InviteListInvitationCreatedBy
claimer_email: str
status: InvitationStatus

class Device:
addr: ParsecInvitationAddr
token: InvitationToken
created_on: DateTime
created_by: InviteListInvitationCreatedBy
status: InvitationStatus

class ShamirRecovery:
addr: ParsecInvitationAddr
token: InvitationToken
created_on: DateTime
created_by: InviteListInvitationCreatedBy
claimer_user_id: UserID
shamir_recovery_created_on: DateTime
status: InvitationStatus
Expand Down
Loading

0 comments on commit d1dd3b3

Please sign in to comment.