Skip to content

Commit

Permalink
Merge pull request #2153 from h3poteto/fix/pleroma-custom-emoji
Browse files Browse the repository at this point in the history
Fix pleroma custom emoji
  • Loading branch information
h3poteto authored Feb 8, 2024
2 parents a39fa68 + 7b8cf13 commit e9d3847
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
28 changes: 28 additions & 0 deletions example/typescript/src/pleroma/custom_emoji.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import * as readline from 'readline'
import generator, { Entity, Response } from 'megalodon'

declare var process: {
env: {
PLEROMA_ACCESS_TOKEN: string
}
stdin: any
stdout: any
}

const rl: readline.ReadLine = readline.createInterface({
input: process.stdin,
output: process.stdout
})

const BASE_URL: string = 'https://pleroma.io'

const access_token: string = process.env.PLEROMA_ACCESS_TOKEN

const client = generator('pleroma', BASE_URL, access_token)

rl.question(`Enter status id of ${BASE_URL}: `, id => {
client.createEmojiReaction(id, 'arch_linux').then((res: Response<Entity.Status>) => {
console.log(res.data)
rl.close()
})
})
8 changes: 5 additions & 3 deletions megalodon/src/pleroma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3139,7 +3139,9 @@ export default class Pleroma implements MegalodonInterface {
* @param {string} emoji Reaction emoji string. This string is raw unicode emoji or custom emoji name (not shortcode).
*/
public async createEmojiReaction(id: string, emoji: string): Promise<Response<Entity.Status>> {
return this.client.put<PleromaAPI.Entity.Status>(`/api/v1/pleroma/statuses/${id}/reactions/:${encodeURI(emoji)}:`).then(res => {
// We can pass both name and shortcode to Pleroma.
// Furthermore, it accepts external server's emoji reactions, like `0010@lain.com`.
return this.client.put<PleromaAPI.Entity.Status>(`/api/v1/pleroma/statuses/${id}/reactions/${encodeURI(emoji)}`).then(res => {
return Object.assign(res, {
data: PleromaAPI.Converter.status(res.data)
})
Expand All @@ -3153,7 +3155,7 @@ export default class Pleroma implements MegalodonInterface {
* @param {string} emoji Reaction emoji string. This string is raw unicode emoji or custom emoji name (not shortcode).
*/
public async deleteEmojiReaction(id: string, emoji: string): Promise<Response<Entity.Status>> {
return this.client.del<PleromaAPI.Entity.Status>(`/api/v1/pleroma/statuses/${id}/reactions/:${encodeURI(emoji)}:`).then(res => {
return this.client.del<PleromaAPI.Entity.Status>(`/api/v1/pleroma/statuses/${id}/reactions/${encodeURI(emoji)}`).then(res => {
return Object.assign(res, {
data: PleromaAPI.Converter.status(res.data)
})
Expand All @@ -3180,7 +3182,7 @@ export default class Pleroma implements MegalodonInterface {
* @param {string} emoji Reaction emoji string. This string is raw unicode emoji or custom emoji name (not shortcode).
*/
public async getEmojiReaction(id: string, emoji: string): Promise<Response<Entity.Reaction>> {
return this.client.get<PleromaAPI.Entity.Reaction>(`/api/v1/pleroma/statuses/${id}/reactions/:${encodeURI(emoji)}:`).then(res => {
return this.client.get<PleromaAPI.Entity.Reaction>(`/api/v1/pleroma/statuses/${id}/reactions/${encodeURI(emoji)}`).then(res => {
return Object.assign(res, {
data: PleromaAPI.Converter.reaction(res.data)
})
Expand Down

0 comments on commit e9d3847

Please sign in to comment.