Skip to content

Commit

Permalink
Merge pull request #1553 from h3poteto/iss-1514/tag
Browse files Browse the repository at this point in the history
refs #1472 Add APIs regarding tags
  • Loading branch information
h3poteto authored Jan 25, 2023
2 parents 0dfc922 + eb61ce0 commit f753b0b
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 2 deletions.
1 change: 1 addition & 0 deletions megalodon/src/entities/tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ namespace Entity {
name: string
url: string
history: Array<History> | null
following: boolean
}
}
27 changes: 27 additions & 0 deletions megalodon/src/mastodon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1063,6 +1063,33 @@ export default class Mastodon implements MegalodonInterface {
}
}

// ======================================
// accounts/tags
// ======================================
public async getTag(id: string): Promise<Response<Entity.Tag>> {
return this.client.get<MastodonAPI.Entity.Tag>(`/api/v1/tags/${id}`).then(res => {
return Object.assign(res, {
data: MastodonAPI.Converter.tag(res.data)
})
})
}

public async followTag(id: string): Promise<Response<Entity.Tag>> {
return this.client.post<MastodonAPI.Entity.Tag>(`/api/v1/tags/${id}/follow`).then(res => {
return Object.assign(res, {
data: MastodonAPI.Converter.tag(res.data)
})
})
}

public async unfollowTag(id: string): Promise<Response<Entity.Tag>> {
return this.client.post<MastodonAPI.Entity.Tag>(`/api/v1/tags/${id}/unfollow`).then(res => {
return Object.assign(res, {
data: MastodonAPI.Converter.tag(res.data)
})
})
}

// ======================================
// statuses
// ======================================
Expand Down
1 change: 1 addition & 0 deletions megalodon/src/mastodon/entities/tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ namespace MastodonEntity {
name: string
url: string
history: Array<History> | null
following: boolean
}
}
24 changes: 24 additions & 0 deletions megalodon/src/megalodon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,30 @@ export interface MegalodonInterface {
*/
getSuggestions(limit?: number): Promise<Response<Array<Entity.Account>>>
// ======================================
// accounts/tag
// ======================================
/**
* GET /api/v1/tags/:id
*
* @param id Target hashtag id.
* @return Tag
*/
getTag(id: string): Promise<Response<Entity.Tag>>
/**
* POST /api/v1/tags/:id/follow
*
* @param id Target hashtag id.
* @return Tag
*/
followTag(id: string): Promise<Response<Entity.Tag>>
/**
* POST /api/v1/tags/:id/unfollow
*
* @param id Target hashtag id.
* @return Tag
*/
unfollowTag(id: string): Promise<Response<Entity.Tag>>
// ======================================
// statuses
// ======================================
/**
Expand Down
26 changes: 25 additions & 1 deletion megalodon/src/misskey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -978,6 +978,30 @@ export default class Misskey implements MegalodonInterface {
.then(res => ({ ...res, data: res.data.map(u => MisskeyAPI.Converter.userDetail(u)) }))
}

// ======================================
// accounts/tags
// ======================================
public async getTag(_id: string): Promise<Response<Entity.Tag>> {
return new Promise((_, reject) => {
const err = new NoImplementedError('misskey does not support')
reject(err)
})
}

public async followTag(_id: string): Promise<Response<Entity.Tag>> {
return new Promise((_, reject) => {
const err = new NoImplementedError('misskey does not support')
reject(err)
})
}

public async unfollowTag(_id: string): Promise<Response<Entity.Tag>> {
return new Promise((_, reject) => {
const err = new NoImplementedError('misskey does not support')
reject(err)
})
}

// ======================================
// statuses
// ======================================
Expand Down Expand Up @@ -2000,7 +2024,7 @@ export default class Misskey implements MegalodonInterface {
data: {
accounts: [],
statuses: [],
hashtags: res.data.map(h => ({ name: h, url: h, history: null }))
hashtags: res.data.map(h => ({ name: h, url: h, history: null, following: false }))
}
}))
}
Expand Down
3 changes: 2 additions & 1 deletion megalodon/src/misskey/api_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,8 @@ namespace MisskeyAPI {
return {
name: h.tag,
url: h.tag,
history: null
history: null,
following: false
}
}
}
Expand Down
27 changes: 27 additions & 0 deletions megalodon/src/pleroma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1055,6 +1055,33 @@ export default class Pleroma implements MegalodonInterface {
}
}

// ======================================
// accounts/tags
// ======================================
public async getTag(id: string): Promise<Response<Entity.Tag>> {
return this.client.get<PleromaAPI.Entity.Tag>(`/api/v1/tags/${id}`).then(res => {
return Object.assign(res, {
data: PleromaAPI.Converter.tag(res.data)
})
})
}

public async followTag(id: string): Promise<Response<Entity.Tag>> {
return this.client.post<PleromaAPI.Entity.Tag>(`/api/v1/tags/${id}/follow`).then(res => {
return Object.assign(res, {
data: PleromaAPI.Converter.tag(res.data)
})
})
}

public async unfollowTag(id: string): Promise<Response<Entity.Tag>> {
return this.client.post<PleromaAPI.Entity.Tag>(`/api/v1/tags/${id}/unfollow`).then(res => {
return Object.assign(res, {
data: PleromaAPI.Converter.tag(res.data)
})
})
}

// ======================================
// statuses
// ======================================
Expand Down
1 change: 1 addition & 0 deletions megalodon/src/pleroma/entities/tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ namespace PleromaEntity {
name: string
url: string
history: Array<History> | null
following: boolean
}
}

0 comments on commit f753b0b

Please sign in to comment.