-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #86 from takke/support_pinned_post
Support pinned post
- Loading branch information
Showing
12 changed files
with
131 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
core/src/commonMain/kotlin/work/socialhub/kbsky/model/app/bsky/feed/FeedDefsReasonPin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package work.socialhub.kbsky.model.app.bsky.feed | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
import work.socialhub.kbsky.BlueskyTypes | ||
|
||
@Serializable | ||
class FeedDefsReasonPin : FeedDefsReasonUnion() { | ||
|
||
companion object { | ||
val TYPE = BlueskyTypes.FeedDefs + "#reasonPin" | ||
} | ||
|
||
@SerialName("\$type") | ||
override var type = TYPE | ||
} |
12 changes: 11 additions & 1 deletion
12
core/src/commonMain/kotlin/work/socialhub/kbsky/model/app/bsky/feed/FeedDefsReasonRepost.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,20 @@ | ||
package work.socialhub.kbsky.model.app.bsky.feed | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
import work.socialhub.kbsky.BlueskyTypes | ||
import work.socialhub.kbsky.model.app.bsky.actor.ActorDefsProfileViewBasic | ||
|
||
@Serializable | ||
class FeedDefsReasonRepost { | ||
class FeedDefsReasonRepost : FeedDefsReasonUnion() { | ||
|
||
companion object { | ||
val TYPE = BlueskyTypes.FeedDefs + "#reasonRepost" | ||
} | ||
|
||
@SerialName("\$type") | ||
override var type = TYPE | ||
|
||
var by: ActorDefsProfileViewBasic? = null | ||
var indexedAt: String? = null | ||
} |
18 changes: 18 additions & 0 deletions
18
core/src/commonMain/kotlin/work/socialhub/kbsky/model/app/bsky/feed/FeedDefsReasonUnion.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package work.socialhub.kbsky.model.app.bsky.feed | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
import work.socialhub.kbsky.util.json.FeedDefsReasonPolymorphicSerializer | ||
|
||
/** | ||
* @see FeedDefsReasonRepost | ||
* @see FeedDefsReasonPin | ||
*/ | ||
@Serializable(with = FeedDefsReasonPolymorphicSerializer::class) | ||
abstract class FeedDefsReasonUnion { | ||
@SerialName("\$type") | ||
abstract var type: String | ||
|
||
val asReasonRepost get() = this as? FeedDefsReasonRepost | ||
val asReasonPin get() = this as? FeedDefsReasonPin | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...c/commonMain/kotlin/work/socialhub/kbsky/util/json/FeedDefsReasonPolymorphicSerializer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package work.socialhub.kbsky.util.json | ||
|
||
import kotlinx.serialization.DeserializationStrategy | ||
import kotlinx.serialization.Serializable | ||
import kotlinx.serialization.json.JsonContentPolymorphicSerializer | ||
import kotlinx.serialization.json.JsonElement | ||
import work.socialhub.kbsky.model.app.bsky.feed.FeedDefsReasonPin | ||
import work.socialhub.kbsky.model.app.bsky.feed.FeedDefsReasonRepost | ||
import work.socialhub.kbsky.model.app.bsky.feed.FeedDefsReasonUnion | ||
import work.socialhub.kbsky.util.json.JsonElementUtil.type | ||
|
||
object FeedDefsReasonPolymorphicSerializer : | ||
JsonContentPolymorphicSerializer<FeedDefsReasonUnion>( | ||
FeedDefsReasonUnion::class | ||
) { | ||
|
||
override fun selectDeserializer( | ||
element: JsonElement | ||
): DeserializationStrategy<FeedDefsReasonUnion> { | ||
return when (val type = element.type()) { | ||
FeedDefsReasonRepost.TYPE -> FeedDefsReasonRepost.serializer() | ||
FeedDefsReasonPin.TYPE -> FeedDefsReasonPin.serializer() | ||
else -> { | ||
println("[Warning] Unknown Item type: $type (FeedDefsReasonUnion)") | ||
Unknown.serializer() | ||
} | ||
} | ||
} | ||
|
||
@Serializable | ||
class Unknown : FeedDefsReasonUnion() { | ||
override var type: String = "unknown" | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
core/src/commonMain/kotlin/work/socialhub/kbsky/util/json/PinnedPostSerializer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package work.socialhub.kbsky.util.json | ||
|
||
import kotlinx.serialization.json.JsonElement | ||
import kotlinx.serialization.json.JsonObject | ||
import kotlinx.serialization.json.JsonPrimitive | ||
import kotlinx.serialization.json.JsonTransformingSerializer | ||
import work.socialhub.kbsky.model.com.atproto.repo.RepoStrongRef | ||
|
||
object PinnedPostSerializer : | ||
JsonTransformingSerializer<RepoStrongRef>( | ||
RepoStrongRef.serializer() | ||
) { | ||
|
||
override fun transformDeserialize( | ||
element: JsonElement | ||
): JsonElement { | ||
return if (element is JsonObject) { | ||
element | ||
} else { | ||
// fallback for old pinned post format | ||
JsonObject(mapOf("uri" to element, "cid" to JsonPrimitive(""))) | ||
} | ||
} | ||
} |