Skip to content

Commit

Permalink
Merge pull request h3poteto#1689 from h3poteto/fix/follow_request
Browse files Browse the repository at this point in the history
Return FollowRequest object in get_follow_requests for Friendica
  • Loading branch information
h3poteto authored Apr 24, 2023
2 parents 595aec6 + 18185f8 commit 33435b6
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 11 deletions.
27 changes: 27 additions & 0 deletions megalodon/src/entities/follow_request.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/// <reference path="emoji.ts" />
/// <reference path="field.ts" />

namespace Entity {
export type FollowRequest = {
id: number
username: string
acct: string
display_name: string
locked: boolean
bot: boolean
discoverable?: boolean
group: boolean
created_at: string
note: string
url: string
avatar: string
avatar_static: string
header: string
header_static: string
followers_count: number
following_count: number
statuses_count: number
emojis: Array<Emoji>
fields: Array<Field>
}
}
1 change: 1 addition & 0 deletions megalodon/src/entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
/// <reference path="./entities/featured_tag.ts" />
/// <reference path="./entities/field.ts" />
/// <reference path="./entities/filter.ts" />
/// <reference path="./entities/follow_request.ts" />
/// <reference path="./entities/history.ts" />
/// <reference path="./entities/identity_proof.ts" />
/// <reference path="./entities/instance.ts" />
Expand Down
14 changes: 7 additions & 7 deletions megalodon/src/friendica.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1011,21 +1011,21 @@ export default class Friendica implements MegalodonInterface {
* @param limit Maximum number of results.
* @return Array of FollowRequest.
*/
public async getFollowRequests(limit?: number): Promise<Response<Array<Entity.Account>>> {
public async getFollowRequests(limit?: number): Promise<Response<Array<Entity.FollowRequest>>> {
if (limit) {
return this.client
.get<Array<FriendicaAPI.Entity.Account>>('/api/v1/follow_requests', {
.get<Array<FriendicaAPI.Entity.FollowRequest>>('/api/v1/follow_requests', {
limit: limit
})
.then(res => {
return Object.assign(res, {
data: res.data.map(a => FriendicaAPI.Converter.account(a))
data: res.data.map(a => FriendicaAPI.Converter.follow_request(a))
})
})
} else {
return this.client.get<Array<FriendicaAPI.Entity.Account>>('/api/v1/follow_requests').then(res => {
return this.client.get<Array<FriendicaAPI.Entity.FollowRequest>>('/api/v1/follow_requests').then(res => {
return Object.assign(res, {
data: res.data.map(a => FriendicaAPI.Converter.account(a))
data: res.data.map(a => FriendicaAPI.Converter.follow_request(a))
})
})
}
Expand All @@ -1034,7 +1034,7 @@ export default class Friendica implements MegalodonInterface {
/**
* POST /api/v1/follow_requests/:id/authorize
*
* @param id Target account ID.
* @param id The FollowRequest ID.
* @return Relationship.
*/
public async acceptFollowRequest(id: string): Promise<Response<Entity.Relationship>> {
Expand All @@ -1048,7 +1048,7 @@ export default class Friendica implements MegalodonInterface {
/**
* POST /api/v1/follow_requests/:id/reject
*
* @param id Target account ID.
* @param id The FollowRequest ID.
* @return Relationship.
*/
public async rejectFollowRequest(id: string): Promise<Response<Entity.Relationship>> {
Expand Down
2 changes: 2 additions & 0 deletions megalodon/src/friendica/api_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ namespace FriendicaAPI {
export type FeaturedTag = FriendicaEntity.FeaturedTag
export type Field = FriendicaEntity.Field
export type Filter = FriendicaEntity.Filter
export type FollowRequest = FriendicaEntity.FollowRequest
export type History = FriendicaEntity.History
export type IdentityProof = FriendicaEntity.IdentityProof
export type Instance = FriendicaEntity.Instance
Expand Down Expand Up @@ -562,6 +563,7 @@ namespace FriendicaAPI {
export const featured_tag = (e: Entity.FeaturedTag): MegalodonEntity.FeaturedTag => e
export const field = (f: Entity.Field): MegalodonEntity.Field => f
export const filter = (f: Entity.Filter): MegalodonEntity.Filter => f
export const follow_request = (f: Entity.FollowRequest): MegalodonEntity.FollowRequest => f
export const history = (h: Entity.History): MegalodonEntity.History => h
export const identity_proof = (i: Entity.IdentityProof): MegalodonEntity.IdentityProof => i
export const instance = (i: Entity.Instance): MegalodonEntity.Instance => {
Expand Down
27 changes: 27 additions & 0 deletions megalodon/src/friendica/entities/follow_request.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/// <reference path="emoji.ts" />
/// <reference path="field.ts" />

namespace FriendicaEntity {
export type FollowRequest = {
id: number
username: string
acct: string
display_name: string
locked: boolean
bot: boolean
discoverable?: boolean
group: boolean
created_at: string
note: string
url: string
avatar: string
avatar_static: string
header: string
header_static: string
followers_count: number
following_count: number
statuses_count: number
emojis: Array<Emoji>
fields: Array<Field>
}
}
1 change: 1 addition & 0 deletions megalodon/src/friendica/entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
/// <reference path="./entities/featured_tag.ts" />
/// <reference path="./entities/field.ts" />
/// <reference path="./entities/filter.ts" />
/// <reference path="./entities/follow_request.ts" />
/// <reference path="./entities/history.ts" />
/// <reference path="./entities/identity_proof.ts" />
/// <reference path="./entities/instance.ts" />
Expand Down
8 changes: 4 additions & 4 deletions megalodon/src/megalodon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -534,20 +534,20 @@ export interface MegalodonInterface {
* Get pending follow requests.
*
* @param limit Maximum number of results.
* @return Array of account.
* @return Array of account or follow request.
*/
getFollowRequests(limit?: number): Promise<Response<Array<Entity.Account>>>
getFollowRequests(limit?: number): Promise<Response<Array<Entity.Account | Entity.FollowRequest>>>
/**
* Accept the follow request.
*
* @param id Target account ID.
* @param id Target account ID. Or follow request ID in Friendica.
* @return Relationship.
*/
acceptFollowRequest(id: string): Promise<Response<Entity.Relationship>>
/**
* Reject the follow request.
*
* @param id Target account ID.
* @param id Target account ID. Or follow request ID in Friendica.
* @return Relationship.
*/
rejectFollowRequest(id: string): Promise<Response<Entity.Relationship>>
Expand Down

0 comments on commit 33435b6

Please sign in to comment.