mirror of
https://github.com/BlowaterNostr/blowater.git
synced 2024-10-18 15:43:20 +00:00
remove unused code (#228)
This commit is contained in:
parent
65186eee5f
commit
d6bbaed8e6
@ -21,10 +21,8 @@ import {
|
||||
import { PublicKey } from "./lib/nostr-ts/key.ts";
|
||||
import { NoteID } from "./lib/nostr-ts/nip19.ts";
|
||||
import { DirectMessageGetter } from "./UI/app_update.tsx";
|
||||
import { ProfileController, ProfileGetter } from "./UI/search.tsx";
|
||||
import { GroupChatController } from "./group-chat.ts";
|
||||
import { ProfileController } from "./UI/search.tsx";
|
||||
|
||||
export const NotFound = Symbol("Not Found");
|
||||
const buffer_size = 2000;
|
||||
export interface Indices {
|
||||
readonly id?: string;
|
||||
|
@ -1,13 +1,5 @@
|
||||
import * as csp from "https://raw.githubusercontent.com/BlowaterNostr/csp/master/csp.ts";
|
||||
import { Database_Contextual_View, NotFound, whoIamTalkingTo } from "../database.ts";
|
||||
import {
|
||||
DecryptionFailure,
|
||||
decryptNostrEvent,
|
||||
NostrAccountContext,
|
||||
NostrEvent,
|
||||
NostrKind,
|
||||
RelayResponse_Event,
|
||||
} from "../lib/nostr-ts/nostr.ts";
|
||||
import { NostrAccountContext, NostrEvent, NostrKind } from "../lib/nostr-ts/nostr.ts";
|
||||
import { ConnectionPool } from "../lib/nostr-ts/relay.ts";
|
||||
import { prepareNostrImageEvent, Tag } from "../nostr.ts";
|
||||
import { PublicKey } from "../lib/nostr-ts/key.ts";
|
||||
@ -144,14 +136,6 @@ async function* getAllEncryptedMessagesReceivedBy(
|
||||
}
|
||||
}
|
||||
|
||||
async function decryptMessage(
|
||||
relayResponse: RelayResponse_Event,
|
||||
ctx: NostrAccountContext,
|
||||
publicKey: string,
|
||||
): Promise<NostrEvent | DecryptionFailure> {
|
||||
return decryptNostrEvent(relayResponse.event, ctx, publicKey);
|
||||
}
|
||||
|
||||
function merge<T>(...iters: AsyncIterable<T>[]) {
|
||||
let merged = csp.chan<T>();
|
||||
async function coroutine<T>(
|
||||
@ -180,75 +164,3 @@ function merge<T>(...iters: AsyncIterable<T>[]) {
|
||||
}
|
||||
return merged;
|
||||
}
|
||||
|
||||
//////////////////
|
||||
// Read from DB //
|
||||
//////////////////
|
||||
|
||||
// get the messages send by and received by pubkey
|
||||
export function getDirectMessageEventsOf(db: Database_Contextual_View, pubkey: PublicKey) {
|
||||
return db.filterEvents(filterDMof(pubkey));
|
||||
}
|
||||
|
||||
export function getContactPubkeysOf(db: Database_Contextual_View, pubkey: PublicKey): Set<string> | Error {
|
||||
const msgs = getDirectMessageEventsOf(db, pubkey);
|
||||
const contactList = new Set<string>();
|
||||
for (const event of msgs) {
|
||||
const whoIAmTalkingTo = whoIamTalkingTo(event, pubkey);
|
||||
if (whoIAmTalkingTo instanceof Error) {
|
||||
return whoIAmTalkingTo;
|
||||
}
|
||||
contactList.add(whoIAmTalkingTo);
|
||||
}
|
||||
return contactList;
|
||||
}
|
||||
|
||||
export function getNewestEventOf(
|
||||
db: Database_Contextual_View,
|
||||
pubkey: PublicKey,
|
||||
): NostrEvent | typeof NotFound {
|
||||
const events = Array.from(getDirectMessageEventsOf(db, pubkey));
|
||||
if (events.length === 0) {
|
||||
return NotFound;
|
||||
}
|
||||
let newest = events[0];
|
||||
for (let event of events.slice(1)) {
|
||||
if (event.created_at > newest.created_at) {
|
||||
newest = event;
|
||||
}
|
||||
}
|
||||
return newest;
|
||||
}
|
||||
|
||||
export function get_Kind4_Events_Between(
|
||||
db: Database_Contextual_View,
|
||||
myPubKey: string,
|
||||
contactPubkey: string,
|
||||
) {
|
||||
const events = db.filterEvents(
|
||||
filterDMBetween(myPubKey, contactPubkey),
|
||||
);
|
||||
return events;
|
||||
}
|
||||
|
||||
function filterDMof(pubkey: PublicKey) {
|
||||
return (e: NostrEvent) => {
|
||||
const isAuthor = e.pubkey === pubkey.hex;
|
||||
const isReceiver = e.tags.filter((t) => t[0] === "p" && t[1] === pubkey.hex).length === 1;
|
||||
const isDM = e.kind === NostrKind.DIRECT_MESSAGE;
|
||||
return isDM && (isAuthor || isReceiver);
|
||||
};
|
||||
}
|
||||
|
||||
function filterDMBetween(myPubKey: string, contactPubKey: string) {
|
||||
return (e: NostrEvent) => {
|
||||
const isDM = e.kind === NostrKind.DIRECT_MESSAGE;
|
||||
const iAmAuthor = e.pubkey === myPubKey;
|
||||
const otherIsReceiver = e.tags.filter((t) => t[0] === "p" && t[1] === contactPubKey)
|
||||
.length > 0;
|
||||
const otherIsAuthor = e.pubkey === contactPubKey;
|
||||
const iAmReceiver = e.tags.filter((t) => t[0] === "p" && t[1] === myPubKey).length > 0;
|
||||
return isDM &&
|
||||
((iAmAuthor && otherIsReceiver) || (otherIsAuthor && iAmReceiver));
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user