updates to include alt text editing
This commit is contained in:
parent
6eed038028
commit
61dde4c0b0
|
@ -16,7 +16,7 @@ import { unique, toArray, toSingle } from "@/prelude/array.js";
|
||||||
import { extractPollFromQuestion, updateQuestion } from "./question.js";
|
import { extractPollFromQuestion, updateQuestion } from "./question.js";
|
||||||
import vote from "@/services/note/polls/vote.js";
|
import vote from "@/services/note/polls/vote.js";
|
||||||
import { apLogger } from "../logger.js";
|
import { apLogger } from "../logger.js";
|
||||||
import type { DriveFile } from "@/models/entities/drive-file.js";
|
import { DriveFile } from "@/models/entities/drive-file.js";
|
||||||
import { deliverQuestionUpdate } from "@/services/note/polls/update.js";
|
import { deliverQuestionUpdate } from "@/services/note/polls/update.js";
|
||||||
import { extractDbHost, toPuny } from "@/misc/convert-host.js";
|
import { extractDbHost, toPuny } from "@/misc/convert-host.js";
|
||||||
import {
|
import {
|
||||||
|
@ -25,6 +25,7 @@ import {
|
||||||
MessagingMessages,
|
MessagingMessages,
|
||||||
Notes,
|
Notes,
|
||||||
NoteEdits,
|
NoteEdits,
|
||||||
|
DriveFiles,
|
||||||
} from "@/models/index.js";
|
} from "@/models/index.js";
|
||||||
import type { IMentionedRemoteUsers, Note } from "@/models/entities/note.js";
|
import type { IMentionedRemoteUsers, Note } from "@/models/entities/note.js";
|
||||||
import type { IObject, IPost } from "../type.js";
|
import type { IObject, IPost } from "../type.js";
|
||||||
|
@ -49,6 +50,8 @@ import { publishNoteStream } from "@/services/stream.js";
|
||||||
import { extractHashtags } from "@/misc/extract-hashtags.js";
|
import { extractHashtags } from "@/misc/extract-hashtags.js";
|
||||||
import { UserProfiles } from "@/models/index.js";
|
import { UserProfiles } from "@/models/index.js";
|
||||||
import { In } from "typeorm";
|
import { In } from "typeorm";
|
||||||
|
import { DB_MAX_IMAGE_COMMENT_LENGTH } from "@/misc/hard-limits.js";
|
||||||
|
import { truncate } from "@/misc/truncate.js";
|
||||||
|
|
||||||
const logger = apLogger;
|
const logger = apLogger;
|
||||||
|
|
||||||
|
@ -516,6 +519,10 @@ type TagDetail = {
|
||||||
name: string;
|
name: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function notEmpty(partial: Partial<any>) {
|
||||||
|
return Object.keys(partial).length > 0;
|
||||||
|
}
|
||||||
|
|
||||||
export async function updateNote(value: string | IObject, resolver?: Resolver) {
|
export async function updateNote(value: string | IObject, resolver?: Resolver) {
|
||||||
const uri = typeof value === "string" ? value : value.id;
|
const uri = typeof value === "string" ? value : value.id;
|
||||||
if (!uri) throw new Error("Missing note uri");
|
if (!uri) throw new Error("Missing note uri");
|
||||||
|
@ -540,6 +547,9 @@ export async function updateNote(value: string | IObject, resolver?: Resolver) {
|
||||||
return await createNote(post, resolver);
|
return await createNote(post, resolver);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Whether to tell clients the note has been updated and requires refresh.
|
||||||
|
let publishing = false;
|
||||||
|
|
||||||
// Text parsing
|
// Text parsing
|
||||||
let text: string | null = null;
|
let text: string | null = null;
|
||||||
if (
|
if (
|
||||||
|
@ -569,7 +579,23 @@ export async function updateNote(value: string | IObject, resolver?: Resolver) {
|
||||||
const driveFiles = (
|
const driveFiles = (
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
fileList.map(
|
fileList.map(
|
||||||
(x) => limit(() => resolveImage(actor, x)) as Promise<DriveFile>,
|
(x) =>
|
||||||
|
limit(async () => {
|
||||||
|
const file = await resolveImage(actor, x);
|
||||||
|
const update: Partial<DriveFile> = {};
|
||||||
|
|
||||||
|
const altText = truncate(x.name, DB_MAX_IMAGE_COMMENT_LENGTH);
|
||||||
|
if (file.comment !== altText) {
|
||||||
|
update.comment = altText;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (notEmpty(update)) {
|
||||||
|
await DriveFiles.update(file.id, update);
|
||||||
|
publishing = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return file;
|
||||||
|
}) as Promise<DriveFile>,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
).filter((file) => file != null);
|
).filter((file) => file != null);
|
||||||
|
@ -616,42 +642,33 @@ export async function updateNote(value: string | IObject, resolver?: Resolver) {
|
||||||
} as IMentionedRemoteUsers[0];
|
} as IMentionedRemoteUsers[0];
|
||||||
});
|
});
|
||||||
|
|
||||||
let updating = false;
|
|
||||||
let publishing = false;
|
|
||||||
const update = {} as Partial<Note>;
|
const update = {} as Partial<Note>;
|
||||||
if (text && text !== note.text) {
|
if (text && text !== note.text) {
|
||||||
update.text = text;
|
update.text = text;
|
||||||
updating = true;
|
|
||||||
}
|
}
|
||||||
if (cw !== note.cw) {
|
if (cw !== note.cw) {
|
||||||
update.cw = cw ? cw : null;
|
update.cw = cw ? cw : null;
|
||||||
updating = true;
|
|
||||||
}
|
}
|
||||||
if (fileIds.sort().join(",") !== note.fileIds.sort().join(",")) {
|
if (fileIds.sort().join(",") !== note.fileIds.sort().join(",")) {
|
||||||
update.fileIds = fileIds;
|
update.fileIds = fileIds;
|
||||||
update.attachedFileTypes = fileTypes;
|
update.attachedFileTypes = fileTypes;
|
||||||
updating = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hashTags.sort().join(",") !== note.tags.sort().join(",")) {
|
if (hashTags.sort().join(",") !== note.tags.sort().join(",")) {
|
||||||
update.tags = hashTags;
|
update.tags = hashTags;
|
||||||
updating = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mentionUserIds.sort().join(",") !== note.mentions.sort().join(",")) {
|
if (mentionUserIds.sort().join(",") !== note.mentions.sort().join(",")) {
|
||||||
update.mentions = mentionUserIds;
|
update.mentions = mentionUserIds;
|
||||||
update.mentionedRemoteUsers = JSON.stringify(mentionedRemoteUsers);
|
update.mentionedRemoteUsers = JSON.stringify(mentionedRemoteUsers);
|
||||||
updating = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (apEmojis.sort().join(",") !== note.emojis.sort().join(",")) {
|
if (apEmojis.sort().join(",") !== note.emojis.sort().join(",")) {
|
||||||
update.emojis = apEmojis;
|
update.emojis = apEmojis;
|
||||||
updating = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (note.hasPoll !== !!poll) {
|
if (note.hasPoll !== !!poll) {
|
||||||
update.hasPoll = !!poll;
|
update.hasPoll = !!poll;
|
||||||
updating = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (poll) {
|
if (poll) {
|
||||||
|
@ -697,7 +714,7 @@ export async function updateNote(value: string | IObject, resolver?: Resolver) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update Note
|
// Update Note
|
||||||
if (updating) {
|
if (notEmpty(update)) {
|
||||||
update.updatedAt = new Date();
|
update.updatedAt = new Date();
|
||||||
|
|
||||||
// Save updated note to the database
|
// Save updated note to the database
|
||||||
|
|
Loading…
Reference in New Issue