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

[POC] User invitation from any admin #9445

Closed
wants to merge 3 commits into from
Closed
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
14 changes: 11 additions & 3 deletions bindings/electron/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,15 @@ export interface UserClaimInProgress3Info {
}


export interface UserClaimInitialInfo {
handle: number
greeterUserId: string
greeterHumanHandle: HumanHandle
onlineStatus: UserOnlineStatus
lastGreetingAttemptJoinedOn: number | null
}


export interface UserGreetInProgress1Info {
handle: number
greeterSas: string
Expand Down Expand Up @@ -415,10 +424,9 @@ export interface AnyClaimRetrievedInfoShamirRecovery {
}
export interface AnyClaimRetrievedInfoUser {
tag: "User"
handle: number
claimer_email: string
greeter_user_id: string
greeter_human_handle: HumanHandle
created_by: InviteInfoInvitationCreatedBy
user_claim_initial_infos: Array<UserClaimInitialInfo>
}
export type AnyClaimRetrievedInfo =
| AnyClaimRetrievedInfoDevice
Expand Down
185 changes: 143 additions & 42 deletions bindings/electron/src/meths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2715,6 +2715,122 @@ fn struct_user_claim_in_progress3_info_rs_to_js<'a>(
Ok(js_obj)
}

// UserClaimInitialInfo

#[allow(dead_code)]
fn struct_user_claim_initial_info_js_to_rs<'a>(
cx: &mut impl Context<'a>,
obj: Handle<'a, JsObject>,
) -> NeonResult<libparsec::UserClaimInitialInfo> {
let handle = {
let js_val: Handle<JsNumber> = obj.get(cx, "handle")?;
{
let v = js_val.value(cx);
if v < (u32::MIN as f64) || (u32::MAX as f64) < v {
cx.throw_type_error("Not an u32 number")?
}
let v = v as u32;
v
}
};
let greeter_user_id = {
let js_val: Handle<JsString> = obj.get(cx, "greeterUserId")?;
{
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 greeter_human_handle = {
let js_val: Handle<JsObject> = obj.get(cx, "greeterHumanHandle")?;
struct_human_handle_js_to_rs(cx, js_val)?
};
let online_status = {
let js_val: Handle<JsString> = obj.get(cx, "onlineStatus")?;
{
let js_string = js_val.value(cx);
enum_user_online_status_js_to_rs(cx, js_string.as_str())?
}
};
let last_greeting_attempt_joined_on = {
let js_val: Handle<JsValue> = obj.get(cx, "lastGreetingAttemptJoinedOn")?;
{
if js_val.is_a::<JsNull, _>(cx) {
None
} else {
let js_val = js_val.downcast_or_throw::<JsNumber, _>(cx)?;
Some({
let v = js_val.value(cx);
let custom_from_rs_f64 = |n: f64| -> Result<_, &'static str> {
libparsec::DateTime::from_timestamp_micros((n * 1_000_000f64) as i64)
.map_err(|_| "Out-of-bound datetime")
};
match custom_from_rs_f64(v) {
Ok(val) => val,
Err(err) => return cx.throw_type_error(err),
}
})
}
}
};
Ok(libparsec::UserClaimInitialInfo {
handle,
greeter_user_id,
greeter_human_handle,
online_status,
last_greeting_attempt_joined_on,
})
}

#[allow(dead_code)]
fn struct_user_claim_initial_info_rs_to_js<'a>(
cx: &mut impl Context<'a>,
rs_obj: libparsec::UserClaimInitialInfo,
) -> NeonResult<Handle<'a, JsObject>> {
let js_obj = cx.empty_object();
let js_handle = JsNumber::new(cx, rs_obj.handle as f64);
js_obj.set(cx, "handle", js_handle)?;
let js_greeter_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(rs_obj.greeter_user_id) {
Ok(ok) => ok,
Err(err) => return cx.throw_type_error(err),
}
})
.or_throw(cx)?;
js_obj.set(cx, "greeterUserId", js_greeter_user_id)?;
let js_greeter_human_handle = struct_human_handle_rs_to_js(cx, rs_obj.greeter_human_handle)?;
js_obj.set(cx, "greeterHumanHandle", js_greeter_human_handle)?;
let js_online_status =
JsString::try_new(cx, enum_user_online_status_rs_to_js(rs_obj.online_status))
.or_throw(cx)?;
js_obj.set(cx, "onlineStatus", js_online_status)?;
let js_last_greeting_attempt_joined_on = match rs_obj.last_greeting_attempt_joined_on {
Some(elem) => JsNumber::new(cx, {
let custom_to_rs_f64 = |dt: libparsec::DateTime| -> Result<f64, &'static str> {
Ok((dt.as_timestamp_micros() as f64) / 1_000_000f64)
};
match custom_to_rs_f64(elem) {
Ok(ok) => ok,
Err(err) => return cx.throw_type_error(err),
}
})
.as_value(cx),
None => JsNull::new(cx).as_value(cx),
};
js_obj.set(
cx,
"lastGreetingAttemptJoinedOn",
js_last_greeting_attempt_joined_on,
)?;
Ok(js_obj)
}

