Add getRelationships method to get all relationships
This commit is contained in:
parent
c429d00be8
commit
68ca0ae132
17
example/typescript/src/misskey/relationships.ts
Normal file
17
example/typescript/src/misskey/relationships.ts
Normal file
|
@ -0,0 +1,17 @@
|
|||
import generator from 'megalodon'
|
||||
|
||||
declare var process: {
|
||||
env: {
|
||||
MISSKEY_ACCESS_TOKEN: string
|
||||
}
|
||||
}
|
||||
|
||||
const BASE_URL: string = 'https://misskey.io'
|
||||
|
||||
const access_token: string = process.env.MISSKEY_ACCESS_TOKEN
|
||||
|
||||
const client = generator('misskey', BASE_URL, access_token)
|
||||
|
||||
client.getRelationships(['7rl99pkppb', '7rkr4nmz19']).then(res => {
|
||||
console.log(res.data)
|
||||
})
|
|
@ -514,6 +514,18 @@ export default class Mastodon implements MegalodonInterface {
|
|||
})
|
||||
}
|
||||
|
||||
public async getRelationships(ids: Array<string>): Promise<Response<Array<Entity.Relationship>>> {
|
||||
return this.client
|
||||
.get<Array<MastodonAPI.Entity.Relationship>>('/api/v1/accounts/relationships', {
|
||||
id: ids
|
||||
})
|
||||
.then(res => {
|
||||
return Object.assign(res, {
|
||||
data: res.data.map(r => MastodonAPI.Converter.relationship(r))
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
public async searchAccount(
|
||||
q: string,
|
||||
options?: {
|
||||
|
|
|
@ -314,6 +314,13 @@ export interface MegalodonInterface {
|
|||
* @return Relationship
|
||||
*/
|
||||
getRelationship(id: string): Promise<Response<Entity.Relationship>>
|
||||
/**
|
||||
* Get multiple relationships in one method
|
||||
*
|
||||
* @param ids Array of account IDs.
|
||||
* @return Array of Relationship.
|
||||
*/
|
||||
getRelationships(ids: Array<string>): Promise<Response<Array<Entity.Relationship>>>
|
||||
/**
|
||||
* GET /api/v1/accounts/search
|
||||
*
|
||||
|
|
|
@ -566,6 +566,18 @@ export default class Misskey implements MegalodonInterface {
|
|||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /api/users/relation
|
||||
*
|
||||
* @param id Array of account ID, for example `['1sdfag', 'ds12aa']`.
|
||||
*/
|
||||
public async getRelationships(ids: Array<string>): Promise<Response<Array<Entity.Relationship>>> {
|
||||
return Promise.all(ids.map(id => this.getRelationship(id))).then(results => ({
|
||||
...results[0],
|
||||
data: results.map(r => r.data)
|
||||
}))
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /api/users/search
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue