mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
Stop adding unnecessary newlines to the top of posts with images only
This commit is contained in:
parent
bb50ad7a43
commit
f72fdf79bb
1 changed files with 41 additions and 33 deletions
|
|
@ -149,26 +149,6 @@ const createStatusController: AppController = async (c) => {
|
||||||
|
|
||||||
const pubkeys = new Set<string>();
|
const pubkeys = new Set<string>();
|
||||||
|
|
||||||
const content = await asyncReplaceAll(
|
|
||||||
data.status ?? '',
|
|
||||||
/(?<![\w/])@([\w@+._]+)(?![\w/\.])/g,
|
|
||||||
async (match, username) => {
|
|
||||||
const pubkey = await lookupPubkey(username);
|
|
||||||
if (!pubkey) return match;
|
|
||||||
|
|
||||||
// Content addressing (default)
|
|
||||||
if (!data.to) {
|
|
||||||
pubkeys.add(pubkey);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
return `nostr:${nip19.nprofileEncode({ pubkey, relays: [Conf.relay] })}`;
|
|
||||||
} catch {
|
|
||||||
return match;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
// Explicit addressing
|
// Explicit addressing
|
||||||
for (const to of data.to ?? []) {
|
for (const to of data.to ?? []) {
|
||||||
const pubkey = await lookupPubkey(to);
|
const pubkey = await lookupPubkey(to);
|
||||||
|
|
@ -190,18 +170,6 @@ const createStatusController: AppController = async (c) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const mediaUrls: string[] = media
|
|
||||||
.map(({ url }) => url)
|
|
||||||
.filter((url): url is string => Boolean(url));
|
|
||||||
|
|
||||||
const quoteCompat = quoted
|
|
||||||
? `\n\nnostr:${
|
|
||||||
nip19.neventEncode({ id: quoted.id, kind: quoted.kind, author: quoted.pubkey, relays: [Conf.relay] })
|
|
||||||
}`
|
|
||||||
: '';
|
|
||||||
|
|
||||||
const mediaCompat = mediaUrls.length ? `\n\n${mediaUrls.join('\n')}` : '';
|
|
||||||
|
|
||||||
const pubkey = await c.get('signer')?.getPublicKey()!;
|
const pubkey = await c.get('signer')?.getPublicKey()!;
|
||||||
const author = pubkey ? await getAuthor(pubkey) : undefined;
|
const author = pubkey ? await getAuthor(pubkey) : undefined;
|
||||||
|
|
||||||
|
|
@ -235,9 +203,49 @@ const createStatusController: AppController = async (c) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const mediaUrls: string[] = media
|
||||||
|
.map(({ url }) => url)
|
||||||
|
.filter((url): url is string => Boolean(url));
|
||||||
|
|
||||||
|
let content = await asyncReplaceAll(
|
||||||
|
data.status ?? '',
|
||||||
|
/(?<![\w/])@([\w@+._]+)(?![\w/\.])/g,
|
||||||
|
async (match, username) => {
|
||||||
|
const pubkey = await lookupPubkey(username);
|
||||||
|
if (!pubkey) return match;
|
||||||
|
|
||||||
|
// Content addressing (default)
|
||||||
|
if (!data.to) {
|
||||||
|
pubkeys.add(pubkey);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
return `nostr:${nip19.nprofileEncode({ pubkey, relays: [Conf.relay] })}`;
|
||||||
|
} catch {
|
||||||
|
return match;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
if (quoted) {
|
||||||
|
if (content) {
|
||||||
|
content += '\n\n';
|
||||||
|
}
|
||||||
|
content += `nostr:${
|
||||||
|
nip19.neventEncode({ id: quoted.id, kind: quoted.kind, author: quoted.pubkey, relays: [Conf.relay] })
|
||||||
|
}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mediaUrls.length) {
|
||||||
|
if (content) {
|
||||||
|
content += '\n\n';
|
||||||
|
}
|
||||||
|
content += mediaUrls.join('\n');
|
||||||
|
}
|
||||||
|
|
||||||
const event = await createEvent({
|
const event = await createEvent({
|
||||||
kind: 1,
|
kind: 1,
|
||||||
content: content + quoteCompat + mediaCompat,
|
content,
|
||||||
tags,
|
tags,
|
||||||
}, c);
|
}, c);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue