forked from misskey-dev/misskey
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(backend): incorrect logic for determining whether Quote or not (m…
…isskey-dev#13700) * fix(backend): incorrect logic for determining whether Quote or not * Update CHANGELOG.md --------- Co-authored-by: syuilo <[email protected]>
- Loading branch information
Showing
11 changed files
with
296 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* SPDX-FileCopyrightText: syuilo and misskey-project | ||
* SPDX-License-Identifier: AGPL-3.0-only | ||
*/ | ||
|
||
import type { MiNote } from '@/models/Note.js'; | ||
|
||
type Renote = | ||
MiNote & { | ||
renoteId: NonNullable<MiNote['renoteId']> | ||
}; | ||
|
||
type Quote = | ||
Renote & ({ | ||
text: NonNullable<MiNote['text']> | ||
} | { | ||
cw: NonNullable<MiNote['cw']> | ||
} | { | ||
replyId: NonNullable<MiNote['replyId']> | ||
reply: NonNullable<MiNote['reply']> | ||
} | { | ||
hasPoll: true | ||
}); | ||
|
||
export function isRenote(note: MiNote): note is Renote { | ||
return note.renoteId != null; | ||
} | ||
|
||
export function isQuote(note: Renote): note is Quote { | ||
// NOTE: SYNC WITH NoteCreateService.isQuote | ||
return note.text != null || | ||
note.cw != null || | ||
note.replyId != null || | ||
note.hasPoll || | ||
note.fileIds.length > 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
/* | ||
* SPDX-FileCopyrightText: syuilo and misskey-project | ||
* SPDX-License-Identifier: AGPL-3.0-only | ||
*/ | ||
|
||
import { Test } from '@nestjs/testing'; | ||
|
||
import { CoreModule } from '@/core/CoreModule.js'; | ||
import { NoteCreateService } from '@/core/NoteCreateService.js'; | ||
import { GlobalModule } from '@/GlobalModule.js'; | ||
import { MiNote } from '@/models/Note.js'; | ||
import { IPoll } from '@/models/Poll.js'; | ||
import { MiDriveFile } from '@/models/DriveFile.js'; | ||
|
||
describe('NoteCreateService', () => { | ||
let noteCreateService: NoteCreateService; | ||
|
||
beforeAll(async () => { | ||
const app = await Test.createTestingModule({ | ||
imports: [GlobalModule, CoreModule], | ||
}).compile(); | ||
noteCreateService = app.get<NoteCreateService>(NoteCreateService); | ||
}); | ||
|
||
describe('is-renote', () => { | ||
const base: MiNote = { | ||
id: 'some-note-id', | ||
replyId: null, | ||
reply: null, | ||
renoteId: null, | ||
renote: null, | ||
threadId: null, | ||
text: null, | ||
name: null, | ||
cw: null, | ||
userId: 'some-user-id', | ||
user: null, | ||
localOnly: false, | ||
reactionAcceptance: null, | ||
renoteCount: 0, | ||
repliesCount: 0, | ||
clippedCount: 0, | ||
reactions: {}, | ||
visibility: 'public', | ||
uri: null, | ||
url: null, | ||
fileIds: [], | ||
attachedFileTypes: [], | ||
visibleUserIds: [], | ||
mentions: [], | ||
mentionedRemoteUsers: '', | ||
reactionAndUserPairCache: [], | ||
emojis: [], | ||
tags: [], | ||
hasPoll: false, | ||
channelId: null, | ||
channel: null, | ||
userHost: null, | ||
replyUserId: null, | ||
replyUserHost: null, | ||
renoteUserId: null, | ||
renoteUserHost: null, | ||
}; | ||
|
||
const poll: IPoll = { | ||
choices: ['kinoko', 'takenoko'], | ||
multiple: false, | ||
expiresAt: null, | ||
}; | ||
|
||
const file: MiDriveFile = { | ||
id: 'some-file-id', | ||
userId: null, | ||
user: null, | ||
userHost: null, | ||
md5: '', | ||
name: '', | ||
type: '', | ||
size: 0, | ||
comment: null, | ||
blurhash: null, | ||
properties: {}, | ||
storedInternal: false, | ||
url: '', | ||
thumbnailUrl: null, | ||
webpublicUrl: null, | ||
webpublicType: null, | ||
accessKey: null, | ||
thumbnailAccessKey: null, | ||
webpublicAccessKey: null, | ||
uri: null, | ||
src: null, | ||
folderId: null, | ||
folder: null, | ||
isSensitive: false, | ||
maybeSensitive: false, | ||
maybePorn: false, | ||
isLink: false, | ||
requestHeaders: null, | ||
requestIp: null, | ||
}; | ||
|
||
test('note without renote should not be Renote', () => { | ||
const note = { renote: null }; | ||
expect(noteCreateService['isRenote'](note)).toBe(false); | ||
}); | ||
|
||
test('note with renote should be Renote and not be Quote', () => { | ||
const note = { renote: base }; | ||
expect(noteCreateService['isRenote'](note)).toBe(true); | ||
expect(noteCreateService['isQuote'](note)).toBe(false); | ||
}); | ||
|
||
test('note with renote and text should be Quote', () => { | ||
const note = { renote: base, text: 'some-text' }; | ||
expect(noteCreateService['isRenote'](note)).toBe(true); | ||
expect(noteCreateService['isQuote'](note)).toBe(true); | ||
}); | ||
|
||
test('note with renote and cw should be Quote', () => { | ||
const note = { renote: base, cw: 'some-cw' }; | ||
expect(noteCreateService['isRenote'](note)).toBe(true); | ||
expect(noteCreateService['isQuote'](note)).toBe(true); | ||
}); | ||
|
||
test('note with renote and reply should be Quote', () => { | ||
const note = { renote: base, reply: { ...base, id: 'another-note-id' } }; | ||
expect(noteCreateService['isRenote'](note)).toBe(true); | ||
expect(noteCreateService['isQuote'](note)).toBe(true); | ||
}); | ||
|
||
test('note with renote and poll should be Quote', () => { | ||
const note = { renote: base, poll }; | ||
expect(noteCreateService['isRenote'](note)).toBe(true); | ||
expect(noteCreateService['isQuote'](note)).toBe(true); | ||
}); | ||
|
||
test('note with renote and non-empty files should be Quote', () => { | ||
const note = { renote: base, files: [file] }; | ||
expect(noteCreateService['isRenote'](note)).toBe(true); | ||
expect(noteCreateService['isQuote'](note)).toBe(true); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.