refs #125 Implement accounts methods for misskey
This commit is contained in:
parent
f3af5c3f68
commit
7ed2fd2d63
225
src/misskey.ts
225
src/misskey.ts
|
@ -312,4 +312,229 @@ export default class Misskey {
|
|||
reject(err)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /api/users/followers
|
||||
*/
|
||||
public async getAccountFollowers(
|
||||
id: string,
|
||||
limit?: number | null,
|
||||
_max_id?: string | null,
|
||||
_since_id?: string | null
|
||||
): Promise<Response<Array<Entity.Account>>> {
|
||||
let params = {
|
||||
userId: id
|
||||
}
|
||||
if (limit) {
|
||||
params = Object.assign(params, {
|
||||
limit: limit
|
||||
})
|
||||
}
|
||||
return this.client.post<Array<MisskeyAPI.Entity.Follower>>('/api/users/followers', params).then(res => {
|
||||
return Object.assign(res, {
|
||||
data: res.data.map(f => MisskeyAPI.Converter.follower(f))
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /api/users/following
|
||||
*/
|
||||
public async getAccountFollowing(
|
||||
id: string,
|
||||
limit?: number | null,
|
||||
_max_id?: string | null,
|
||||
_since_id?: string | null
|
||||
): Promise<Response<Array<Entity.Account>>> {
|
||||
let params = {
|
||||
userId: id
|
||||
}
|
||||
if (limit) {
|
||||
params = Object.assign(params, {
|
||||
limit: limit
|
||||
})
|
||||
}
|
||||
return this.client.post<Array<MisskeyAPI.Entity.Follower>>('/api/users/following', params).then(res => {
|
||||
return Object.assign(res, {
|
||||
data: res.data.map(f => MisskeyAPI.Converter.follower(f))
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
public async getAccountLists(_id: string): Promise<Response<Array<Entity.List>>> {
|
||||
return new Promise((_, reject) => {
|
||||
const err = new NoImplementedError('misskey does not support')
|
||||
reject(err)
|
||||
})
|
||||
}
|
||||
|
||||
public async getIdentityProof(_id: string): Promise<Response<Array<Entity.IdentityProof>>> {
|
||||
return new Promise((_, reject) => {
|
||||
const err = new NoImplementedError('misskey does not support')
|
||||
reject(err)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /api/following/create
|
||||
*/
|
||||
public async followAccount(id: string, _reblog: boolean): Promise<Response<Entity.Relationship>> {
|
||||
await this.client.post<{}>('api/following/create', {
|
||||
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/delete
|
||||
*/
|
||||
public async unfollowAccount(id: string): Promise<Response<Entity.Relationship>> {
|
||||
await this.client.post<{}>('api/following/delete', {
|
||||
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/blocking/create
|
||||
*/
|
||||
public async blockAccount(id: string): Promise<Response<Entity.Relationship>> {
|
||||
await this.client.post<{}>('api/blocking/create', {
|
||||
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/blocking/delete
|
||||
*/
|
||||
public async unblockAccount(id: string): Promise<Response<Entity.Relationship>> {
|
||||
await this.client.post<{}>('api/blocking/delete', {
|
||||
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/mute/create
|
||||
*/
|
||||
public async muteAccount(id: string, _notifications: boolean): Promise<Response<Entity.Relationship>> {
|
||||
await this.client.post<{}>('api/mute/create', {
|
||||
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/mute/delete
|
||||
*/
|
||||
public async unmuteAccount(id: string): Promise<Response<Entity.Relationship>> {
|
||||
await this.client.post<{}>('api/mute/delete', {
|
||||
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)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
public async pinAccount(_id: string): Promise<Response<Entity.Relationship>> {
|
||||
return new Promise((_, reject) => {
|
||||
const err = new NoImplementedError('misskey does not support')
|
||||
reject(err)
|
||||
})
|
||||
}
|
||||
|
||||
public async unpinAccount(_id: string): Promise<Response<Entity.Relationship>> {
|
||||
return new Promise((_, reject) => {
|
||||
const err = new NoImplementedError('misskey does not support')
|
||||
reject(err)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /api/users/relation
|
||||
*
|
||||
* @param ids Array of the accountID, for example `['1sdfag']`. Only the first element is used.
|
||||
*/
|
||||
public async getRelationship(ids: Array<string>): Promise<Response<Entity.Relationship>> {
|
||||
return this.client
|
||||
.post<MisskeyAPI.Entity.Relation>('/api/users/relation', {
|
||||
userId: ids[0]
|
||||
})
|
||||
.then(res => {
|
||||
return Object.assign(res, {
|
||||
data: MisskeyAPI.Converter.relation(res.data)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /api/users/search
|
||||
*/
|
||||
public async searchAccount(
|
||||
q: string,
|
||||
limit?: number | null,
|
||||
_max_id?: string | null,
|
||||
_since_id?: string | null
|
||||
): Promise<Response<Array<Entity.Account>>> {
|
||||
let params = {
|
||||
query: q
|
||||
}
|
||||
if (limit) {
|
||||
params = Object.assign(params, {
|
||||
limit: limit
|
||||
})
|
||||
}
|
||||
return this.client.post<Array<MisskeyAPI.Entity.UserDetail>>('/api/users/search', params).then(res => {
|
||||
return Object.assign(res, {
|
||||
data: res.data.map(u => MisskeyAPI.Converter.userDetail(u))
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,10 @@ namespace MisskeyAPI {
|
|||
export type App = MisskeyEntity.App
|
||||
export type Emoji = MisskeyEntity.Emoji
|
||||
export type File = MisskeyEntity.File
|
||||
export type Follower = MisskeyEntity.Follower
|
||||
export type Following = MisskeyEntity.Following
|
||||
export type Note = MisskeyEntity.Note
|
||||
export type Relation = MisskeyEntity.Relation
|
||||
export type User = MisskeyEntity.User
|
||||
export type UserDetail = MisskeyEntity.UserDetail
|
||||
export type UserKey = MisskeyEntity.UserKey
|
||||
|
@ -108,6 +111,29 @@ namespace MisskeyAPI {
|
|||
}
|
||||
}
|
||||
|
||||
export const follower = (f: Entity.Follower): MegalodonEntity.Account => {
|
||||
return user(f.follower)
|
||||
}
|
||||
|
||||
export const following = (f: Entity.Following): MegalodonEntity.Account => {
|
||||
return user(f.followee)
|
||||
}
|
||||
|
||||
export const relation = (r: Entity.Relation): MegalodonEntity.Relationship => {
|
||||
return {
|
||||
id: r.id,
|
||||
following: r.isFollowing,
|
||||
followed_by: r.isFollowed,
|
||||
blocking: r.isBlocking,
|
||||
muting: r.isMuted,
|
||||
muting_notifications: false,
|
||||
requested: r.hasPendingFollowRequestFromYou,
|
||||
domain_blocking: false,
|
||||
showing_reblogs: true,
|
||||
endorsed: false
|
||||
}
|
||||
}
|
||||
|
||||
export const note = (n: Entity.Note): MegalodonEntity.Status => {
|
||||
return {
|
||||
id: n.id,
|
||||
|
|
11
src/misskey/entities/following.ts
Normal file
11
src/misskey/entities/following.ts
Normal file
|
@ -0,0 +1,11 @@
|
|||
/// <reference path="userDetail.ts" />
|
||||
|
||||
namespace MisskeyEntity {
|
||||
export type Following = {
|
||||
id: string
|
||||
createdAt: string
|
||||
followeeId: string
|
||||
followerId: string
|
||||
followee: UserDetail
|
||||
}
|
||||
}
|
12
src/misskey/entities/relation.ts
Normal file
12
src/misskey/entities/relation.ts
Normal file
|
@ -0,0 +1,12 @@
|
|||
namespace MisskeyEntity {
|
||||
export type Relation = {
|
||||
id: string
|
||||
isFollowing: boolean
|
||||
hasPendingFollowRequestFromYou: boolean
|
||||
hasPendingFollowRequestToYou: boolean
|
||||
isFollowed: boolean
|
||||
isBlocking: boolean
|
||||
isBlocked: boolean
|
||||
isMuted: boolean
|
||||
}
|
||||
}
|
|
@ -1,7 +1,10 @@
|
|||
/// <reference path="entities/app.ts" />
|
||||
/// <reference path="entities/emoji.ts" />
|
||||
/// <reference path="entities/file.ts" />
|
||||
/// <reference path="entities/follower.ts" />
|
||||
/// <reference path="entities/following.ts" />
|
||||
/// <reference path="entities/note.ts" />
|
||||
/// <reference path="entities/relation.ts" />
|
||||
/// <reference path="entities/user.ts" />
|
||||
/// <reference path="entities/userDetail.ts" />
|
||||
/// <reference path="entities/userkey.ts" />
|
||||
|
|
Loading…
Reference in a new issue