Skip to content

Commit

Permalink
Merge pull request #80 from akiomik/fix-embed
Browse files Browse the repository at this point in the history
Fix embed
  • Loading branch information
akiomik authored Apr 3, 2023
2 parents fdc4211 + 9f41ca0 commit f506cb0
Show file tree
Hide file tree
Showing 28 changed files with 77 additions and 76 deletions.
4 changes: 2 additions & 2 deletions app/src/main/java/io/github/akiomik/seiun/api/AtpService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import com.squareup.moshi.Moshi
import com.squareup.moshi.adapters.Rfc3339DateJsonAdapter
import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
import io.github.akiomik.seiun.model.AtpError
import io.github.akiomik.seiun.model.app.bsky.actor.ProfileView
import io.github.akiomik.seiun.model.app.bsky.actor.ProfileViewDetailed
import io.github.akiomik.seiun.model.app.bsky.feed.AuthorFeed
import io.github.akiomik.seiun.model.app.bsky.feed.Like
import io.github.akiomik.seiun.model.app.bsky.feed.Post
Expand Down Expand Up @@ -87,7 +87,7 @@ interface AtpService {
suspend fun getProfile(
@Header("Authorization") authorization: String,
@Query("actor") actor: String
): ApiResult<ProfileView, AtpError>
): ApiResult<ProfileViewDetailed, AtpError>

// @DecodeErrorBody
// @POST("com.atproto.repo.putRecord")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package io.github.akiomik.seiun.model.app.bsky.actor
import com.squareup.moshi.JsonClass

