From f7ddcc9871d939219ac00732e806199e4b2ac559 Mon Sep 17 00:00:00 2001 From: Eyre_S Date: Tue, 22 Apr 2025 16:26:32 +0800 Subject: [PATCH] fix FXApi error --- .../social_share/external/twitter/FXApi.scala | 2 + .../external/twitter/FXFacet.scala | 47 +++++++++++++++++++ .../external/twitter/FXPhoto.scala | 6 ++- .../external/twitter/FXRawText.scala | 13 +++++ .../external/twitter/FXTweet.scala | 6 ++- 5 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 morny-coeur/src/main/scala/cc/sukazyo/cono/morny/social_share/external/twitter/FXFacet.scala create mode 100644 morny-coeur/src/main/scala/cc/sukazyo/cono/morny/social_share/external/twitter/FXRawText.scala diff --git a/morny-coeur/src/main/scala/cc/sukazyo/cono/morny/social_share/external/twitter/FXApi.scala b/morny-coeur/src/main/scala/cc/sukazyo/cono/morny/social_share/external/twitter/FXApi.scala index d748b93..b75afa6 100644 --- a/morny-coeur/src/main/scala/cc/sukazyo/cono/morny/social_share/external/twitter/FXApi.scala +++ b/morny-coeur/src/main/scala/cc/sukazyo/cono/morny/social_share/external/twitter/FXApi.scala @@ -49,6 +49,8 @@ object FXApi { implicit val decoder_FXPoolChoice: Decoder[FXPoolChoice] = deriveDecoder implicit val decoder_FXPool: Decoder[FXPool] = deriveDecoder implicit val decoder_FXTranslate: Decoder[FXTranslate] = deriveDecoder + implicit val decoder_FXFacet: Decoder[FXFacet] = deriveDecoder + implicit val decoder_FXRawText: Decoder[FXRawText] = deriveDecoder implicit val decoder_FXTweet_media: Decoder[FXTweet.mediaType] = deriveDecoder implicit val decoder_FXTweet: Decoder[FXTweet] = deriveDecoder implicit val decoder_FXApi: Decoder[FXApi] = deriveDecoder diff --git a/morny-coeur/src/main/scala/cc/sukazyo/cono/morny/social_share/external/twitter/FXFacet.scala b/morny-coeur/src/main/scala/cc/sukazyo/cono/morny/social_share/external/twitter/FXFacet.scala new file mode 100644 index 0000000..b9bb584 --- /dev/null +++ b/morny-coeur/src/main/scala/cc/sukazyo/cono/morny/social_share/external/twitter/FXFacet.scala @@ -0,0 +1,47 @@ +package cc.sukazyo.cono.morny.social_share.external.twitter + +/** The facets (rich text indicators) of the text. + * + * Every facet is a part of the original text, contains some extra information about the + * text segment. + * + * @param `type` The type of the facet. + * This may be one of the following (not fully listed): + * + * - `hashtag` - A hashtag (like #topic) + * - `media` - A media, like a photo or a video. + * + * @param indices The indices of the text segment in the original text. + * + * This should always be a list of two integers, the first one is the start + * index, and the second one is the end index of the text + * segment in the raw_text's text. + * + * @param original The original text of the facet. + * Should be the same with texts that the indices point to. + * + * The content type is different for each type: + * - for `media`, this is a media shortcode (like `t.co/abcde`). + * - for `hashtag`, this is the hashtag name without hash char (like `topic`, + * but not `#topic`). + * + * @param replacement Alternative method to show this facet. + * + * For now, only `media` have this field, and it is a URL that points to + * the media in the tweet (`https://x.com/user/status/123/photo/1`). + * + * @param display The display text of the facet. + * + * For now, only `media` have this field, and it seems like the permanent URL + * of the media (`pic.x.com/abcde`). + * + * @param id A very large integer ID of the facet. Seems only `media` have this field. + */ +case class FXFacet ( + `type`: String, + indices: List[Int], + original: Option[String], + replacement: Option[String], + display: Option[String], + id: Option[String], +) diff --git a/morny-coeur/src/main/scala/cc/sukazyo/cono/morny/social_share/external/twitter/FXPhoto.scala b/morny-coeur/src/main/scala/cc/sukazyo/cono/morny/social_share/external/twitter/FXPhoto.scala index 78c690d..cd4190f 100644 --- a/morny-coeur/src/main/scala/cc/sukazyo/cono/morny/social_share/external/twitter/FXPhoto.scala +++ b/morny-coeur/src/main/scala/cc/sukazyo/cono/morny/social_share/external/twitter/FXPhoto.scala @@ -6,11 +6,15 @@ package cc.sukazyo.cono.morny.social_share.external.twitter * @param url URL of the photo * @param width Width of the photo, in pixels * @param height Height of the photo, in pixels + * @param altText Alternative text of the photo, or also known as photo description. + * + * It seems that this is not provided by Fix-Twitter API after 2025-04. */ case class FXPhoto ( `type`: "photo", url: String, width: Int, height: Int, - altText: String // todo + // todo: Find a tweet to test if this can still work + altText: Option[String] ) diff --git a/morny-coeur/src/main/scala/cc/sukazyo/cono/morny/social_share/external/twitter/FXRawText.scala b/morny-coeur/src/main/scala/cc/sukazyo/cono/morny/social_share/external/twitter/FXRawText.scala new file mode 100644 index 0000000..a2c77ab --- /dev/null +++ b/morny-coeur/src/main/scala/cc/sukazyo/cono/morny/social_share/external/twitter/FXRawText.scala @@ -0,0 +1,13 @@ +package cc.sukazyo.cono.morny.social_share.external.twitter + +/** The raw text of the tweet. + * + * Contains all information that you want to know about the tweet content. + * + * @param text The text-formatted tweet content. Medias is also attached as a URL in the text. + * @param facets The facets (rich text information) of the text. + */ +case class FXRawText ( + text: String, + facets: List[FXFacet] +) diff --git a/morny-coeur/src/main/scala/cc/sukazyo/cono/morny/social_share/external/twitter/FXTweet.scala b/morny-coeur/src/main/scala/cc/sukazyo/cono/morny/social_share/external/twitter/FXTweet.scala index 78955c2..17542ee 100644 --- a/morny-coeur/src/main/scala/cc/sukazyo/cono/morny/social_share/external/twitter/FXTweet.scala +++ b/morny-coeur/src/main/scala/cc/sukazyo/cono/morny/social_share/external/twitter/FXTweet.scala @@ -7,7 +7,10 @@ import cc.sukazyo.cono.morny.system.utils.EpochDateTime.EpochSeconds * * @param id Status (Tweet) ID * @param url Link to original Tweet - * @param text Text of Tweet + * @param text Text of Tweet. May not contains some extra information like URLs. + * @param raw_text Raw text of Tweet, contains a full article text and facets (rich information). + * Comparing with the `text` field, this contains all information that you want + * to know, like even the media is included. * @param created_at Date/Time in UTC when the Tweet was created * @param created_timestamp Date/Time in UTC when the Tweet was created * @param color Dominant color pulled from either Tweet media or from the author's profile picture. @@ -39,6 +42,7 @@ case class FXTweet ( id: String, url: String, text: String, + raw_text: FXRawText, created_at: String, created_timestamp: EpochSeconds, is_note_tweet: Boolean, // todo