feat(sharkey): unfollow notification + send notifs to a webhook

also moved to patching sources instead of patching built dockerfile
This commit is contained in:
alina 🌸 2024-05-17 03:19:58 +03:00
parent c3beb572e6
commit 5a5aecc14b
Signed by: teidesu
SSH key fingerprint: SHA256:uNeCpw6aTSU4aIObXLvHfLkDa82HWH9EiOj9AXOIRpI
7 changed files with 330 additions and 46 deletions

View file

@ -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"]

View file

@ -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
// ブラウザで直接表示することを許可するファイルの種類のリスト

View file

@ -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,
},

View file

@ -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,

View file

@ -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
<img v-else-if="notification.icon" :class="[$style.icon, $style.icon_app]" :src="notification.icon" alt=""/>
<div
:class="[$style.subIcon, {
- [$style.t_follow]: notification.type === 'follow',
+ [$style.t_follow]: notification.type === 'follow' || notification.type === 'unfollow',
[$style.t_followRequestAccepted]: notification.type === 'followRequestAccepted',
[$style.t_receiveFollowRequest]: notification.type === 'receiveFollowRequest',
[$style.t_renote]: notification.type === 'renote',
@@ -29,6 +29,7 @@ SPDX-License-Identifier: AGPL-3.0-only
}]"
> <!-- we re-use t_pollEnded for "edited" instead of making an identical style -->
<i v-if="notification.type === 'follow'" class="ph-plus ph-bold ph-lg"></i>
+ <i v-else-if="notification.type === 'unfollow'" class="ph-minus ph-bold ph-lg"></i>
<i v-else-if="notification.type === 'receiveFollowRequest'" class="ph-clock ph-bold ph-lg"></i>
<i v-else-if="notification.type === 'followRequestAccepted'" class="ph-check ph-bold ph-lg"></i>
<i v-else-if="notification.type === 'renote'" class="ph-rocket-launch ph-bold ph-lg"></i>
@@ -60,6 +61,7 @@ SPDX-License-Identifier: AGPL-3.0-only
<span v-else-if="notification.type === 'achievementEarned'">{{ i18n.ts._notification.achievementEarned }}</span>
<span v-else-if="notification.type === 'test'">{{ i18n.ts._notification.testNotification }}</span>
<MkA v-else-if="notification.type === 'follow' || notification.type === 'mention' || notification.type === 'reply' || notification.type === 'renote' || notification.type === 'quote' || notification.type === 'reaction' || notification.type === 'receiveFollowRequest' || notification.type === 'followRequestAccepted'" v-user-preview="notification.user.id" :class="$style.headerName" :to="userPage(notification.user)"><MkUserName :user="notification.user"/></MkA>
+ <MkA v-else-if="notification.type === 'unfollow'" v-user-preview="notification.user.id" :class="$style.headerName" :to="userPage(notification.user)"><MkUserName :user="notification.user"/></MkA>
<span v-else-if="notification.type === 'reaction:grouped'">{{ i18n.tsx._notification.reactedBySomeUsers({ n: notification.reactions.length }) }}</span>
<span v-else-if="notification.type === 'renote:grouped'">{{ i18n.tsx._notification.renotedBySomeUsers({ n: notification.users.length }) }}</span>
<span v-else-if="notification.type === 'app'">{{ notification.header }}</span>
@@ -103,6 +105,9 @@ SPDX-License-Identifier: AGPL-3.0-only
<template v-else-if="notification.type === 'follow'">
<span :class="$style.text" style="opacity: 0.6;">{{ i18n.ts.youGotNewFollower }}</span>
</template>
+ <template v-else-if="notification.type === 'unfollow'">
+ <span :class="$style.text" style="opacity: 0.6;">unfollowed you</span>
+ </template>
<span v-else-if="notification.type === 'followRequestAccepted'" :class="$style.text" style="opacity: 0.6;">{{ i18n.ts.followRequestAccepted }}</span>
<template v-else-if="notification.type === 'receiveFollowRequest'">
<span :class="$style.text" style="opacity: 0.6;">{{ i18n.ts.receiveFollowRequest }}</span>

View file

