Merge pull request #270 from h3poteto/add/relationships

Add getRelationships method to get all relationships
This commit is contained in:
AkiraFukushima 2020-03-18 23:48:31 +09:00 committed by GitHub
commit bda7abed87
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 48 additions and 0 deletions

View 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)
})

View file

@ -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?: {

View file

@ -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
*

View file

@ -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
*/