Skip to content

Commit

Permalink
EOF-22
Browse files Browse the repository at this point in the history
EOF-22
  • Loading branch information
umerov1999 committed Sep 22, 2023
1 parent e3133fa commit 06f3629
Show file tree
Hide file tree
Showing 35 changed files with 397 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import dev.ragnarok.fenrir.model.Link
import dev.ragnarok.fenrir.model.Market
import dev.ragnarok.fenrir.model.MarketAlbum
import dev.ragnarok.fenrir.model.Message
import dev.ragnarok.fenrir.model.Narratives
import dev.ragnarok.fenrir.model.Peer
import dev.ragnarok.fenrir.model.Photo
import dev.ragnarok.fenrir.model.PhotoAlbum
Expand Down Expand Up @@ -209,6 +210,8 @@ class QuickAnswerActivity : AppCompatActivity() {
}

override fun onStoryOpen(story: Story) {}
override fun onNarrativeOpen(narratives: Narratives) {}

override fun onWallReplyOpen(reply: WallReply) {}
override fun onAudioPlaylistOpen(playlist: AudioPlaylist) {}
override fun onPhotoAlbumOpen(album: PhotoAlbum) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ class AttachmentsDtoAdapter : AbsDtoAdapter<VKApiAttachments>("VKApiAttachments"
kJson.decodeFromJsonElement(VKApiStory.serializer(), o ?: return null)
}

VKApiAttachment.TYPE_NARRATIVE == type -> {
kJson.decodeFromJsonElement(VKApiNarratives.serializer(), o ?: return null)
}

