From 71e57c897db4be66a8bfa784db4206bfc81ae8b9 Mon Sep 17 00:00:00 2001 From: Wing <44992537+wingio@users.noreply.github.com> Date: Thu, 21 Dec 2023 17:38:23 -0500 Subject: [PATCH] Add a few models * List * Marker * MediaAttachment * MediaMetadata --- .../fediapi/software/mastodon/model/List.kt | 41 ++++++++++++ .../fediapi/software/mastodon/model/Marker.kt | 19 ++++++ .../mastodon/model/media/MediaAttachment.kt | 65 +++++++++++++++++++ .../mastodon/model/media/MediaMetadata.kt | 64 ++++++++++++++++++ 4 files changed, 189 insertions(+) create mode 100644 fediapi/src/commonMain/kotlin/xyz/wingio/fediapi/software/mastodon/model/List.kt create mode 100644 fediapi/src/commonMain/kotlin/xyz/wingio/fediapi/software/mastodon/model/Marker.kt create mode 100644 fediapi/src/commonMain/kotlin/xyz/wingio/fediapi/software/mastodon/model/media/MediaAttachment.kt create mode 100644 fediapi/src/commonMain/kotlin/xyz/wingio/fediapi/software/mastodon/model/media/MediaMetadata.kt diff --git a/fediapi/src/commonMain/kotlin/xyz/wingio/fediapi/software/mastodon/model/List.kt b/fediapi/src/commonMain/kotlin/xyz/wingio/fediapi/software/mastodon/model/List.kt new file mode 100644 index 0000000..cab2e47 --- /dev/null +++ b/fediapi/src/commonMain/kotlin/xyz/wingio/fediapi/software/mastodon/model/List.kt @@ -0,0 +1,41 @@ +package xyz.wingio.fediapi.software.mastodon.model + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +/** + * Represents a list of some users that the authenticated user follows. + * + * @param id The internal database ID of the list. + * @param title The user-defined title of the list. + * @param repliesPolicy Which replies should be shown in the list. + */ +@Serializable +public data class List( + val id: String, + val title: String, + @SerialName("replies_policy") val repliesPolicy: ReplyPolicy +) { + + /** + * Which replies should be shown in a list. + */ + @Serializable + public enum class ReplyPolicy { + /** + * Show replies to any followed user + */ + @SerialName("followed") FOLLOWED, + + /** + * Show replies to members of the list + */ + @SerialName("list") LIST, + + /** + * Show replies to no one + */ + @SerialName("none") NONE + } + +} \ No newline at end of file diff --git a/fediapi/src/commonMain/kotlin/xyz/wingio/fediapi/software/mastodon/model/Marker.kt b/fediapi/src/commonMain/kotlin/xyz/wingio/fediapi/software/mastodon/model/Marker.kt new file mode 100644 index 0000000..b4e691e --- /dev/null +++ b/fediapi/src/commonMain/kotlin/xyz/wingio/fediapi/software/mastodon/model/Marker.kt @@ -0,0 +1,19 @@ +package xyz.wingio.fediapi.software.mastodon.model + +import kotlinx.datetime.Instant +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +/** + * Represents the last read position within a user's timelines. + * + * @param lastReadId The ID of the most recently viewed entity. + * @param version An incrementing counter, used for locking to prevent write conflicts. + * @param updatedAt The timestamp of when the marker was set. + */ +@Serializable +public data class Marker( + @SerialName("last_read_id") val lastReadId: String, + val version: Int, + @SerialName("updated_at") val updatedAt: Instant +) \ No newline at end of file diff --git a/fediapi/src/commonMain/kotlin/xyz/wingio/fediapi/software/mastodon/model/media/MediaAttachment.kt b/fediapi/src/commonMain/kotlin/xyz/wingio/fediapi/software/mastodon/model/media/MediaAttachment.kt new file mode 100644 index 0000000..5b1b9b6 --- /dev/null +++ b/fediapi/src/commonMain/kotlin/xyz/wingio/fediapi/software/mastodon/model/media/MediaAttachment.kt @@ -0,0 +1,65 @@ +package xyz.wingio.fediapi.software.mastodon.model.media + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable +import xyz.wingio.fediapi.Blurhash +import xyz.wingio.fediapi.URL + +/** + * Represents a file or media attachment that can be added to a status. + * + * @param id The ID of the attachment in the database. + * @param type The type of the attachment. + * @param url The location of the original full-size attachment. + * @param previewUrl The location of a scaled-down preview of the attachment. + * @param remoteUrl The location of the full-size original attachment on the remote website. + * @param textUrl A shorter URL for the attachment. + * @param meta Metadata returned by Paperclip. + * @param description Alternate text that describes what is in the media attachment, to be used for the visually impaired or when media attachments do not load. + * @param blurhash A hash computed by [the BlurHash algorithm](https://github.com/woltapp/blurhash), for generating colorful preview thumbnails when media has not been downloaded yet. + */ +@Serializable +public data class MediaAttachment( + val id: String, + val type: Type, + val url: URL, + @SerialName("preview_url") val previewUrl: URL, + @SerialName("remote_url") val remoteUrl: URL?, + @Deprecated("Deprecated since Mastodon 3.5.0") @SerialName("text_url") val textUrl: String? = null, + val meta: MediaMetadata, + val description: String?, + val blurhash: Blurhash +) { + + /** + * Type of attachment + */ + @Serializable + public enum class Type { + /** + * unsupported or unrecognized file type + */ + @SerialName("unknown") UNKNOWN, + + /** + * Static image + */ + @SerialName("image") IMAGE, + + /** + * Looping, soundless animation + */ + @SerialName("gifv") GIFV, + + /** + * Video clip + */ + @SerialName("video") VIDEO, + + /** + * Audio track + */ + @SerialName("audio") AUDIO + } + +} \ No newline at end of file diff --git a/fediapi/src/commonMain/kotlin/xyz/wingio/fediapi/software/mastodon/model/media/MediaMetadata.kt b/fediapi/src/commonMain/kotlin/xyz/wingio/fediapi/software/mastodon/model/media/MediaMetadata.kt new file mode 100644 index 0000000..be37cf2 --- /dev/null +++ b/fediapi/src/commonMain/kotlin/xyz/wingio/fediapi/software/mastodon/model/media/MediaMetadata.kt @@ -0,0 +1,64 @@ +package xyz.wingio.fediapi.software.mastodon.model.media + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +/** + * Metadata for a given piece of media + * + * @param length Length of the media (VIDEO, GIFV, AUDIO). + * @param duration Length of the media in seconds (VIDEO, GIFV, AUDIO). + * @param fps Frames/second of the media (VIDEO, GIFV). + * @param size Size of the media (WxH) (VIDEO, GIFV). + * @param width Width of the media in pixels (VIDEO, GIFV). + * @param height Height of the media in pixels (VIDEO, GIFV). + * @param aspect Aspect ratio of the media (w/h) (VIDEO, GIFV). + * @param frameRate Framerate of the given media (VIDEO, GIFV). + * @param audioEncode The encoding used for the audio in this media (VIDEO, AUDIO). + * @param audioBitrate The bitrate for the audio used in this media (VIDEO, AUDIO). + * @param audioChannels Channels used for this media's audio (VIDEO, AUDIO). + * @param bitrate Bits/sec sample rate for this media (VIDEO, GIFV, AUDIO) + * @param original The original size/length (ALL) + * @param small A smaller or static version of this media (IMAGE, VIDEO, GIFV). + * @param focus Focal point for an image (IMAGE) + */ +@Serializable +public data class MediaMetadata( + val length: String? = null, + val duration: Float? = null, + val fps: Int? = null, + val size: String? = null, + val width: Int? = null, + val height: Int? = null, + val aspect: Float? = null, + @SerialName("frame_rate") val frameRate: String? = null, + @SerialName("audio_encode") val audioEncode: String? = null, + @SerialName("audio_bitrate") val audioBitrate: String? = null, + @SerialName("audio_channels") val audioChannels: AudioChannels? = null, + val bitrate: Int? = null, + val original: MediaMetadata? = null, + val small: MediaMetadata? = null, + val focus: Focus? = null +) { + + @Serializable + public enum class AudioChannels { + @SerialName("mono") MONO, + @SerialName("stereo") STEREO + } + + /** + * Focal point for an image, ranging from (-1, -1) to (1, 1) with (0, 0) being the center of the original image. + * + * [Additional information](https://docs.joinmastodon.org/api/guidelines/#focal-points) + * + * @param x Ranging from -1 to 1, the relative x coordinate for the focal point + * @param y Ranging from -1 to 1, the relative y coordinate for the focal point + */ + @Serializable + public data class Focus( + val x: Float, + val y: Float + ) + +} \ No newline at end of file