ProfileLink to /npub if profile not present
continuous-integration/drone/push Build is running Details

This commit is contained in:
Martti Malmi 2023-11-29 14:11:57 +02:00
parent 61e93bd194
commit d2b95375b6
4 changed files with 37 additions and 41 deletions

View File

@ -7,14 +7,12 @@ import { randomSample } from "@/SnortUtils";
export function ProfileLink({
pubkey,
user,
link,
explicitLink,
children,
...others
}: {
pubkey: string;
user?: UserMetadata | MetadataCache;
link?: NostrLink;
explicitLink?: string;
children?: ReactNode;
} & Omit<LinkProps, "to">) {
@ -27,27 +25,21 @@ export function ProfileLink({
if (explicitLink) {
return explicitLink;
}
if (user) {
if (
user.nip05 &&
user.nip05.endsWith(`@${CONFIG.nip05Domain}`) &&
(!("isNostrAddressValid" in user) || user.isNostrAddressValid)
) {
const [username] = user.nip05.split("@");
return `/${username}`;
}
return `/${new NostrLink(
NostrPrefix.Profile,
pubkey,
undefined,
undefined,
relays ? randomSample(relays, 3) : undefined,
).encode(CONFIG.profileLinkPrefix)}`;
if (
user?.nip05 &&
user.nip05.endsWith(`@${CONFIG.nip05Domain}`) &&
(!("isNostrAddressValid" in user) || user.isNostrAddressValid)
) {
const [username] = user.nip05.split("@");
return `/${username}`;
}
if (link && (link.type === NostrPrefix.Profile || link.type === NostrPrefix.PublicKey)) {
return `/${link.encode()}`;
}
return "#";
return `/${new NostrLink(
NostrPrefix.Profile,
pubkey,
undefined,
undefined,
relays ? randomSample(relays, 3) : undefined,
).encode(CONFIG.profileLinkPrefix)}`;
}
const oFiltered = others as Record<string, unknown>;

View File

@ -24,7 +24,7 @@ import useFollowsFeed from "@/Feed/FollowsFeed";
import useProfileBadges from "@/Feed/BadgesFeed";
import useModeration from "@/Hooks/useModeration";
import FollowButton from "@/Element/User/FollowButton";
import { parseId, hexToBech32 } from "@/SnortUtils";
import { parseId } from "@/SnortUtils";
import Avatar from "@/Element/User/Avatar";
import Timeline from "@/Element/Feed/Timeline";
import Text from "@/Element/Text";
@ -61,7 +61,6 @@ import { useMuteList, usePinList } from "@/Hooks/useLists";
import messages from "../messages";
import FollowDistanceIndicator from "@/Element/User/FollowDistanceIndicator";
import classNames from "classnames";
import { ProfileLink } from "@/Element/User/ProfileLink";
interface ProfilePageProps {
@ -84,7 +83,6 @@ export default function ProfilePage({ id: propId, state }: ProfilePageProps) {
const [showProfileQr, setShowProfileQr] = useState<boolean>(false);
const [modalImage, setModalImage] = useState<string>("");
const aboutText = user?.about || "";
const npub = !id?.startsWith(NostrPrefix.PublicKey) ? hexToBech32(NostrPrefix.PublicKey, id || undefined) : id;
const lnurl = (() => {
try {
@ -168,22 +166,26 @@ export default function ProfilePage({ id: propId, state }: ProfilePageProps) {
</h2>
{user?.nip05 && <Nip05 nip05={user.nip05} pubkey={user.pubkey} />}
<div className="flex flex-row items-center">
{user?.pubkey && <FollowDistanceIndicator className="p-2" pubkey={user.pubkey} />}
<div className="flex flex-row items-center">
{user?.pubkey && <FollowDistanceIndicator className="p-2" pubkey={user.pubkey} />}
{followedByFriendsArray.map((a, index) => {
const zIndex = followedByFriendsArray.length - index;
return (
<div className={`inline-block ${index > 0 ? "-ml-5" : ""}`} key={a} style={{ zIndex }}>
<ProfileImage showFollowDistance={false} pubkey={a} size={24} showUsername={false} />
</div>
);
})}
</div>
{followedByFriends.size > 0 && (
<div className="text-gray-light">
{followedByFriendsArray.map((a, index) => {
return (
<span className={classNames({ "-ml-4": index > 0 }, "inline-block")} key={a}>
<ProfileImage showFollowDistance={false} pubkey={a} size={24} showUsername={false} />
</span>
);
})}
<span className="mr-1">
<FormattedMessage defaultMessage="Followed by" id="6mr8WU" />
</span>
{followedByFriendsArray.map((a, index) => (
<Fragment key={a}>
<ProfileLink pubkey={a} user={undefined} className="link inline">
<ProfileLink pubkey={a} className="link inline">
<DisplayName user={undefined} pubkey={a} />
</ProfileLink>
{index < followedByFriendsArray.length - 1 && ","}{" "}
@ -204,9 +206,7 @@ export default function ProfilePage({ id: propId, state }: ProfilePageProps) {
</div>
{showBadges && <BadgeList badges={badges} />}
{showStatus && <>{musicStatus()}</>}
<div className="link-section">
{links()}
</div>
<div className="link-section">{links()}</div>
</>
);
}

View File

@ -404,9 +404,6 @@
"DZzCem": {
"defaultMessage": "Show latest {n} notes"
},
"DcL8P+": {
"defaultMessage": "Supporter"
},
"Dh3hbq": {
"defaultMessage": "Auto Zap"
},
@ -537,6 +534,9 @@
"IKKHqV": {
"defaultMessage": "Follows"
},
"IOu4Xh": {
"defaultMessage": "You must be a {tier} subscriber to access {app} deck"
},
"IVbtTS": {
"defaultMessage": "Zap all {n} sats"
},
@ -1525,6 +1525,9 @@
"xmcVZ0": {
"defaultMessage": "Search"
},
"xybOUv": {
"defaultMessage": "FAN"
},
"y1Z3or": {
"defaultMessage": "Language"
},

View File

@ -133,7 +133,6 @@
"DBiVK1": "Cache",
"DKnriN": "Send sats",
"DZzCem": "Show latest {n} notes",
"DcL8P+": "Supporter",
"Dh3hbq": "Auto Zap",
"Dn82AL": "Live",
"DtYelJ": "Transfer",
@ -177,6 +176,7 @@
"HhcAVH": "You don't follow this person, click here to load media from <i>{link}</i>, or update <a><i>your preferences</i></a> to always load media from everybody.",
"IEwZvs": "Are you sure you want to unpin this note?",
"IKKHqV": "Follows",
"IOu4Xh": "You must be a {tier} subscriber to access {app} deck",
"IVbtTS": "Zap all {n} sats",
"IWz1ta": "Auto Translate",
"Ig9/a1": "Sent {n} sats to {name}",
@ -502,6 +502,7 @@
"xhQMeQ": "Expires",
"xl4s/X": "Additional Terms:",
"xmcVZ0": "Search",
"xybOUv": "FAN",
"y1Z3or": "Language",
"yCLnBC": "LNURL or Lightning Address",
"yNBPJp": "Help fund the development of {site}",