Skip to content

Commit

Permalink
Fix sync group join
Browse files Browse the repository at this point in the history
  • Loading branch information
fogodev committed Oct 2, 2024
1 parent bc093a2 commit b53bd44
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ rust-version = "1.80"

[workspace.dependencies]
# First party dependencies
sd-cloud-schema = { git = "https://github.com/spacedriveapp/cloud-services-schema", rev = "29d6381040" }
sd-cloud-schema = { git = "https://github.com/spacedriveapp/cloud-services-schema", rev = "eb06d128ef" }

# Third party dependencies used by one or more of our crates
async-channel = "2.3"
Expand Down
1 change: 1 addition & 0 deletions apps/mobile/src/screens/settings/info/Debug.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const DebugScreen = ({ navigation }: SettingsStackScreenProps<'Debug'>) => {
'cloud.syncGroups.get',
{
pub_id: '01924497-a1be-76e3-b62f-9582ea15463a',
// pub_id: '01924a25-966b-7c00-a582-9eed3aadd2cd',
kind: 'WithDevices'
}
]);
Expand Down
29 changes: 26 additions & 3 deletions core/src/api/cloud/sync_groups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ use sd_cloud_schema::{
cloud_p2p, devices, libraries,
sync::{groups, KeyHash},
};
use sd_crypto::{cloud::secret_key::SecretKey, CryptoRng, SeedableRng};

use std::sync::Arc;

use futures::FutureExt;
use futures_concurrency::future::TryJoin;
use rspc::alpha::AlphaRouter;
use sd_crypto::{cloud::secret_key::SecretKey, CryptoRng, SeedableRng};
use serde::Deserialize;
use serde::{Deserialize, Serialize};
use tokio::{spawn, sync::oneshot};
use tracing::{debug, error};

Expand Down Expand Up @@ -114,6 +114,29 @@ pub fn mount() -> AlphaRouter<Ctx> {
pub kind: groups::get::RequestKind,
}

// This is a compatibility layer because quic-rpc uses bincode for serialization
// and bincode doesn't support serde's tagged enums, and we need them for serializing
// to frontend
#[derive(Debug, Serialize, specta::Type)]
#[serde(tag = "kind", content = "data")]
pub enum CloudSyncGroupGetResponseKind {
WithDevices(groups::GroupWithDevices),
FullData(groups::Group),
}

impl From<groups::get::ResponseKind> for CloudSyncGroupGetResponseKind {
fn from(kind: groups::get::ResponseKind) -> Self {
match kind {
groups::get::ResponseKind::WithDevices(data) => {
CloudSyncGroupGetResponseKind::WithDevices(data)
}
groups::get::ResponseKind::FullData(data) => {
CloudSyncGroupGetResponseKind::FullData(data)
}
}
}
}

R.query(
|node, CloudGetSyncGroupArgs { pub_id, kind }: CloudGetSyncGroupArgs| async move {
use groups::get::{Request, Response};
Expand All @@ -135,7 +158,7 @@ pub fn mount() -> AlphaRouter<Ctx> {

debug!(?response_kind, "Got sync group");

Ok(response_kind)
Ok(CloudSyncGroupGetResponseKind::from(response_kind))
},
)
})
Expand Down
2 changes: 1 addition & 1 deletion core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ impl Node {
"RUST_LOG",
format!(
"info,\
iroh_net=debug,\
iroh_net=info,\
sd_core={level},\
sd_p2p={level},\
sd_core_heavy_lifting={level},\
Expand Down
32 changes: 17 additions & 15 deletions interface/app/$libraryId/settings/client/account/Profile.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { Envelope } from '@phosphor-icons/react';
import { Dispatch, SetStateAction, useEffect } from 'react';
import {
CloudSyncGroupWithLibraryAndDevices,
useBridgeMutation,
useBridgeQuery,
useLibraryMutation
} from '@sd/client';
import { useBridgeMutation, useBridgeQuery, useLibraryMutation } from '@sd/client';
import { Button, Card, tw } from '@sd/ui';
import StatCard from '~/app/$libraryId/overview/StatCard';
import { TruncatedText } from '~/components';
Expand Down Expand Up @@ -43,7 +38,8 @@ const Profile = ({
const getGroup = useBridgeQuery([
'cloud.syncGroups.get',
{
pub_id: '019237a1-586c-7651-afd3-525047b02375',
// pub_id: '019237a1-586c-7651-afd3-525047b02375',
pub_id: '01924a25-966b-7c00-a582-9eed3aadd2cd',
kind: 'WithDevices'
}
]);
Expand Down Expand Up @@ -141,14 +137,20 @@ const Profile = ({
<Button
className="mt-4 w-full"
onClick={async () => {
requestJoinSyncGroup.mutate({
sync_group: (
getGroup.data! as unknown as {
WithDevices: CloudSyncGroupWithLibraryAndDevices;
}
).WithDevices,
asking_device: currentDevice.data!
});
if (!currentDevice.data) currentDevice.refetch();

if (
currentDevice.data &&
getGroup.data &&
getGroup.data.kind === 'WithDevices'
) {
console.log('Current Device: ', currentDevice.data);
console.log('Get Group: ', getGroup.data.data);
requestJoinSyncGroup.mutate({
sync_group: getGroup.data.data,
asking_device: currentDevice.data
});
}
}}
>
Request Join Sync Group
Expand Down
1 change: 0 additions & 1 deletion scripts/utils/patchTauri.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ export async function patchTauri(root, nativeDeps, targets, args) {
const pubKey = await tauriUpdaterKey(nativeDeps)
if (pubKey != null) tauriPatch.plugins.updater.pubkey = pubKey
}
tauriPatch.build.features.push('devtools')
break
}
}
Expand Down

0 comments on commit b53bd44

Please sign in to comment.