Skip to content

Commit

Permalink
Add a few models
Browse files Browse the repository at this point in the history
* List
* Marker
* MediaAttachment
* MediaMetadata
  • Loading branch information
wingio committed Dec 21, 2023
1 parent cef3aba commit 71e57c8
Show file tree
Hide file tree
Showing 4 changed files with 189 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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
}

}
Original file line number Diff line number Diff line change
@@ -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
)
Original file line number Diff line number Diff line change
@@ -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
}

}
Original file line number Diff line number Diff line change
@@ -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
)

}

0 comments on commit 71e57c8

Please sign in to comment.