refs #330 Add emoji reaction API for Pleroma

This commit is contained in:
AkiraFukushima 2020-04-16 21:38:56 +09:00
parent cfa14cefb8
commit 8aa9add0ed
10 changed files with 121 additions and 2 deletions

View file

@ -2,5 +2,7 @@
"tabWidth": 2,
"semi": false,
"singleQuote": true,
"printWidth": 140
}
"printWidth": 140,
"trailingComma": "none",
"arrowParens": "avoid"
}

10
src/entities/reaction.ts Normal file
View file

@ -0,0 +1,10 @@
/// <reference path="account.ts" />
namespace Entity {
export type Reaction = {
count: number
me: boolean
name: string
accounts: Array<Account>
}
}

View file

@ -20,6 +20,7 @@
/// <reference path="./entities/poll_option.ts" />
/// <reference path="./entities/preferences.ts" />
/// <reference path="./entities/push_subscription.ts" />
/// <reference path="./entities/reaction.ts" />
/// <reference path="./entities/relationship.ts" />
/// <reference path="./entities/report.ts" />
/// <reference path="./entities/results.ts" />

View file

@ -56,6 +56,40 @@ export default class Pleroma extends Mastodon implements MegalodonInterface {
})
})
}
// ======================================
// Emoji reactions
// ======================================
public async createEmojiReaction(id: string, emoji: string): Promise<Response<Entity.Status>> {
return this.client.put<PleromaAPI.Entity.Status>(`/api/v1/pleroma/statuses/${id}/reactions/${emoji}`).then(res => {
return Object.assign(res, {
data: PleromaAPI.Converter.status(res.data)
})
})
}
public async deleteEmojiReaction(id: string, emoji: string): Promise<Response<Entity.Status>> {
return this.client.del<PleromaAPI.Entity.Status>(`/api/v1/pleroma/statuses/${id}/reactions/${emoji}`).then(res => {
return Object.assign(res, {
data: PleromaAPI.Converter.status(res.data)
})
})
}
public async getEmojiReactions(id: string): Promise<Response<Array<Entity.Reaction>>> {
return this.client.get<Array<PleromaAPI.Entity.Reaction>>(`/api/v1/pleroma/statuses/${id}/reactions`).then(res => {
return Object.assign(res, {
data: res.data.map(r => PleromaAPI.Converter.reaction(r))
})
})
}
public async getEmojiReaction(id: string, emoji: string): Promise<Response<Entity.Reaction>> {
return this.client.get<PleromaAPI.Entity.Reaction>(`/api/v1/pleroma/statuses/${id}/reactions/${emoji}`).then(res => {
return Object.assign(res, {
data: PleromaAPI.Converter.reaction(res.data)
})
})
}
// ======================================
// HTTP Streaming

View file

@ -1,15 +1,27 @@
import MastodonAPI from '../mastodon/api_client'
import MegalodonEntity from '../entity'
import PleromaEntity from './entity'
namespace PleromaAPI {
export namespace Entity {
export type Account = PleromaEntity.Account
export type Emoji = PleromaEntity.Emoji
export type Status = MastodonAPI.Entity.Status
export type Relationship = MastodonAPI.Entity.Relationship
export type Reaction = PleromaEntity.Reaction
export type Source = PleromaEntity.Source
}
export namespace Converter {
export const account = (a: Entity.Account): MegalodonEntity.Account => a
export const status = (s: Entity.Status): MegalodonEntity.Status => s
export const relationship = (r: Entity.Relationship): MegalodonEntity.Relationship => r
export const reaction = (r: Entity.Reaction): MegalodonEntity.Reaction => ({
count: r.count,
me: r.me,
name: r.name,
accounts: r.accounts.map(a => account(a))
})
}
}

View file

@ -0,0 +1,27 @@
/// <reference path="emoji.ts" />
/// <reference path="source.ts" />
namespace PleromaEntity {
export type Account = {
id: string
username: string
acct: string
display_name: string
locked: boolean
created_at: string
followers_count: number
following_count: number
statuses_count: number
note: string
url: string
avatar: string
avatar_static: string
header: string
header_static: string
emojis: Array<Emoji>
moved: Account | null
fields: object | null
bot: boolean | null
source?: Source
}
}

View file

@ -0,0 +1,8 @@
namespace PleromaEntity {
export type Emoji = {
shortcode: string
static_url: string
url: string
visible_in_picker: boolean
}
}

View file

@ -0,0 +1,10 @@
/// <reference path="./account.ts" />
namespace PleromaEntity {
export type Reaction = {
count: number
me: boolean
name: string
accounts: Array<Account>
}
}

View file

@ -0,0 +1,9 @@
namespace PleromaEntity {
export type Source = {
privacy: string | null
sensitive: boolean | null
language: string | null
note: string
fields: object
}
}

6
src/pleroma/entity.ts Normal file
View file

@ -0,0 +1,6 @@
/// <reference path="./entities/account.ts" />
/// <reference path="./entities/emoji.ts" />
/// <reference path="./entities/reaction.ts" />
/// <reference path="./entities/source.ts" />
export default PleromaEntity