feat(models): support bot metadata, canonical sessions, and group sync in Profile models (#973)
This commit is contained in:
2 files changed
+269
No files matched your search
@@ -1,9 +1,14 @@
|
||||
package com.m57.hermescontrol.data.model
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.json.Json
|
||||
import kotlinx.serialization.json.JsonElement
|
||||
import kotlinx.serialization.json.decodeFromJsonElement
|
||||
|
||||
@Serializable
|
||||
data class ProfilesResponse(
|
||||
val profiles: List<ProfileInfo>,
|
||||
val bot_mode_protocol: Boolean? = null,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
@@ -17,7 +22,111 @@ data class ProfileInfo(
|
||||
val skill_count: Int? = null,
|
||||
val gateway_running: Boolean? = null,
|
||||
val description: String? = null,
|
||||
val display_name: String? = null,
|
||||
val description_auto: Boolean? = null,
|
||||
val has_avatar: Boolean? = null,
|
||||
val ui_meta: Map<String, JsonElement>? = null,
|
||||
val ui_meta_revisions: Map<String, Int>? = null,
|
||||
val canonical_session: CanonicalSessionInfo? = null,
|
||||
val last_session: ProfileSessionSummary? = null,
|
||||
val worker_session: ProfileWorkerSummary? = null,
|
||||
) {
|
||||
fun botMeta(
|
||||
json: Json =
|
||||
Json {
|
||||
ignoreUnknownKeys = true
|
||||
isLenient = true
|
||||
},
|
||||
): BotRosterMeta? {
|
||||
val element = ui_meta?.get("hermes-bots") ?: return null
|
||||
return try {
|
||||
json.decodeFromJsonElement<BotRosterMeta>(element)
|
||||
} catch (_: Exception) {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
val effectiveTitle: String
|
||||
get() =
|
||||
botMeta()?.title?.takeIf { it.isNotBlank() }
|
||||
?: display_name?.takeIf { it.isNotBlank() }
|
||||
?: name
|
||||
|
||||
val effectiveDescription: String
|
||||
get() =
|
||||
botMeta()?.description?.takeIf { it.isNotBlank() }
|
||||
?: description
|
||||
?: ""
|
||||
|
||||
val isHidden: Boolean
|
||||
get() = botMeta()?.hidden == true
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class CanonicalSessionInfo(
|
||||
val id: String,
|
||||
val resolved_id: String? = null,
|
||||
val root_title: String? = null,
|
||||
val title: String? = null,
|
||||
val preview: String? = null,
|
||||
val started_at: Long? = null,
|
||||
val last_active: Long? = null,
|
||||
val message_count: Int? = null,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class ProfileSessionSummary(
|
||||
val id: String,
|
||||
val title: String? = null,
|
||||
val preview: String? = null,
|
||||
val started_at: Long? = null,
|
||||
val last_active: Long? = null,
|
||||
val message_count: Int? = null,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class ProfileWorkerSummary(
|
||||
val id: String,
|
||||
val source: String? = null,
|
||||
val title: String? = null,
|
||||
val last_active: Long? = null,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class BotRosterMeta(
|
||||
val title: String? = null,
|
||||
val description: String? = null,
|
||||
val avatar: BotAvatarMeta? = null,
|
||||
val hidden: Boolean? = null,
|
||||
val groups: List<String>? = null,
|
||||
val group: String? = null,
|
||||
val created: Long? = null,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class BotAvatarMeta(
|
||||
val shape: String? = null,
|
||||
val color: String? = null,
|
||||
val icon: String? = null,
|
||||
val image_url: String? = null,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class GroupChatSyncSnapshot(
|
||||
val version: Int? = null,
|
||||
val updatedAt: Long? = null,
|
||||
val rooms: Map<String, GroupChatRoomMeta>? = null,
|
||||
val deleted: Map<String, Long>? = null,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class GroupChatRoomMeta(
|
||||
val id: String,
|
||||
val name: String? = null,
|
||||
val members: List<String>? = null,
|
||||
val picture: String? = null,
|
||||
val updatedAt: Long? = null,
|
||||
val createdAt: Long? = null,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
|
||||
Reference in new issue
Block a user