@JsonClass(generateAdapter = true)
data class WithInfo(
data class ProfileViewBasic(
val did: String,
val handle: String,
val displayName: String? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.squareup.moshi.JsonClass
import java.util.*

@JsonClass(generateAdapter = true)
data class ProfileView(
data class ProfileViewDetailed(
val did: String,
val handle: String,
val displayName: String? = null,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package io.github.akiomik.seiun.model.app.bsky.feed

import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass
import io.github.akiomik.seiun.model.app.bsky.embed.External
import io.github.akiomik.seiun.model.app.bsky.embed.ExternalExternal
import io.github.akiomik.seiun.model.app.bsky.embed.ImagesImage

@JsonClass(generateAdapter = true)
data class ImagesOrExternal(
@Json(name = "\$type")
val type: String,
val images: List<ImagesImage>? = null, // from app.bsky.embed.images
val external: External? = null // from app.bsky.embed.external
val external: ExternalExternal? = null // from app.bsky.embed.external
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ package io.github.akiomik.seiun.model.app.bsky.feed

import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass
import io.github.akiomik.seiun.model.app.bsky.embed.External
import io.github.akiomik.seiun.model.app.bsky.embed.ExternalExternal
import io.github.akiomik.seiun.model.app.bsky.embed.ImagesImage

@JsonClass(generateAdapter = true)
data class ImagesOrExternalOrRecordOrRecordOrRecordWithMedia(
@Json(name = "\$type")
val type: String,
val images: List<ImagesImage>? = null, // from app.bsky.embed.images
val external: External? = null, // from app.bsky.embed.external
val external: ExternalExternal? = null, // from app.bsky.embed.external
val record: StrongRefOrRecord? = null, // from app.bsky.embed.record and app.bsky.embed.recordWithMedia // TODO: union
val media: ImagesOrExternal? = null // from app.bsky.embed.recordWithMedia // TODO: union
)
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package io.github.akiomik.seiun.model.app.bsky.feed

import com.squareup.moshi.JsonClass
import io.github.akiomik.seiun.model.app.bsky.actor.WithInfo
import io.github.akiomik.seiun.model.app.bsky.actor.ProfileViewBasic
import io.github.akiomik.seiun.model.com.atproto.repo.StrongRef
import java.util.*

@JsonClass(generateAdapter = true)
data class PostView(
val uri: String,
val cid: String,
val author: WithInfo,
val author: ProfileViewBasic,
val record: Post, // TODO: unknown
val indexedAt: Date,
val replyCount: Int? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package io.github.akiomik.seiun.model.app.bsky.feed

import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass
import io.github.akiomik.seiun.model.app.bsky.actor.WithInfo
import io.github.akiomik.seiun.model.app.bsky.actor.ProfileViewBasic
import java.util.*

@JsonClass(generateAdapter = true)
data class ReasonRepost(
@Json(name = "\$type")
val type: String,
val by: WithInfo,
val by: ProfileViewBasic,
val indexedAt: Date
) {
fun id(): String = "$type-${by.did}-${indexedAt.time}"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.github.akiomik.seiun.model.app.bsky.feed

import com.squareup.moshi.JsonClass
import io.github.akiomik.seiun.model.app.bsky.actor.WithInfo
import io.github.akiomik.seiun.model.app.bsky.actor.ProfileViewBasic
import java.util.*

@JsonClass(generateAdapter = true)
Expand All @@ -11,7 +11,7 @@ data class RecordViewRecordOrRecordViewNotFound(
// from app.bsky.embed.record#viewRecord
val uri: String? = null, // is used by app.bsky.embed.record#viewNotFound too
val cid: String? = null,
val author: WithInfo? = null,
val author: ProfileViewBasic? = null,
// val record: Record, // TODO unknown
val indexedAt: Date? = null,
val embeds: List<ImagesViewOrExternalViewOrRecordViewOrRecordWithMediaView>? = null
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package io.github.akiomik.seiun.model.app.bsky.feed

import com.squareup.moshi.JsonClass
import io.github.akiomik.seiun.model.com.atproto.repo.StrongRef

// FIXME: May have embed, author, record, viewer, indexedAt, likeCount, replyCount, repostCount?
@JsonClass(generateAdapter = true)
data class StrongRefOrRecord(
val uri: String? = null, // from com.atproto.repo.strongRef
val cid: String? = null, // from com.atproto.repo.strongRef
val record: StrongRef? = null // from app.bsky.embed.record
val cid: String? = null // from com.atproto.repo.strongRef
// FIXME: record may app.bsky.feed.post?
// val record: StrongRef? = null // from app.bsky.embed.record
)
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package io.github.akiomik.seiun.model.app.bsky.graph

import com.squareup.moshi.JsonClass
import io.github.akiomik.seiun.model.app.bsky.actor.WithInfo
import io.github.akiomik.seiun.model.app.bsky.actor.ProfileViewBasic

@JsonClass(generateAdapter = true)
data class Followers(
val subject: WithInfo,
val followers: List<WithInfo>,
val subject: ProfileViewBasic,
val followers: List<ProfileViewBasic>,
val cursor: String? = null
)
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package io.github.akiomik.seiun.model.app.bsky.graph

import com.squareup.moshi.JsonClass
import io.github.akiomik.seiun.model.app.bsky.actor.WithInfo
import io.github.akiomik.seiun.model.app.bsky.actor.ProfileViewBasic

@JsonClass(generateAdapter = true)
data class Follows(
val subject: WithInfo,
val follows: List<WithInfo>,
val subject: ProfileViewBasic,
val follows: List<ProfileViewBasic>,
val cursor: String? = null
)
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package io.github.akiomik.seiun.model.app.bsky.notification

import com.squareup.moshi.JsonClass
import io.github.akiomik.seiun.model.app.bsky.actor.WithInfo
import io.github.akiomik.seiun.model.app.bsky.actor.ProfileViewBasic
import java.util.*

@JsonClass(generateAdapter = true)
data class Notification(
val uri: String,
val cid: String,
val author: WithInfo,
val author: ProfileViewBasic,
val reason: String,
val record: NotificationRecord, // TODO unknown
val isRead: Boolean,
Expand Down
6 changes: 4 additions & 2 deletions app/src/main/java/io/github/akiomik/seiun/model/type/Blob.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ package io.github.akiomik.seiun.model.type
import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass

// NOTE: The old blob formats don't have ref and size
@JsonClass(generateAdapter = true)
data class Blob(
val ref: Ref?,
val ref: Ref? = null,
val mimeType: String,
val size: Int?,
val size: Int? = null,
val original: BlobOriginal? = null,
@Json(name = "\$type")
val type: String? = "blob"
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package io.github.akiomik.seiun.model.type

data class BlobOriginal(
val cid: String,
val mimeType: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import android.util.Log
import io.github.akiomik.seiun.SeiunApplication
import io.github.akiomik.seiun.api.RequestHelper
import io.github.akiomik.seiun.datasources.PostFeedCacheDataSource
import io.github.akiomik.seiun.model.app.bsky.actor.ProfileView
import io.github.akiomik.seiun.model.app.bsky.actor.ProfileViewDetailed
import io.github.akiomik.seiun.model.app.bsky.feed.AuthorFeed
import io.github.akiomik.seiun.model.app.bsky.feed.FeedViewPost
import io.github.akiomik.seiun.model.app.bsky.feed.ImagesOrExternalOrRecordOrRecordOrRecordWithMedia
Expand Down Expand Up @@ -41,7 +41,7 @@ class PostFeedRepository(private val authRepository: AuthRepository) : Applicati
return timeline
}

suspend fun getAuthorFeed(author: ProfileView, cursor: String? = null): AuthorFeed {
suspend fun getAuthorFeed(author: ProfileViewDetailed, cursor: String? = null): AuthorFeed {
Log.d(SeiunApplication.TAG, "Get author feed: cursor = $cursor")

val feed = RequestHelper.executeWithRetry(authRepository) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package io.github.akiomik.seiun.repository
import android.util.Log
import io.github.akiomik.seiun.SeiunApplication
import io.github.akiomik.seiun.api.RequestHelper
import io.github.akiomik.seiun.model.app.bsky.actor.ProfileView
import io.github.akiomik.seiun.model.app.bsky.actor.ProfileViewDetailed
import io.github.akiomik.seiun.model.app.bsky.graph.Follow
import io.github.akiomik.seiun.model.app.bsky.graph.Followers
import io.github.akiomik.seiun.model.app.bsky.graph.Follows
Expand All @@ -16,15 +16,15 @@ import io.github.akiomik.seiun.utilities.UriConverter
import java.util.*

class UserRepository(private val authRepository: AuthRepository) : ApplicationRepository() {
suspend fun getProfile(): ProfileView {
suspend fun getProfile(): ProfileViewDetailed {
Log.d(SeiunApplication.TAG, "Get profile")

return RequestHelper.executeWithRetry(authRepository) {
getAtpClient().getProfile("Bearer ${it.accessJwt}", it.did)
}
}

suspend fun getProfileOf(did: String): ProfileView {
suspend fun getProfileOf(did: String): ProfileViewDetailed {
Log.d(SeiunApplication.TAG, "Get profile of $did")

return RequestHelper.executeWithRetry(authRepository) {
Expand Down
10 changes: 5 additions & 5 deletions app/src/main/java/io/github/akiomik/seiun/ui/app/AppDrawer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ import androidx.lifecycle.viewmodel.compose.viewModel
import coil.compose.AsyncImage
import com.google.android.gms.oss.licenses.OssLicensesMenuActivity
import io.github.akiomik.seiun.R
import io.github.akiomik.seiun.model.app.bsky.actor.ProfileView
import io.github.akiomik.seiun.model.app.bsky.actor.ProfileViewDetailed
import io.github.akiomik.seiun.viewmodels.AppViewModel
import kotlinx.coroutines.launch

@Composable
private fun Profile(onClicked: (ProfileView) -> Unit) {
private fun Profile(onClicked: (ProfileViewDetailed) -> Unit) {
val viewModel: AppViewModel = viewModel()
val profile by viewModel.profile.collectAsState()

Expand All @@ -55,7 +55,7 @@ private fun Profile(onClicked: (ProfileView) -> Unit) {
}

@Composable
private fun Avatar(profile: ProfileView?) {
private fun Avatar(profile: ProfileViewDetailed?) {
AsyncImage(
model = profile?.avatar,
contentDescription = null,
Expand All @@ -67,7 +67,7 @@ private fun Avatar(profile: ProfileView?) {
}

@Composable
private fun NameAndHandle(profile: ProfileView?) {
private fun NameAndHandle(profile: ProfileViewDetailed?) {
Column {
Text(
text = profile?.displayName.orEmpty(),
Expand All @@ -85,7 +85,7 @@ private fun NameAndHandle(profile: ProfileView?) {
fun AppDrawer(
state: DrawerState,
enabled: Boolean,
onProfileClick: (ProfileView) -> Unit,
onProfileClick: (ProfileViewDetailed) -> Unit,
content: @Composable () -> Unit
) {
// var selected by remember { mutableStateOf("") }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import androidx.compose.ui.res.stringResource
import androidx.lifecycle.viewmodel.compose.viewModel
import io.github.akiomik.seiun.R
import io.github.akiomik.seiun.SeiunApplication
import io.github.akiomik.seiun.model.app.bsky.actor.WithInfo
import io.github.akiomik.seiun.model.app.bsky.actor.ProfileViewBasic
import io.github.akiomik.seiun.viewmodels.PostViewModel

@Composable
fun MuteDialog(actor: WithInfo, onDismissRequest: () -> Unit) {
fun MuteDialog(actor: ProfileViewBasic, onDismissRequest: () -> Unit) {
val viewModel: PostViewModel = viewModel()
val context = LocalContext.current
val mutedMessage = stringResource(id = R.string.dialog_muted)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import coil.compose.AsyncImage
import io.github.akiomik.seiun.R
import io.github.akiomik.seiun.model.app.bsky.actor.WithInfo
import io.github.akiomik.seiun.model.app.bsky.actor.ProfileViewBasic
import io.github.akiomik.seiun.ui.dialog.FullScreenDialog
import io.github.akiomik.seiun.viewmodels.FollowersViewModel

@Composable
private fun Avatar(user: WithInfo, onClicked: (String) -> Unit) {
private fun Avatar(user: ProfileViewBasic, onClicked: (String) -> Unit) {
AsyncImage(
model = user.avatar,
contentDescription = null,
Expand All @@ -39,7 +39,7 @@ private fun Avatar(user: WithInfo, onClicked: (String) -> Unit) {
}

@Composable
private fun FollowersListItem(user: WithInfo, onProfileClick: (String) -> Unit) {
private fun FollowersListItem(user: ProfileViewBasic, onProfileClick: (String) -> Unit) {
ListItem(
leadingContent = { Avatar(user = user, onClicked = onProfileClick) },
headlineContent = { Text(text = user.displayName ?: "@${user.handle}") },
Expand Down Expand Up @@ -67,7 +67,7 @@ private fun FollowersListItem(user: WithInfo, onProfileClick: (String) -> Unit)

@Composable
private fun FollowersListContent(
followers: List<WithInfo>,
followers: List<ProfileViewBasic>,
viewModel: FollowersViewModel,
onProfileClick: (String) -> Unit
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import coil.compose.AsyncImage
import io.github.akiomik.seiun.R
import io.github.akiomik.seiun.model.app.bsky.actor.WithInfo
import io.github.akiomik.seiun.model.app.bsky.actor.ProfileViewBasic
import io.github.akiomik.seiun.ui.dialog.FullScreenDialog
import io.github.akiomik.seiun.viewmodels.FollowsViewModel

@Composable
private fun Avatar(user: WithInfo, onClicked: (String) -> Unit) {
private fun Avatar(user: ProfileViewBasic, onClicked: (String) -> Unit) {
AsyncImage(
model = user.avatar,
contentDescription = null,
Expand All @@ -39,7 +39,7 @@ private fun Avatar(user: WithInfo, onClicked: (String) -> Unit) {
}

@Composable
private fun FollowsListItem(user: WithInfo, onProfileClick: (String) -> Unit) {
private fun FollowsListItem(user: ProfileViewBasic, onProfileClick: (String) -> Unit) {
ListItem(
leadingContent = { Avatar(user = user, onClicked = onProfileClick) },
headlineContent = { Text(text = user.displayName ?: "@${user.handle}") },
Expand Down Expand Up @@ -67,7 +67,7 @@ private fun FollowsListItem(user: WithInfo, onProfileClick: (String) -> Unit) {

@Composable
private fun FollowsListContent(
follows: List<WithInfo>,
follows: List<ProfileViewBasic>,
viewModel: FollowsViewModel,
onProfileClick: (String) -> Unit
) {
Expand Down
Loading

0 comments on commit f506cb0

Please sign in to comment.