From 5a5aecc14b987ec8d0e3c001f6db4ad6bf099d75 Mon Sep 17 00:00:00 2001 From: teidesu Date: Fri, 17 May 2024 03:19:58 +0300 Subject: [PATCH] feat(sharkey): unfollow notification + send notifs to a webhook also moved to patching sources instead of patching built dockerfile --- hosts/koi/containers/sharkey/Dockerfile | 107 ++++++++++++++++-- .../containers/sharkey/patches/limits.patch | 20 ++++ .../containers/sharkey/patches/software.patch | 23 ++-- .../containers/sharkey/patches/stats.patch | 52 +++++---- .../patches/unfollow-notification.patch | 65 +++++++++++ .../patches/webhook-notification.patch | 105 +++++++++++++++++ .../koi/containers/sharkey/patches/zond.patch | 4 +- 7 files changed, 330 insertions(+), 46 deletions(-) create mode 100644 hosts/koi/containers/sharkey/patches/limits.patch create mode 100644 hosts/koi/containers/sharkey/patches/unfollow-notification.patch create mode 100644 hosts/koi/containers/sharkey/patches/webhook-notification.patch diff --git a/hosts/koi/containers/sharkey/Dockerfile b/hosts/koi/containers/sharkey/Dockerfile index c7618ce..5b1253c 100644 --- a/hosts/koi/containers/sharkey/Dockerfile +++ b/hosts/koi/containers/sharkey/Dockerfile @@ -1,13 +1,102 @@ -FROM registry.activitypub.software/transfem-org/sharkey:develop@sha256:42fcccd8248a77331b7b2a7a4a751f0f108c9e000890b33fb0745bb33c9358ad +# based on https://activitypub.software/TransFem-org/Sharkey/-/blob/develop/Dockerfile +ARG NODE_VERSION=20.10.0-alpine3.18 +ARG COMMIT=a9e4630cc4c6fd1e51347fdf577cfd7bbc4feec2 +FROM node:${NODE_VERSION} as build + +RUN apk add git linux-headers build-base patch + +ENV PYTHONUNBUFFERED=1 +RUN apk add --update python3 && ln -sf python3 /usr/bin/python +RUN python3 -m ensurepip +RUN pip3 install --no-cache --upgrade pip setuptools + +RUN corepack enable + +# begin fetch +RUN git clone https://activitypub.software/TransFem-org/Sharkey.git /sharkey --depth=1 && \ + cd /sharkey && \ + git fetch --depth=1 origin ${COMMIT} && \ + git checkout ${COMMIT} && \ + git submodule update --init --recursive +# end fetch + +WORKDIR /sharkey + +RUN pnpm config set fetch-retries 5 +RUN --mount=type=cache,target=/root/.local/share/pnpm/store,sharing=locked \ + pnpm i --frozen-lockfile --aggregate-output + +# begin patch COPY patches /patches -USER root -RUN apk add patch -USER sharkey +RUN git apply /patches/zond.patch +RUN git apply /patches/software.patch +RUN git apply /patches/stats.patch +RUN git apply /patches/limits.patch +RUN git apply /patches/unfollow-notification.patch +RUN git apply /patches/webhook-notification.patch +RUN cp -f /patches/robots.txt packages/backend/assets/robots.txt +# end patch -RUN patch -p0 < /patches/zond.patch && \ - patch -p0 < /patches/software.patch && \ - patch -p0 < /patches/stats.patch && \ - cp -f /patches/robots.txt /sharkey/packages/backend/assets/robots.txt && \ - node /patches/patch-locale.js +RUN pnpm build +RUN node scripts/trim-deps.mjs +RUN mv packages/frontend/assets sharkey-assets +RUN --mount=type=cache,target=/root/.local/share/pnpm/store,sharing=locked \ + pnpm prune +RUN rm -r node_modules packages/frontend packages/sw +RUN --mount=type=cache,target=/root/.local/share/pnpm/store,sharing=locked \ + pnpm i --prod --frozen-lockfile --aggregate-output +RUN rm -rf .git + +# begin post-build patch +RUN node /patches/patch-locale.js +# end post-build patch + +FROM node:${NODE_VERSION} + +ARG UID="991" +ARG GID="991" + +RUN apk add ffmpeg tini jemalloc \ + && corepack enable \ + && addgroup -g "${GID}" sharkey \ + && adduser -D -u "${UID}" -G sharkey -h /sharkey sharkey \ + && find / -type d -path /sys -prune -o -type d -path /proc -prune -o -type f -perm /u+s -exec chmod u-s {} \; \ + && find / -type d -path /sys -prune -o -type d -path /proc -prune -o -type f -perm /g+s -exec chmod g-s {} \; + +USER sharkey +WORKDIR /sharkey + +COPY --chown=sharkey:sharkey --from=build /sharkey/node_modules ./node_modules +COPY --chown=sharkey:sharkey --from=build /sharkey/packages/backend/node_modules ./packages/backend/node_modules +COPY --chown=sharkey:sharkey --from=build /sharkey/packages/misskey-js/node_modules ./packages/misskey-js/node_modules +COPY --chown=sharkey:sharkey --from=build /sharkey/packages/misskey-reversi/node_modules ./packages/misskey-reversi/node_modules +COPY --chown=sharkey:sharkey --from=build /sharkey/packages/misskey-bubble-game/node_modules ./packages/misskey-bubble-game/node_modules +COPY --chown=sharkey:sharkey --from=build /sharkey/packages/megalodon/node_modules ./packages/megalodon/node_modules +COPY --chown=sharkey:sharkey --from=build /sharkey/built ./built +COPY --chown=sharkey:sharkey --from=build /sharkey/packages/misskey-js/built ./packages/misskey-js/built +COPY --chown=sharkey:sharkey --from=build /sharkey/packages/misskey-reversi/built ./packages/misskey-reversi/built +COPY --chown=sharkey:sharkey --from=build /sharkey/packages/misskey-bubble-game/built ./packages/misskey-bubble-game/built +COPY --chown=sharkey:sharkey --from=build /sharkey/packages/backend/built ./packages/backend/built +COPY --chown=sharkey:sharkey --from=build /sharkey/packages/megalodon/lib ./packages/megalodon/lib +COPY --chown=sharkey:sharkey --from=build /sharkey/fluent-emojis ./fluent-emojis +COPY --chown=sharkey:sharkey --from=build /sharkey/tossface-emojis/dist ./tossface-emojis/dist +COPY --chown=sharkey:sharkey --from=build /sharkey/sharkey-assets ./packages/frontend/assets + +COPY --chown=sharkey:sharkey --from=build /sharkey/package.json ./package.json +COPY --chown=sharkey:sharkey --from=build /sharkey/pnpm-workspace.yaml ./pnpm-workspace.yaml +COPY --chown=sharkey:sharkey --from=build /sharkey/packages/backend/package.json ./packages/backend/package.json +COPY --chown=sharkey:sharkey --from=build /sharkey/packages/backend/check_connect.js ./packages/backend/check_connect.js +COPY --chown=sharkey:sharkey --from=build /sharkey/packages/backend/ormconfig.js ./packages/backend/ormconfig.js +COPY --chown=sharkey:sharkey --from=build /sharkey/packages/backend/migration ./packages/backend/migration +COPY --chown=sharkey:sharkey --from=build /sharkey/packages/backend/assets ./packages/backend/assets +COPY --chown=sharkey:sharkey --from=build /sharkey/packages/megalodon/package.json ./packages/megalodon/package.json +COPY --chown=sharkey:sharkey --from=build /sharkey/packages/misskey-js/package.json ./packages/misskey-js/package.json +COPY --chown=sharkey:sharkey --from=build /sharkey/packages/misskey-reversi/package.json ./packages/misskey-reversi/package.json +COPY --chown=sharkey:sharkey --from=build /sharkey/packages/misskey-bubble-game/package.json ./packages/misskey-bubble-game/package.json + +ENV LD_PRELOAD=/usr/lib/libjemalloc.so.2 +ENV NODE_ENV=production +ENTRYPOINT ["/sbin/tini", "--"] +CMD ["pnpm", "run", "migrateandstart"] diff --git a/hosts/koi/containers/sharkey/patches/limits.patch b/hosts/koi/containers/sharkey/patches/limits.patch new file mode 100644 index 0000000..03fa356 --- /dev/null +++ b/hosts/koi/containers/sharkey/patches/limits.patch @@ -0,0 +1,20 @@ +diff --git a/packages/backend/src/const.ts b/packages/backend/src/const.ts +index 02c2777..cd46330 100644 +--- a/packages/backend/src/const.ts ++++ b/packages/backend/src/const.ts +@@ -15,13 +15,13 @@ export const USER_ACTIVE_THRESHOLD = 1000 * 60 * 60 * 24 * 3; // 3days + * Maximum note text length that can be stored in DB. + * Surrogate pairs count as one + */ +-export const DB_MAX_NOTE_TEXT_LENGTH = 8192; ++export const DB_MAX_NOTE_TEXT_LENGTH = 32768; + + /** + * Maximum image description length that can be stored in DB. + * Surrogate pairs count as one + */ +-export const DB_MAX_IMAGE_COMMENT_LENGTH = 8192; ++export const DB_MAX_IMAGE_COMMENT_LENGTH = 32768; + //#endregion + + // ブラウザで直接表示することを許可するファイルの種類のリスト diff --git a/hosts/koi/containers/sharkey/patches/software.patch b/hosts/koi/containers/sharkey/patches/software.patch index ea16675..d611234 100644 --- a/hosts/koi/containers/sharkey/patches/software.patch +++ b/hosts/koi/containers/sharkey/patches/software.patch @@ -1,11 +1,12 @@ ---- packages/backend/built/server/NodeinfoServerService.js -+++ packages/backend/built/server/NodeinfoServerService.js -@@ -73,7 +73,7 @@ - // eslint-disable-next-line @typescript-eslint/no-explicit-any - const document = { - software: { -- name: 'sharkey', -+ name: 'fishkey', - version: this.config.version, - homepage: nodeinfo_homepage, - repository: meta.repositoryUrl +--- a/packages/backend/src/server/NodeinfoServerService.ts ++++ b/packages/backend/src/server/NodeinfoServerService.ts +@@ -76,7 +76,7 @@ + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const document: any = { + software: { +- name: 'sharkey', ++ name: 'fishkey', + version: this.config.version, + homepage: nodeinfo_homepage, + repository: meta.repositoryUrl, + }, diff --git a/hosts/koi/containers/sharkey/patches/stats.patch b/hosts/koi/containers/sharkey/patches/stats.patch index de20cae..8717377 100644 --- a/hosts/koi/containers/sharkey/patches/stats.patch +++ b/hosts/koi/containers/sharkey/patches/stats.patch @@ -1,25 +1,29 @@ ---- packages/backend/built/server/api/endpoints/stats.js -+++ packages/backend/built/server/api/endpoints/stats.js -@@ -85,8 +85,8 @@ - const originalNotesCount = notesChart.local.total[0]; - const usersChart = await this.usersChart.getChart('hour', 1, null); -- const usersCount = usersChart.local.total[0] + usersChart.remote.total[0]; -- const originalUsersCount = usersChart.local.total[0]; -+ const usersCount = 1 + usersChart.remote.total[0]; -+ const originalUsersCount = 1; - const [reactionsCount, //originalReactionsCount, - instances] = await Promise.all([ - this.noteReactionsRepository.count({ +--- a/packages/backend/src/server/api/endpoints/stats.ts ++++ b/packages/backend/src/server/api/endpoints/stats.ts +@@ -75,9 +75,9 @@ + const originalNotesCount = notesChart.local.total[0]; + + const usersChart = await this.usersChart.getChart('hour', 1, null); +- const usersCount = usersChart.local.total[0] + usersChart.remote.total[0]; +- const originalUsersCount = usersChart.local.total[0]; ++ const usersCount = 1 + usersChart.remote.total[0]; ++ const originalUsersCount = 1; + + const [ + reactionsCount, + //originalReactionsCount, ---- packages/backend/built/server/NodeinfoServerService.js -+++ packages/backend/built/server/NodeinfoServerService.js -@@ -58,8 +58,7 @@ - const now = Date.now(); - const notesChart = await this.notesChart.getChart('hour', 1, null); - const localPosts = notesChart.local.total[0]; -- const usersChart = await this.usersChart.getChart('hour', 1, null); -- const total = usersChart.local.total[0]; -+ const total = 1; - const [meta] = await Promise.all([ - this.metaService.fetch(true) - ]); +--- a/packages/backend/src/server/NodeinfoServerService.ts ++++ b/packages/backend/src/server/NodeinfoServerService.ts +@@ -50,10 +50,9 @@ + const now = Date.now(); + + const notesChart = await this.notesChart.getChart('hour', 1, null); + const localPosts = notesChart.local.total[0]; + +- const usersChart = await this.usersChart.getChart('hour', 1, null); +- const total = usersChart.local.total[0]; ++ const total = 1; + + const [ + meta, diff --git a/hosts/koi/containers/sharkey/patches/unfollow-notification.patch b/hosts/koi/containers/sharkey/patches/unfollow-notification.patch new file mode 100644 index 0000000..6375de3 --- /dev/null +++ b/hosts/koi/containers/sharkey/patches/unfollow-notification.patch @@ -0,0 +1,65 @@ +diff --git a/packages/backend/src/core/UserFollowingService.ts b/packages/backend/src/core/UserFollowingService.ts +index deeecde..02beb42 100644 +--- a/packages/backend/src/core/UserFollowingService.ts ++++ b/packages/backend/src/core/UserFollowingService.ts +@@ -403,6 +403,8 @@ export class UserFollowingService implements OnModuleInit { + }); + } + }); ++ ++ this.notificationService.createNotification(followee.id, 'unfollow', {}, follower.id); + } + + if (this.userEntityService.isLocalUser(follower) && this.userEntityService.isRemoteUser(followee)) { +diff --git a/packages/backend/src/models/Notification.ts b/packages/backend/src/models/Notification.ts +index 4ed71a1..0bbd0ca 100644 +--- a/packages/backend/src/models/Notification.ts ++++ b/packages/backend/src/models/Notification.ts +@@ -15,7 +15,7 @@ export type MiNotification = { + notifierId: MiUser['id']; + noteId: MiNote['id']; + } | { +- type: 'follow'; ++ type: 'follow' | 'unfollow'; + id: string; + createdAt: string; + notifierId: MiUser['id']; +diff --git a/packages/frontend/src/components/MkNotification.vue b/packages/frontend/src/components/MkNotification.vue +index 562cc38..6ea1598 100644 +--- a/packages/frontend/src/components/MkNotification.vue ++++ b/packages/frontend/src/components/MkNotification.vue +@@ -15,7 +15,7 @@ SPDX-License-Identifier: AGPL-3.0-only + +
+ ++ + + + +@@ -60,6 +61,7 @@ SPDX-License-Identifier: AGPL-3.0-only + {{ i18n.ts._notification.achievementEarned }} + {{ i18n.ts._notification.testNotification }} + ++ + {{ i18n.tsx._notification.reactedBySomeUsers({ n: notification.reactions.length }) }} + {{ i18n.tsx._notification.renotedBySomeUsers({ n: notification.users.length }) }} + {{ notification.header }} +@@ -103,6 +105,9 @@ SPDX-License-Identifier: AGPL-3.0-only + ++ + {{ i18n.ts.followRequestAccepted }} +