Skip to content

Commit

Permalink
fix chat state caching problem (#5940)
Browse files Browse the repository at this point in the history
  • Loading branch information
julianjelfs authored Jun 14, 2024
1 parent 51be054 commit 0af5784
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 13 deletions.
4 changes: 3 additions & 1 deletion frontend/app/src/components/register/Register.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import UsernameInput from "../UsernameInput.svelte";
import { createEventDispatcher, getContext } from "svelte";
import { writable, type Writable } from "svelte/store";
import type { CreatedUser, OpenChat } from "openchat-client";
import { type CreatedUser, type OpenChat } from "openchat-client";
import Button from "../Button.svelte";
import Select from "../Select.svelte";
import ModalContent from "../ModalContent.svelte";
Expand Down Expand Up @@ -107,6 +107,8 @@
isBot: false,
};
dispatch("createdUser", createdUser);
} else {
error.set(`Unexpected register user response: ${resp}`);
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/openchat-agent/src/services/openchatAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1787,7 +1787,7 @@ export class OpenChatAgent extends EventTarget {

const updatedEvents = getUpdatedEvents(directChatUpdates, groupUpdates, communityUpdates);

if (!anyErrors) {
if (!anyErrors && this.userClient.userId !== ANON_USER_ID) {
setCachedChats(this.db, this.principal, state, updatedEvents);
}

Expand Down
5 changes: 5 additions & 0 deletions frontend/openchat-agent/src/services/user/anonUser.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,14 @@ import type {
TokenSwapStatusResponse,
ApproveTransferResponse,
} from "openchat-shared";
import { ANON_USER_ID } from "openchat-shared";
import { AnonymousOperationError } from "openchat-shared";

export class AnonUserClient {
public get userId(): string {
return ANON_USER_ID;
}

static create(): AnonUserClient {
console.debug("ANON: creating anonymous user client");
return new AnonUserClient();
Expand Down
2 changes: 1 addition & 1 deletion frontend/openchat-agent/src/utils/caching.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import type { CryptocurrencyContent } from "openchat-shared";
import type { PrizeContent } from "openchat-shared";
import type { P2PSwapContent } from "openchat-shared";

const CACHE_VERSION = 103;
const CACHE_VERSION = 104;
const MAX_INDEX = 9999999999;

export type Database = Promise<IDBPDatabase<ChatSchema>>;
Expand Down
4 changes: 2 additions & 2 deletions frontend/openchat-client/src/openchat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -646,8 +646,8 @@ export class OpenChat extends OpenChatAgentWorker {
this.loadUser();
}

logError(message?: unknown, ...optionalParams: unknown[]): void {
this._logger.error(message, ...optionalParams);
logError(message: unknown, error: unknown, ...optionalParams: unknown[]): void {
this._logger.error(message, error, ...optionalParams);
}

logMessage(message?: unknown, ...optionalParams: unknown[]): void {
Expand Down
8 changes: 5 additions & 3 deletions frontend/openchat-client/src/stores/markRead.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,11 @@ export class MessageReadTracker {

if (req.length > 0) {
console.log("Sending messages read to the server: ", JSON.stringify(req));
api.sendRequest({ kind: "markMessagesRead", payload: req }).finally(() =>
this.triggerLoop(api),
);
api.sendRequest({ kind: "markMessagesRead", payload: req })
.catch((err) => {
console.log("Error calling markMessagesRead", err);
})
.finally(() => this.triggerLoop(api));
} else {
this.triggerLoop(api);
}
Expand Down
10 changes: 5 additions & 5 deletions frontend/openchat-shared/src/utils/logging.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export type Logger = {
error(message?: unknown, ...optionalParams: unknown[]): void;
error(message: unknown, error: unknown, ...optionalParams: unknown[]): void;
log(message?: unknown, ...optionalParams: unknown[]): void;
debug(message?: unknown, ...optionalParams: unknown[]): void;
};

import Rollbar from "rollbar";
import Rollbar, { type LogArgument } from "rollbar";
import { offline } from "./network";

let rollbar: Rollbar | undefined;
Expand Down Expand Up @@ -32,10 +32,10 @@ export function inititaliseLogger(apikey: string, version: string, env: string):
});
}
return {
error(message?: unknown, ...optionalParams: unknown[]): void {
console.error(message as string, optionalParams);
error(message: unknown, error: unknown, ...optionalParams: unknown[]): void {
console.error(message as string, error, optionalParams);
if (!offline()) {
rollbar?.error(message as string, optionalParams);
rollbar?.error(error as LogArgument, message as LogArgument, optionalParams);
}
},
log(message?: unknown, ...optionalParams: unknown[]): void {
Expand Down

0 comments on commit 0af5784

Please sign in to comment.