small cleanup

This commit is contained in:
hzrd149 2023-06-09 09:09:48 -04:00
parent 3939f6636c
commit 56988de14c
5 changed files with 9 additions and 13 deletions

View File

@ -82,7 +82,6 @@ export function getReferences(event: NostrEvent | DraftNostrEvent) {
const pTags = event.tags.filter(isPTag);
const events = eTags.map((t) => t[1]);
const pubkeys = pTags.map((t) => t[1]);
const contentTagRefs = getContentTagRefs(event.content, event.tags);
let replyId = eTags.find((t) => t[3] === "reply")?.[1];
@ -116,7 +115,6 @@ export function getReferences(event: NostrEvent | DraftNostrEvent) {
}
return {
pubkeys,
events,
rootId,
replyId,

View File

@ -1,6 +1,6 @@
import moment, { MomentInput } from "moment";
import { NostrMultiSubscription } from "../classes/nostr-multi-subscription";
import { NostrEvent } from "../types/nostr-event";
import { NostrEvent, isPTag } from "../types/nostr-event";
import clientRelaysService from "./client-relays";
import { utils } from "nostr-tools";
import { SuperMap } from "../classes/super-map";
@ -9,10 +9,9 @@ import accountService from "./account";
import { NostrQuery } from "../types/nostr-query";
import { convertTimestampToDate } from "../helpers/date";
import { Kind } from "nostr-tools";
import { getReferences } from "../helpers/nostr-event";
export function getMessageRecipient(event: NostrEvent): string | undefined {
return getReferences(event).pubkeys[0];
return event.tags.filter(isPTag)[0][1];
}
class DirectMessagesService {

View File

@ -1,9 +1,8 @@
import { NostrEvent } from "../types/nostr-event";
import { NostrEvent, isPTag } from "../types/nostr-event";
import { NostrQuery } from "../types/nostr-query";
import { PubkeySubjectCache } from "../classes/pubkey-subject-cache";
import { NostrMultiSubscription } from "../classes/nostr-multi-subscription";
import db from "./db";
import { getReferences } from "../helpers/nostr-event";
import userContactsService from "./user-contacts";
import { Subject } from "../classes/subject";
import { Kind } from "nostr-tools";
@ -63,9 +62,9 @@ function receiveEvent(event: NostrEvent) {
if (event.kind !== Kind.Contacts) return;
const follower = event.pubkey;
const refs = getReferences(event);
if (refs.pubkeys.length > 0) {
for (const pubkey of refs.pubkeys) {
const pTags = event.tags.filter(isPTag);
if (pTags.length > 0) {
for (const [_, pubkey] of pTags) {
if (subjects.hasSubject(pubkey)) {
const subject = subjects.getSubject(pubkey);
mergeNext(subject, [follower]);
@ -75,7 +74,7 @@ function receiveEvent(event: NostrEvent) {
}
}
db.put("userFollows", { pubkey: event.pubkey, follows: refs.pubkeys });
db.put("userFollows", { pubkey: event.pubkey, follows: pTags.map((p) => p[1]) });
}
subscription.onEvent.subscribe((event) => {

View File

@ -1,5 +1,5 @@
export type ETag = ["e", string] | ["e", string, string] | ["e", string, string, string];
export type PTag = ["p", string] | ["p", string, string];
export type PTag = ["p", string] | ["p", string, string] | ["p", string, string, string];
export type RTag = ["r", string] | ["r", string, string];
export type DTag = ["d"] | ["d", string];
export type Tag = string[] | ETag | PTag | RTag | DTag;

View File

@ -24,7 +24,7 @@ import RequireCurrentAccount from "../../providers/require-current-account";
function MessageContent({ event, text }: { event: NostrEvent; text: string }) {
let content: EmbedableContent = [text];
content = embedNostrLinks(content, event);
content = embedNostrLinks(content);
content = embedUrls(content, [renderImageUrl, renderVideoUrl, renderGenericUrl]);