2018-04-07 09:36:40 +02:00
|
|
|
export type obj = { [x: string]: any };
|
2019-09-26 21:58:28 +02:00
|
|
|
export type ApObject = IObject | string | (IObject | string)[];
|
2018-04-07 08:39:40 +02:00
|
|
|
|
|
|
|
export interface IObject {
|
2018-04-07 09:36:40 +02:00
|
|
|
'@context': string | obj | obj[];
|
2018-03-31 12:55:00 +02:00
|
|
|
type: string;
|
2018-04-07 08:39:40 +02:00
|
|
|
id?: string;
|
|
|
|
summary?: string;
|
2018-04-07 23:55:26 +02:00
|
|
|
published?: string;
|
2019-09-26 21:58:28 +02:00
|
|
|
cc?: ApObject;
|
|
|
|
to?: ApObject;
|
|
|
|
attributedTo: ApObject;
|
2018-04-08 21:08:56 +02:00
|
|
|
attachment?: any[];
|
|
|
|
inReplyTo?: any;
|
2019-03-06 14:55:47 +01:00
|
|
|
replies?: ICollection;
|
2019-04-13 11:58:29 +02:00
|
|
|
content?: string;
|
2019-03-06 14:55:47 +01:00
|
|
|
name?: string;
|
|
|
|
startTime?: Date;
|
|
|
|
endTime?: Date;
|
2018-04-08 21:08:56 +02:00
|
|
|
icon?: any;
|
|
|
|
image?: any;
|
2018-04-08 22:14:47 +02:00
|
|
|
url?: string;
|
2018-05-06 19:54:14 +02:00
|
|
|
tag?: any[];
|
2018-08-19 11:08:29 +02:00
|
|
|
sensitive?: boolean;
|
2018-04-07 08:39:40 +02:00
|
|
|
}
|
|
|
|
|
2019-06-28 11:54:10 +02:00
|
|
|
/**
|
|
|
|
* Get array of ActivityStreams Objects id
|
|
|
|
*/
|
2019-09-26 21:58:28 +02:00
|
|
|
export function getApIds(value: ApObject | undefined): string[] {
|
2019-06-28 11:54:10 +02:00
|
|
|
if (value == null) return [];
|
|
|
|
const array = Array.isArray(value) ? value : [value];
|
|
|
|
return array.map(x => getApId(x));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get first ActivityStreams Object id
|
|
|
|
*/
|
2019-09-26 21:58:28 +02:00
|
|
|
export function getOneApId(value: ApObject): string {
|
2019-06-28 11:54:10 +02:00
|
|
|
const firstOne = Array.isArray(value) ? value[0] : value;
|
|
|
|
return getApId(firstOne);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get ActivityStreams Object id
|
|
|
|
*/
|
|
|
|
export function getApId(value: string | IObject): string {
|
|
|
|
if (typeof value === 'string') return value;
|
|
|
|
if (typeof value.id === 'string') return value.id;
|
|
|
|
throw new Error(`cannot detemine id`);
|
|
|
|
}
|
|
|
|
|
2018-04-07 09:14:35 +02:00
|
|
|
export interface IActivity extends IObject {
|
|
|
|
//type: 'Activity';
|
|
|
|
actor: IObject | string;
|
|
|
|
object: IObject | string;
|
|
|
|
target?: IObject | string;
|
|
|
|
}
|
|
|
|
|
2018-04-07 08:39:40 +02:00
|
|
|
export interface ICollection extends IObject {
|
|
|
|
type: 'Collection';
|
|
|
|
totalItems: number;
|
2019-09-26 21:58:28 +02:00
|
|
|
items: ApObject;
|
2018-04-07 08:39:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface IOrderedCollection extends IObject {
|
|
|
|
type: 'OrderedCollection';
|
|
|
|
totalItems: number;
|
2019-09-26 21:58:28 +02:00
|
|
|
orderedItems: ApObject;
|
2018-04-07 08:39:40 +02:00
|
|
|
}
|
|
|
|
|
2020-01-29 17:38:05 +01:00
|
|
|
export const validPost = ['Note', 'Question', 'Article', 'Audio', 'Document', 'Image', 'Page', 'Video', 'Event'];
|
2019-06-28 11:54:10 +02:00
|
|
|
|
2020-01-29 17:38:05 +01:00
|
|
|
export interface IPost extends IObject {
|
|
|
|
type: 'Note' | 'Question' | 'Article' | 'Audio' | 'Document' | 'Image' | 'Page' | 'Video' | 'Event';
|
2019-04-13 11:58:29 +02:00
|
|
|
_misskey_content?: string;
|
|
|
|
_misskey_quote?: string;
|
2019-12-14 19:37:54 +01:00
|
|
|
quoteUrl?: string;
|
2019-10-28 22:01:14 +01:00
|
|
|
_misskey_talk: boolean;
|
2018-04-07 23:55:26 +02:00
|
|
|
}
|
|
|
|
|
2019-03-07 13:19:32 +01:00
|
|
|
export interface IQuestion extends IObject {
|
|
|
|
type: 'Note' | 'Question';
|
2019-04-13 11:58:29 +02:00
|
|
|
_misskey_content?: string;
|
|
|
|
_misskey_quote?: string;
|
2019-12-14 19:37:54 +01:00
|
|
|
quoteUrl?: string;
|
2019-03-07 13:19:32 +01:00
|
|
|
oneOf?: IQuestionChoice[];
|
|
|
|
anyOf?: IQuestionChoice[];
|
|
|
|
endTime?: Date;
|
2019-07-19 20:20:06 +02:00
|
|
|
closed?: Date;
|
2019-03-07 13:19:32 +01:00
|
|
|
}
|
|
|
|
|
2019-06-28 11:54:10 +02:00
|
|
|
export const isQuestion = (object: IObject): object is IQuestion =>
|
|
|
|
object.type === 'Note' || object.type === 'Question';
|
|
|
|
|
2019-03-07 13:19:32 +01:00
|
|
|
interface IQuestionChoice {
|
|
|
|
name?: string;
|
|
|
|
replies?: ICollection;
|
|
|
|
_misskey_votes?: number;
|
|
|
|
}
|
|
|
|
|
2020-01-29 17:36:44 +01:00
|
|
|
export const validActor = ['Person', 'Service', 'Group', 'Organization'];
|
2019-04-10 20:09:12 +02:00
|
|
|
|
2018-04-08 21:08:56 +02:00
|
|
|
export interface IPerson extends IObject {
|
|
|
|
type: 'Person';
|
2019-10-28 12:34:01 +01:00
|
|
|
name?: string;
|
|
|
|
preferredUsername?: string;
|
|
|
|
manuallyApprovesFollowers?: boolean;
|
|
|
|
inbox?: string;
|
|
|
|
sharedInbox?: string; // 後方互換性のため
|
|
|
|
publicKey: {
|
|
|
|
id: string;
|
|
|
|
publicKeyPem: string;
|
|
|
|
};
|
|
|
|
followers?: string | ICollection | IOrderedCollection;
|
|
|
|
following?: string | ICollection | IOrderedCollection;
|
|
|
|
featured?: string | IOrderedCollection;
|
|
|
|
outbox?: string | IOrderedCollection;
|
|
|
|
endpoints?: {
|
|
|
|
sharedInbox?: string;
|
|
|
|
};
|
2018-04-08 21:08:56 +02:00
|
|
|
}
|
|
|
|
|
2018-04-07 08:39:40 +02:00
|
|
|
export const isCollection = (object: IObject): object is ICollection =>
|
|
|
|
object.type === 'Collection';
|
|
|
|
|
|
|
|
export const isOrderedCollection = (object: IObject): object is IOrderedCollection =>
|
|
|
|
object.type === 'OrderedCollection';
|
|
|
|
|
|
|
|
export const isCollectionOrOrderedCollection = (object: IObject): object is ICollection | IOrderedCollection =>
|
|
|
|
isCollection(object) || isOrderedCollection(object);
|
2018-04-07 09:14:35 +02:00
|
|
|
|
|
|
|
export interface ICreate extends IActivity {
|
|
|
|
type: 'Create';
|
|
|
|
}
|
|
|
|
|
2018-04-07 09:36:40 +02:00
|
|
|
export interface IDelete extends IActivity {
|
|
|
|
type: 'Delete';
|
|
|
|
}
|
|
|
|
|
2019-03-07 13:19:32 +01:00
|
|
|
export interface IUpdate extends IActivity {
|
|
|
|
type: 'Update';
|
|
|
|
}
|
|
|
|
|
2019-12-14 19:37:19 +01:00
|
|
|
export interface IRead extends IActivity {
|
|
|
|
type: 'Read';
|
|
|
|
}
|
|
|
|
|
2018-04-07 09:14:35 +02:00
|
|
|
export interface IUndo extends IActivity {
|
|
|
|
type: 'Undo';
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface IFollow extends IActivity {
|
|
|
|
type: 'Follow';
|
|
|
|
}
|
2018-04-07 09:36:40 +02:00
|
|
|
|
|
|
|
export interface IAccept extends IActivity {
|
|
|
|
type: 'Accept';
|
|
|
|
}
|
|
|
|
|
2018-05-31 17:42:37 +02:00
|
|
|
export interface IReject extends IActivity {
|
|
|
|
type: 'Reject';
|
|
|
|
}
|
|
|
|
|
2018-10-02 09:27:36 +02:00
|
|
|
export interface IAdd extends IActivity {
|
|
|
|
type: 'Add';
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface IRemove extends IActivity {
|
|
|
|
type: 'Remove';
|
|
|
|
}
|
|
|
|
|
2018-04-07 10:05:14 +02:00
|
|
|
export interface ILike extends IActivity {
|
2020-01-30 00:03:50 +01:00
|
|
|
type: 'Like' | 'EmojiReaction';
|
2019-04-13 11:58:29 +02:00
|
|
|
_misskey_reaction?: string;
|
2018-04-07 10:05:14 +02:00
|
|
|
}
|
|
|
|
|
2018-04-07 23:55:26 +02:00
|
|
|
export interface IAnnounce extends IActivity {
|
|
|
|
type: 'Announce';
|
|
|
|
}
|
|
|
|
|
2018-10-29 12:32:42 +01:00
|
|
|
export interface IBlock extends IActivity {
|
|
|
|
type: 'Block';
|
|
|
|
}
|
|
|
|
|
2019-09-26 21:58:28 +02:00
|
|
|
export const isCreate = (object: IObject): object is ICreate => object.type === 'Create';
|
|
|
|
export const isDelete = (object: IObject): object is IDelete => object.type === 'Delete';
|
|
|
|
export const isUpdate = (object: IObject): object is IUpdate => object.type === 'Update';
|
2019-12-14 19:37:19 +01:00
|
|
|
export const isRead = (object: IObject): object is IRead => object.type === 'Read';
|
2019-09-26 21:58:28 +02:00
|
|
|
export const isUndo = (object: IObject): object is IUndo => object.type === 'Undo';
|
|
|
|
export const isFollow = (object: IObject): object is IFollow => object.type === 'Follow';
|
|
|
|
export const isAccept = (object: IObject): object is IAccept => object.type === 'Accept';
|
|
|
|
export const isReject = (object: IObject): object is IReject => object.type === 'Reject';
|
|
|
|
export const isAdd = (object: IObject): object is IAdd => object.type === 'Add';
|
|
|
|
export const isRemove = (object: IObject): object is IRemove => object.type === 'Remove';
|
2020-01-30 00:03:50 +01:00
|
|
|
export const isLike = (object: IObject): object is ILike => object.type === 'Like' || object.type === 'EmojiReaction';
|
2019-09-26 21:58:28 +02:00
|
|
|
export const isAnnounce = (object: IObject): object is IAnnounce => object.type === 'Announce';
|
|
|
|
export const isBlock = (object: IObject): object is IBlock => object.type === 'Block';
|