Skip to content

Commit

Permalink
disable eose notification; improve event handling
Browse files Browse the repository at this point in the history
  • Loading branch information
franzos committed Aug 23, 2023
1 parent 2f1cb32 commit 1c0c3d0
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 20 deletions.
2 changes: 2 additions & 0 deletions client-web/src/components/bottom-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ export function BottomBar() {
} else if (event.data[0] === RELAY_MESSAGE_TYPE.OK) {
description = `${event.data[2]}. Event ${event.data[1]}: ${event.data[3]}`;
} else if (event.data[0] === RELAY_MESSAGE_TYPE.EOSE) {
// Ignore for now
return;
description = `Loaded all requested events for subscription ${event.data[1]}`;
} else if (event.data[0] === RELAY_MESSAGE_TYPE.COUNT) {
description = `Relay ${event.data[1]}: ${JSON.stringify(
Expand Down
2 changes: 1 addition & 1 deletion client-web/src/components/events.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function Events(props: {
key={event.event.id}
userComponent={
props && props.userComponent ? (
event.user ? (
event.user && event.user.pubkey ? (
<props.userComponent
user={event.user}
relayId={event.eventRelayIds[0]}
Expand Down
2 changes: 1 addition & 1 deletion client-web/src/routes/following.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function FollowingRoute() {
{followingUsers.length > 0 ? (
<>
{followingUsers.map((item) => (
<Box mb="3">
<Box mb="3" key={item.user.pubkey}>
<User
user={item.user}
key={item.user.pubkey}
Expand Down
5 changes: 3 additions & 2 deletions client-web/src/state/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ export const useNClient = create<NClient>((set, get) => ({
// Check if POW is needed and which relays are available
const { relays, pow } = await get().determineApplicableRelays(payload);
if (relays.length === 0) {
throw new Error("No relays available");
throw new Error("No (write-enabled) relays available. Check relays.");
}

let requestedPOW = payload.pow;
Expand Down Expand Up @@ -553,7 +553,8 @@ export const useNClient = create<NClient>((set, get) => ({
}[] = [];

for (const ev of get().events) {
if (ev.event?.pubkey) {
// TODO: Check if user is stale
if (ev.event?.pubkey && !ev.user?.pubkey) {
eventUserPubkeys.push({
pubkey: ev.event.pubkey,
relayIds: ev.eventRelayIds,
Expand Down
36 changes: 20 additions & 16 deletions client-web/src/state/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,10 +384,10 @@ class WorkerClass implements NClientWorker {
for (const event of this.eventsMap.values()) {
if (event.user?.pubkey === newUser.pubkey) {
event.user = newUser;
postMessage({
type: "event:update",
data: event,
});
console.log(
`User ${event.user.pubkey} metadata updated for event ${event.event.id}`
);
this.updateEvent(event);
}
}
});
Expand All @@ -402,18 +402,20 @@ class WorkerClass implements NClientWorker {
return;
}

for (const event of this.eventsMap.values()) {
if (inResponse.find((tag) => tag.eventId === event.event.id)) {
if (event.reactions) {
const eventIds = inResponse
.filter((tag) => tag.eventId)
.map((tag) => tag.eventId);

for (const id of eventIds) {
const event = this.eventsMap.get(id);
if (event) {
if (event.reactions && event.reactions.length) {
event.reactions.push(ev);
} else {
event.reactions = [ev];
}

console.log(`Reaction event added to event ${event.event.id}`);
this.updateEvent(event);
// it's safe to assume that there's only one matching event
return;
}
}
});
Expand All @@ -428,18 +430,20 @@ class WorkerClass implements NClientWorker {
return;
}

for (const event of this.eventsMap.values()) {
if (inResponse.find((tag) => tag.eventId === event.event.id)) {
const eventIds = inResponse
.filter((tag) => tag.eventId)
.map((tag) => tag.eventId);

for (const id of eventIds) {
const event = this.eventsMap.get(id);
if (event) {
if (event.reposts) {
event.reposts.push(ev);
} else {
event.reposts = [ev];
}

console.log(`Repost event found for ${event.event.id}`);
console.log(`Repost event added to event ${event.event.id}`);
this.updateEvent(event);
// it's safe to assume that there's only one matching event
return;
}
}
});
Expand Down

0 comments on commit 1c0c3d0

Please sign in to comment.