Skip to content

Commit

Permalink
UserWebhookPayload<'followed'> 修正
Browse files Browse the repository at this point in the history
Signed-off-by: eternal-flame-AD <[email protected]>
  • Loading branch information
eternal-flame-AD committed Nov 12, 2024
1 parent f60335c commit fd2fa3c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
6 changes: 3 additions & 3 deletions packages/backend/src/core/QueueService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -469,10 +469,10 @@ export class QueueService {
* @see UserWebhookDeliverProcessorService
*/
@bindThis
public userWebhookDeliver(
public userWebhookDeliver<T extends WebhookEventTypes>(
webhook: MiWebhook,
type: typeof webhookEventTypes[number],
content: UserWebhookPayload<WebhookEventTypes>,
type: T,
content: UserWebhookPayload<T>,
opts?: { attempts?: number },
) {
const data: UserWebhookDeliverJobData = {
Expand Down
7 changes: 5 additions & 2 deletions packages/backend/src/core/UserWebhookService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ export type UserWebhookPayload<T extends WebhookEventTypes> =
T extends 'note' | 'reply' | 'renote' |'mention' ? {
note: Packed<'Note'>,
} :
T extends 'follow' | 'followed' | 'unfollow' ? {
user: Packed<'User'>,
T extends 'follow' | 'unfollow' ? {
user: Packed<'UserDetailedNotMe'>,
} :
T extends 'followed' ? {
user: Packed<'UserLite'>,
} : never;

@Injectable()
Expand Down
18 changes: 9 additions & 9 deletions packages/backend/src/core/WebhookTestService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,15 +321,15 @@ export class WebhookTestService {
}

const webhook = webhooks[0];
const send = <U extends WebhookEventTypes>(contents: UserWebhookPayload<U>) => {
const send = <U extends WebhookEventTypes>(type: U, contents: UserWebhookPayload<U>) => {
const merged = {
...webhook,
...params.override,
};

// テスト目的なのでUserWebhookServiceの機能を経由せず直接キューに追加する(チェック処理などをスキップする意図).
// また、Jobの試行回数も1回だけ.
this.queueService.userWebhookDeliver(merged, params.type, contents, { attempts: 1 });
this.queueService.userWebhookDeliver(merged, type, contents, { attempts: 1 });
};

const dummyNote1 = generateDummyNote({
Expand Down Expand Up @@ -361,31 +361,31 @@ export class WebhookTestService {

switch (params.type) {
case 'note': {
send({ note: toPackedNote(dummyNote1) });
send('note', { note: toPackedNote(dummyNote1) });
break;
}
case 'reply': {
send({ note: toPackedNote(dummyReply1) });
send('reply', { note: toPackedNote(dummyReply1) });
break;
}
case 'renote': {
send({ note: toPackedNote(dummyRenote1) });
send('renote', { note: toPackedNote(dummyRenote1) });
break;
}
case 'mention': {
send({ note: toPackedNote(dummyMention1) });
send('mention', { note: toPackedNote(dummyMention1) });
break;
}
case 'follow': {
send({ user: toPackedUserDetailedNotMe(dummyUser1) });
send('follow', { user: toPackedUserDetailedNotMe(dummyUser1) });
break;
}
case 'followed': {
send({ user: toPackedUserDetailedNotMe(dummyUser2) });
send('followed', { user: toPackedUserLite(dummyUser2) });
break;
}
case 'unfollow': {
send({ user: toPackedUserDetailedNotMe(dummyUser3) });
send('unfollow', { user: toPackedUserDetailedNotMe(dummyUser3) });
break;
}
// まだ実装されていない (#9485)
Expand Down

0 comments on commit fd2fa3c

Please sign in to comment.