Skip to content

Commit

Permalink
Merge pull request #76 from akiomik/fix-lex
Browse files Browse the repository at this point in the history
Fix lex
  • Loading branch information
akiomik authored Apr 2, 2023
2 parents 0512d49 + e56d083 commit 5c7715a
Show file tree
Hide file tree
Showing 19 changed files with 77 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ import com.squareup.moshi.JsonClass

@JsonClass(generateAdapter = true)
data class External(
val external: ExternalExternal
val external: ExternalExternal? = null
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.github.akiomik.seiun.model.app.bsky.feed

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

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
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ 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.ImagesImage
import io.github.akiomik.seiun.model.com.atproto.repo.StrongRef

@JsonClass(generateAdapter = true)
data class ImagesOrExternalOrRecord(
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 record: StrongRef? = null // from app.bsky.embed.record
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
@@ -0,0 +1,12 @@
package io.github.akiomik.seiun.model.app.bsky.feed

import com.squareup.moshi.Json
import io.github.akiomik.seiun.model.app.bsky.embed.ExternalViewExternal
import io.github.akiomik.seiun.model.app.bsky.embed.ImagesViewImage

data class ImagesViewOrExternalView(
@Json(name = "\$type")
val type: String,
val images: List<ImagesViewImage>? = null, // from app.bsky.embed.images#view
val external: ExternalViewExternal? = null // from app.bsky.embed.external#view
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import io.github.akiomik.seiun.model.app.bsky.embed.ExternalViewExternal
import io.github.akiomik.seiun.model.app.bsky.embed.ImagesViewImage

@JsonClass(generateAdapter = true)
data class ImagesViewOrExternalViewOrRecordView(
data class ImagesViewOrExternalViewOrRecordViewOrRecordWithMediaView(
@Json(name = "\$type")
val type: String,
val images: List<ImagesViewImage>? = null, // from app.bsky.embed.images#view
val external: ExternalViewExternal? = null, // from app.bsky.embed.external#view
val record: RecordViewRecordOrRecordViewNotFound? = null // from app.bsky.embed.record#view
val record: RecordViewRecordOrRecordViewNotFound? = null, // from app.bsky.embed.record#view
val media: ImagesViewOrExternalView? = null // from app.bsky.embed.recordWithMedia#view
)
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ data class Post(
val entities: List<PostEntity>? = null,
val facets: List<Facet>? = null,
val reply: PostReplyRef? = null,
val embed: ImagesOrExternalOrRecord? = null // TODO: union type
val embed: ImagesOrExternalOrRecordOrRecordOrRecordWithMedia? = null // TODO: union type
)
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ data class PostView(
val repostCount: Int? = null,
val likeCount: Int? = null,
val viewer: ViewerState? = null,
val embed: ImagesViewOrExternalViewOrRecordView? = null // TODO: union type
val embed: ImagesViewOrExternalViewOrRecordViewOrRecordWithMediaView? = null // TODO: union type
) {
fun reposted(uri: String): PostView {
return copy(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package io.github.akiomik.seiun.model.app.bsky.feed

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

data class RecordViewRecordOrRecordViewNotFound(
@Json(name = "\$type")
val type: String,
// @Json(name = "\$type")
// val type: String,
// from app.bsky.embed.record#viewRecord
val uri: String, // is used by app.bsky.embed.record#viewNotFound too
val cid: String,
val author: WithInfo,
val uri: String? = null, // is used by app.bsky.embed.record#viewNotFound too
val cid: String? = null,
val author: WithInfo? = null,
// val record: Record, // TODO unknown
val indexedAt: Date,
val embeds: List<ImagesViewOrExternalViewOrRecordView>? = null
val indexedAt: Date? = null,
val embeds: List<ImagesViewOrExternalViewOrRecordViewOrRecordWithMediaView>? = null
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package io.github.akiomik.seiun.model.app.bsky.feed

import io.github.akiomik.seiun.model.com.atproto.repo.StrongRef

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
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package io.github.akiomik.seiun.model.app.bsky.notification
import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass
import io.github.akiomik.seiun.model.app.bsky.feed.PostReplyRef
import io.github.akiomik.seiun.model.com.atproto.repo.StrongRef
import java.util.*

// app.bsky.graph.follow (subject, createdAt) or
Expand All @@ -16,6 +15,6 @@ data class NotificationRecord(
val type: String,
val createdAt: Date,
val text: String? = null,
val reply: PostReplyRef? = null,
val subject: StrongRef? = null
val reply: PostReplyRef? = null
// val subject: StrongRef? = null // TODO: support union of StrongRef or String
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.github.akiomik.seiun.model.app.bsky.richtext

data class Facet(
val index: FacetTextSlice,
val value: FacetMentionOrFacetLink // TODO: union
val index: FacetByteSlice,
val features: List<FacetMentionOrFacetLink> // TODO: union
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package io.github.akiomik.seiun.model.app.bsky.richtext

class FacetByteSlice(
val byteStart: Int,
val byteEnd: Int
)

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.squareup.moshi.JsonClass

@JsonClass(generateAdapter = true)
data class CreateRecordInput<A>(
val did: String,
val repo: String,
val record: A,
val collection: String,
val rkey: 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

@JsonClass(generateAdapter = true)
data class DeleteRecordInput(
val did: String,
val repo: String,
val collection: String,
val rkey: String,
val swapRecord: String? = null,
Expand Down
4 changes: 2 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 @@ -5,9 +5,9 @@ import com.squareup.moshi.JsonClass

@JsonClass(generateAdapter = true)
data class Blob(
val ref: Ref,
val ref: Ref?,
val mimeType: String,
val size: Int,
val size: Int?,
@Json(name = "\$type")
val type: String? = "blob"
)
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ 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.feed.AuthorFeed
import io.github.akiomik.seiun.model.app.bsky.feed.FeedViewPost
import io.github.akiomik.seiun.model.app.bsky.feed.ImagesOrExternalOrRecord
import io.github.akiomik.seiun.model.app.bsky.feed.ImagesOrExternalOrRecordOrRecordOrRecordWithMedia
import io.github.akiomik.seiun.model.app.bsky.feed.Like
import io.github.akiomik.seiun.model.app.bsky.feed.Post
import io.github.akiomik.seiun.model.app.bsky.feed.PostReplyRef
Expand Down Expand Up @@ -63,7 +63,7 @@ class PostFeedRepository(private val authRepository: AuthRepository) : Applicati

val res = RequestHelper.executeWithRetry(authRepository) {
val body = CreateRecordInput(
did = it.did,
repo = it.did,
record = Like(subject = subject, createdAt = Date()),
collection = "app.bsky.feed.like"
)
Expand All @@ -82,7 +82,7 @@ class PostFeedRepository(private val authRepository: AuthRepository) : Applicati
val rkey = UriConverter.toRkey(uri)
RequestHelper.executeWithRetry(authRepository) {
val body = DeleteRecordInput(
did = it.did,
repo = it.did,
collection = "app.bsky.feed.like",
rkey = rkey
)
Expand All @@ -99,7 +99,7 @@ class PostFeedRepository(private val authRepository: AuthRepository) : Applicati
val res = RequestHelper.executeWithRetry(authRepository) {
val record = Repost(subject = subject, Date())
val body = CreateRecordInput(
did = it.did,
repo = it.did,
record = record,
collection = "app.bsky.feed.repost"
)
Expand All @@ -119,7 +119,7 @@ class PostFeedRepository(private val authRepository: AuthRepository) : Applicati
val rkey = UriConverter.toRkey(uri)
RequestHelper.executeWithRetry(authRepository) {
val body =
DeleteRecordInput(did = it.did, rkey = rkey, collection = "app.bsky.feed.repost")
DeleteRecordInput(repo = it.did, rkey = rkey, collection = "app.bsky.feed.repost")
getAtpClient().deleteRecord("Bearer ${it.accessJwt}", body = body)
}

Expand All @@ -134,7 +134,7 @@ class PostFeedRepository(private val authRepository: AuthRepository) : Applicati
image = imageBlob,
alt = ""
)
ImagesOrExternalOrRecord(images = listOf(image), type = "app.bsky.embed.images")
ImagesOrExternalOrRecordOrRecordOrRecordWithMedia(images = listOf(image), type = "app.bsky.embed.images")
} else {
null
}
Expand All @@ -143,7 +143,7 @@ class PostFeedRepository(private val authRepository: AuthRepository) : Applicati

val res = RequestHelper.executeWithRetry(authRepository) {
val body =
CreateRecordInput(did = it.did, record = record, collection = "app.bsky.feed.post")
CreateRecordInput(repo = it.did, record = record, collection = "app.bsky.feed.post")
getAtpClient().createPost(authorization = "Bearer ${it.accessJwt}", body = body)
}

Expand All @@ -165,15 +165,15 @@ class PostFeedRepository(private val authRepository: AuthRepository) : Applicati
image = imageBlob,
alt = "app.bsky.feed.post"
)
ImagesOrExternalOrRecord(images = listOf(image), type = "app.bsky.embed.images")
ImagesOrExternalOrRecordOrRecordOrRecordWithMedia(images = listOf(image), type = "app.bsky.embed.images")
} else {
null
}
val record = Post(text = content, createdAt = Date(), reply = to, embed = embed)

val res = RequestHelper.executeWithRetry(authRepository) {
val body =
CreateRecordInput(did = it.did, record = record, collection = "app.bsky.feed.post")
CreateRecordInput(repo = it.did, record = record, collection = "app.bsky.feed.post")
getAtpClient().createPost(authorization = "Bearer ${it.accessJwt}", body = body)
}

Expand All @@ -188,7 +188,7 @@ class PostFeedRepository(private val authRepository: AuthRepository) : Applicati
val rkey = UriConverter.toRkey(feedViewPost.post.uri)
RequestHelper.executeWithRetry(authRepository) {
val body =
DeleteRecordInput(did = it.did, collection = "app.bsky.feed.post", rkey = rkey)
DeleteRecordInput(repo = it.did, collection = "app.bsky.feed.post", rkey = rkey)
getAtpClient().deleteRecord("Bearer ${it.accessJwt}", body)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class UserRepository(private val authRepository: AuthRepository) : ApplicationRe

return RequestHelper.executeWithRetry(authRepository) {
val body = CreateRecordInput(
did = it.did,
repo = it.did,
record = Follow(subject = did, Date()),
collection = "app.bsky.graph.follow"
)
Expand All @@ -88,7 +88,7 @@ class UserRepository(private val authRepository: AuthRepository) : ApplicationRe

return RequestHelper.executeWithRetry(authRepository) {
val body = DeleteRecordInput(
did = it.did,
repo = it.did,
collection = "app.bsky.graph.follow",
rkey = UriConverter.toRkey(uri)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class NotificationViewModel : ApplicationViewModel() {

// NOTE: Update always for updating isRead
val newNotifications =
mergeNotifications(_notifications.value.orEmpty(), notifications.notifications)
mergeNotifications(_notifications.value, notifications.notifications)
_notifications.value = newNotifications
Log.d(SeiunApplication.TAG, "Notifications are merged")
}, onComplete = {
Expand All @@ -85,7 +85,7 @@ class NotificationViewModel : ApplicationViewModel() {

if (res.cursor != _cursor.value) {
if (res.notifications.isNotEmpty()) {
val newNotifications = notifications.value.orEmpty() + res.notifications
val newNotifications = notifications.value + res.notifications
_notifications.value = newNotifications
_cursor.value = res.cursor
_state.value = State.Loaded
Expand Down

0 comments on commit 5c7715a

Please sign in to comment.