File tree 3 files changed +20
-14
lines changed
3 files changed +20
-14
lines changed Original file line number Diff line number Diff line change
1
+ import { type Context , Emoji , Image } from "@fedify/fedify" ;
2
+
3
+ interface CustomEmoji {
4
+ shortcode : string ;
5
+ url : string ;
6
+ }
7
+
8
+ export function toEmoji ( ctx : Context < unknown > , emoji : CustomEmoji ) : Emoji {
9
+ const shortcode = emoji . shortcode . replace ( / ^ : | : $ / g, "" ) ;
10
+ return new Emoji ( {
11
+ id : ctx . getObjectUri ( Emoji , { shortcode } ) ,
12
+ name : `:${ shortcode } :` ,
13
+ icon : new Image ( { url : new URL ( emoji . url ) } ) ,
14
+ } ) ;
15
+ }
Original file line number Diff line number Diff line change @@ -63,6 +63,7 @@ import {
63
63
reports ,
64
64
} from "../schema" ;
65
65
import { toTemporalInstant } from "./date" ;
66
+ import { toEmoji } from "./emoji" ;
66
67
import {
67
68
onAccountDeleted ,
68
69
onAccountMoved ,
@@ -574,13 +575,7 @@ federation.setObjectDispatcher(
574
575
where : eq ( customEmojis . shortcode , shortcode ) ,
575
576
} ) ;
576
577
if ( emoji == null ) return null ;
577
- return new Emoji ( {
578
- id : ctx . getObjectUri ( Emoji , { shortcode } ) ,
579
- name : `:${ shortcode } :` ,
580
- icon : new Image ( {
581
- url : new URL ( emoji . url ) ,
582
- } ) ,
583
- } ) ;
578
+ return toEmoji ( ctx , emoji ) ;
584
579
} ,
585
580
) ;
586
581
Original file line number Diff line number Diff line change @@ -69,6 +69,7 @@ import { extractPreviewLink } from "../text";
69
69
import { persistAccount , persistAccountByIri } from "./account" ;
70
70
import { iterateCollection } from "./collection" ;
71
71
import { toDate , toTemporalInstant } from "./date" ;
72
+ import { toEmoji } from "./emoji" ;
72
73
73
74
const logger = getLogger ( [ "hollo" , "federation" , "post" ] ) ;
74
75
@@ -714,13 +715,8 @@ export function toObject(
714
715
href : new URL ( url ) ,
715
716
} ) ,
716
717
) ,
717
- ...Object . entries ( post . emojis ) . map (
718
- ( [ shortcode , url ] ) =>
719
- new Emoji ( {
720
- id : ctx . getObjectUri ( Emoji , { shortcode } ) ,
721
- name : `:${ shortcode . replace ( / ^ : | : $ / g, "" ) } :` ,
722
- icon : new Image ( { url : new URL ( url ) } ) ,
723
- } ) ,
718
+ ...Object . entries ( post . emojis ) . map ( ( [ shortcode , url ] ) =>
719
+ toEmoji ( ctx , { shortcode, url } ) ,
724
720
) ,
725
721
...( post . quoteTarget == null
726
722
? [ ]
You can’t perform that action at this time.
0 commit comments