Skip to content

Commit

Permalink
make sure we switch to default route if we remove the last fav (#6824)
Browse files Browse the repository at this point in the history
  • Loading branch information
julianjelfs authored Nov 14, 2024
1 parent 39449a9 commit 74ecd1f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions frontend/app/src/components/home/Home.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,7 @@
role: "owner",
},
messagesVisibleToNonMembers: false,
externalUrl: embeddedContent ? "" : undefined,
},
};
}
Expand Down
4 changes: 4 additions & 0 deletions frontend/openchat-client/src/liveState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import type {
DiamondMembershipStatus,
ChitState,
WalletConfig,
ObjectSet,
} from "openchat-shared";
import { selectedAuthProviderStore } from "./stores/authProviders";
import {
Expand Down Expand Up @@ -49,6 +50,7 @@ import {
currentChatMembers,
currentChatRules,
pinnedChatsStore,
favouritesStore,
} from "./stores/chat";
import { remainingStorage } from "./stores/storage";
import { userCreatedStore } from "./stores/userCreated";
Expand Down Expand Up @@ -119,6 +121,7 @@ export class LiveState {
chatListScope!: ChatListScope;
globalState!: GlobalState;
pinnedChats!: PinnedByScope;
favourites!: ObjectSet<ChatIdentifier>;
allChats!: ChatMap<ChatSummary>;
selectedCommunity!: CommunitySummary | undefined;
currentCommunityMembers!: Map<string, Member>;
Expand Down Expand Up @@ -183,6 +186,7 @@ export class LiveState {
chatListScopeStore.subscribe((scope) => (this.chatListScope = scope));
globalStateStore.subscribe((data) => (this.globalState = data));
pinnedChatsStore.subscribe((data) => (this.pinnedChats = data));
favouritesStore.subscribe((data) => (this.favourites = data));
allChats.subscribe((data) => (this.allChats = data));
selectedCommunity.subscribe((data) => (this.selectedCommunity = data));
currentCommunityMembers.subscribe((data) => (this.currentCommunityMembers = data));
Expand Down
8 changes: 7 additions & 1 deletion frontend/openchat-client/src/openchat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7271,6 +7271,10 @@ export class OpenChat extends OpenChatAgentWorker {

removeFromFavourites(chatId: ChatIdentifier): Promise<boolean> {
localChatSummaryUpdates.unfavourite(chatId);
if (this._liveState.chatSummariesList.length === 0) {
this.dispatchEvent(new SelectedChatInvalid());
}

return this.sendRequest({ kind: "removeFromFavourites", chatId })
.then((resp) => {
if (resp !== "success") {
Expand Down Expand Up @@ -7445,8 +7449,10 @@ export class OpenChat extends OpenChatAgentWorker {
// However, with communities enabled it is not clear what this means
// we actually need to direct the user to one of the global scopes "direct", "group" or "favourites"
// which one we choose is kind of unclear and probably depends on the state

const global = this._liveState.globalState;
if (global.favourites.size > 0) return { kind: "favourite" };
const favourites = this._liveState.favourites;
if (favourites.size > 0) return { kind: "favourite" };
if (global.groupChats.size > 0) return { kind: "group_chat" };
return { kind: "direct_chat" };
}
Expand Down

0 comments on commit 74ecd1f

Please sign in to comment.