refs #125 Implement sub accounts methods for misskey

This commit is contained in:
AkiraFukushima 2020-02-29 01:20:49 +09:00
parent 8324fce53e
commit 9bf300373d
10 changed files with 390 additions and 15 deletions

View file

@ -762,23 +762,20 @@ export default class Mastodon implements MegalodonInterface {
// ======================================
public async report(
account_id: string,
comment: string,
status_ids?: Array<string> | null,
comment?: string | null,
forward?: boolean | null
): Promise<Response<Entity.Report>> {
let params = {
account_id: account_id
account_id: account_id,
comment: comment
}
if (status_ids) {
params = Object.assign(params, {
status_ids: status_ids
})
}
if (comment) {
params = Object.assign(params, {
comment: comment
})
}
if (forward !== null) {
params = Object.assign(params, {
forward: forward

View file

@ -450,12 +450,7 @@ export interface MegalodonInterface {
* @param forward If the account is remote, should the report be forwarded to the remote admin?
* @return Report
*/
report(
account_id: string,
status_ids?: Array<string> | null,
comment?: string | null,
forward?: boolean | null
): Promise<Response<Entity.Report>>
report(account_id: string, comment: string, status_ids?: Array<string> | null, forward?: boolean | null): Promise<Response<Entity.Report>>
// ======================================
// accounts/follow_requests
// ======================================

View file

@ -537,4 +537,340 @@ export default class Misskey {
})
})
}
// ======================================
// accounts/bookmarks
// ======================================
public async getBookmarks(
_limit?: number | null,
_max_id?: string | null,
_since_id?: string | null,
_min_id?: string | null
): Promise<Response<Array<Entity.Status>>> {
return new Promise((_, reject) => {
const err = new NoImplementedError('misskey does not support')
reject(err)
})
}
// ======================================
// accounts/favourites
// ======================================
/**
* POST /api/i/favorites
*/
public async getFavourites(
limit?: number | null,
max_id?: string | null,
min_id?: string | null
): Promise<Response<Array<Entity.Status>>> {
let params = {}
if (limit) {
params = Object.assign(params, {
limit: limit
})
}
if (max_id) {
params = Object.assign(params, {
untilId: max_id
})
}
if (min_id) {
params = Object.assign(params, {
sinceId: min_id
})
}
return this.client.post<Array<MisskeyAPI.Entity.Favorite>>('/api/i/favorites', params).then(res => {
return Object.assign(res, {
data: res.data.map(fav => MisskeyAPI.Converter.note(fav.note))
})
})
}
// ======================================
// accounts/mutes
// ======================================
/**
* POST /api/mute/list
*/
public async getMutes(limit?: number | null, max_id?: string | null, min_id?: string | null): Promise<Response<Array<Entity.Account>>> {
let params = {}
if (limit) {
params = Object.assign(params, {
limit: limit
})
}
if (max_id) {
params = Object.assign(params, {
untilId: max_id
})
}
if (min_id) {
params = Object.assign(params, {
sinceId: min_id
})
}
return this.client.post<Array<MisskeyAPI.Entity.Mute>>('/api/mute/list', params).then(res => {
return Object.assign(res, {
data: res.data.map(mute => MisskeyAPI.Converter.userDetail(mute.mutee))
})
})
}
// ======================================
// accounts/blocks
// ======================================
/**
* POST /api/blocking/list
*/
public async getBlocks(limit?: number | null, max_id?: string | null, min_id?: string | null): Promise<Response<Array<Entity.Account>>> {
let params = {}
if (limit) {
params = Object.assign(params, {
limit: limit
})
}
if (max_id) {
params = Object.assign(params, {
untilId: max_id
})
}
if (min_id) {
params = Object.assign(params, {
sinceId: min_id
})
}
return this.client.post<Array<MisskeyAPI.Entity.Blocking>>('/api/blocking/list', params).then(res => {
return Object.assign(res, {
data: res.data.map(blocking => MisskeyAPI.Converter.userDetail(blocking.blockee))
})
})
}
// ======================================
// accounts/domain_blocks
// ======================================
public async getDomainBlocks(_limit?: number | null, _max_id?: string | null, _min_id?: string | null): Promise<Response<Array<string>>> {
return new Promise((_, reject) => {
const err = new NoImplementedError('misskey does not support')
reject(err)
})
}
public async blockDomain(_domain: string): Promise<Response<{}>> {
return new Promise((_, reject) => {
const err = new NoImplementedError('misskey does not support')
reject(err)
})
}
public async unblockDomain(_domain: string): Promise<Response<{}>> {
return new Promise((_, reject) => {
const err = new NoImplementedError('misskey does not support')
reject(err)
})
}
// ======================================
// accounts/filters
// ======================================
public async getFilters(): Promise<Response<Array<Entity.Filter>>> {
return new Promise((_, reject) => {
const err = new NoImplementedError('misskey does not support')
reject(err)
})
}
public async getFilter(_id: string): Promise<Response<Entity.Filter>> {
return new Promise((_, reject) => {
const err = new NoImplementedError('misskey does not support')
reject(err)
})
}
public async createFilter(
_phrase: string,
_context: Array<'home' | 'notifications' | 'public' | 'thread'>,
_irreversible?: boolean | null,
_whole_word?: boolean | null,
_expires_in?: string | null
): Promise<Response<Entity.Filter>> {
return new Promise((_, reject) => {
const err = new NoImplementedError('misskey does not support')
reject(err)
})
}
public async updateFilter(
_id: string,
_phrase: string,
_context: Array<'home' | 'notifications' | 'public' | 'thread'>,
_irreversible?: boolean | null,
_whole_word?: boolean | null,
_expires_in?: string | null
): Promise<Response<Entity.Filter>> {
return new Promise((_, reject) => {
const err = new NoImplementedError('misskey does not support')
reject(err)
})
}
public async deleteFilter(_id: string): Promise<Response<Entity.Filter>> {
return new Promise((_, reject) => {
const err = new NoImplementedError('misskey does not support')
reject(err)
})
}
// ======================================
// accounts/reports
// ======================================
/**
* POST /api/users/report-abuse
*/
public async report(
account_id: string,
comment: string,
_status_ids?: Array<string> | null,
_forward?: boolean | null
): Promise<Response<Entity.Report>> {
return this.client
.post<{}>('/api/users/report-abuse', {
userId: account_id,
comment: comment
})
.then(res => {
return Object.assign(res, {
data: {
id: '',
action_taken: '',
comment: comment,
account_id: account_id,
status_ids: []
}
})
})
}
// ======================================
// accounts/follow_requests
// ======================================
/**
* POST /api/following/requests/list
*/
public async getFollowRequests(_limit?: number): Promise<Response<Array<Entity.Account>>> {
return this.client.post<Array<MisskeyAPI.Entity.FollowRequest>>('/api/folllowing/requests/list').then(res => {
return Object.assign(res, {
data: res.data.map(r => MisskeyAPI.Converter.user(r.follower))
})
})
}
/**
* POST /api/following/requests/accept
*/
public async acceptFollowRequest(id: string): Promise<Response<Entity.Relationship>> {
await this.client.post<{}>('/api/following/requests/accept', {
userId: id
})
return this.client
.post<MisskeyAPI.Entity.Relation>('/api/users/relation', {
userId: id
})
.then(res => {
return Object.assign(res, {
data: MisskeyAPI.Converter.relation(res.data)
})
})
}
/**
* POST /api/following/requests/reject
*/
public async rejectFollowRequest(id: string): Promise<Response<Entity.Relationship>> {
await this.client.post<{}>('/api/following/requests/reject', {
userId: id
})
return this.client
.post<MisskeyAPI.Entity.Relation>('/api/users/relation', {
userId: id
})
.then(res => {
return Object.assign(res, {
data: MisskeyAPI.Converter.relation(res.data)
})
})
}
// ======================================
// accounts/endorsements
// ======================================
public async getEndorsements(
_limit?: number | null,
_max_id?: string | null,
_since_id?: string | null
): Promise<Response<Array<Entity.Account>>> {
return new Promise((_, reject) => {
const err = new NoImplementedError('misskey does not support')
reject(err)
})
}
// ======================================
// accounts/featured_tags
// ======================================
public async getFeaturedTags(): Promise<Response<Array<Entity.FeaturedTag>>> {
return new Promise((_, reject) => {
const err = new NoImplementedError('misskey does not support')
reject(err)
})
}
public async createFeaturedTag(_name: string): Promise<Response<Entity.FeaturedTag>> {
return new Promise((_, reject) => {
const err = new NoImplementedError('misskey does not support')
reject(err)
})
}
public async deleteFeaturedTag(_id: string): Promise<Response<{}>> {
return new Promise((_, reject) => {
const err = new NoImplementedError('misskey does not support')
reject(err)
})
}
public async getSuggestedTags(): Promise<Response<Array<Entity.Tag>>> {
return new Promise((_, reject) => {
const err = new NoImplementedError('misskey does not support')
reject(err)
})
}
// ======================================
// accounts/preferences
// ======================================
public async getPreferences(): Promise<Response<Entity.Preferences>> {
return new Promise((_, reject) => {
const err = new NoImplementedError('misskey does not support')
reject(err)
})
}
// ======================================
// accounts/suggestions
// ======================================
/**
* POST /api/users/recommendation
*/
public async getSuggestions(limit?: number): Promise<Response<Array<Entity.Account>>> {
let params = {}
if (limit) {
params = {
...params,
limit: limit
}
}
return this.client
.post<Array<MisskeyAPI.Entity.UserDetail>>('/api/users/recommendation', params)
.then(res => ({ ...res, data: res.data.map(u => MisskeyAPI.Converter.userDetail(u)) }))
}
}

View file

@ -8,10 +8,14 @@ import MegalodonEntity from '../entity'
namespace MisskeyAPI {
export namespace Entity {
export type App = MisskeyEntity.App
export type Blocking = MisskeyEntity.Blocking
export type Emoji = MisskeyEntity.Emoji
export type Favorite = MisskeyEntity.Favorite
export type File = MisskeyEntity.File
export type Follower = MisskeyEntity.Follower
export type Following = MisskeyEntity.Following
export type FollowRequest = MisskeyEntity.FollowRequest
export type Mute = MisskeyEntity.Mute
export type Note = MisskeyEntity.Note
export type Relation = MisskeyEntity.Relation
export type User = MisskeyEntity.User

View file

@ -0,0 +1,10 @@
/// <reference path="userDetail.ts" />
namespace MisskeyEntity {
export type Blocking = {
id: string
createdAt: string
blockeeId: string
blockee: UserDetail
}
}

View file

@ -0,0 +1,10 @@
/// <reference path="note.ts" />
namespace MisskeyEntity {
export type Favorite = {
id: string
createdAt: string
noteId: string
note: Note
}
}

View file

@ -0,0 +1,9 @@
/// <reference path="user.ts" />
namespace MisskeyEntity {
export type FollowRequest = {
id: string
follower: User
followee: User
}
}

View file

@ -0,0 +1,10 @@
/// <reference path="userDetail.ts" />
namespace MisskeyEntity {
export type Mute = {
id: string
createdAt: string
muteeId: string
mutee: UserDetail
}
}

View file

@ -15,10 +15,10 @@ namespace MisskeyEntity {
renote?: Note
repliesCount: number
renoteCount: number
viaMobile: boolean
viaMobile?: boolean
visibility: 'public' | 'home' | 'followers' | 'direct'
reactions: { [key: string]: number }
tags: Array<string>
tags?: Array<string>
emojis: Array<Emoji>
fileIds: Array<string>
files: Array<File>

View file

@ -1,8 +1,12 @@
/// <reference path="entities/app.ts" />
/// <reference path="entities/blocking.ts" />
/// <reference path="entities/emoji.ts" />
/// <reference path="entities/favorite.ts" />
/// <reference path="entities/file.ts" />
/// <reference path="entities/follower.ts" />
/// <reference path="entities/following.ts" />
/// <reference path="entities/followRequest.ts" />
/// <reference path="entities/mute.ts" />
/// <reference path="entities/note.ts" />
/// <reference path="entities/relation.ts" />
/// <reference path="entities/user.ts" />