Skip to content

Commit

Permalink
+
Browse files Browse the repository at this point in the history
  • Loading branch information
BlowaterNostr committed Feb 23, 2024
1 parent 2b763a7 commit bc22d90
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 23 deletions.
43 changes: 26 additions & 17 deletions app/UI/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Channel } from "https://raw.githubusercontent.com/BlowaterNostr/csp/mas
import { PublicKey } from "../../libs/nostr.ts/key.ts";
import { NostrAccountContext, NostrEvent, NostrKind } from "../../libs/nostr.ts/nostr.ts";
import { ConnectionPool } from "../../libs/nostr.ts/relay-pool.ts";
import { Datebase_View } from "../database.ts";
import { Datebase_View, RelayRecordGetter } from "../database.ts";
import { EventBus } from "../event-bus.ts";
import { DirectedMessageController, getAllEncryptedMessagesOf, InvalidEvent } from "../features/dm.ts";
import { group_GM_events, GroupChatSyncer, GroupMessageController } from "../features/gm.ts";
Expand Down Expand Up @@ -469,21 +469,6 @@ export class AppComponent extends Component<AppProps, AppState> {
) {
if (model.navigationModel.activeNav == "DM" && this.state.selectedRelay) {
const messageGetter = app.dmController;
function f(messageGetter: ChatMessagesGetter, relay: SingleRelayConnection) {
return {
getChatMessages: (publicKey: string) => {
const msgs = messageGetter.getChatMessages(publicKey);
const ret = [];
for (const msg of msgs) {
const relays = app.database.getRelayRecord(msg.event.id);
if (relays.has(relay.url)) {
ret.push(msg);
}
}
return ret;
},
};
}
dmVNode = (
<DirectMessageContainer
{...model.dm}
Expand All @@ -496,7 +481,11 @@ export class AppComponent extends Component<AppProps, AppState> {
pinListGetter={app.otherConfig}
groupChatController={app.groupChatController}
newMessageChecker={app.conversationLists}
messageGetter={f(messageGetter, this.state.selectedRelay)}
messageGetter={PerRelayMessageGetter(
this.state.selectedRelay.url,
messageGetter,
app.database,
)}
newMessageListener={app.dmController}
relayRecordGetter={app.database}
userBlocker={app.conversationLists}
Expand Down Expand Up @@ -580,3 +569,23 @@ export function getFocusedContent(
};
}
}

function PerRelayMessageGetter(
relay: string,
messageGetter: ChatMessagesGetter,
recordGetter: RelayRecordGetter,
): ChatMessagesGetter {
return {
getChatMessages: (publicKey: string) => {
const msgs = messageGetter.getChatMessages(publicKey);
const ret = [];
for (const msg of msgs) {
const relays = recordGetter.getRelayRecord(msg.event.id);
if (relays.has(relay)) {
ret.push(msg);
}
}
return ret;
},
};
}
7 changes: 1 addition & 6 deletions app/UI/conversation-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ export class ConversationList extends Component<Props, State> {
let listToRender: ConversationSummary[];
const contacts = Array.from(props.convoListRetriever.getContacts());
const strangers = Array.from(props.convoListRetriever.getStrangers());
// const groups = Array.from(props.groupChatListGetter.getConversationList());
const blocked = props.userBlocker.getBlockedUsers();
let isGroupChat = false;
switch (this.state.selectedContactGroup) {
Expand All @@ -101,10 +100,6 @@ export class ConversationList extends Component<Props, State> {
case "strangers":
listToRender = strangers;
break;
// case "Group":
// listToRender = groups;
// isGroupChat = true;
// break;
case "blocked":
listToRender = Array.from(props.convoListRetriever.getConversations(blocked));
}
Expand Down Expand Up @@ -387,7 +382,7 @@ function ConversationListItem(props: ListItemProps) {
}

const selectConversation = (emit: emitFunc<SelectConversation>, pubkey: PublicKey) => () => {
emit({
return emit({
type: "SelectConversation",
pubkey,
});
Expand Down

0 comments on commit bc22d90

Please sign in to comment.