mirror of
https://codeberg.org/yeentown/barkey.git
synced 2025-07-07 20:44:34 +00:00
convert notification types in mastodon API
This commit is contained in:
parent
8a9979b3d3
commit
58cdee77d5
7 changed files with 84 additions and 41 deletions
|
@ -6,6 +6,8 @@
|
||||||
import { Inject, Injectable } from '@nestjs/common';
|
import { Inject, Injectable } from '@nestjs/common';
|
||||||
import { Entity } from 'megalodon';
|
import { Entity } from 'megalodon';
|
||||||
import mfm from '@transfem-org/sfm-js';
|
import mfm from '@transfem-org/sfm-js';
|
||||||
|
import { MastodonNotificationType } from 'megalodon/lib/src/mastodon/notification.js';
|
||||||
|
import { NotificationType } from 'megalodon/lib/src/notification.js';
|
||||||
import { DI } from '@/di-symbols.js';
|
import { DI } from '@/di-symbols.js';
|
||||||
import { MfmService } from '@/core/MfmService.js';
|
import { MfmService } from '@/core/MfmService.js';
|
||||||
import type { Config } from '@/config.js';
|
import type { Config } from '@/config.js';
|
||||||
|
@ -355,27 +357,9 @@ export class MastodonConverters {
|
||||||
created_at: notification.created_at,
|
created_at: notification.created_at,
|
||||||
id: notification.id,
|
id: notification.id,
|
||||||
status: notification.status ? await this.convertStatus(notification.status, me) : undefined,
|
status: notification.status ? await this.convertStatus(notification.status, me) : undefined,
|
||||||
type: notification.type,
|
type: convertNotificationType(notification.type as NotificationType),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// public convertEmoji(emoji: string): MastodonEntity.Emoji {
|
|
||||||
// const reaction: MastodonEntity.Reaction = {
|
|
||||||
// name: emoji,
|
|
||||||
// count: 1,
|
|
||||||
// };
|
|
||||||
//
|
|
||||||
// if (emoji.startsWith(':')) {
|
|
||||||
// const [, name] = emoji.match(/^:([^@:]+(?:@[^@:]+)?):$/) ?? [];
|
|
||||||
// if (name) {
|
|
||||||
// const url = `${this.config.url}/emoji/${name}.webp`;
|
|
||||||
// reaction.url = url;
|
|
||||||
// reaction.static_url = url;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return reaction;
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function simpleConvert<T>(data: T): T {
|
function simpleConvert<T>(data: T): T {
|
||||||
|
@ -383,6 +367,19 @@ function simpleConvert<T>(data: T): T {
|
||||||
return Object.assign({}, data);
|
return Object.assign({}, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function convertNotificationType(type: NotificationType): MastodonNotificationType {
|
||||||
|
switch (type) {
|
||||||
|
case 'emoji_reaction': return 'reaction';
|
||||||
|
case 'poll_vote':
|
||||||
|
case 'poll_expired':
|
||||||
|
return 'poll';
|
||||||
|
// Not supported by mastodon
|
||||||
|
case 'move':
|
||||||
|
return type as MastodonNotificationType;
|
||||||
|
default: return type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function convertAnnouncement(announcement: Entity.Announcement): MastodonEntity.Announcement {
|
export function convertAnnouncement(announcement: Entity.Announcement): MastodonEntity.Announcement {
|
||||||
return {
|
return {
|
||||||
...announcement,
|
...announcement,
|
||||||
|
|
|
@ -6,7 +6,7 @@ import { MegalodonInterface, WebSocketInterface } from './megalodon'
|
||||||
import { detector } from './detector'
|
import { detector } from './detector'
|
||||||
import Misskey from './misskey'
|
import Misskey from './misskey'
|
||||||
import Entity from './entity'
|
import Entity from './entity'
|
||||||
import NotificationType from './notification'
|
import * as NotificationType from './notification'
|
||||||
import FilterContext from './filter_context'
|
import FilterContext from './filter_context'
|
||||||
import Converter from './converter'
|
import Converter from './converter'
|
||||||
import MastodonEntity from './mastodon/entity';
|
import MastodonEntity from './mastodon/entity';
|
||||||
|
|
33
packages/megalodon/src/mastodon/notification.ts
Normal file
33
packages/megalodon/src/mastodon/notification.ts
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
export const Mention = 'mention' as const;
|
||||||
|
export const Reblog = 'reblog' as const;
|
||||||
|
export const Favourite = 'favourite' as const;
|
||||||
|
export const Follow = 'follow' as const;
|
||||||
|
export const Poll = 'poll' as const;
|
||||||
|
export const FollowRequest = 'follow_request' as const;
|
||||||
|
export const Status = 'status' as const;
|
||||||
|
export const Update = 'update' as const;
|
||||||
|
export const AdminSignup = 'admin.sign_up' as const;
|
||||||
|
export const AdminReport = 'admin.report' as const;
|
||||||
|
export const Reaction = 'reaction' as const;
|
||||||
|
export const ModerationWarning = 'moderation_warning' as const;
|
||||||
|
export const SeveredRelationships = 'severed_relationships' as const;
|
||||||
|
export const AnnualReport = 'annual_report' as const;
|
||||||
|
|
||||||
|
export const mastodonNotificationTypes = [
|
||||||
|
Mention,
|
||||||
|
Reblog,
|
||||||
|
Favourite,
|
||||||
|
Follow,
|
||||||
|
Poll,
|
||||||
|
FollowRequest,
|
||||||
|
Status,
|
||||||
|
Update,
|
||||||
|
AdminSignup,
|
||||||
|
AdminReport,
|
||||||
|
Reaction,
|
||||||
|
ModerationWarning,
|
||||||
|
SeveredRelationships,
|
||||||
|
AnnualReport,
|
||||||
|
];
|
||||||
|
|
||||||
|
export type MastodonNotificationType = typeof mastodonNotificationTypes[number];
|
|
@ -9,7 +9,8 @@ import MisskeyEntity from './entity'
|
||||||
import MegalodonEntity from '../entity'
|
import MegalodonEntity from '../entity'
|
||||||
import WebSocket from './web_socket'
|
import WebSocket from './web_socket'
|
||||||
import MisskeyNotificationType from './notification'
|
import MisskeyNotificationType from './notification'
|
||||||
import NotificationType, { UnknownNotificationTypeError } from '../notification'
|
import * as NotificationType from '../notification'
|
||||||
|
import { UnknownNotificationTypeError } from '../notification';
|
||||||
|
|
||||||
namespace MisskeyAPI {
|
namespace MisskeyAPI {
|
||||||
export namespace Entity {
|
export namespace Entity {
|
||||||
|
|
|
@ -1,20 +1,16 @@
|
||||||
import Entity from './entity'
|
export const Follow = 'follow' as const;
|
||||||
|
export const Favourite = 'favourite' as const;
|
||||||
namespace NotificationType {
|
export const Reblog = 'reblog' as const;
|
||||||
export const Follow: Entity.NotificationType = 'follow'
|
export const Mention = 'mention' as const;
|
||||||
export const Favourite: Entity.NotificationType = 'favourite'
|
export const EmojiReaction = 'emoji_reaction' as const;
|
||||||
export const Reblog: Entity.NotificationType = 'reblog'
|
export const FollowRequest = 'follow_request' as const;
|
||||||
export const Mention: Entity.NotificationType = 'mention'
|
export const Status = 'status' as const;
|
||||||
export const EmojiReaction: Entity.NotificationType = 'emoji_reaction'
|
export const PollVote = 'poll_vote' as const;
|
||||||
export const FollowRequest: Entity.NotificationType = 'follow_request'
|
export const PollExpired = 'poll_expired' as const;
|
||||||
export const Status: Entity.NotificationType = 'status'
|
export const Update = 'update' as const;
|
||||||
export const PollVote: Entity.NotificationType = 'poll_vote'
|
export const Move = 'move' as const;
|
||||||
export const PollExpired: Entity.NotificationType = 'poll_expired'
|
export const AdminSignup = 'admin.sign_up' as const;
|
||||||
export const Update: Entity.NotificationType = 'update'
|
export const AdminReport = 'admin.report' as const;
|
||||||
export const Move: Entity.NotificationType = 'move'
|
|
||||||
export const AdminSignup: Entity.NotificationType = 'admin.sign_up'
|
|
||||||
export const AdminReport: Entity.NotificationType = 'admin.report'
|
|
||||||
}
|
|
||||||
|
|
||||||
export class UnknownNotificationTypeError extends Error {
|
export class UnknownNotificationTypeError extends Error {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
@ -23,4 +19,20 @@ export class UnknownNotificationTypeError extends Error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default NotificationType
|
export const notificationTypes = [
|
||||||
|
Follow,
|
||||||
|
Favourite,
|
||||||
|
Reblog,
|
||||||
|
Mention,
|
||||||
|
EmojiReaction,
|
||||||
|
FollowRequest,
|
||||||
|
Status,
|
||||||
|
PollVote,
|
||||||
|
PollExpired,
|
||||||
|
Update,
|
||||||
|
Move,
|
||||||
|
AdminSignup,
|
||||||
|
AdminReport,
|
||||||
|
];
|
||||||
|
|
||||||
|
export type NotificationType = typeof notificationTypes[number];
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import MisskeyEntity from '@/misskey/entity'
|
import MisskeyEntity from '@/misskey/entity'
|
||||||
import MisskeyNotificationType from '@/misskey/notification'
|
import MisskeyNotificationType from '@/misskey/notification'
|
||||||
import Misskey from '@/misskey'
|
import Misskey from '@/misskey'
|
||||||
import MegalodonNotificationType from '@/notification'
|
import * as MegalodonNotificationType from '@/notification'
|
||||||
import axios, { AxiosHeaders, AxiosResponse, InternalAxiosRequestConfig } from 'axios'
|
import axios, { AxiosHeaders, AxiosResponse, InternalAxiosRequestConfig } from 'axios'
|
||||||
|
|
||||||
jest.mock('axios')
|
jest.mock('axios')
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import MisskeyAPI from '@/misskey/api_client'
|
import MisskeyAPI from '@/misskey/api_client'
|
||||||
import MegalodonEntity from '@/entity'
|
import MegalodonEntity from '@/entity'
|
||||||
import MisskeyEntity from '@/misskey/entity'
|
import MisskeyEntity from '@/misskey/entity'
|
||||||
import MegalodonNotificationType from '@/notification'
|
import * as MegalodonNotificationType from '@/notification'
|
||||||
import MisskeyNotificationType from '@/misskey/notification'
|
import MisskeyNotificationType from '@/misskey/notification'
|
||||||
|
|
||||||
const user: MisskeyEntity.User = {
|
const user: MisskeyEntity.User = {
|
||||||
|
|
Loading…
Add table
Reference in a new issue