merge: Allow for sending announcement mails with List-Unsubscribe: (!1164)
View MR for information: https://activitypub.software/TransFem-org/Sharkey/-/merge_requests/1164 Closes #854 Approved-by: dakkar <dakkar@thenautilus.net> Approved-by: Hazelnoot <acomputerdog@gmail.com>
This commit is contained in:
commit
13b6097a12
7 changed files with 162 additions and 3 deletions
|
|
@ -9,7 +9,7 @@ import multipart from '@fastify/multipart';
|
|||
import { ModuleRef } from '@nestjs/core';
|
||||
import { AuthenticationResponseJSON } from '@simplewebauthn/types';
|
||||
import type { Config } from '@/config.js';
|
||||
import type { InstancesRepository, AccessTokensRepository } from '@/models/_.js';
|
||||
import type { InstancesRepository, AccessTokensRepository, UserProfilesRepository } from '@/models/_.js';
|
||||
import { DI } from '@/di-symbols.js';
|
||||
import { UserEntityService } from '@/core/entities/UserEntityService.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
|
@ -18,6 +18,7 @@ import { ApiCallService } from './ApiCallService.js';
|
|||
import { SignupApiService } from './SignupApiService.js';
|
||||
import { SigninApiService } from './SigninApiService.js';
|
||||
import { SigninWithPasskeyApiService } from './SigninWithPasskeyApiService.js';
|
||||
import { CacheService } from '@/core/CacheService.js';
|
||||
import type { FastifyInstance, FastifyPluginOptions } from 'fastify';
|
||||
|
||||
@Injectable()
|
||||
|
|
@ -34,11 +35,15 @@ export class ApiServerService {
|
|||
@Inject(DI.accessTokensRepository)
|
||||
private accessTokensRepository: AccessTokensRepository,
|
||||
|
||||
@Inject(DI.userProfilesRepository)
|
||||
private userProfilesRepository: UserProfilesRepository,
|
||||
|
||||
private userEntityService: UserEntityService,
|
||||
private apiCallService: ApiCallService,
|
||||
private signupApiService: SignupApiService,
|
||||
private signinApiService: SigninApiService,
|
||||
private signinWithPasskeyApiService: SigninWithPasskeyApiService,
|
||||
private cacheService: CacheService,
|
||||
) {
|
||||
//this.createServer = this.createServer.bind(this);
|
||||
}
|
||||
|
|
@ -145,6 +150,33 @@ export class ApiServerService {
|
|||
|
||||
fastify.post<{ Body: { code: string; } }>('/signup-pending', (request, reply) => this.signupApiService.signupPending(request, reply));
|
||||
|
||||
// POST unsubscribes (and is sent by compatible MUAs), GET redirects to the interactive user-facing non-API page
|
||||
fastify.get<{ Params: { user: string, token: string; } }>('/unsubscribe/:user/:token', (request, reply) => {
|
||||
return reply.redirect(`${this.config.url}/unsubscribe/${request.params.user}/${request.params.token}`, 302);
|
||||
});
|
||||
|
||||
fastify.post<{ Params: { user: string, token: string; } }>('/unsubscribe/:user/:token', async (request, reply) => {
|
||||
const { affected } = await this.userProfilesRepository.update({
|
||||
userId: request.params.user,
|
||||
oneClickUnsubscribeToken: request.params.token,
|
||||
}, {
|
||||
receiveAnnouncementEmail: false,
|
||||
});
|
||||
if (affected) {
|
||||
await this.cacheService.userProfileCache.delete(request.params.user);
|
||||
return ["Unsubscribed."];
|
||||
} else {
|
||||
reply.code(401);
|
||||
return {
|
||||
error: {
|
||||
message: 'Invalid parameters.',
|
||||
code: 'INVALID_PARAMETERS',
|
||||
id: '26654194-410e-44e2-b42e-460ff6f92476',
|
||||
},
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
fastify.get('/v1/instance/peers', async (request, reply) => {
|
||||
const instances = await this.instancesRepository.find({
|
||||
select: ['host'],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue