Skip to content

Commit

Permalink
Merge pull request #575 from DimensionDev/feature/update_server_list
Browse files Browse the repository at this point in the history
update server list order
  • Loading branch information
Tlaster authored Nov 29, 2024
2 parents edd2764 + 802f99b commit 5ea8d96
Show file tree
Hide file tree
Showing 4 changed files with 154 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package dev.dimension.flare.data.datasource.microblog
import androidx.paging.PagingSource
import androidx.paging.PagingState
import dev.dimension.flare.data.network.mastodon.JoinMastodonService
import dev.dimension.flare.data.network.mastodon.MastodonInstanceService
import dev.dimension.flare.data.network.misskey.JoinMisskeyService
import dev.dimension.flare.model.PlatformType
import dev.dimension.flare.model.logoUrl
Expand Down Expand Up @@ -49,22 +50,53 @@ internal class RecommendInstancePagingSource : PagingSource<Int, UiInstance>() {
}
}.getOrDefault(emptyList())
},
async {
runCatching {
MastodonInstanceService("https://pawoo.net/").instance().let {
listOf(
UiInstance(
name = it.domain ?: "pawoo.net",
description = it.title,
iconUrl = it.thumbnail?.url ?: PlatformType.Mastodon.logoUrl,
domain = it.domain ?: "pawoo.net",
type = PlatformType.Mastodon,
bannerUrl = it.thumbnail?.url ?: PlatformType.Mastodon.logoUrl,
usersCount = it.usage?.users?.activeMonth ?: 0,
),
)
}
}.getOrDefault(emptyList())
},
).awaitAll().flatMap { it }
}
val bsky =
listOf(
val mstdnJP =
instances.firstOrNull { it.domain == "mstdn.jp" } ?: run {
UiInstance(
name = "Bluesky",
description =
"The web. Email. RSS feeds. XMPP chats. " +
"What all these technologies had in common is they allowed people to freely interact " +
"and create content, without a single intermediary.",
iconUrl = PlatformType.Bluesky.logoUrl,
domain = "bsky.social",
type = PlatformType.Bluesky,
name = "mstdn.jp",
description = "mstdn.jp",
iconUrl = PlatformType.Mastodon.logoUrl,
domain = "mstdn.jp",
type = PlatformType.Mastodon,
bannerUrl = null,
usersCount = 0,
),
)
}
val pawoo =
instances.firstOrNull { it.domain == "pawoo.net" } ?: run {
UiInstance(
name = "pawoo.net",
description = "pawoo.net",
iconUrl = PlatformType.Mastodon.logoUrl,
domain = "pawoo.net",
type = PlatformType.Mastodon,
bannerUrl = null,
usersCount = 0,
)
}
val extra =
listOf(
mstdnJP,
pawoo,
UiInstance(
name = "X",
description =
Expand All @@ -76,9 +108,21 @@ internal class RecommendInstancePagingSource : PagingSource<Int, UiInstance>() {
bannerUrl = null,
usersCount = 0,
),
UiInstance(
name = "Bluesky",
description =
"The web. Email. RSS feeds. XMPP chats. " +
"What all these technologies had in common is they allowed people to freely interact " +
"and create content, without a single intermediary.",
iconUrl = PlatformType.Bluesky.logoUrl,
domain = "bsky.social",
type = PlatformType.Bluesky,
bannerUrl = null,
usersCount = 0,
),
)
LoadResult.Page(
data = bsky + instances.sortedByDescending { it.usersCount },
data = extra + (instances.sortedByDescending { it.usersCount }.filter { it !in extra }),
prevKey = null,
nextKey = null,
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
package dev.dimension.flare.data.network.mastodon

import dev.dimension.flare.data.network.ktorfit
import dev.dimension.flare.data.network.mastodon.api.InstanceResources
import dev.dimension.flare.data.network.mastodon.api.JoinMastodonResources
import dev.dimension.flare.data.network.mastodon.api.createInstanceResources
import dev.dimension.flare.data.network.mastodon.api.createJoinMastodonResources

internal object JoinMastodonService :
JoinMastodonResources by ktorfit("https://api.joinmastodon.org/").createJoinMastodonResources()

internal class MastodonInstanceService(
val baseUrl: String,
) : InstanceResources by ktorfit(baseUrl).createInstanceResources()
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package dev.dimension.flare.data.network.mastodon.api

import de.jensklingenberg.ktorfit.http.GET
import dev.dimension.flare.data.network.mastodon.api.model.InstanceData

internal interface InstanceResources {
@GET("api/v2/instance")
suspend fun instance(): InstanceData
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,86 @@ internal data class MastodonInstanceElement(
val language: String,
val category: String,
)

@Serializable
internal data class InstanceData(
val domain: String? = null,
val title: String? = null,
val version: String? = null,
@SerialName("source_url")
val sourceURL: String? = null,
val description: String? = null,
val usage: Usage? = null,
val thumbnail: Thumbnail? = null,
val languages: List<String>? = null,
val configuration: Configuration? = null,
val registrations: Registrations? = null,
val contact: Contact? = null,
)

@Serializable
internal data class Configuration(
val urls: Urls? = null,
val accounts: Accounts? = null,
val statuses: Statuses? = null,
@SerialName("media_attachments")
val translation: Translation? = null,
)

@Serializable
internal data class Accounts(
@SerialName("max_featured_tags")
val maxFeaturedTags: Long? = null,
)

@Serializable
internal data class Thumbnail(
val url: String? = null,
val blurhash: String? = null,
val versions: Map<String, String>? = null,
)

@Serializable
internal data class Users(
@SerialName("active_month")
val activeMonth: Long? = null,
)

@Serializable
internal data class Translation(
val enabled: Boolean? = null,
)

@Serializable
internal data class Urls(
val streaming: String? = null,
val status: String? = null,
)

@Serializable
internal data class Statuses(
@SerialName("max_characters")
val maxCharacters: Long? = null,
@SerialName("max_media_attachments")
val maxMediaAttachments: Long? = null,
@SerialName("characters_reserved_per_url")
val charactersReservedPerURL: Long? = null,
)

@Serializable
internal data class Contact(
val email: String? = null,
val account: Account? = null,
)

@Serializable
internal data class Registrations(
val enabled: Boolean? = null,
@SerialName("approval_required")
val approvalRequired: Boolean? = null,
)

@Serializable
internal data class Usage(
val users: Users? = null,
)

0 comments on commit 5ea8d96

Please sign in to comment.