iceshrimp/packages/backend/src/remote/activitypub/models/note.ts

772 lines
19 KiB
TypeScript
Raw Normal View History

2023-01-13 05:40:33 +01:00
import promiseLimit from "promise-limit";
2023-04-30 18:29:50 +02:00
import * as mfm from "mfm-js";
2023-01-13 05:40:33 +01:00
import config from "@/config/index.js";
import Resolver from "../resolver.js";
import post from "@/services/note/create.js";
2023-04-30 18:29:50 +02:00
import { extractMentionedUsers } from "@/services/note/create.js";
2023-01-13 05:40:33 +01:00
import { resolvePerson } from "./person.js";
import { resolveImage } from "./image.js";
2023-04-30 18:29:50 +02:00
import type {
ILocalUser,
CacheableRemoteUser,
} from "@/models/entities/user.js";
2023-01-13 05:40:33 +01:00
import { htmlToMfm } from "../misc/html-to-mfm.js";
import { extractApHashtags } from "./tag.js";
import { unique, toArray, toSingle } from "@/prelude/array.js";
2023-06-18 23:14:38 +02:00
import { extractPollFromQuestion } from "./question.js";
2023-01-13 05:40:33 +01:00
import vote from "@/services/note/polls/vote.js";
import { apLogger } from "../logger.js";
2023-05-02 09:37:48 +02:00
import { DriveFile } from "@/models/entities/drive-file.js";
2023-01-13 05:40:33 +01:00
import { extractDbHost, toPuny } from "@/misc/convert-host.js";
2023-04-30 18:29:50 +02:00
import {
Emojis,
Polls,
MessagingMessages,
Notes,
NoteEdits,
2023-05-02 09:37:48 +02:00
DriveFiles,
2023-04-30 18:29:50 +02:00
} from "@/models/index.js";
import type { IMentionedRemoteUsers, Note } from "@/models/entities/note.js";
2023-01-13 05:40:33 +01:00
import type { IObject, IPost } from "../type.js";
import {
getOneApId,
getApId,
getOneApHrefNullable,
validPost,
isEmoji,
getApType,
} from "../type.js";
import type { Emoji } from "@/models/entities/emoji.js";
import { genId } from "@/misc/gen-id.js";
import { getApLock } from "@/misc/app-lock.js";
import { createMessage } from "@/services/messages/create.js";
import { parseAudience } from "../audience.js";
import { extractApMentions } from "./mention.js";
import DbResolver from "../db-resolver.js";
import { StatusError } from "@/misc/fetch.js";
import { shouldBlockInstance } from "@/misc/should-block-instance.js";
import { publishNoteStream, publishNoteUpdatesStream } from "@/services/stream.js";
2023-04-30 18:29:50 +02:00
import { extractHashtags } from "@/misc/extract-hashtags.js";
import { UserProfiles } from "@/models/index.js";
import { In } from "typeorm";
2023-05-02 09:37:48 +02:00
import { DB_MAX_IMAGE_COMMENT_LENGTH } from "@/misc/hard-limits.js";
import { truncate } from "@/misc/truncate.js";
2023-06-06 21:16:49 +02:00
import { type Size, getEmojiSize } from "@/misc/emoji-meta.js";
2023-06-06 21:11:15 +02:00
import { fetchMeta } from "@/misc/fetch-meta.js";
2018-04-08 21:08:56 +02:00
2019-02-03 08:45:13 +01:00
const logger = apLogger;
2018-04-08 21:08:56 +02:00
2019-05-09 08:43:31 +02:00
export function validateNote(object: any, uri: string) {
const expectHost = extractDbHost(uri);
if (object == null) {
2023-01-13 05:40:33 +01:00
return new Error("invalid Note: object is null");
2019-05-09 08:43:31 +02:00
}
if (!validPost.includes(getApType(object))) {
return new Error(`invalid Note: invalid object type ${getApType(object)}`);
2019-05-09 08:43:31 +02:00
}
if (object.id && extractDbHost(object.id) !== expectHost) {
2023-01-13 05:40:33 +01:00
return new Error(
`invalid Note: id has different host. expected: ${expectHost}, actual: ${extractDbHost(
object.id,
)}`,
);
2019-05-09 08:43:31 +02:00
}
2023-01-13 05:40:33 +01:00
if (
object.attributedTo &&
extractDbHost(getOneApId(object.attributedTo)) !== expectHost
) {
return new Error(
`invalid Note: attributedTo has different host. expected: ${expectHost}, actual: ${extractDbHost(
object.attributedTo,
)}`,
);
2019-05-09 08:43:31 +02:00
}
return null;
}
2018-04-08 21:08:56 +02:00
/**
2022-12-15 23:13:48 +01:00
* Fetch Notes.
*
* If the target Note is registered in Iceshrimp, it will be returned.
2022-12-15 23:13:48 +01:00
*/
2023-01-13 05:40:33 +01:00
export async function fetchNote(
object: string | IObject,
): Promise<Note | null> {
const dbResolver = new DbResolver();
return await dbResolver.getNoteFromApId(object);
2018-04-08 21:08:56 +02:00
}
/**
* Create a Note.
2018-04-08 21:08:56 +02:00
*/
2023-01-13 05:40:33 +01:00
export async function createNote(
value: string | IObject,
resolver?: Resolver,
silent = false,
): Promise<Note | null> {
2018-04-08 21:08:56 +02:00
if (resolver == null) resolver = new Resolver();
Enhance poll (#4409) * Start working * WIP: Enhance poll * Fix bug * Use `name` in voting note refs: https://github.com/syuilo/misskey/issues/4407#issuecomment-469057296 * Fix style * Refactor Co-authored-by: MeiMei <30769358+mei23@users.noreply.github.com> * WIP: Update poll editor * Fix bug * Fix bug refs: https://github.com/syuilo/misskey/pull/4409#discussion_r * Fix typo * Better design * Beautify poll editor * Fix UI * Fix bug refs: https://github.com/syuilo/misskey/pull/4409#discussion_r262217524 * Add debug logging * Fix bug * Log deliver * fix vote * Update ap/show refs: https://github.com/syuilo/misskey/pull/4409#issuecomment-469652386 * Update poll view * Maybe done * Add tests * Fix path * Fix test * Fix test * Fix test * Fix expired check on AP * Update note.ts * Squashed commit of the following: commit d9a4beabf851893b8992a0f4568265eb9d4f0b8e Author: mei23 <m@m544.net> Date: Wed Mar 6 05:16:14 2019 +0900 tune commit 83ff421a6e978243f80ba9ec820189bc897e6e3b Author: mei23 <m@m544.net> Date: Wed Mar 6 05:01:14 2019 +0900 fallback commit 0b566af973b115ade9e75ea4b8094ee2b329dabc Author: mei23 <m@m544.net> Date: Wed Mar 6 04:40:12 2019 +0900 Note commit cc0296dd6127580ac584c40398db3f762a311f8b Author: mei23 <m@m544.net> Date: Wed Mar 6 04:33:58 2019 +0900 createで送る * Squashed commit of the following: commit ae696b1ed12568b27c27367ac5a77035c97c9a1f Author: mei23 <m@m544.net> Date: Wed Mar 6 06:11:17 2019 +0900 fix commit b735e354e7a9e64534c4f17d04ecbc65fb735c21 Author: mei23 <m@m544.net> Date: Wed Mar 6 06:08:33 2019 +0900 messge commit d9a4beabf851893b8992a0f4568265eb9d4f0b8e Author: mei23 <m@m544.net> Date: Wed Mar 6 05:16:14 2019 +0900 tune commit 83ff421a6e978243f80ba9ec820189bc897e6e3b Author: mei23 <m@m544.net> Date: Wed Mar 6 05:01:14 2019 +0900 fallback commit 0b566af973b115ade9e75ea4b8094ee2b329dabc Author: mei23 <m@m544.net> Date: Wed Mar 6 04:40:12 2019 +0900 Note commit cc0296dd6127580ac584c40398db3f762a311f8b Author: mei23 <m@m544.net> Date: Wed Mar 6 04:33:58 2019 +0900 createで送る * Fix typo * Update vote.ts * Update vote.ts * Update poll-editor.vue * Update tslint.json * Fix layout * Add note * Fix bug * Rename text key * 投票するときに投稿として扱わないように (#4425) * wip * 形式をMastodonと合わせた * Bye something * Use - instead of ~ * Redundancy * Yes! * Refactor * Use moment instead of Date * Fix indent * Refactor if (votes.length) は必要なさそう * Clean up * Bye Date * Clean * Fix timer is not displayed * Fix リモートから無期限pollにvoteできない * Fix vote actor
2019-03-06 14:55:47 +01:00
const object: any = await resolver.resolve(value);
2018-04-08 21:08:56 +02:00
const entryUri = getApId(value);
2019-05-09 08:43:31 +02:00
const err = validateNote(object, entryUri);
if (err) {
logger.error(`${err.message}`, {
2019-03-04 06:02:42 +01:00
resolver: {
2021-12-09 15:58:30 +01:00
history: resolver.getHistory(),
2019-03-04 06:02:42 +01:00
},
value: value,
2021-12-09 15:58:30 +01:00
object: object,
2019-03-04 06:02:42 +01:00
});
2023-01-13 05:40:33 +01:00
throw new Error("invalid note");
2018-04-08 21:08:56 +02:00
}
const note: IPost = object;
2018-04-08 21:08:56 +02:00
2023-02-11 00:41:19 +01:00
if (note.id && !note.id.startsWith("https://")) {
2023-03-29 21:10:01 +02:00
throw new Error(`unexpected schema of note.id: ${note.id}`);
2023-02-10 20:14:33 +01:00
}
const url = getOneApHrefNullable(note.url);
2023-02-11 00:41:19 +01:00
if (url && !url.startsWith("https://")) {
2023-03-29 21:10:01 +02:00
throw new Error(`unexpected schema of note url: ${url}`);
2023-02-10 20:14:33 +01:00
}
Enhance poll (#4409) * Start working * WIP: Enhance poll * Fix bug * Use `name` in voting note refs: https://github.com/syuilo/misskey/issues/4407#issuecomment-469057296 * Fix style * Refactor Co-authored-by: MeiMei <30769358+mei23@users.noreply.github.com> * WIP: Update poll editor * Fix bug * Fix bug refs: https://github.com/syuilo/misskey/pull/4409#discussion_r * Fix typo * Better design * Beautify poll editor * Fix UI * Fix bug refs: https://github.com/syuilo/misskey/pull/4409#discussion_r262217524 * Add debug logging * Fix bug * Log deliver * fix vote * Update ap/show refs: https://github.com/syuilo/misskey/pull/4409#issuecomment-469652386 * Update poll view * Maybe done * Add tests * Fix path * Fix test * Fix test * Fix test * Fix expired check on AP * Update note.ts * Squashed commit of the following: commit d9a4beabf851893b8992a0f4568265eb9d4f0b8e Author: mei23 <m@m544.net> Date: Wed Mar 6 05:16:14 2019 +0900 tune commit 83ff421a6e978243f80ba9ec820189bc897e6e3b Author: mei23 <m@m544.net> Date: Wed Mar 6 05:01:14 2019 +0900 fallback commit 0b566af973b115ade9e75ea4b8094ee2b329dabc Author: mei23 <m@m544.net> Date: Wed Mar 6 04:40:12 2019 +0900 Note commit cc0296dd6127580ac584c40398db3f762a311f8b Author: mei23 <m@m544.net> Date: Wed Mar 6 04:33:58 2019 +0900 createで送る * Squashed commit of the following: commit ae696b1ed12568b27c27367ac5a77035c97c9a1f Author: mei23 <m@m544.net> Date: Wed Mar 6 06:11:17 2019 +0900 fix commit b735e354e7a9e64534c4f17d04ecbc65fb735c21 Author: mei23 <m@m544.net> Date: Wed Mar 6 06:08:33 2019 +0900 messge commit d9a4beabf851893b8992a0f4568265eb9d4f0b8e Author: mei23 <m@m544.net> Date: Wed Mar 6 05:16:14 2019 +0900 tune commit 83ff421a6e978243f80ba9ec820189bc897e6e3b Author: mei23 <m@m544.net> Date: Wed Mar 6 05:01:14 2019 +0900 fallback commit 0b566af973b115ade9e75ea4b8094ee2b329dabc Author: mei23 <m@m544.net> Date: Wed Mar 6 04:40:12 2019 +0900 Note commit cc0296dd6127580ac584c40398db3f762a311f8b Author: mei23 <m@m544.net> Date: Wed Mar 6 04:33:58 2019 +0900 createで送る * Fix typo * Update vote.ts * Update vote.ts * Update poll-editor.vue * Update tslint.json * Fix layout * Add note * Fix bug * Rename text key * 投票するときに投稿として扱わないように (#4425) * wip * 形式をMastodonと合わせた * Bye something * Use - instead of ~ * Redundancy * Yes! * Refactor * Use moment instead of Date * Fix indent * Refactor if (votes.length) は必要なさそう * Clean up * Bye Date * Clean * Fix timer is not displayed * Fix リモートから無期限pollにvoteできない * Fix vote actor
2019-03-06 14:55:47 +01:00
logger.debug(`Note fetched: ${JSON.stringify(note, null, 2)}`);
2019-02-03 08:45:13 +01:00
logger.info(`Creating the Note: ${note.id}`);
2018-04-08 21:08:56 +02:00
2023-02-11 12:13:55 +01:00
// Skip if note is made before 2007 (1yr before Fedi was created)
2023-02-11 12:26:05 +01:00
// OR skip if note is made 3 days in advance
2023-02-11 12:13:55 +01:00
if (note.published) {
2023-02-11 22:16:45 +01:00
const DateChecker = new Date(note.published);
const FutureCheck = new Date();
FutureCheck.setDate(FutureCheck.getDate() + 3); // Allow some wiggle room for misconfigured hosts
2023-02-11 12:13:55 +01:00
if (DateChecker.getFullYear() < 2007) {
2023-02-11 22:16:45 +01:00
logger.warn(
"Note somehow made before Activitypub was created; discarding",
);
2023-02-11 12:13:55 +01:00
return null;
}
2023-02-11 13:18:56 +01:00
if (DateChecker > FutureCheck) {
2023-02-11 22:16:45 +01:00
logger.warn("Note somehow made after today; discarding");
2023-02-11 12:26:05 +01:00
return null;
}
2023-02-11 12:13:55 +01:00
}
// Fetch author
2023-01-13 05:40:33 +01:00
const actor = (await resolvePerson(
getOneApId(note.attributedTo),
resolver,
)) as CacheableRemoteUser;
2018-04-08 21:08:56 +02:00
// Skip if author is suspended.
2018-04-19 11:54:34 +02:00
if (actor.isSuspended) {
2023-02-11 00:41:19 +01:00
logger.debug(
`User ${actor.usernameLower}@${actor.host} suspended; discarding.`,
);
2023-02-10 06:19:47 +01:00
return null;
2018-04-19 11:54:34 +02:00
}
const noteAudience = await parseAudience(actor, note.to, note.cc);
let visibility = noteAudience.visibility;
const visibleUsers = noteAudience.visibleUsers;
// If Audience (to, cc) was not specified
2023-01-13 05:40:33 +01:00
if (visibility === "specified" && visibleUsers.length === 0) {
if (typeof value === "string") {
// If the input is a string, GET occurs in resolver
// Public if you can GET anonymously from here
2023-01-13 05:40:33 +01:00
visibility = "public";
2018-04-28 21:44:58 +02:00
}
}
2023-01-13 05:40:33 +01:00
let isTalk = note._misskey_talk && visibility === "specified";
2020-02-06 09:11:02 +01:00
const apMentions = await extractApMentions(note.tag);
const apHashtags = await extractApHashtags(note.tag);
// Attachments
2018-04-08 21:08:56 +02:00
// TODO: attachmentは必ずしもImageではない
// TODO: attachmentは必ずしも配列ではない
2018-08-19 11:08:29 +02:00
// Noteがsensitiveなら添付もsensitiveにする
const limit = promiseLimit(2);
Enhance poll (#4409) * Start working * WIP: Enhance poll * Fix bug * Use `name` in voting note refs: https://github.com/syuilo/misskey/issues/4407#issuecomment-469057296 * Fix style * Refactor Co-authored-by: MeiMei <30769358+mei23@users.noreply.github.com> * WIP: Update poll editor * Fix bug * Fix bug refs: https://github.com/syuilo/misskey/pull/4409#discussion_r * Fix typo * Better design * Beautify poll editor * Fix UI * Fix bug refs: https://github.com/syuilo/misskey/pull/4409#discussion_r262217524 * Add debug logging * Fix bug * Log deliver * fix vote * Update ap/show refs: https://github.com/syuilo/misskey/pull/4409#issuecomment-469652386 * Update poll view * Maybe done * Add tests * Fix path * Fix test * Fix test * Fix test * Fix expired check on AP * Update note.ts * Squashed commit of the following: commit d9a4beabf851893b8992a0f4568265eb9d4f0b8e Author: mei23 <m@m544.net> Date: Wed Mar 6 05:16:14 2019 +0900 tune commit 83ff421a6e978243f80ba9ec820189bc897e6e3b Author: mei23 <m@m544.net> Date: Wed Mar 6 05:01:14 2019 +0900 fallback commit 0b566af973b115ade9e75ea4b8094ee2b329dabc Author: mei23 <m@m544.net> Date: Wed Mar 6 04:40:12 2019 +0900 Note commit cc0296dd6127580ac584c40398db3f762a311f8b Author: mei23 <m@m544.net> Date: Wed Mar 6 04:33:58 2019 +0900 createで送る * Squashed commit of the following: commit ae696b1ed12568b27c27367ac5a77035c97c9a1f Author: mei23 <m@m544.net> Date: Wed Mar 6 06:11:17 2019 +0900 fix commit b735e354e7a9e64534c4f17d04ecbc65fb735c21 Author: mei23 <m@m544.net> Date: Wed Mar 6 06:08:33 2019 +0900 messge commit d9a4beabf851893b8992a0f4568265eb9d4f0b8e Author: mei23 <m@m544.net> Date: Wed Mar 6 05:16:14 2019 +0900 tune commit 83ff421a6e978243f80ba9ec820189bc897e6e3b Author: mei23 <m@m544.net> Date: Wed Mar 6 05:01:14 2019 +0900 fallback commit 0b566af973b115ade9e75ea4b8094ee2b329dabc Author: mei23 <m@m544.net> Date: Wed Mar 6 04:40:12 2019 +0900 Note commit cc0296dd6127580ac584c40398db3f762a311f8b Author: mei23 <m@m544.net> Date: Wed Mar 6 04:33:58 2019 +0900 createで送る * Fix typo * Update vote.ts * Update vote.ts * Update poll-editor.vue * Update tslint.json * Fix layout * Add note * Fix bug * Rename text key * 投票するときに投稿として扱わないように (#4425) * wip * 形式をMastodonと合わせた * Bye something * Use - instead of ~ * Redundancy * Yes! * Refactor * Use moment instead of Date * Fix indent * Refactor if (votes.length) は必要なさそう * Clean up * Bye Date * Clean * Fix timer is not displayed * Fix リモートから無期限pollにvoteできない * Fix vote actor
2019-03-06 14:55:47 +01:00
2023-01-13 05:40:33 +01:00
note.attachment = Array.isArray(note.attachment)
? note.attachment
: note.attachment
? [note.attachment]
: [];
const files = note.attachment.map(
(attach) => (attach.sensitive = note.sensitive),
)
? (
await Promise.all(
note.attachment.map(
(x) => limit(() => resolveImage(actor, x)) as Promise<DriveFile>,
),
)
).filter((image) => image != null)
2018-04-08 21:08:56 +02:00
: [];
// Reply
const reply: Note | null = note.inReplyTo
2023-01-13 05:40:33 +01:00
? await resolveNote(note.inReplyTo, resolver)
.then((x) => {
if (x == null) {
logger.warn("Specified inReplyTo, but nout found");
throw new Error("inReplyTo not found");
} else {
return x;
}
})
.catch(async (e) => {
// トークだったらinReplyToのエラーは無視
const uri = getApId(note.inReplyTo);
if (uri.startsWith(`${config.url}/`)) {
const id = uri.split("/").pop();
const talk = await MessagingMessages.findOneBy({ id });
if (talk) {
isTalk = true;
return null;
}
}
logger.warn(
`Error in inReplyTo ${note.inReplyTo} - ${e.statusCode || e}`,
);
throw e;
})
: null;
2018-04-08 21:08:56 +02:00
// Quote
let quote: Note | undefined | null;
2018-11-22 18:10:07 +01:00
if (note._misskey_quote || note.quoteUrl || note.quoteUri) {
2023-01-13 05:40:33 +01:00
const tryResolveNote = async (
uri: string,
): Promise<
| {
status: "ok";
res: Note | null;
}
| {
status: "permerror" | "temperror";
}
> => {
if (typeof uri !== "string" || !uri.match(/^https?:/))
return { status: "permerror" };
try {
const res = await resolveNote(uri);
if (res) {
return {
2023-01-13 05:40:33 +01:00
status: "ok",
2021-12-09 15:58:30 +01:00
res,
};
} else {
return {
2023-01-13 05:40:33 +01:00
status: "permerror",
};
}
} catch (e) {
return {
2023-01-13 05:40:33 +01:00
status:
e instanceof StatusError && e.isClientError
? "permerror"
: "temperror",
};
2019-03-13 03:21:16 +01:00
}
};
2023-01-13 05:40:33 +01:00
const uris = unique(
[note._misskey_quote, note.quoteUrl, note.quoteUri].filter(
(x): x is string => typeof x === "string",
),
);
const results = await Promise.all(uris.map((uri) => tryResolveNote(uri)));
quote = results
.filter((x): x is { status: "ok"; res: Note | null } => x.status === "ok")
.map((x) => x.res)
.find((x) => x);
if (!quote) {
2023-01-13 05:40:33 +01:00
if (results.some((x) => x.status === "temperror")) {
throw new Error("quote resolve failed");
}
}
2018-11-22 18:10:07 +01:00
}
2023-01-13 05:40:33 +01:00
const cw = note.summary === "" ? null : note.summary;
2018-11-30 23:15:10 +01:00
// Text parsing
let text: string | null = null;
2023-01-13 05:40:33 +01:00
if (
note.source?.mediaType === "text/x.misskeymarkdown" &&
typeof note.source?.content === "string"
) {
text = note.source.content;
2023-01-13 05:40:33 +01:00
} else if (typeof note._misskey_content !== "undefined") {
text = note._misskey_content;
2023-01-13 05:40:33 +01:00
} else if (typeof note.content === "string") {
text = await htmlToMfm(note.content, note.tag);
}
2018-04-08 21:08:56 +02:00
// vote
2023-01-13 05:40:33 +01:00
if (reply?.hasPoll) {
const poll = await Polls.findOneByOrFail({ noteId: reply.id });
2023-01-13 05:40:33 +01:00
const tryCreateVote = async (
name: string,
index: number,
): Promise<null> => {
Use PostgreSQL instead of MongoDB (#4572) * wip * Update note.ts * Update timeline.ts * Update core.ts * wip * Update generate-visibility-query.ts * wip * wip * wip * wip * wip * Update global-timeline.ts * wip * wip * wip * Update vote.ts * wip * wip * Update create.ts * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * Update files.ts * wip * wip * Update CONTRIBUTING.md * wip * wip * wip * wip * wip * wip * wip * wip * Update read-notification.ts * wip * wip * wip * wip * wip * wip * wip * Update cancel.ts * wip * wip * wip * Update show.ts * wip * wip * Update gen-id.ts * Update create.ts * Update id.ts * wip * wip * wip * wip * wip * wip * wip * Docker: Update files about Docker (#4599) * Docker: Use cache if files used by `yarn install` was not updated This patch reduces the number of times to installing node_modules. For example, `yarn install` step will be skipped when only ".config/default.yml" is updated. * Docker: Migrate MongoDB to Postgresql Misskey uses Postgresql as a database instead of Mongodb since version 11. * Docker: Uncomment about data persistence This patch will save a lot of databases. * wip * wip * wip * Update activitypub.ts * wip * wip * wip * Update logs.ts * wip * Update drive-file.ts * Update register.ts * wip * wip * Update mentions.ts * wip * wip * wip * Update recommendation.ts * wip * Update index.ts * wip * Update recommendation.ts * Doc: Update docker.ja.md and docker.en.md (#1) (#4608) Update how to set up misskey. * wip * :v: * wip * Update note.ts * Update postgre.ts * wip * wip * wip * wip * Update add-file.ts * wip * wip * wip * Clean up * Update logs.ts * wip * :pizza: * wip * Ad notes * wip * Update api-visibility.ts * Update note.ts * Update add-file.ts * tests * tests * Update postgre.ts * Update utils.ts * wip * wip * Refactor * wip * Refactor * wip * wip * Update show-users.ts * Update update-instance.ts * wip * Update feed.ts * Update outbox.ts * Update outbox.ts * Update user.ts * wip * Update list.ts * Update update-hashtag.ts * wip * Update update-hashtag.ts * Refactor * Update update.ts * wip * wip * :v: * clean up * docs * Update push.ts * wip * Update api.ts * wip * :v: * Update make-pagination-query.ts * :v: * Delete hashtags.ts * Update instances.ts * Update instances.ts * Update create.ts * Update search.ts * Update reversi-game.ts * Update signup.ts * Update user.ts * id * Update example.yml * :art: * objectid * fix * reversi * reversi * Fix bug of chart engine * Add test of chart engine * Improve test * Better testing * Improve chart engine * Refactor * Add test of chart engine * Refactor * Add chart test * Fix bug * コミットし忘れ * Refactoring * :v: * Add tests * Add test * Extarct note tests * Refactor * 存在しないユーザーにメンションできなくなっていた問題を修正 * Fix bug * Update update-meta.ts * Fix bug * Update mention.vue * Fix bug * Update meta.ts * Update CONTRIBUTING.md * Fix bug * Fix bug * Fix bug * Clean up * Clean up * Update notification.ts * Clean up * Add mute tests * Add test * Refactor * Add test * Fix test * Refactor * Refactor * Add tests * Update utils.ts * Update utils.ts * Fix test * Update package.json * Update update.ts * Update manifest.ts * Fix bug * Fix bug * Add test * :art: * Update endpoint permissions * Updaye permisison * Update person.ts #4299 * データベースと同期しないように * Fix bug * Fix bug * Update reversi-game.ts * Use a feature of Node v11.7.0 to extract a public key (#4644) * wip * wip * :v: * Refactoring #1540 * test * test * test * test * test * test * test * Fix bug * Fix test * :sushi: * wip * #4471 * Add test for #4335 * Refactor * Fix test * Add tests * :clock4: * Fix bug * Add test * Add test * rename * Fix bug
2019-04-07 14:50:36 +02:00
if (poll.expiresAt && Date.now() > new Date(poll.expiresAt).getTime()) {
2023-01-13 05:40:33 +01:00
logger.warn(
`vote to expired poll from AP: actor=${actor.username}@${actor.host}, note=${note.id}, choice=${name}`,
);
Enhance poll (#4409) * Start working * WIP: Enhance poll * Fix bug * Use `name` in voting note refs: https://github.com/syuilo/misskey/issues/4407#issuecomment-469057296 * Fix style * Refactor Co-authored-by: MeiMei <30769358+mei23@users.noreply.github.com> * WIP: Update poll editor * Fix bug * Fix bug refs: https://github.com/syuilo/misskey/pull/4409#discussion_r * Fix typo * Better design * Beautify poll editor * Fix UI * Fix bug refs: https://github.com/syuilo/misskey/pull/4409#discussion_r262217524 * Add debug logging * Fix bug * Log deliver * fix vote * Update ap/show refs: https://github.com/syuilo/misskey/pull/4409#issuecomment-469652386 * Update poll view * Maybe done * Add tests * Fix path * Fix test * Fix test * Fix test * Fix expired check on AP * Update note.ts * Squashed commit of the following: commit d9a4beabf851893b8992a0f4568265eb9d4f0b8e Author: mei23 <m@m544.net> Date: Wed Mar 6 05:16:14 2019 +0900 tune commit 83ff421a6e978243f80ba9ec820189bc897e6e3b Author: mei23 <m@m544.net> Date: Wed Mar 6 05:01:14 2019 +0900 fallback commit 0b566af973b115ade9e75ea4b8094ee2b329dabc Author: mei23 <m@m544.net> Date: Wed Mar 6 04:40:12 2019 +0900 Note commit cc0296dd6127580ac584c40398db3f762a311f8b Author: mei23 <m@m544.net> Date: Wed Mar 6 04:33:58 2019 +0900 createで送る * Squashed commit of the following: commit ae696b1ed12568b27c27367ac5a77035c97c9a1f Author: mei23 <m@m544.net> Date: Wed Mar 6 06:11:17 2019 +0900 fix commit b735e354e7a9e64534c4f17d04ecbc65fb735c21 Author: mei23 <m@m544.net> Date: Wed Mar 6 06:08:33 2019 +0900 messge commit d9a4beabf851893b8992a0f4568265eb9d4f0b8e Author: mei23 <m@m544.net> Date: Wed Mar 6 05:16:14 2019 +0900 tune commit 83ff421a6e978243f80ba9ec820189bc897e6e3b Author: mei23 <m@m544.net> Date: Wed Mar 6 05:01:14 2019 +0900 fallback commit 0b566af973b115ade9e75ea4b8094ee2b329dabc Author: mei23 <m@m544.net> Date: Wed Mar 6 04:40:12 2019 +0900 Note commit cc0296dd6127580ac584c40398db3f762a311f8b Author: mei23 <m@m544.net> Date: Wed Mar 6 04:33:58 2019 +0900 createで送る * Fix typo * Update vote.ts * Update vote.ts * Update poll-editor.vue * Update tslint.json * Fix layout * Add note * Fix bug * Rename text key * 投票するときに投稿として扱わないように (#4425) * wip * 形式をMastodonと合わせた * Bye something * Use - instead of ~ * Redundancy * Yes! * Refactor * Use moment instead of Date * Fix indent * Refactor if (votes.length) は必要なさそう * Clean up * Bye Date * Clean * Fix timer is not displayed * Fix リモートから無期限pollにvoteできない * Fix vote actor
2019-03-06 14:55:47 +01:00
} else if (index >= 0) {
2023-01-13 05:40:33 +01:00
logger.info(
`vote from AP: actor=${actor.username}@${actor.host}, note=${note.id}, choice=${name}`,
);
Enhance poll (#4409) * Start working * WIP: Enhance poll * Fix bug * Use `name` in voting note refs: https://github.com/syuilo/misskey/issues/4407#issuecomment-469057296 * Fix style * Refactor Co-authored-by: MeiMei <30769358+mei23@users.noreply.github.com> * WIP: Update poll editor * Fix bug * Fix bug refs: https://github.com/syuilo/misskey/pull/4409#discussion_r * Fix typo * Better design * Beautify poll editor * Fix UI * Fix bug refs: https://github.com/syuilo/misskey/pull/4409#discussion_r262217524 * Add debug logging * Fix bug * Log deliver * fix vote * Update ap/show refs: https://github.com/syuilo/misskey/pull/4409#issuecomment-469652386 * Update poll view * Maybe done * Add tests * Fix path * Fix test * Fix test * Fix test * Fix expired check on AP * Update note.ts * Squashed commit of the following: commit d9a4beabf851893b8992a0f4568265eb9d4f0b8e Author: mei23 <m@m544.net> Date: Wed Mar 6 05:16:14 2019 +0900 tune commit 83ff421a6e978243f80ba9ec820189bc897e6e3b Author: mei23 <m@m544.net> Date: Wed Mar 6 05:01:14 2019 +0900 fallback commit 0b566af973b115ade9e75ea4b8094ee2b329dabc Author: mei23 <m@m544.net> Date: Wed Mar 6 04:40:12 2019 +0900 Note commit cc0296dd6127580ac584c40398db3f762a311f8b Author: mei23 <m@m544.net> Date: Wed Mar 6 04:33:58 2019 +0900 createで送る * Squashed commit of the following: commit ae696b1ed12568b27c27367ac5a77035c97c9a1f Author: mei23 <m@m544.net> Date: Wed Mar 6 06:11:17 2019 +0900 fix commit b735e354e7a9e64534c4f17d04ecbc65fb735c21 Author: mei23 <m@m544.net> Date: Wed Mar 6 06:08:33 2019 +0900 messge commit d9a4beabf851893b8992a0f4568265eb9d4f0b8e Author: mei23 <m@m544.net> Date: Wed Mar 6 05:16:14 2019 +0900 tune commit 83ff421a6e978243f80ba9ec820189bc897e6e3b Author: mei23 <m@m544.net> Date: Wed Mar 6 05:01:14 2019 +0900 fallback commit 0b566af973b115ade9e75ea4b8094ee2b329dabc Author: mei23 <m@m544.net> Date: Wed Mar 6 04:40:12 2019 +0900 Note commit cc0296dd6127580ac584c40398db3f762a311f8b Author: mei23 <m@m544.net> Date: Wed Mar 6 04:33:58 2019 +0900 createで送る * Fix typo * Update vote.ts * Update vote.ts * Update poll-editor.vue * Update tslint.json * Fix layout * Add note * Fix bug * Rename text key * 投票するときに投稿として扱わないように (#4425) * wip * 形式をMastodonと合わせた * Bye something * Use - instead of ~ * Redundancy * Yes! * Refactor * Use moment instead of Date * Fix indent * Refactor if (votes.length) は必要なさそう * Clean up * Bye Date * Clean * Fix timer is not displayed * Fix リモートから無期限pollにvoteできない * Fix vote actor
2019-03-06 14:55:47 +01:00
await vote(actor, reply, index);
}
return null;
Enhance poll (#4409) * Start working * WIP: Enhance poll * Fix bug * Use `name` in voting note refs: https://github.com/syuilo/misskey/issues/4407#issuecomment-469057296 * Fix style * Refactor Co-authored-by: MeiMei <30769358+mei23@users.noreply.github.com> * WIP: Update poll editor * Fix bug * Fix bug refs: https://github.com/syuilo/misskey/pull/4409#discussion_r * Fix typo * Better design * Beautify poll editor * Fix UI * Fix bug refs: https://github.com/syuilo/misskey/pull/4409#discussion_r262217524 * Add debug logging * Fix bug * Log deliver * fix vote * Update ap/show refs: https://github.com/syuilo/misskey/pull/4409#issuecomment-469652386 * Update poll view * Maybe done * Add tests * Fix path * Fix test * Fix test * Fix test * Fix expired check on AP * Update note.ts * Squashed commit of the following: commit d9a4beabf851893b8992a0f4568265eb9d4f0b8e Author: mei23 <m@m544.net> Date: Wed Mar 6 05:16:14 2019 +0900 tune commit 83ff421a6e978243f80ba9ec820189bc897e6e3b Author: mei23 <m@m544.net> Date: Wed Mar 6 05:01:14 2019 +0900 fallback commit 0b566af973b115ade9e75ea4b8094ee2b329dabc Author: mei23 <m@m544.net> Date: Wed Mar 6 04:40:12 2019 +0900 Note commit cc0296dd6127580ac584c40398db3f762a311f8b Author: mei23 <m@m544.net> Date: Wed Mar 6 04:33:58 2019 +0900 createで送る * Squashed commit of the following: commit ae696b1ed12568b27c27367ac5a77035c97c9a1f Author: mei23 <m@m544.net> Date: Wed Mar 6 06:11:17 2019 +0900 fix commit b735e354e7a9e64534c4f17d04ecbc65fb735c21 Author: mei23 <m@m544.net> Date: Wed Mar 6 06:08:33 2019 +0900 messge commit d9a4beabf851893b8992a0f4568265eb9d4f0b8e Author: mei23 <m@m544.net> Date: Wed Mar 6 05:16:14 2019 +0900 tune commit 83ff421a6e978243f80ba9ec820189bc897e6e3b Author: mei23 <m@m544.net> Date: Wed Mar 6 05:01:14 2019 +0900 fallback commit 0b566af973b115ade9e75ea4b8094ee2b329dabc Author: mei23 <m@m544.net> Date: Wed Mar 6 04:40:12 2019 +0900 Note commit cc0296dd6127580ac584c40398db3f762a311f8b Author: mei23 <m@m544.net> Date: Wed Mar 6 04:33:58 2019 +0900 createで送る * Fix typo * Update vote.ts * Update vote.ts * Update poll-editor.vue * Update tslint.json * Fix layout * Add note * Fix bug * Rename text key * 投票するときに投稿として扱わないように (#4425) * wip * 形式をMastodonと合わせた * Bye something * Use - instead of ~ * Redundancy * Yes! * Refactor * Use moment instead of Date * Fix indent * Refactor if (votes.length) は必要なさそう * Clean up * Bye Date * Clean * Fix timer is not displayed * Fix リモートから無期限pollにvoteできない * Fix vote actor
2019-03-06 14:55:47 +01:00
};
if (note.name) {
2023-01-13 05:40:33 +01:00
return await tryCreateVote(
note.name,
poll.choices.findIndex((x) => x === note.name),
);
Enhance poll (#4409) * Start working * WIP: Enhance poll * Fix bug * Use `name` in voting note refs: https://github.com/syuilo/misskey/issues/4407#issuecomment-469057296 * Fix style * Refactor Co-authored-by: MeiMei <30769358+mei23@users.noreply.github.com> * WIP: Update poll editor * Fix bug * Fix bug refs: https://github.com/syuilo/misskey/pull/4409#discussion_r * Fix typo * Better design * Beautify poll editor * Fix UI * Fix bug refs: https://github.com/syuilo/misskey/pull/4409#discussion_r262217524 * Add debug logging * Fix bug * Log deliver * fix vote * Update ap/show refs: https://github.com/syuilo/misskey/pull/4409#issuecomment-469652386 * Update poll view * Maybe done * Add tests * Fix path * Fix test * Fix test * Fix test * Fix expired check on AP * Update note.ts * Squashed commit of the following: commit d9a4beabf851893b8992a0f4568265eb9d4f0b8e Author: mei23 <m@m544.net> Date: Wed Mar 6 05:16:14 2019 +0900 tune commit 83ff421a6e978243f80ba9ec820189bc897e6e3b Author: mei23 <m@m544.net> Date: Wed Mar 6 05:01:14 2019 +0900 fallback commit 0b566af973b115ade9e75ea4b8094ee2b329dabc Author: mei23 <m@m544.net> Date: Wed Mar 6 04:40:12 2019 +0900 Note commit cc0296dd6127580ac584c40398db3f762a311f8b Author: mei23 <m@m544.net> Date: Wed Mar 6 04:33:58 2019 +0900 createで送る * Squashed commit of the following: commit ae696b1ed12568b27c27367ac5a77035c97c9a1f Author: mei23 <m@m544.net> Date: Wed Mar 6 06:11:17 2019 +0900 fix commit b735e354e7a9e64534c4f17d04ecbc65fb735c21 Author: mei23 <m@m544.net> Date: Wed Mar 6 06:08:33 2019 +0900 messge commit d9a4beabf851893b8992a0f4568265eb9d4f0b8e Author: mei23 <m@m544.net> Date: Wed Mar 6 05:16:14 2019 +0900 tune commit 83ff421a6e978243f80ba9ec820189bc897e6e3b Author: mei23 <m@m544.net> Date: Wed Mar 6 05:01:14 2019 +0900 fallback commit 0b566af973b115ade9e75ea4b8094ee2b329dabc Author: mei23 <m@m544.net> Date: Wed Mar 6 04:40:12 2019 +0900 Note commit cc0296dd6127580ac584c40398db3f762a311f8b Author: mei23 <m@m544.net> Date: Wed Mar 6 04:33:58 2019 +0900 createで送る * Fix typo * Update vote.ts * Update vote.ts * Update poll-editor.vue * Update tslint.json * Fix layout * Add note * Fix bug * Rename text key * 投票するときに投稿として扱わないように (#4425) * wip * 形式をMastodonと合わせた * Bye something * Use - instead of ~ * Redundancy * Yes! * Refactor * Use moment instead of Date * Fix indent * Refactor if (votes.length) は必要なさそう * Clean up * Bye Date * Clean * Fix timer is not displayed * Fix リモートから無期限pollにvoteできない * Fix vote actor
2019-03-06 14:55:47 +01:00
}
}
2023-01-13 05:40:33 +01:00
const emojis = await extractEmojis(note.tag || [], actor.host).catch((e) => {
2019-02-03 08:45:13 +01:00
logger.info(`extractEmojis: ${e}`);
Use PostgreSQL instead of MongoDB (#4572) * wip * Update note.ts * Update timeline.ts * Update core.ts * wip * Update generate-visibility-query.ts * wip * wip * wip * wip * wip * Update global-timeline.ts * wip * wip * wip * Update vote.ts * wip * wip * Update create.ts * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * Update files.ts * wip * wip * Update CONTRIBUTING.md * wip * wip * wip * wip * wip * wip * wip * wip * Update read-notification.ts * wip * wip * wip * wip * wip * wip * wip * Update cancel.ts * wip * wip * wip * Update show.ts * wip * wip * Update gen-id.ts * Update create.ts * Update id.ts * wip * wip * wip * wip * wip * wip * wip * Docker: Update files about Docker (#4599) * Docker: Use cache if files used by `yarn install` was not updated This patch reduces the number of times to installing node_modules. For example, `yarn install` step will be skipped when only ".config/default.yml" is updated. * Docker: Migrate MongoDB to Postgresql Misskey uses Postgresql as a database instead of Mongodb since version 11. * Docker: Uncomment about data persistence This patch will save a lot of databases. * wip * wip * wip * Update activitypub.ts * wip * wip * wip * Update logs.ts * wip * Update drive-file.ts * Update register.ts * wip * wip * Update mentions.ts * wip * wip * wip * Update recommendation.ts * wip * Update index.ts * wip * Update recommendation.ts * Doc: Update docker.ja.md and docker.en.md (#1) (#4608) Update how to set up misskey. * wip * :v: * wip * Update note.ts * Update postgre.ts * wip * wip * wip * wip * Update add-file.ts * wip * wip * wip * Clean up * Update logs.ts * wip * :pizza: * wip * Ad notes * wip * Update api-visibility.ts * Update note.ts * Update add-file.ts * tests * tests * Update postgre.ts * Update utils.ts * wip * wip * Refactor * wip * Refactor * wip * wip * Update show-users.ts * Update update-instance.ts * wip * Update feed.ts * Update outbox.ts * Update outbox.ts * Update user.ts * wip * Update list.ts * Update update-hashtag.ts * wip * Update update-hashtag.ts * Refactor * Update update.ts * wip * wip * :v: * clean up * docs * Update push.ts * wip * Update api.ts * wip * :v: * Update make-pagination-query.ts * :v: * Delete hashtags.ts * Update instances.ts * Update instances.ts * Update create.ts * Update search.ts * Update reversi-game.ts * Update signup.ts * Update user.ts * id * Update example.yml * :art: * objectid * fix * reversi * reversi * Fix bug of chart engine * Add test of chart engine * Improve test * Better testing * Improve chart engine * Refactor * Add test of chart engine * Refactor * Add chart test * Fix bug * コミットし忘れ * Refactoring * :v: * Add tests * Add test * Extarct note tests * Refactor * 存在しないユーザーにメンションできなくなっていた問題を修正 * Fix bug * Update update-meta.ts * Fix bug * Update mention.vue * Fix bug * Update meta.ts * Update CONTRIBUTING.md * Fix bug * Fix bug * Fix bug * Clean up * Clean up * Update notification.ts * Clean up * Add mute tests * Add test * Refactor * Add test * Fix test * Refactor * Refactor * Add tests * Update utils.ts * Update utils.ts * Fix test * Update package.json * Update update.ts * Update manifest.ts * Fix bug * Fix bug * Add test * :art: * Update endpoint permissions * Updaye permisison * Update person.ts #4299 * データベースと同期しないように * Fix bug * Fix bug * Update reversi-game.ts * Use a feature of Node v11.7.0 to extract a public key (#4644) * wip * wip * :v: * Refactoring #1540 * test * test * test * test * test * test * test * Fix bug * Fix test * :sushi: * wip * #4471 * Add test for #4335 * Refactor * Fix test * Add tests * :clock4: * Fix bug * Add test * Add test * rename * Fix bug
2019-04-07 14:50:36 +02:00
return [] as Emoji[];
});
2023-01-13 05:40:33 +01:00
const apEmojis = emojis.map((emoji) => emoji.name);
2023-01-13 05:40:33 +01:00
const poll = await extractPollFromQuestion(note, resolver).catch(
() => undefined,
);
2020-02-06 09:11:02 +01:00
if (isTalk) {
2019-10-28 22:01:14 +01:00
for (const recipient of visibleUsers) {
2023-01-13 05:40:33 +01:00
await createMessage(
actor,
recipient,
undefined,
text || undefined,
files && files.length > 0 ? files[0] : null,
object.id,
);
2019-10-28 22:01:14 +01:00
return null;
}
}
2023-01-13 05:40:33 +01:00
return await post(
actor,
{
createdAt: note.published ? new Date(note.published) : null,
files,
reply,
renote: quote,
name: note.name,
cw,
text,
localOnly: false,
visibility,
visibleUsers,
apMentions,
apHashtags,
apEmojis,
poll,
uri: note.id,
2023-02-10 20:14:33 +01:00
url: url,
2023-01-13 05:40:33 +01:00
},
silent,
);
2018-04-08 21:08:56 +02:00
}
/**
2022-12-15 23:13:48 +01:00
* Resolve Note.
*
* If the target Note is registered in Iceshrimp, return it, otherwise
* Fetch from remote server, register with Iceshrimp and return it.
2022-12-15 23:13:48 +01:00
*/
2023-01-13 05:40:33 +01:00
export async function resolveNote(
value: string | IObject,
resolver?: Resolver,
): Promise<Note | null> {
const uri = typeof value === "string" ? value : value.id;
if (uri == null) throw new Error("missing uri");
2018-04-08 21:08:56 +02:00
// Abort if origin host is blocked
2023-01-13 05:40:33 +01:00
if (await shouldBlockInstance(extractDbHost(uri)))
throw new StatusError(
"host blocked",
451,
`host ${extractDbHost(uri)} is blocked`,
);
2019-03-13 03:21:16 +01:00
2019-09-09 15:46:45 +02:00
const unlock = await getApLock(uri);
2018-04-08 21:08:56 +02:00
2019-09-09 15:46:45 +02:00
try {
//#region Returns if already registered with this server
2019-09-09 15:46:45 +02:00
const exist = await fetchNote(uri);
2018-04-08 21:08:56 +02:00
2019-09-09 15:46:45 +02:00
if (exist) {
return exist;
2019-04-12 06:07:56 +02:00
}
2019-09-09 15:46:45 +02:00
//#endregion
if (uri.startsWith(config.url)) {
2023-01-13 05:40:33 +01:00
throw new StatusError(
"cannot resolve local note",
400,
"cannot resolve local note",
);
}
// Fetch from remote server and register
// If the attached `Note` Object is specified here instead of the uri, the note will be generated without going through the server fetch.
// Since the attached Note Object may be disguised, always specify the uri and fetch it from the server.
2019-09-09 15:46:45 +02:00
return await createNote(uri, resolver, true);
} finally {
unlock();
}
2018-04-08 21:08:56 +02:00
}
2023-01-13 05:40:33 +01:00
export async function extractEmojis(
tags: IObject | IObject[],
host: string,
): Promise<Emoji[]> {
2019-04-09 17:59:41 +02:00
host = toPuny(host);
if (!tags) return [];
const eomjiTags = toArray(tags).filter(isEmoji);
2023-01-13 05:40:33 +01:00
return await Promise.all(
eomjiTags.map(async (tag) => {
const name = tag.name!.replace(/^:/, "").replace(/:$/, "");
tag.icon = toSingle(tag.icon);
const exists = await Emojis.findOneBy({
host,
name,
});
if (exists) {
if (
(tag.updated != null && exists.updatedAt == null) ||
(tag.id != null && exists.uri == null) ||
(tag.updated != null &&
exists.updatedAt != null &&
new Date(tag.updated) > exists.updatedAt) ||
2023-05-20 04:26:13 +02:00
tag.icon!.url !== exists.originalUrl ||
!(exists.width && exists.height)
2023-01-13 05:40:33 +01:00
) {
2023-05-20 04:26:13 +02:00
let size: Size = { width: 0, height: 0 };
try {
size = await getEmojiSize(tag.icon!.url);
} catch {
/* skip if any error happens */
}
2023-01-13 05:40:33 +01:00
await Emojis.update(
{
host,
name,
},
{
uri: tag.id,
originalUrl: tag.icon!.url,
publicUrl: tag.icon!.url,
updatedAt: new Date(),
2023-05-20 04:26:13 +02:00
width: size.width || null,
height: size.height || null,
2023-01-13 05:40:33 +01:00
},
);
return (await Emojis.findOneBy({
host,
name,
})) as Emoji;
}
Use PostgreSQL instead of MongoDB (#4572) * wip * Update note.ts * Update timeline.ts * Update core.ts * wip * Update generate-visibility-query.ts * wip * wip * wip * wip * wip * Update global-timeline.ts * wip * wip * wip * Update vote.ts * wip * wip * Update create.ts * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * Update files.ts * wip * wip * Update CONTRIBUTING.md * wip * wip * wip * wip * wip * wip * wip * wip * Update read-notification.ts * wip * wip * wip * wip * wip * wip * wip * Update cancel.ts * wip * wip * wip * Update show.ts * wip * wip * Update gen-id.ts * Update create.ts * Update id.ts * wip * wip * wip * wip * wip * wip * wip * Docker: Update files about Docker (#4599) * Docker: Use cache if files used by `yarn install` was not updated This patch reduces the number of times to installing node_modules. For example, `yarn install` step will be skipped when only ".config/default.yml" is updated. * Docker: Migrate MongoDB to Postgresql Misskey uses Postgresql as a database instead of Mongodb since version 11. * Docker: Uncomment about data persistence This patch will save a lot of databases. * wip * wip * wip * Update activitypub.ts * wip * wip * wip * Update logs.ts * wip * Update drive-file.ts * Update register.ts * wip * wip * Update mentions.ts * wip * wip * wip * Update recommendation.ts * wip * Update index.ts * wip * Update recommendation.ts * Doc: Update docker.ja.md and docker.en.md (#1) (#4608) Update how to set up misskey. * wip * :v: * wip * Update note.ts * Update postgre.ts * wip * wip * wip * wip * Update add-file.ts * wip * wip * wip * Clean up * Update logs.ts * wip * :pizza: * wip * Ad notes * wip * Update api-visibility.ts * Update note.ts * Update add-file.ts * tests * tests * Update postgre.ts * Update utils.ts * wip * wip * Refactor * wip * Refactor * wip * wip * Update show-users.ts * Update update-instance.ts * wip * Update feed.ts * Update outbox.ts * Update outbox.ts * Update user.ts * wip * Update list.ts * Update update-hashtag.ts * wip * Update update-hashtag.ts * Refactor * Update update.ts * wip * wip * :v: * clean up * docs * Update push.ts * wip * Update api.ts * wip * :v: * Update make-pagination-query.ts * :v: * Delete hashtags.ts * Update instances.ts * Update instances.ts * Update create.ts * Update search.ts * Update reversi-game.ts * Update signup.ts * Update user.ts * id * Update example.yml * :art: * objectid * fix * reversi * reversi * Fix bug of chart engine * Add test of chart engine * Improve test * Better testing * Improve chart engine * Refactor * Add test of chart engine * Refactor * Add chart test * Fix bug * コミットし忘れ * Refactoring * :v: * Add tests * Add test * Extarct note tests * Refactor * 存在しないユーザーにメンションできなくなっていた問題を修正 * Fix bug * Update update-meta.ts * Fix bug * Update mention.vue * Fix bug * Update meta.ts * Update CONTRIBUTING.md * Fix bug * Fix bug * Fix bug * Clean up * Clean up * Update notification.ts * Clean up * Add mute tests * Add test * Refactor * Add test * Fix test * Refactor * Refactor * Add tests * Update utils.ts * Update utils.ts * Fix test * Update package.json * Update update.ts * Update manifest.ts * Fix bug * Fix bug * Add test * :art: * Update endpoint permissions * Updaye permisison * Update person.ts #4299 * データベースと同期しないように * Fix bug * Fix bug * Update reversi-game.ts * Use a feature of Node v11.7.0 to extract a public key (#4644) * wip * wip * :v: * Refactoring #1540 * test * test * test * test * test * test * test * Fix bug * Fix test * :sushi: * wip * #4471 * Add test for #4335 * Refactor * Fix test * Add tests * :clock4: * Fix bug * Add test * Add test * rename * Fix bug
2019-04-07 14:50:36 +02:00
2023-01-13 05:40:33 +01:00
return exists;
}
2023-01-13 05:40:33 +01:00
logger.info(`register emoji host=${host}, name=${name}`);
2023-05-20 04:26:13 +02:00
let size: Size = { width: 0, height: 0 };
try {
size = await getEmojiSize(tag.icon!.url);
} catch {
/* skip if any error happens */
}
2023-01-13 05:40:33 +01:00
return await Emojis.insert({
id: genId(),
host,
name,
uri: tag.id,
originalUrl: tag.icon!.url,
publicUrl: tag.icon!.url,
updatedAt: new Date(),
aliases: [],
2023-05-20 04:26:13 +02:00
width: size.width || null,
height: size.height || null,
2023-01-13 05:40:33 +01:00
} as Partial<Emoji>).then((x) =>
Emojis.findOneByOrFail(x.identifiers[0]),
);
}),
);
}
2023-04-30 18:29:50 +02:00
type TagDetail = {
type: string;
name: string;
};
2023-05-02 09:37:48 +02:00
function notEmpty(partial: Partial<any>) {
return Object.keys(partial).length > 0;
}
2023-04-30 18:29:50 +02:00
export async function updateNote(value: string | IObject, resolver?: Resolver) {
const uri = typeof value === "string" ? value : value.id;
if (!uri) throw new Error("Missing note uri");
// Skip if URI points to this server
if (uri.startsWith(`${config.url}/`)) throw new Error("uri points local");
// A new resolver is created if not specified
if (resolver == null) resolver = new Resolver();
// Resolve the updated Note object
const post = (await resolver.resolve(value)) as IPost;
const actor = (await resolvePerson(
getOneApId(post.attributedTo),
resolver,
)) as CacheableRemoteUser;
// Already registered with this server?
const note = await Notes.findOneBy({ uri });
if (note == null) {
return await createNote(post, resolver);
}
2023-05-02 09:37:48 +02:00
// Whether to tell clients the note has been updated and requires refresh.
let publishing = false;
2023-04-30 18:29:50 +02:00
// Text parsing
let text: string | null = null;
if (
post.source?.mediaType === "text/x.misskeymarkdown" &&
typeof post.source?.content === "string"
) {
text = post.source.content;
} else if (typeof post._misskey_content !== "undefined") {
text = post._misskey_content;
} else if (typeof post.content === "string") {
text = await htmlToMfm(post.content, post.tag);
2023-04-30 18:29:50 +02:00
}
const cw = post.sensitive && post.summary;
// File parsing
const fileList = post.attachment
? Array.isArray(post.attachment)
? post.attachment
: [post.attachment]
: [];
const files = fileList.map((f) => (f.sensitive = post.sensitive));
// Fetch files
const limit = promiseLimit(2);
const driveFiles = (
await Promise.all(
fileList.map(
2023-05-02 09:37:48 +02:00
(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;
}
2023-05-02 10:22:42 +02:00
// Don't unmark previously marked sensitive files,
// but if edited post contains sensitive marker, update it.
if (post.sensitive && !file.isSensitive) {
update.isSensitive = post.sensitive;
}
2023-05-02 09:37:48 +02:00
if (notEmpty(update)) {
await DriveFiles.update(file.id, update);
publishing = true;
}
return file;
}) as Promise<DriveFile>,
2023-04-30 18:29:50 +02:00
),
)
).filter((file) => file != null);
const fileIds = driveFiles.map((file) => file.id);
const fileTypes = driveFiles.map((file) => file.type);
const apEmojis = (
await extractEmojis(post.tag || [], actor.host).catch((e) => [])
).map((emoji) => emoji.name);
const apMentions = await extractApMentions(post.tag);
const apHashtags = await extractApHashtags(post.tag);
const poll = await extractPollFromQuestion(post, resolver).catch(
() => undefined,
);
const choices = poll?.choices.flatMap((choice) => mfm.parse(choice)) ?? [];
2023-04-30 18:29:50 +02:00
const tokens = mfm
.parse(text || "")
.concat(mfm.parse(cw || ""))
.concat(choices);
const hashTags: string[] = apHashtags || extractHashtags(tokens);
const mentionUsers =
apMentions || (await extractMentionedUsers(actor, tokens));
const mentionUserIds = mentionUsers.map((user) => user.id);
const remoteUsers = mentionUsers.filter((user) => user.host != null);
const remoteUserIds = remoteUsers.map((user) => user.id);
const remoteProfiles = await UserProfiles.findBy({
userId: In(remoteUserIds),
});
const mentionedRemoteUsers = remoteUsers.map((user) => {
const profile = remoteProfiles.find(
(profile) => profile.userId === user.id,
);
return {
username: user.username,
host: user.host ?? null,
uri: user.uri,
url: profile ? profile.url : undefined,
} as IMentionedRemoteUsers[0];
});
const update = {} as Partial<Note>;
if (text && text !== note.text) {
update.text = text;
}
if (cw !== note.cw) {
update.cw = cw ? cw : null;
}
if (fileIds.sort().join(",") !== note.fileIds.sort().join(",")) {
update.fileIds = fileIds;
update.attachedFileTypes = fileTypes;
}
if (hashTags.sort().join(",") !== note.tags.sort().join(",")) {
update.tags = hashTags;
}
if (mentionUserIds.sort().join(",") !== note.mentions.sort().join(",")) {
update.mentions = mentionUserIds;
update.mentionedRemoteUsers = JSON.stringify(mentionedRemoteUsers);
}
if (apEmojis.sort().join(",") !== note.emojis.sort().join(",")) {
update.emojis = apEmojis;
}
if (note.hasPoll !== !!poll) {
update.hasPoll = !!poll;
}
if (poll) {
const dbPoll = await Polls.findOneBy({ noteId: note.id });
if (dbPoll == null) {
await Polls.insert({
noteId: note.id,
choices: poll?.choices,
multiple: poll?.multiple,
votes: poll?.votes,
expiresAt: poll?.expiresAt,
noteVisibility: note.visibility === "hidden" ? "home" : note.visibility,
2023-04-30 18:29:50 +02:00
userId: actor.id,
userHost: actor.host,
});
updating = true;
} else if (
dbPoll.multiple !== poll.multiple ||
dbPoll.expiresAt !== poll.expiresAt ||
dbPoll.noteVisibility !== note.visibility ||
JSON.stringify(dbPoll.choices) !== JSON.stringify(poll.choices)
) {
await Polls.update(
{ noteId: note.id },
{
choices: poll?.choices,
multiple: poll?.multiple,
votes: poll?.votes,
expiresAt: poll?.expiresAt,
2023-05-05 22:29:39 +02:00
noteVisibility:
note.visibility === "hidden" ? "home" : note.visibility,
2023-04-30 18:29:50 +02:00
},
);
updating = true;
} else {
for (let i = 0; i < poll.choices.length; i++) {
if (dbPoll.votes[i] !== poll.votes?.[i]) {
await Polls.update({ noteId: note.id }, { votes: poll?.votes });
publishing = true;
break;
}
}
2023-04-30 18:29:50 +02:00
}
}
// Update Note
2023-05-02 09:37:48 +02:00
if (notEmpty(update)) {
2023-04-30 18:29:50 +02:00
update.updatedAt = new Date();
// Save updated note to the database
await Notes.update({ uri }, update);
// Save an edit history for the previous note
await NoteEdits.insert({
id: genId(),
noteId: note.id,
text: note.text,
cw: note.cw,
fileIds: note.fileIds,
updatedAt: update.updatedAt,
});
publishing = true;
}
if (publishing) {
2023-04-30 18:29:50 +02:00
// Publish update event for the updated note details
publishNoteStream(note.id, "updated", {
updatedAt: update.updatedAt,
});
const updatedNote = {
...note,
...update
};
publishNoteUpdatesStream("updated", updatedNote);
2023-04-30 18:29:50 +02:00
}
}