feat: client tags

This commit is contained in:
2025-04-30 11:14:02 +01:00
parent f028de7c04
commit e6ca368134
10 changed files with 61 additions and 33 deletions

View File

@ -1,16 +1,3 @@
.note > .header .reply {
font-size: 13px;
color: var(--font-secondary-color);
}
.note > .header .reply a {
color: var(--highlight);
}
.note > .header .reply a:hover {
text-decoration-color: var(--highlight);
}
.note .header .info {
font-size: var(--font-size);
margin-left: 4px;
@ -57,8 +44,7 @@
margin-top: 16px;
}
.note > .header img:hover,
.note > .header .name > .reply:hover {
.note > .header img:hover {
cursor: pointer;
}

View File

@ -0,0 +1,21 @@
import { NostrLink, TaggedNostrEvent } from "@snort/system";
import { FormattedMessage } from "react-intl";
import { Link } from "react-router-dom";
export function ClientTag({ ev }: { ev: TaggedNostrEvent }) {
const tag = ev.tags.find(a => a[0] === "client");
if (!tag) return;
const link = tag[2] ? NostrLink.fromTag(["a", tag[2]]) : undefined;
return (
<span className="text-xs text-gray-light">
{" "}
<FormattedMessage
defaultMessage="via {client}"
description="via {client name} tag"
values={{
client: link ? <Link to={`/${link.encode()}`}>{tag[1]}</Link> : tag[1],
}}
/>
</span>
);
}

View File

@ -9,11 +9,13 @@ import DisplayName from "@/Components/User/DisplayName";
import { ProfileLink } from "@/Components/User/ProfileLink";
import { hexToBech32 } from "@/Utils";
import { ClientTag } from "./ClientTag";
export default function ReplyTag({ ev }: { ev: TaggedNostrEvent }) {
const { formatMessage } = useIntl();
const thread = EventExt.extractThread(ev);
if (thread === undefined) {
return undefined;
return <ClientTag ev={ev} />;
}
const maxMentions = 2;
@ -33,7 +35,7 @@ export default function ReplyTag({ ev }: { ev: TaggedNostrEvent }) {
name: u?.name ?? shortNpub,
link: (
<ProfileLink pubkey={pk} user={u}>
<DisplayName pubkey={pk} user={u} />{" "}
<DisplayName pubkey={pk} user={u} className="text-highlight" />
</ProfileLink>
),
});
@ -53,7 +55,7 @@ export default function ReplyTag({ ev }: { ev: TaggedNostrEvent }) {
const others = mentions.length > maxMentions ? formatMessage(messages.Others, { n: othersLength }) : "";
const link = replyLink?.encode(CONFIG.eventLinkPrefix);
return (
<div className="reply">
<small className="text-xs">
re:&nbsp;
{(mentions?.length ?? 0) > 0 ? (
<>
@ -62,6 +64,7 @@ export default function ReplyTag({ ev }: { ev: TaggedNostrEvent }) {
) : (
replyLink && <Link to={`/${link}`}>{link?.substring(0, 12)}</Link>
)}
</div>
<ClientTag ev={ev} />
</small>
);
}

View File

@ -179,6 +179,10 @@ a.ext {
-webkit-text-stroke: 1px black;
}
.text-highlight {
color: var(--highlight);
}
.br {
border-radius: 16px;
}

View File

@ -773,6 +773,10 @@
"GspYR7": {
"defaultMessage": "{n} Dislike"
},
"GtIxzZ": {
"defaultMessage": "via {client}",
"description": "via {client name} tag"
},
"Gxcr08": {
"defaultMessage": "Broadcast Event"
},

View File

@ -256,6 +256,7 @@
"GpkNYn": "Torrent",
"GqQeu/": "Invalid Lightning Address",
"GspYR7": "{n} Dislike",
"GtIxzZ": "via {client}",
"Gxcr08": "Broadcast Event",
"H+vHiz": "Hex Key..",
"H/oroO": "Dealing with Unknown Events",

View File

@ -226,7 +226,7 @@ export function normalizeReaction(content: string) {
}
}
export class OfflineError extends Error { }
export class OfflineError extends Error {}
export function throwIfOffline() {
if (isOffline()) {
@ -243,8 +243,8 @@ export function isHex(s?: string) {
// 48-57 = 0-9
// 65-90 = A-Z
// 97-122 = a-z
return s.length % 2 == 0 &&
[...s]
.map(v => v.charCodeAt(0))
.every(v => (v >= 48 && v <= 57) || (v >= 65 && v <= 90) || v >= 97 || v <= 122);
return (
s.length % 2 == 0 &&
[...s].map(v => v.charCodeAt(0)).every(v => (v >= 48 && v <= 57) || (v >= 65 && v <= 90) || v >= 97 || v <= 122)
);
}

View File

@ -150,7 +150,11 @@ export class NostrLink implements ToNostrEventTag {
const ifSetCheck = <T>(a: T | undefined, b: T) => {
return !Boolean(a) || a === b;
};
return (EventExt.isReplaceable(ev.kind) || ifSetCheck(this.id, ev.id)) && ifSetCheck(this.author, ev.pubkey) && ifSetCheck(this.kind, ev.kind);
return (
(EventExt.isReplaceable(ev.kind) || ifSetCheck(this.id, ev.id)) &&
ifSetCheck(this.author, ev.pubkey) &&
ifSetCheck(this.kind, ev.kind)
);
}
return false;

View File

@ -74,13 +74,19 @@ export class UserState<TAppData> extends EventEmitter<UserStateEvents> {
this.#stateObj = stateObj;
this.#standardLists = pubkey ? new Map() : undefined;
this.#profile = pubkey ? new JsonEventSync<UserMetadata | undefined>(
undefined,
new NostrLink(NostrPrefix.Event, pubkey, EventKind.SetMetadata, pubkey),
false,
) : undefined;
this.#contacts = pubkey ? new DiffSyncTags(new NostrLink(NostrPrefix.Event, pubkey, EventKind.ContactList, pubkey), false) : undefined;
this.#relays = pubkey ? new DiffSyncTags(new NostrLink(NostrPrefix.Event, pubkey, EventKind.Relays, pubkey), false) : undefined;
this.#profile = pubkey
? new JsonEventSync<UserMetadata | undefined>(
undefined,
new NostrLink(NostrPrefix.Event, pubkey, EventKind.SetMetadata, pubkey),
false,
)
: undefined;
this.#contacts = pubkey
? new DiffSyncTags(new NostrLink(NostrPrefix.Event, pubkey, EventKind.ContactList, pubkey), false)
: undefined;
this.#relays = pubkey
? new DiffSyncTags(new NostrLink(NostrPrefix.Event, pubkey, EventKind.Relays, pubkey), false)
: undefined;
if (options?.appdataId && options.initAppdata) {
const link = new NostrLink(NostrPrefix.Address, options.appdataId, EventKind.AppData, pubkey);
this.#appdata = new JsonEventSync<TAppData>(options.initAppdata, link, options.encryptAppdata ?? false);

View File

@ -13433,7 +13433,6 @@ __metadata:
prettier: "npm:^3.0.3"
typedoc: "npm:^0.25.7"
typescript: "npm:^5.2.2"
vite-plugin-version-mark: "npm:^0.1.4"
languageName: unknown
linkType: soft