Skip to content

Commit ef627e4

Browse files
BiernackiBiernacki
authored andcommitted
Added reading Mastodon's instance max characters setting
1 parent 7e92a76 commit ef627e4

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

apps/frontend/src/components/new-launch/providers/mastodon/mastodon.provider.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,9 @@ export default withProvider({
1111
CustomPreviewComponent: undefined,
1212
dto: undefined,
1313
checkValidity: undefined,
14-
maximumCharacters: 500,
14+
maximumCharacters: (settings) => {
15+
const value = settings?.find((s: any) => s?.title === 'Max characters')?.value;
16+
const parsed = Number(value);
17+
return Number.isFinite(parsed) && parsed > 0 ? parsed : 500;
18+
},
1519
});

libraries/nestjs-libraries/src/integrations/social/mastodon.provider.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,19 @@ export class MastodonProvider extends SocialAbstract implements SocialProvider {
8989
})
9090
).json();
9191

92+
let maxCharacters = 500;
93+
try {
94+
const instanceInfo = await (
95+
await this.fetch(`${url}/api/v1/instance`, {
96+
method: 'GET',
97+
})
98+
).json();
99+
maxCharacters =
100+
instanceInfo?.configuration?.statuses?.max_characters ?? 500;
101+
} catch {
102+
// Keep default maxCharacters = 500 on failure
103+
}
104+
92105
return {
93106
id: personalInformation.id,
94107
name: personalInformation.display_name || personalInformation.acct,
@@ -97,6 +110,14 @@ export class MastodonProvider extends SocialAbstract implements SocialProvider {
97110
expiresIn: dayjs().add(100, 'years').unix() - dayjs().unix(),
98111
picture: personalInformation?.avatar || '',
99112
username: personalInformation.username,
113+
additionalSettings: [
114+
{
115+
title: 'Max characters',
116+
description: 'Maximum characters per post for this instance',
117+
type: 'text' as const,
118+
value: maxCharacters,
119+
},
120+
],
100121
};
101122
}
102123

0 commit comments

Comments
 (0)