Skip to content

Commit

Permalink
feat(backend): 연합 대응 확장
Browse files Browse the repository at this point in the history
  - 이제 노트를 작성 또는 편집하면 다음 항목이 연합됩니다.
    - 우클릭 방지
    - 노트 삭제 예약 (날짜 확인)

enhance(backend): 노트 추출 대응 항목 확장
  - 다음 항목이 노트 추출에 대응합니다.
    - 이벤트
    - 우클릭 방지
  • Loading branch information
noridev committed Nov 9, 2024
1 parent f7b5b8c commit 5cde43d
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 17 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG_CHERRYPICK.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ Misskey의 전체 변경 사항을 확인하려면, [CHANGELOG.md#2024xx](CHANGE
- Fix: 투표가 있는 노트에 답글을 작성할 때 노트 작성 영역에서 투표가 표시되지 않을 수 있음

### Server
- Feat: 연합 대응 확장
- 이제 노트를 작성 또는 편집하면 다음 항목이 연합됩니다.
- 우클릭 방지
- 노트 삭제 예약 (날짜 확인)
- Enhance: 노트 편집 제한 강화
- 5분에 10번 편집할 수 있던 것을 5분에 5번 편집할 수 있도록 제한함.
- Enhance: 노트 편집 강화
Expand All @@ -57,6 +61,10 @@ Misskey의 전체 변경 사항을 확인하려면, [CHANGELOG.md#2024xx](CHANGE
- 우클릭 방지
- Enhance: 로그인 알림 개선
- 로그인 알림에서 로그인 한 장치의 `IP`를 표시하고 승인되지 않은 기기에 대한 대응 방법이 표시됩니다.
- Enhance: 노트 추출 대응 항목 확장
- 다음 항목이 노트 추출에 대응합니다.
- 이벤트
- 우클릭 방지

---

Expand Down
2 changes: 2 additions & 0 deletions packages/backend/src/core/GlobalEventService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ export interface NoteEventTypes {
updated: {
cw: string | null;
text: string | null;
disableRightClick: boolean | null;
deleteAt: Date | null;
};
reacted: {
reaction: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/core/NoteCreateService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ export class NoteCreateService implements OnApplicationShutdown {
localOnly: data.localOnly!,
reactionAcceptance: data.reactionAcceptance,
disableRightClick: data.disableRightClick!,
deleteAt: data.deleteAt,
visibility: data.visibility as any,
visibleUserIds: data.visibility === 'specified'
? data.visibleUsers
Expand All @@ -446,7 +447,6 @@ export class NoteCreateService implements OnApplicationShutdown {
renoteUserId: data.renote ? data.renote.userId : null,
renoteUserHost: data.renote ? data.renote.userHost : null,
userHost: user.host,
deleteAt: data.deleteAt,
});

if (data.uri != null) insert.uri = data.uri;
Expand Down
26 changes: 13 additions & 13 deletions packages/backend/src/core/NoteUpdateService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export class NoteUpdateService implements OnApplicationShutdown {
attachedFileTypes: data.files ? data.files.map(file => file.type) : [],
updatedAtHistory: [...updatedAtHistory, new Date()],
noteEditHistory: [...note.noteEditHistory, (note.cw ? note.cw + '\n' : '') + note.text!],
deleteAt: data.deleteAt,
deleteAt: data.deleteAt!,
});

// 投稿を更新
Expand Down Expand Up @@ -267,7 +267,18 @@ export class NoteUpdateService implements OnApplicationShutdown {
if (!silent) {
if (this.userEntityService.isLocalUser(user)) this.activeUsersChart.write(user);

this.globalEventService.publishNoteStream(note.id, 'updated', { cw: note.cw, text: note.text });
if (note.deleteAt) {
const delay = note.deleteAt.getTime() - Date.now();
await this.queueService.scheduledNoteDeleteQueue.remove(note.id);
await this.queueService.scheduledNoteDeleteQueue.add(note.id, {
noteId: note.id,
}, {
delay,
removeOnComplete: true,
});
}

this.globalEventService.publishNoteStream(note.id, 'updated', { cw: note.cw, text: note.text, disableRightClick: note.disableRightClick, deleteAt: note.deleteAt });

//#region AP deliver
if (this.userEntityService.isLocalUser(user) && !note.localOnly) {
Expand All @@ -282,17 +293,6 @@ export class NoteUpdateService implements OnApplicationShutdown {
//#endregion
}

if (note.deleteAt) {
const delay = note.deleteAt.getTime() - Date.now();
await this.queueService.scheduledNoteDeleteQueue.remove(note.id);
await this.queueService.scheduledNoteDeleteQueue.add(note.id, {
noteId: note.id,
}, {
delay,
removeOnComplete: true,
});
}

// Register to search database
this.reIndex(note);
}
Expand Down
10 changes: 10 additions & 0 deletions packages/backend/src/core/activitypub/ApRendererService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,14 @@ export class ApRendererService {
} as const : {};
}

let asDeleteAt = {};
if (note.deleteAt) {
const n = await this.notesRepository.findOneBy({ id: note.id });
asDeleteAt = n ? {
deleteAt: n.deleteAt,
} as const : {};
}

return {
id: `${this.config.url}/notes/${note.id}`,
type: 'Note',
Expand All @@ -466,6 +474,8 @@ export class ApRendererService {
attachment: files.map(x => this.renderDocument(x)),
sensitive: note.cw != null || files.some(file => file.isSensitive),
tag,
disableRightClick: note.disableRightClick,
...asDeleteAt,
...asEvent,
...asPoll,
...asTalk,
Expand Down
6 changes: 4 additions & 2 deletions packages/backend/src/core/activitypub/models/ApNoteService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ export class ApNoteService {
cw,
text,
localOnly: false,
disableRightClick: false,
disableRightClick: note.disableRightClick,
visibility,
visibleUsers,
apMentions,
Expand All @@ -349,6 +349,7 @@ export class ApNoteService {
event,
uri: note.id,
url: url,
deleteAt: note.deleteAt ? new Date(note.deleteAt) : null,
}, silent);
} catch (err: any) {
if (err.name !== 'duplicated') {
Expand Down Expand Up @@ -434,11 +435,12 @@ export class ApNoteService {
name: note.name,
cw,
text,
disableRightClick: false,
disableRightClick: note.disableRightClick,
apHashtags,
apEmojis,
poll,
event,
deleteAt: note.deleteAt,
}, target, silent);
} catch (err: any) {
this.logger.warn(`note update failed: ${err}`);
Expand Down
2 changes: 2 additions & 0 deletions packages/backend/src/core/activitypub/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export interface IObject {
href?: string;
tag?: IObject | IObject[];
sensitive?: boolean;
disableRightClick?: boolean;
deleteAt?: Date;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/core/entities/NoteEntityService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ export class NoteEntityService implements OnModuleInit {
updatedAt: note.updatedAt ? note.updatedAt.toISOString() : undefined,
updatedAtHistory: note.updatedAtHistory ? note.updatedAtHistory.map(x => x.toISOString()) : undefined,
noteEditHistory: note.noteEditHistory.length ? note.noteEditHistory : undefined,
deleteAt: note.deleteAt ? note.deleteAt.toISOString() : undefined,
userId: note.userId,
user: packedUsers?.get(note.userId) ?? this.userEntityService.pack(note.user ?? note.userId, me),
text: text,
Expand Down Expand Up @@ -436,7 +437,6 @@ export class NoteEntityService implements OnModuleInit {

poll: note.hasPoll ? this.populatePoll(note, meId) : undefined,
event: note.hasEvent ? this.populateEvent(note) : undefined,
deleteAt: note.deleteAt?.toISOString() ?? undefined,

...(meId && Object.keys(reactions).length > 0 ? {
myReaction: this.populateMyReaction({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class NoteStream extends ReadableStream<Record<string, unknown>> {
visibleUserIds: note.visibleUserIds,
localOnly: note.localOnly,
reactionAcceptance: note.reactionAcceptance,
disableRightClick: note.disableRightClick,
};
};

Expand Down

0 comments on commit 5cde43d

Please sign in to comment.