Skip to content

Commit 6917d6a

Browse files
committed
Simplify feed logic to be their own rpc functions. Remove js side grpc calls and have everything go through wasm
1 parent 15f0416 commit 6917d6a

19 files changed

Lines changed: 1305 additions & 419 deletions

File tree

apps/polycentric/src/common/lib/polycentric-hooks/PolycentricProvider.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@ import useFollows from '@/src/features/follow/hooks/useFollows';
33
import {
44
PolycentricClient,
55
createPolycentricClient,
6-
setGrpcWebFetch,
76
types,
87
type IdentityState,
98
} from '@polycentric/react-native';
10-
import { fetch as expoFetch } from 'expo/fetch';
119
import {
1210
createContext,
1311
useCallback,
@@ -147,7 +145,6 @@ export function PolycentricProvider({
147145

148146
(async () => {
149147
try {
150-
setGrpcWebFetch(expoFetch);
151148
// PolycentricClient.initialize() guarantees a keypair exists on
152149
// every device. Identity (the published Identity doc) is a separate
153150
// concept — the onboarding gate handles creating or pairing one.

apps/polycentric/src/features/feed/hooks/useExploreFeed.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,16 @@ export function useExploreFeed(options?: {
2121
setIsLoading(true);
2222
setError(null);
2323
try {
24-
const bundles = await client.listEvents();
24+
const responses = await client.getExploreFeed({
25+
identity: client.activeIdentityKey,
26+
limit: options?.perServerLimit ?? null,
27+
});
2528
const posts: PostData[] = [];
26-
for (const bundle of bundles) {
27-
const decoded = decodeV2PostBundle(bundle);
28-
if (decoded) posts.push(decoded);
29+
for (const response of responses) {
30+
for (const bundle of response.eventBundles) {
31+
const decoded = decodeV2PostBundle(bundle);
32+
if (decoded) posts.push(decoded);
33+
}
2934
}
3035
setItems(posts);
3136
} catch (e) {
@@ -34,7 +39,7 @@ export function useExploreFeed(options?: {
3439
} finally {
3540
setIsLoading(false);
3641
}
37-
}, [client]);
42+
}, [client, options?.perServerLimit]);
3843

3944
useEffect(() => {
4045
if (enabled) fetchFeed();

apps/polycentric/src/features/feed/hooks/useFollowingFeed.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { useCallback, useEffect, useState } from 'react';
2-
import { v2 } from '@polycentric/react-native';
32
import {
43
decodeV2PostBundle,
54
useLocalPostInjection,
@@ -28,14 +27,15 @@ export function useFollowingFeed(options?: {
2827
setIsLoading(true);
2928
setError(null);
3029
try {
31-
const bundles = await client.getFeed({
32-
algorithm: v2.FeedAlgorithm.FOLLOWING,
30+
const responses = await client.getFollowingFeed({
3331
limit: options?.limit ?? null,
3432
});
3533
const posts: PostData[] = [];
36-
for (const bundle of bundles) {
37-
const decoded = decodeV2PostBundle(bundle);
38-
if (decoded) posts.push(decoded);
34+
for (const response of responses) {
35+
for (const bundle of response.eventBundles) {
36+
const decoded = decodeV2PostBundle(bundle);
37+
if (decoded) posts.push(decoded);
38+
}
3939
}
4040
setItems(posts);
4141
} catch (e) {

packages/js-core/src/client-internal/pairing-session-manager.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
import {
2-
createPairingSession,
3-
getPairingSession,
4-
joinPairingSession,
5-
} from '../grpc/transport';
61
import type { PolycentricClient } from '../polycentric-client';
72
import * as Proto from '../proto/v2';
83
import { bytesToHex } from '../utils/hex';
@@ -69,8 +64,13 @@ export class PairingSessionManager {
6964
);
7065
const signedMessage = await this.signMessage(pairingSessionBytes);
7166

72-
// send the gRPC request
73-
const session = await createPairingSession(server, signedMessage);
67+
const sessionBytes = await this.client.core.createPairingSession(
68+
server,
69+
Proto.SignedMessage.toBinary(signedMessage).buffer as ArrayBuffer,
70+
);
71+
const session = Proto.PairingSession.fromBinary(
72+
new Uint8Array(sessionBytes),
73+
);
7474
const initialSession = session.initialSession!;
7575

7676
return {
@@ -91,10 +91,13 @@ export class PairingSessionManager {
9191
const targetServer = server ?? this.client.servers[0];
9292
if (!targetServer) throw new Error('No servers configured');
9393

94-
const session = await getPairingSession(
94+
const sessionBytes = await this.client.core.getPairingSession(
9595
targetServer,
9696
pairingSessionSignature,
9797
);
98+
const session = Proto.PairingSession.fromBinary(
99+
new Uint8Array(sessionBytes),
100+
);
98101
const initialSession = session.initialSession!;
99102
return {
100103
session,
@@ -120,7 +123,13 @@ export class PairingSessionManager {
120123
);
121124
const signedMessage = await this.signMessage(bodyBytes);
122125

123-
const session = await joinPairingSession(server, signedMessage);
126+
const sessionBytes = await this.client.core.joinPairingSession(
127+
server,
128+
Proto.SignedMessage.toBinary(signedMessage).buffer as ArrayBuffer,
129+
);
130+
const session = Proto.PairingSession.fromBinary(
131+
new Uint8Array(sessionBytes),
132+
);
124133
const initialSession = session.initialSession!;
125134
return {
126135
session,

packages/js-core/src/grpc/index.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

packages/js-core/src/grpc/transport.ts

Lines changed: 0 additions & 159 deletions
This file was deleted.

packages/js-core/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ export type {
4141
export * from './errors';
4242
export * as Errors from './errors';
4343
export * from './utils';
44-
export * from './grpc';
4544

4645
export { KEY_TYPE, COLLECTION, HydrationStrategy } from './constants';
4746

0 commit comments

Comments
 (0)