// UserGreetInProgress1Info

#[allow(dead_code)]
Expand Down Expand Up @@ -3615,42 +3731,30 @@ fn variant_any_claim_retrieved_info_js_to_rs<'a>(
})
}
"AnyClaimRetrievedInfoUser" => {
let handle = {
let js_val: Handle<JsNumber> = obj.get(cx, "handle")?;
{
let v = js_val.value(cx);
if v < (u32::MIN as f64) || (u32::MAX as f64) < v {
cx.throw_type_error("Not an u32 number")?
}
let v = v as u32;
v
}
};
let claimer_email = {
let js_val: Handle<JsString> = obj.get(cx, "claimerEmail")?;
js_val.value(cx)
};
let greeter_user_id = {
let js_val: Handle<JsString> = obj.get(cx, "greeterUserId")?;
let created_by = {
let js_val: Handle<JsObject> = obj.get(cx, "createdBy")?;
variant_invite_info_invitation_created_by_js_to_rs(cx, js_val)?
};
let user_claim_initial_infos = {
let js_val: Handle<JsArray> = obj.get(cx, "userClaimInitialInfos")?;
{
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 size = js_val.len(cx);
let mut v = Vec::with_capacity(size as usize);
for i in 0..size {
let js_item: Handle<JsObject> = js_val.get(cx, i)?;
v.push(struct_user_claim_initial_info_js_to_rs(cx, js_item)?);
}
v
}
};
let greeter_human_handle = {
let js_val: Handle<JsObject> = obj.get(cx, "greeterHumanHandle")?;
struct_human_handle_js_to_rs(cx, js_val)?
};
Ok(libparsec::AnyClaimRetrievedInfo::User {
handle,
claimer_email,
greeter_user_id,
greeter_human_handle,
created_by,
user_claim_initial_infos,
})
}
_ => cx.throw_type_error("Object is not a AnyClaimRetrievedInfo"),
Expand Down Expand Up @@ -3751,30 +3855,27 @@ fn variant_any_claim_retrieved_info_rs_to_js<'a>(
js_obj.set(cx, "isRecoverable", js_is_recoverable)?;
}
libparsec::AnyClaimRetrievedInfo::User {
handle,
claimer_email,
greeter_user_id,
greeter_human_handle,
created_by,
user_claim_initial_infos,
..
} => {
let js_tag = JsString::try_new(cx, "AnyClaimRetrievedInfoUser").or_throw(cx)?;
js_obj.set(cx, "tag", js_tag)?;
let js_handle = JsNumber::new(cx, handle as f64);
js_obj.set(cx, "handle", js_handle)?;
let js_claimer_email = JsString::try_new(cx, claimer_email).or_throw(cx)?;
js_obj.set(cx, "claimerEmail", js_claimer_email)?;
let js_greeter_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(greeter_user_id) {
Ok(ok) => ok,
Err(err) => return cx.throw_type_error(err),
let js_created_by = variant_invite_info_invitation_created_by_rs_to_js(cx, created_by)?;
js_obj.set(cx, "createdBy", js_created_by)?;
let js_user_claim_initial_infos = {
// JsArray::new allocates with `undefined` value, that's why we `set` value
let js_array = JsArray::new(cx, user_claim_initial_infos.len());
for (i, elem) in user_claim_initial_infos.into_iter().enumerate() {
let js_elem = struct_user_claim_initial_info_rs_to_js(cx, elem)?;
js_array.set(cx, i as u32, js_elem)?;
}
})
.or_throw(cx)?;
js_obj.set(cx, "greeterUserId", js_greeter_user_id)?;
let js_greeter_human_handle = struct_human_handle_rs_to_js(cx, greeter_human_handle)?;
js_obj.set(cx, "greeterHumanHandle", js_greeter_human_handle)?;
js_array
};
js_obj.set(cx, "userClaimInitialInfos", js_user_claim_initial_infos)?;
}
}
Ok(js_obj)
Expand Down
13 changes: 10 additions & 3 deletions bindings/generator/api/invite.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,19 @@ class ExternalService:
service_label: str


class UserClaimInitialInfo(Structure):
handle: Handle
greeter_user_id: UserID
greeter_human_handle: HumanHandle
online_status: UserOnlineStatus
last_greeting_attempt_joined_on: Optional[DateTime]


class AnyClaimRetrievedInfo(Variant):
class User:
handle: Handle
claimer_email: str
greeter_user_id: UserID
greeter_human_handle: HumanHandle
created_by: InviteInfoInvitationCreatedBy
user_claim_initial_infos: list[UserClaimInitialInfo]

class Device:
handle: Handle
Expand Down
Loading
Loading