refactor: introduce bindThis decorator to bind this automaticaly
This commit is contained in:
parent
e73581f715
commit
bbb49457f9
199 changed files with 969 additions and 96 deletions
|
@ -12,6 +12,7 @@ import { DI } from '@/di-symbols.js';
|
|||
import { deepClone } from '@/misc/clone.js';
|
||||
|
||||
const ACTOR_USERNAME = 'relay.actor' as const;
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class RelayService {
|
||||
|
@ -32,6 +33,7 @@ export class RelayService {
|
|||
this.relaysCache = new Cache<Relay[]>(1000 * 60 * 10);
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private async getRelayActor(): Promise<ILocalUser> {
|
||||
const user = await this.usersRepository.findOneBy({
|
||||
host: IsNull(),
|
||||
|
@ -44,6 +46,7 @@ export class RelayService {
|
|||
return created as ILocalUser;
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async addRelay(inbox: string): Promise<Relay> {
|
||||
const relay = await this.relaysRepository.insert({
|
||||
id: this.idService.genId(),
|
||||
|
@ -59,6 +62,7 @@ export class RelayService {
|
|||
return relay;
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async removeRelay(inbox: string): Promise<void> {
|
||||
const relay = await this.relaysRepository.findOneBy({
|
||||
inbox,
|
||||
|
@ -77,11 +81,13 @@ export class RelayService {
|
|||
await this.relaysRepository.delete(relay.id);
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async listRelay(): Promise<Relay[]> {
|
||||
const relays = await this.relaysRepository.find();
|
||||
return relays;
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async relayAccepted(id: string): Promise<string> {
|
||||
const result = await this.relaysRepository.update(id, {
|
||||
status: 'accepted',
|
||||
|
@ -90,6 +96,7 @@ export class RelayService {
|
|||
return JSON.stringify(result);
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async relayRejected(id: string): Promise<string> {
|
||||
const result = await this.relaysRepository.update(id, {
|
||||
status: 'rejected',
|
||||
|
@ -98,6 +105,7 @@ export class RelayService {
|
|||
return JSON.stringify(result);
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async deliverToRelays(user: { id: User['id']; host: null; }, activity: any): Promise<void> {
|
||||
if (activity == null) return;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue