summaryrefslogtreecommitdiff
path: root/packages/backend/src/models/LatestNote.ts
diff options
context:
space:
mode:
authorHazelnoot <acomputerdog@gmail.com>2024-10-15 18:01:57 -0400
committerHazelnoot <acomputerdog@gmail.com>2024-10-15 18:09:11 -0400
commit8a34d8e9d25546f7ef42f072a69f9923d5ba2e84 (patch)
tree4523856296102c786f724243375d198f3fada789 /packages/backend/src/models/LatestNote.ts
parentFix indentation on locales/generateDTS.js (diff)
parentmerge: Refresh locales after any change, not just a version update (resolves ... (diff)
downloadsharkey-8a34d8e9d25546f7ef42f072a69f9923d5ba2e84.tar.gz
sharkey-8a34d8e9d25546f7ef42f072a69f9923d5ba2e84.tar.bz2
sharkey-8a34d8e9d25546f7ef42f072a69f9923d5ba2e84.zip
Merge branch 'develop' into feature/2024.9.0
# Conflicts: # locales/en-US.yml # locales/ja-JP.yml # packages/backend/src/core/NoteCreateService.ts # packages/backend/src/core/NoteDeleteService.ts # packages/backend/src/core/NoteEditService.ts # packages/frontend-shared/js/config.ts # packages/frontend/src/boot/common.ts # packages/frontend/src/pages/following-feed.vue # packages/misskey-js/src/autogen/endpoint.ts
Diffstat (limited to 'packages/backend/src/models/LatestNote.ts')
-rw-r--r--packages/backend/src/models/LatestNote.ts50
1 files changed, 48 insertions, 2 deletions
diff --git a/packages/backend/src/models/LatestNote.ts b/packages/backend/src/models/LatestNote.ts
index 1163ff3bc0..064fcccc0a 100644
--- a/packages/backend/src/models/LatestNote.ts
+++ b/packages/backend/src/models/LatestNote.ts
@@ -6,6 +6,7 @@
import { PrimaryColumn, Entity, JoinColumn, Column, ManyToOne } from 'typeorm';
import { MiUser } from '@/models/User.js';
import { MiNote } from '@/models/Note.js';
+import { isQuote, isRenote } from '@/misc/is-renote.js';
/**
* Maps a user to the most recent post by that user.
@@ -13,7 +14,7 @@ import { MiNote } from '@/models/Note.js';
* DMs are not counted.
*/
@Entity('latest_note')
-export class LatestNote {
+export class SkLatestNote {
@PrimaryColumn({
name: 'user_id',
type: 'varchar' as const,
@@ -21,6 +22,24 @@ export class LatestNote {
})
public userId: string;
+ @PrimaryColumn('boolean', {
+ name: 'is_public',
+ default: false,
+ })
+ public isPublic: boolean;
+
+ @PrimaryColumn('boolean', {
+ name: 'is_reply',
+ default: false,
+ })
+ public isReply: boolean;
+
+ @PrimaryColumn('boolean', {
+ name: 'is_quote',
+ default: false,
+ })
+ public isQuote: boolean;
+
@ManyToOne(() => MiUser, {
onDelete: 'CASCADE',
})
@@ -44,11 +63,38 @@ export class LatestNote {
})
public note: MiNote | null;
- constructor(data?: Partial<LatestNote>) {
+ constructor(data?: Partial<SkLatestNote>) {
if (!data) return;
for (const [k, v] of Object.entries(data)) {
(this as Record<string, unknown>)[k] = v;
}
}
+
+ /**
+ * Generates a compound key matching a provided note.
+ */
+ static keyFor(note: MiNote) {
+ return {
+ userId: note.userId,
+ isPublic: note.visibility === 'public',
+ isReply: note.replyId != null,
+ isQuote: isRenote(note) && isQuote(note),
+ };
+ }
+
+ /**
+ * Checks if two notes would produce equivalent compound keys.
+ */
+ static areEquivalent(first: MiNote, second: MiNote): boolean {
+ const firstKey = SkLatestNote.keyFor(first);
+ const secondKey = SkLatestNote.keyFor(second);
+
+ return (
+ firstKey.userId === secondKey.userId &&
+ firstKey.isPublic === secondKey.isPublic &&
+ firstKey.isReply === secondKey.isReply &&
+ firstKey.isQuote === secondKey.isQuote
+ );
+ }
}