merge: Split character limits between local and remote notes (resolves #723) (!669)

View MR for information: https://activitypub.software/TransFem-org/Sharkey/-/merge_requests/669

Closes #723

Approved-by: dakkar <dakkar@thenautilus.net>
Approved-by: Julia <julia@insertdomain.name>
This commit is contained in:
Julia 2024-10-29 03:04:25 +00:00
commit 1520bc1715
24 changed files with 244 additions and 68 deletions

View file

@ -45,7 +45,6 @@ import { ApDeliverManagerService } from '@/core/activitypub/ApDeliverManagerServ
import { NoteReadService } from '@/core/NoteReadService.js';
import { RemoteUserResolveService } from '@/core/RemoteUserResolveService.js';
import { bindThis } from '@/decorators.js';
import { DB_MAX_NOTE_TEXT_LENGTH } from '@/const.js';
import { RoleService } from '@/core/RoleService.js';
import { SearchService } from '@/core/SearchService.js';
import { FeaturedService } from '@/core/FeaturedService.js';
@ -335,9 +334,13 @@ export class NoteCreateService implements OnApplicationShutdown {
data.localOnly = true;
}
const maxTextLength = user.host == null
? this.config.maxNoteLength
: this.config.maxRemoteNoteLength;
if (data.text) {
if (data.text.length > DB_MAX_NOTE_TEXT_LENGTH) {
data.text = data.text.slice(0, DB_MAX_NOTE_TEXT_LENGTH);
if (data.text.length > maxTextLength) {
data.text = data.text.slice(0, maxTextLength);
}
data.text = data.text.trim();
if (data.text === '') {
@ -347,9 +350,13 @@ export class NoteCreateService implements OnApplicationShutdown {
data.text = null;
}
const maxCwLength = user.host == null
? this.config.maxCwLength
: this.config.maxRemoteCwLength;
if (data.cw) {
if (data.cw.length > DB_MAX_NOTE_TEXT_LENGTH) {
data.cw = data.cw.slice(0, DB_MAX_NOTE_TEXT_LENGTH);
if (data.cw.length > maxCwLength) {
data.cw = data.cw.slice(0, maxCwLength);
}
data.cw = data.cw.trim();
if (data.cw === '') {

View file

@ -39,7 +39,6 @@ import { ApDeliverManagerService } from '@/core/activitypub/ApDeliverManagerServ
import { NoteReadService } from '@/core/NoteReadService.js';
import { RemoteUserResolveService } from '@/core/RemoteUserResolveService.js';
import { bindThis } from '@/decorators.js';
import { DB_MAX_NOTE_TEXT_LENGTH } from '@/const.js';
import { RoleService } from '@/core/RoleService.js';
import { SearchService } from '@/core/SearchService.js';
import { FanoutTimelineService } from '@/core/FanoutTimelineService.js';
@ -365,9 +364,13 @@ export class NoteEditService implements OnApplicationShutdown {
data.localOnly = true;
}
const maxTextLength = user.host == null
? this.config.maxNoteLength
: this.config.maxRemoteNoteLength;
if (data.text) {
if (data.text.length > DB_MAX_NOTE_TEXT_LENGTH) {
data.text = data.text.slice(0, DB_MAX_NOTE_TEXT_LENGTH);
if (data.text.length > maxTextLength) {
data.text = data.text.slice(0, maxTextLength);
}
data.text = data.text.trim();
if (data.text === '') {
@ -377,9 +380,13 @@ export class NoteEditService implements OnApplicationShutdown {
data.text = null;
}
const maxCwLength = user.host == null
? this.config.maxCwLength
: this.config.maxRemoteCwLength;
if (data.cw) {
if (data.cw.length > DB_MAX_NOTE_TEXT_LENGTH) {
data.cw = data.cw.slice(0, DB_MAX_NOTE_TEXT_LENGTH);
if (data.cw.length > maxCwLength) {
data.cw = data.cw.slice(0, maxCwLength);
}
data.cw = data.cw.trim();
if (data.cw === '') {

View file

@ -9,12 +9,12 @@ import type { DriveFilesRepository, MiMeta } from '@/models/_.js';
import type { MiRemoteUser } from '@/models/User.js';
import type { MiDriveFile } from '@/models/DriveFile.js';
import { truncate } from '@/misc/truncate.js';
import { DB_MAX_IMAGE_COMMENT_LENGTH } from '@/const.js';
import { DriveService } from '@/core/DriveService.js';
import type Logger from '@/logger.js';
import { bindThis } from '@/decorators.js';
import { checkHttps } from '@/misc/check-https.js';
import { FederatedInstanceService } from '@/core/FederatedInstanceService.js';
import type { Config } from '@/config.js';
import { ApResolverService } from '../ApResolverService.js';
import { ApLoggerService } from '../ApLoggerService.js';
import { isDocument, type IObject } from '../type.js';
@ -29,6 +29,8 @@ export class ApImageService {
@Inject(DI.driveFilesRepository)
private driveFilesRepository: DriveFilesRepository,
@Inject(DI.config)
private config: Config,
private apResolverService: ApResolverService,
private driveService: DriveService,
@ -83,7 +85,7 @@ export class ApImageService {
uri: image.url,
sensitive: !!(image.sensitive),
isLink: !shouldBeCached,
comment: truncate(image.name ?? undefined, DB_MAX_IMAGE_COMMENT_LENGTH),
comment: truncate(image.name ?? undefined, this.config.maxRemoteAltTextLength),
});
if (!file.isLink || file.url === image.url) return file;

View file

@ -110,6 +110,11 @@ export class MetaEntityService {
backgroundImageUrl: instance.backgroundImageUrl,
logoImageUrl: instance.logoImageUrl,
maxNoteTextLength: this.config.maxNoteLength,
maxRemoteNoteTextLength: this.config.maxRemoteNoteLength,
maxCwLength: this.config.maxCwLength,
maxRemoteCwLength: this.config.maxRemoteCwLength,
maxAltTextLength: this.config.maxAltTextLength,
maxRemoteAltTextLength: this.config.maxRemoteAltTextLength,
defaultLightTheme,
defaultDarkTheme,
defaultLike: instance.defaultLike,