Skip to content

Commit

Permalink
Add filter models
Browse files Browse the repository at this point in the history
* Filter
* FilterKeyword
* FilterResult
* FilterStatus
* FeaturedTag
  • Loading branch information
wingio committed Dec 20, 2023
1 parent fc66cee commit 68e2992
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package xyz.wingio.fediapi.software.mastodon.model

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

/**
* Represents a hashtag that is featured on a profile.
*
* @param id The internal ID of the featured tag in the database.
* @param name The name of the hashtag being featured.
* @param url A link to all statuses by a user that contain this hashtag.
* @param statusesCount The number of authored statuses containing this hashtag.
* @param lastStatusAt The timestamp of the last authored status containing this hashtag.
*/
@Serializable
public data class FeaturedTag(
val id: String,
val name: String,
val url: URL,
@SerialName("statuses_count") val statusesCount: Int,
@SerialName("last_status_at") val lastStatusAt: Instant
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package xyz.wingio.fediapi.software.mastodon.model.filter

import kotlinx.datetime.Instant
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

/**
* Represents a user-defined filter for determining which statuses should not be shown to the user.
*
* @param id The ID of the [Filter] in the database.
* @param title A title given by the user to name the filter.
* @param context The contexts in which the filter should be applied.
* @param expiresAt When the filter should no longer be applied.
* @param filterAction The action to be taken when a status matches this filter.
* @param keywords The keywords grouped under this filter.
* @param statuses The statuses grouped under this filter.
*/
@Serializable
public data class Filter(
val id: String,
val title: String,
val context: Context,
@SerialName("expires_at") val expiresAt: Instant?,
@SerialName("filter_action") val filterAction: FilterAction,
val keywords: List<FilterKeyword>,
val statuses: List<FilterStatus>
) {

@Serializable
public enum class Context {
/**
* Home timeline and lists
*/
@SerialName("home") HOME,

/**
* Notifications timeline
*/
@SerialName("notifications") NOTIFICATIONS,

/**
* Public timelines
*/
@SerialName("public") PUBLIC,

/**
* Expanded thread of a detailed status
*/
@SerialName("thread") THREAD,

/**
* When viewing a profile
*/
@SerialName("account") ACCOUNT
}

@Serializable
public enum class FilterAction {
/**
* Show a warning that identifies the matching filter by [title], and
* allow the user to expand the filtered status.
* This is the default (and unknown values should be
* treated as equivalent to [WARN]).
*/
@SerialName("warn") WARN,

/**
* Do not show this status if it is received
*/
@SerialName("hide") HIDE
}

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

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

/**
* Represents a keyword that, if matched, should cause the filter action to be taken.
*
* @param id The ID of the [FilterKeyword] in the database.
* @param keyword The phrase to be matched against.
* @param wholeWord Should the filter consider word boundaries? See [implementation guidelines for filters](https://docs.joinmastodon.org/api/guidelines/#filters).
*/
@Serializable
public data class FilterKeyword(
val id: String,
val keyword: String,
@SerialName("whole_word") val wholeWord: Boolean
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package xyz.wingio.fediapi.software.mastodon.model.filter

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

/**
* Represents a filter whose keywords matched a given status.
*
* @param filter The filter that was matched.
* @param keywordMatches The keyword within the filter that was matched.
* @param statusMatches The status ID within the filter that was matched.
*/
@Serializable
public data class FilterResult(
val filter: Filter,
@SerialName("keyword_matches") val keywordMatches: List<String>?,
@SerialName("status_matches") val statusMatches: List<String>?
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package xyz.wingio.fediapi.software.mastodon.model.filter

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

/**
* Represents a status ID that, if matched, should cause the filter action to be taken.
*
* @param id The ID of the [FilterStatus] in the database.
* @param statusId The ID of the [Status] that will be filtered.
*/
@Serializable
public data class FilterStatus(
val id: String,
@SerialName("status_id") val statusId: String
)

0 comments on commit 68e2992

Please sign in to comment.