@ -0,0 +1,105 @@
diff --git a/packages/backend/src/core/NotificationService.ts b/packages/backend/src/core/NotificationService.ts
index 68ad92f..69b04c1 100644
--- a/packages/backend/src/core/NotificationService.ts
+++ b/packages/backend/src/core/NotificationService.ts
@@ -21,6 +21,8 @@ import type { Config } from '@/config.js';
import { UserListService } from '@/core/UserListService.js';
import type { FilterUnionByProperty } from '@/types.js';
import { trackPromise } from '@/misc/promise-tracker.js';
+import { WebhookService } from './WebhookService.js';
+import { QueueService } from './QueueService.js';
@Injectable()
export class NotificationService implements OnApplicationShutdown {
@@ -42,6 +44,8 @@ export class NotificationService implements OnApplicationShutdown {
private pushNotificationService: PushNotificationService,
private cacheService: CacheService,
private userListService: UserListService,
+ private webhookService: WebhookService,
+ private queueService: QueueService,
) {
}
@@ -175,6 +179,13 @@ export class NotificationService implements OnApplicationShutdown {
const latestReadNotificationId = await this.redisClient.get(`latestReadNotification:${notifieeId}`);
if (latestReadNotificationId && (latestReadNotificationId >= (await redisIdPromise)!)) return;
+ const webhooks = (await this.webhookService.getActiveWebhooks()).filter(x => x.userId === notifieeId && x.on.includes('notification'));
+ for (const webhook of webhooks) {
+ this.queueService.webhookDeliver(webhook, 'notification', {
+ notification: packed
+ });
+ }
+
this.globalEventService.publishMainStream(notifieeId, 'unreadNotification', packed);
this.pushNotificationService.pushNotification(notifieeId, 'notification', packed);
diff --git a/packages/backend/src/models/Webhook.ts b/packages/backend/src/models/Webhook.ts
index 2a727f8..c4d490e 100644
--- a/packages/backend/src/models/Webhook.ts
+++ b/packages/backend/src/models/Webhook.ts
@@ -7,7 +7,7 @@ import { PrimaryColumn, Entity, Index, JoinColumn, Column, ManyToOne } from 'typ
import { id } from './util/id.js';
import { MiUser } from './User.js';
-export const webhookEventTypes = ['mention', 'unfollow', 'follow', 'followed', 'note', 'reply', 'renote', 'reaction', 'edited'] as const;
+export const webhookEventTypes = ['mention', 'unfollow', 'follow', 'followed', 'note', 'reply', 'renote', 'reaction', 'edited', 'notification'] as const;
@Entity('webhook')
export class MiWebhook {
diff --git a/packages/frontend/src/pages/settings/webhook.edit.vue b/packages/frontend/src/pages/settings/webhook.edit.vue
index 99326c8..fbfabc4 100644
--- a/packages/frontend/src/pages/settings/webhook.edit.vue
+++ b/packages/frontend/src/pages/settings/webhook.edit.vue
@@ -29,6 +29,7 @@ SPDX-License-Identifier: AGPL-3.0-only
<MkSwitch v-model="event_renote">{{ i18n.ts._webhookSettings._events.renote }}</MkSwitch>
<MkSwitch v-model="event_reaction">{{ i18n.ts._webhookSettings._events.reaction }}</MkSwitch>
<MkSwitch v-model="event_mention">{{ i18n.ts._webhookSettings._events.mention }}</MkSwitch>
+ <MkSwitch v-model="event_notification">on notification</MkSwitch>
</div>
</FormSection>
@@ -75,6 +76,7 @@ const event_reply = ref(webhook.on.includes('reply'));
const event_renote = ref(webhook.on.includes('renote'));
const event_reaction = ref(webhook.on.includes('reaction'));
const event_mention = ref(webhook.on.includes('mention'));
+const event_notification = ref(webhook.on.includes('notification'));
async function save(): Promise<void> {
const events = [];
@@ -85,6 +87,7 @@ async function save(): Promise<void> {
if (event_renote.value) events.push('renote');
if (event_reaction.value) events.push('reaction');
if (event_mention.value) events.push('mention');
+ if (event_notification.value) events.push('notification');
os.apiWithDialog('i/webhooks/update', {
name: name.value,
diff --git a/packages/frontend/src/pages/settings/webhook.new.vue b/packages/frontend/src/pages/settings/webhook.new.vue
index 2993863..c2db510 100644
--- a/packages/frontend/src/pages/settings/webhook.new.vue
+++ b/packages/frontend/src/pages/settings/webhook.new.vue
@@ -29,6 +29,7 @@ SPDX-License-Identifier: AGPL-3.0-only
<MkSwitch v-model="event_renote">{{ i18n.ts._webhookSettings._events.renote }}</MkSwitch>
<MkSwitch v-model="event_reaction">{{ i18n.ts._webhookSettings._events.reaction }}</MkSwitch>
<MkSwitch v-model="event_mention">{{ i18n.ts._webhookSettings._events.mention }}</MkSwitch>
+ <MkSwitch v-model="event_notification">on notification</MkSwitch>
</div>
</FormSection>
@@ -59,6 +60,7 @@ const event_reply = ref(true);
const event_renote = ref(true);
const event_reaction = ref(true);
const event_mention = ref(true);
+const event_notification = ref(true);
async function create(): Promise<void> {
const events = [];
@@ -69,6 +71,7 @@ async function create(): Promise<void> {
if (event_renote.value) events.push('renote');
if (event_reaction.value) events.push('reaction');
if (event_mention.value) events.push('mention');
+ if (event_notification.value) events.push('notification');
os.apiWithDialog('i/webhooks/create', {
name: name.value,

View file

@ -1,5 +1,5 @@
--- packages/backend/built/server/web/views/base.pug
+++ packages/backend/built/server/web/views/base.pug
--- a/packages/backend/src/server/web/views/base.pug
+++ b/packages/backend/src/server/web/views/base.pug
@@ -44,5 +44,6 @@
link(rel='stylesheet' href='/static-assets/fonts/sharkey-icons/style.css')
link(rel='modulepreload' href=`/vite/${clientEntry.file}`)