Skip to content

Commit

Permalink
Add more models
Browse files Browse the repository at this point in the history
* Poll
* Preferences
* PreviewCard
* Reaction
* Relationship

* List -> UserList
  • Loading branch information
wingio committed Dec 22, 2023
1 parent 71e57c8 commit 35cbdf3
Show file tree
Hide file tree
Showing 7 changed files with 241 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public data class Announcement(
val statuses: List<Status>,
val tags: List<String>, // TODO: Model
val emojis: List<CustomEmoji>,
val reactions: List<String> // TODO: Model
val reactions: List<Reaction>
) {

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package xyz.wingio.fediapi.software.mastodon.model

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import xyz.wingio.fediapi.Language

/**
* Represents a user's preferences.
*
* @param defaultStatusVisibility Default visibility for new posts.
* @param defaultStatusSensitive Default sensitivity flag for new posts.
* @param defaultLanguage Default language for new posts
* @param mediaExpandPreference Whether media attachments should be automatically displayed or blurred/hidden.
* @param expandSpoilers Whether CWs should be expanded by default.
*/
@Serializable
public data class Preferences(
@SerialName("posting:default:visibility") val defaultStatusVisibility: Visibility,
@SerialName("posting:default:sensitive") val defaultStatusSensitive: Boolean,
@SerialName("posting:default:language") val defaultLanguage: Language?,
@SerialName("reading:expand:media") val mediaExpandPreference: MediaExpandPreference,
@SerialName("reading:expand:spoilers") val expandSpoilers: Boolean
) {

@Serializable
public enum class MediaExpandPreference {
/**
* Hide media marked as sensitive
*/
@SerialName("default") DEFAULT,

/**
* Always show all media by default, regardless of sensitivity
*/
@SerialName("show_all") SHOW_ALL,

/**
* Always hide all media by default, regardless of sensitivity
*/
@SerialName("hide_all") HIDE_ALL,
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package xyz.wingio.fediapi.software.mastodon.model

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import xyz.wingio.fediapi.URL

/**
* Represents an emoji reaction to an [Announcement].
*
* @param name The emoji used for the reaction. Either a unicode emoji, or a custom emoji’s shortcode.
* @param count The total number of users who have added this reaction.
* @param me If there is a currently authorized user: Have you added this reaction?
* @param url If the reaction is a custom emoji: A link to the custom emoji.
* @param staticUrl If the reaction is a custom emoji: A link to a non-animated version of the custom emoji.
*/
@Serializable
public data class Reaction(
val name: String,
val count: String,
val me: Boolean? = null,
val url: URL? = null,
@SerialName("static_url") val staticUrl: URL? = null
)
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
import xyz.wingio.fediapi.Language

/**
* Represents the relationship between accounts, such as following / blocking / muting / etc.
*
* @param id The account ID.
* @param following Are you following this user?
* @param showingReblogs Are you receiving this user’s boosts in your home timeline?
* @param notifying Have you enabled notifications for this user?
* @param languages Which languages are you following from this user?
* @param followedBy Are you followed by this user?
* @param blocking Are you blocking this user?
* @param blockedBy Is this user blocking you?
* @param muting Are you muting this user?
* @param mutingNotifications Are you muting notifications from this user?
* @param requested Do you have a pending follow request for this user?
* @param domainBlocking Are you blocking this user’s domain?
* @param endorsed Are you featuring this user on your profile?
* @param note This user’s profile bio
*/
@Serializable
public data class Relationship(
val id: String,
val following: Boolean,
@SerialName("showing_reblogs") val showingReblogs: Boolean,
val notifying: Boolean,
val languages: List<Language>,
@SerialName("followed_by") val followedBy: Boolean,
val blocking: Boolean,
@SerialName("blocked_by") val blockedBy: Boolean,
val muting: Boolean,
@SerialName("muting_notifications") val mutingNotifications: Boolean,
val requested: Boolean,
@SerialName("domain_blocking") val domainBlocking: Boolean,
val endorsed: Boolean,
val note: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import kotlinx.serialization.Serializable
* @param repliesPolicy Which replies should be shown in the list.
*/
@Serializable
public data class List(
public data class UserList(
val id: String,
val title: String,
@SerialName("replies_policy") val repliesPolicy: ReplyPolicy
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package xyz.wingio.fediapi.software.mastodon.model.status

import kotlinx.datetime.Instant
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import xyz.wingio.fediapi.software.mastodon.model.CustomEmoji

/**
* Represents a poll attached to a status.
*
* @param id The ID of the poll in the database.
* @param expiresAt When the poll ends.
* @param expired Is the poll currently expired?
* @param multiple Does the poll allow multiple-choice answers?
* @param voteCount How many votes have been received.
* @param voterCount How many unique accounts have voted on a multiple-choice poll.
* @param options Possible answers for the poll.
* @param emojis Custom emoji to be used for rendering poll options.
* @param voted When called with a user token, has the authorized user voted?
* @param ownVotes When called with a user token, which options has the authorized user chosen? Contains an array of index values for [options].
*/
@Serializable
public data class Poll(
val id: String,
@SerialName("expires_at") val expiresAt: Instant?,
val expired: Boolean,
val multiple: Boolean,
@SerialName("votes_count") val voteCount: Int,
@SerialName("voters_count") val voterCount: Int,
val options: List<Option>,
val emojis: List<CustomEmoji>,
val voted: Boolean? = null,
@SerialName("own_votes") val ownVotes: List<Int>? = null
) {

/**
* An option in a [Poll]
*
* @param title The text value of the poll option.
* @param voteCount The total number of received votes for this option, null if results are not published yet.
*/
@Serializable
public data class Option(
val title: String,
@SerialName("votes_count") val voteCount: Int?
)

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package xyz.wingio.fediapi.software.mastodon.model.status

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import xyz.wingio.fediapi.Blurhash
import xyz.wingio.fediapi.HTML
import xyz.wingio.fediapi.URL

/**
* Represents a rich preview card that is generated using OpenGraph tags from a URL.
*
* @param url Location of linked resource.
* @param title Title of linked resource.
* @param description Description of preview.
* @param type The type of the preview card.
* @param authorName The author of the original resource.
* @param authorUrl A link to the author of the original resource.
* @param providerName The provider of the original resource.
* @param providerUrl A link to the provider of the original resource.
* @param html HTML to be used for generating the preview card.
* @param width Width of preview, in pixels.
* @param height Height of preview, in pixels.
* @param image Preview thumbnail.
* @param embedUrl Used for photo embeds, instead of custom [html].
* @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.
* @param history (Trends::Link only) Usage statistics for given days (typically the past week).
*/
@Serializable
public data class PreviewCard(
val url: URL,
val title: String,
val description: String,
val type: Type,
@SerialName("author_name") val authorName: String,
@SerialName("author_url") val authorUrl: URL,
@SerialName("provider_name") val providerName: String,
@SerialName("provider_url") val providerUrl: URL,
val html: HTML,
val width: Int,
val height: Int,
val image: URL?,
@SerialName("embed_url") val embedUrl: URL,
val blurhash: Blurhash?,
val history: List<HistoryDay>? = null
) {

@Serializable
public enum class Type {
/**
* Link OEmbed
*/
@SerialName("link") LINK,

/**
* Photo OEmbed
*/
@SerialName("photo") PHOTO,

/**
* Video OEmbed
*/
@SerialName("video") VIDEO,

/**
* iframe OEmbed. Not currently accepted, so won’t show up in practice.
*/
@SerialName("rich") RICH
}

/**
* Usage statistics for a given day
*
* @param day UNIX timestamp on midnight of the given day.
* @param accounts The counted accounts using the link within that day.
* @param uses The counted statuses using the link within that day.
*/
@Serializable
public data class HistoryDay(
val day: Long,
val accounts: Int,
val uses: Int
)

}

0 comments on commit 35cbdf3

Please sign in to comment.