VKApiAttachment.TYPE_CALL == type -> {
kJson.decodeFromJsonElement(VKApiCall.serializer(), o ?: return null)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class NarrativesDtoAdapter : AbsDtoAdapter<VKApiNarratives>("VKApiNarratives") {
val root = json.jsonObject
dto.id = optInt(root, "id")
dto.owner_id = optLong(root, "owner_id")
dto.access_key = optString(root, "access_key")
dto.title = optString(root, "title")
if (hasArray(root, "story_ids")) {
val temp = root["story_ids"]?.jsonArray
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ object AttachmentsTokenCreator {
return AttachmentTokens.AttachmentToken("story", id, ownerId, accessKey)
}

fun ofNarrative(id: Int, ownerId: Long, accessKey: String?): IAttachmentToken {
return AttachmentTokens.AttachmentToken("narrative", id, ownerId, accessKey)
}

fun ofPhotoAlbum(id: Int, ownerId: Long): IAttachmentToken {
return AttachmentTokens.AttachmentToken("album", id, ownerId)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
package dev.ragnarok.fenrir.api.model

import dev.ragnarok.fenrir.api.adapters.NarrativesDtoAdapter
import kotlinx.serialization.SerialName
import dev.ragnarok.fenrir.api.model.interfaces.VKApiAttachment
import kotlinx.serialization.Serializable

@Serializable(with = NarrativesDtoAdapter::class)
class VKApiNarratives {
@SerialName("id")
class VKApiNarratives : VKApiAttachment {
var id = 0

@SerialName("owner_id")
var owner_id = 0L

@SerialName("title")
var title: String? = null

@SerialName("story_ids")
var access_key: String? = null
var story_ids: IntArray? = null

@SerialName("cover")
var cover: String? = null

override fun getType(): String {
return VKApiAttachment.TYPE_NARRATIVE
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ interface VKApiAttachment {
const val TYPE_LINK = "link"
const val TYPE_ARTICLE = "article"
const val TYPE_STORY = "story"
const val TYPE_NARRATIVE = "narrative"
const val TYPE_CALL = "call"
const val TYPE_NOT_SUPPORT = "not_support"
const val TYPE_NOTE = "note"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import androidx.annotation.IntDef
AttachmentsTypes.ARTICLE,
AttachmentsTypes.LINK,
AttachmentsTypes.STORY,
AttachmentsTypes.NARRATIVE,
AttachmentsTypes.CALL,
AttachmentsTypes.POLL,
AttachmentsTypes.PAGE,
Expand Down Expand Up @@ -41,23 +42,24 @@ annotation class AttachmentsTypes {
const val ARTICLE = 6
const val LINK = 7
const val STORY = 8
const val CALL = 9
const val POLL = 10
const val PAGE = 11
const val AUDIO_PLAYLIST = 12
const val STICKER = 13
const val TOPIC = 14
const val AUDIO_MESSAGE = 15
const val GIFT = 16
const val GRAFFITI = 17
const val ALBUM = 18
const val NOT_SUPPORTED = 19
const val WALL_REPLY = 20
const val EVENT = 21
const val MARKET = 22
const val MARKET_ALBUM = 23
const val ARTIST = 24
const val WIKI_PAGE = 25
const val GEO = 26
const val NARRATIVE = 9
const val CALL = 10
const val POLL = 11
const val PAGE = 12
const val AUDIO_PLAYLIST = 13
const val STICKER = 14
const val TOPIC = 15
const val AUDIO_MESSAGE = 16
const val GIFT = 17
const val GRAFFITI = 18
const val ALBUM = 19
const val NOT_SUPPORTED = 20
const val WALL_REPLY = 21
const val EVENT = 22
const val MARKET = 23
const val MARKET_ALBUM = 24
const val ARTIST = 25
const val WIKI_PAGE = 26
const val GEO = 27
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package dev.ragnarok.fenrir.db.model.entity

import androidx.annotation.Keep
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Keep
@Serializable
@SerialName("narrative")
class NarrativesDboEntity : DboEntity() {
var id: Int = 0
var owner_id: Long = 0L
var accessKey: String? = null
private set
var title: String? = null
private set
var cover: String? = null
private set
var stories: IntArray? = null
private set

fun setId(id: Int): NarrativesDboEntity {
this.id = id
return this
}

fun setOwnerId(ownerId: Long): NarrativesDboEntity {
owner_id = ownerId
return this
}

fun setAccessKey(access_key: String?): NarrativesDboEntity {
accessKey = access_key
return this
}

fun setTitle(title: String?): NarrativesDboEntity {
this.title = title
return this
}

fun setCover(cover: String?): NarrativesDboEntity {
this.cover = cover
return this
}

fun setStory_ids(stories: IntArray?): NarrativesDboEntity {
this.stories = stories
return this
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import dev.ragnarok.fenrir.Extra
import dev.ragnarok.fenrir.Includes.provideMainThreadScheduler
import dev.ragnarok.fenrir.R
import dev.ragnarok.fenrir.activity.SendAttachmentsActivity.Companion.startForSendAttachments
import dev.ragnarok.fenrir.domain.InteractorFactory
import dev.ragnarok.fenrir.fragment.base.AttachmentsViewBinder.OnAttachmentsActionCallback
import dev.ragnarok.fenrir.fromIOToMain
import dev.ragnarok.fenrir.link.LinkHelper
import dev.ragnarok.fenrir.media.music.MusicPlaybackService.Companion.startForPlayList
import dev.ragnarok.fenrir.model.Article
Expand All @@ -20,6 +22,7 @@ import dev.ragnarok.fenrir.model.Link
import dev.ragnarok.fenrir.model.Market
import dev.ragnarok.fenrir.model.MarketAlbum
import dev.ragnarok.fenrir.model.Message
import dev.ragnarok.fenrir.model.Narratives
import dev.ragnarok.fenrir.model.Photo
import dev.ragnarok.fenrir.model.PhotoAlbum
import dev.ragnarok.fenrir.model.Poll
Expand All @@ -28,6 +31,7 @@ import dev.ragnarok.fenrir.model.Story
import dev.ragnarok.fenrir.model.Video
import dev.ragnarok.fenrir.model.WallReply
import dev.ragnarok.fenrir.model.WikiPage
import dev.ragnarok.fenrir.nonNullNoEmpty
import dev.ragnarok.fenrir.place.PlaceFactory.getArtistPlace
import dev.ragnarok.fenrir.place.PlaceFactory.getAudiosInAlbumPlace
import dev.ragnarok.fenrir.place.PlaceFactory.getCommentsPlace
Expand Down Expand Up @@ -167,6 +171,22 @@ abstract class AccountDependencyDialogFragment : BaseDialogFragment(), OnAttachm
)
}

override fun onNarrativeOpen(narratives: Narratives) {
appendDisposable(
InteractorFactory.createStoriesInteractor()
.getStoryById(accountId, narratives.getStoriesIds())
.fromIOToMain()
.subscribe({
if (it.nonNullNoEmpty()) {
getHistoryVideoPreviewPlace(accountId, ArrayList(it), 0).tryOpenWith(
requireActivity()
)
}
}, {
})
)
}

override fun onUrlPhotoOpen(url: String, prefix: String, photo_prefix: String) {
getSingleURLPhotoPlace(url, prefix, photo_prefix).tryOpenWith(requireActivity())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import dev.ragnarok.fenrir.domain.IOwnersRepository
import dev.ragnarok.fenrir.domain.IStoriesShortVideosInteractor
import dev.ragnarok.fenrir.domain.mappers.Dto2Model
import dev.ragnarok.fenrir.domain.mappers.Dto2Model.transform
import dev.ragnarok.fenrir.domain.mappers.Dto2Model.transformNarrative
import dev.ragnarok.fenrir.domain.mappers.Dto2Model.transformOwner
import dev.ragnarok.fenrir.domain.mappers.MapUtil
import dev.ragnarok.fenrir.model.IOwnersBundle
Expand Down Expand Up @@ -85,7 +86,7 @@ class StoriesShortVideosInteractor(
.getNarratives(owner_id, offset, count)
.flatMap { story ->
val dtos = listEmptyIfNull(story.items)
Single.just(MapUtil.mapAll(dtos) { transform(it) })
Single.just(MapUtil.mapAll(dtos) { transformNarrative(it) })
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import dev.ragnarok.fenrir.api.model.VKApiMarket
import dev.ragnarok.fenrir.api.model.VKApiMarketAlbum
import dev.ragnarok.fenrir.api.model.VKApiMessage
import dev.ragnarok.fenrir.api.model.VKApiMilitary
import dev.ragnarok.fenrir.api.model.VKApiNarratives
import dev.ragnarok.fenrir.api.model.VKApiNews
import dev.ragnarok.fenrir.api.model.VKApiNotSupported
import dev.ragnarok.fenrir.api.model.VKApiPhoto
Expand Down Expand Up @@ -97,6 +98,7 @@ import dev.ragnarok.fenrir.db.model.entity.MarketAlbumDboEntity
import dev.ragnarok.fenrir.db.model.entity.MarketDboEntity
import dev.ragnarok.fenrir.db.model.entity.MessageDboEntity
import dev.ragnarok.fenrir.db.model.entity.MilitaryEntity
import dev.ragnarok.fenrir.db.model.entity.NarrativesDboEntity
import dev.ragnarok.fenrir.db.model.entity.NewsDboEntity
import dev.ragnarok.fenrir.db.model.entity.NotSupportedDboEntity
import dev.ragnarok.fenrir.db.model.entity.OwnerEntities
Expand Down Expand Up @@ -1028,6 +1030,10 @@ object Dto2Entity {
return mapStory(dto as VKApiStory)
}

VKApiAttachment.TYPE_NARRATIVE -> {
return mapNarrative(dto as VKApiNarratives)
}

VKApiAttachment.TYPE_GRAFFITI -> {
return mapGraffiti(dto as VKApiGraffiti)
}
Expand Down Expand Up @@ -1368,6 +1374,15 @@ object Dto2Entity {
.setVideo(dto.video?.let { mapVideo(it) })
}

private fun mapNarrative(dto: VKApiNarratives): NarrativesDboEntity {
return NarrativesDboEntity().setId(dto.id)
.setOwnerId(dto.owner_id)
.setAccessKey(dto.access_key)
.setTitle(dto.title)
.setCover(dto.cover)
.setStory_ids(dto.story_ids)
}

private fun mapWallReply(dto: VKApiWallReply): WallReplyDboEntity {
val attachmentsEntities: List<DboEntity>? = dto.attachments?.let { mapAttachmentsList(it) }
return WallReplyDboEntity().setId(dto.id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,12 @@ object Dto2Model {
.setTitle(chat.title)
}

fun transform(narrative: VKApiNarratives): Narratives {
fun transformNarrative(narrative: VKApiNarratives): Narratives {
return Narratives(narrative.id, narrative.owner_id)
.setTitle(narrative.title)
.setCover(narrative.cover)
.setStory_ids(narrative.story_ids)
.setAccessKey(narrative.access_key)
}

fun transformOwner(owner: VKApiOwner?): Owner? {
Expand Down Expand Up @@ -1267,6 +1268,9 @@ object Dto2Model {
VKApiAttachment.TYPE_STORY -> attachments.prepareStories()
.add(transformStory(attachment as VKApiStory, owners))

VKApiAttachment.TYPE_NARRATIVE -> attachments.prepareNarratives()
.add(transformNarrative(attachment as VKApiNarratives))

VKApiAttachment.TYPE_ALBUM -> attachments.preparePhotoAlbums().add(
transform(attachment as VKApiPhotoAlbum)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import dev.ragnarok.fenrir.db.model.entity.GraffitiDboEntity
import dev.ragnarok.fenrir.db.model.entity.LinkDboEntity
import dev.ragnarok.fenrir.db.model.entity.MarketAlbumDboEntity
import dev.ragnarok.fenrir.db.model.entity.MarketDboEntity
import dev.ragnarok.fenrir.db.model.entity.NarrativesDboEntity
import dev.ragnarok.fenrir.db.model.entity.NotSupportedDboEntity
import dev.ragnarok.fenrir.db.model.entity.PhotoAlbumDboEntity
import dev.ragnarok.fenrir.db.model.entity.PhotoDboEntity
Expand Down Expand Up @@ -63,6 +64,14 @@ object Entity2Dto {
)
}

is NarrativesDboEntity -> {
return AttachmentsTokenCreator.ofNarrative(
dboEntity.id,
dboEntity.owner_id,
dboEntity.accessKey
)
}

is PhotoAlbumDboEntity -> {
return AttachmentsTokenCreator.ofPhotoAlbum(dboEntity.id, dboEntity.ownerId)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import dev.ragnarok.fenrir.db.model.entity.MarketAlbumDboEntity
import dev.ragnarok.fenrir.db.model.entity.MarketDboEntity
import dev.ragnarok.fenrir.db.model.entity.MessageDboEntity
import dev.ragnarok.fenrir.db.model.entity.MilitaryEntity
import dev.ragnarok.fenrir.db.model.entity.NarrativesDboEntity
import dev.ragnarok.fenrir.db.model.entity.NewsDboEntity
import dev.ragnarok.fenrir.db.model.entity.NotSupportedDboEntity
import dev.ragnarok.fenrir.db.model.entity.PageDboEntity
Expand Down Expand Up @@ -86,6 +87,7 @@ import dev.ragnarok.fenrir.model.Market
import dev.ragnarok.fenrir.model.MarketAlbum
import dev.ragnarok.fenrir.model.Message
import dev.ragnarok.fenrir.model.Military
import dev.ragnarok.fenrir.model.Narratives
import dev.ragnarok.fenrir.model.News
import dev.ragnarok.fenrir.model.NotSupported
import dev.ragnarok.fenrir.model.Owner
Expand Down Expand Up @@ -711,6 +713,10 @@ object Entity2Model {
return buildStoryFromDbo(dboEntity, owners)
}

is NarrativesDboEntity -> {
return buildNarrativeFromDbo(dboEntity)
}

is PhotoAlbumDboEntity -> {
return mapPhotoAlbum(dboEntity)
}
Expand Down Expand Up @@ -1097,6 +1103,14 @@ object Entity2Model {
.setVideo(dbo.video?.let { buildVideoFromDbo(it) })
}

private fun buildNarrativeFromDbo(dbo: NarrativesDboEntity): Narratives {
return Narratives(dbo.id, dbo.owner_id)
.setTitle(dbo.title)
.setCover(dbo.cover)
.setStory_ids(dbo.stories)
.setAccessKey(dbo.accessKey)
}

private fun buildGraffitiFromDbo(dto: GraffitiDboEntity): Graffiti {
return Graffiti().setId(dto.id)
.setOwner_id(dto.owner_id)
Expand Down
Loading

0 comments on commit 06f3629

Please sign in to comment.