Skip to content

Commit

Permalink
Add all possible parameters to ChannelUi and MemberUi class, (#59)
Browse files Browse the repository at this point in the history
Mappers updated,
Sealed class changed to interface to allow extending,
  • Loading branch information
Chesteer89 authored Dec 8, 2022
1 parent 5d9d9a5 commit a710499
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,9 @@ fun RepositoryProvider(
val memberFormatter: (UserId) -> MemberUi.Data = { id ->
runBlocking {
(memberRepository.get(id)?.let { memberDbMapper.map(it) } ?: MemberUi.Data(
id,
unknownMemberTitle,
null,
unknownMemberDescription,
id = id,
name = unknownMemberTitle,
description = unknownMemberDescription,
))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,23 @@ class DBChannelMapper : Mapper<DBChannelWithMembers, ChannelUi.Data> {
type = ChannelUi.Data.typeFromString(input.channel.type),
profileUrl = input.channel.profileUrl,
updated = input.updated?.toInstant(),
members = input.members.toUi()
members = input.members.toUi(),
status = input.status,
custom = input.custom,
)

private fun List<DBMember>.toUi(): List<MemberUi.Data> =
map { input ->
MemberUi.Data(
input.id,
input.name,
input.profileUrl,
input.custom.asMap()?.get("description") as? String?
id = input.id,
name = input.name,
type = input.type,
email = input.email,
externalId = input.externalId,
profileUrl = input.profileUrl,
description = input.custom.asMap()?.get("description") as? String?,
status = input.status,
custom = input.custom,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@ import com.pubnub.framework.mapper.Mapper
class DBMemberMapper : Mapper<DBMemberWithChannels, MemberUi.Data> {
override fun map(input: DBMemberWithChannels): MemberUi.Data =
MemberUi.Data(
input.id,
input.name,
input.profileUrl,
input.member.custom.asMap()?.get("description") as? String?
id = input.id,
name = input.name,
type = input.type,
email = input.email,
externalId = input.externalId,
profileUrl = input.profileUrl,
description = input.custom.asMap()?.get("description") as? String?,
status = input.status,
custom = input.custom,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,23 @@ import com.pubnub.components.chat.ui.component.message.MessageUi
import com.pubnub.components.data.message.DBMessage
import com.pubnub.components.data.message.action.DBMessageWithActions
import com.pubnub.framework.mapper.Mapper
import com.pubnub.framework.util.toIsoString
import com.pubnub.framework.util.toTimetoken

class DomainMessageMapper : Mapper<MessageUi.Data, DBMessageWithActions> {
override fun map(input: MessageUi.Data): DBMessageWithActions =

DBMessageWithActions(
DBMessage(
id = input.uuid,
text = input.text,
contentType = input.contentType,
content = input.content,
createdAt = input.timetoken.toIsoString(),
createdAt = input.createdAt,
custom = input.custom,

publisher = input.publisher.id,
published = input.published,
channel = input.channel,
timetoken = input.timetoken,
timetoken = input.createdAt.toTimetoken(),
isSent = !input.isSending && input.isDelivered,
exception = null,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import com.pubnub.components.chat.ui.component.member.MemberUi
import com.pubnub.framework.data.ChannelId
import kotlinx.datetime.Instant


sealed class ChannelUi {

interface ChannelUi {
data class Data(
val id: ChannelId,
val name: String,
Expand All @@ -16,7 +14,9 @@ sealed class ChannelUi {
val description: String? = null,
val profileUrl: String? = null,
val updated: Instant? = null,
) : ChannelUi() {
val status: String? = null,
val custom: Any? = null,
) : ChannelUi {
@Retention(AnnotationRetention.SOURCE)
@StringDef(DEFAULT, DIRECT, GROUP)
annotation class TypeDef
Expand All @@ -35,5 +35,5 @@ sealed class ChannelUi {
}
}

data class Header(val title: String) : ChannelUi()
data class Header(val title: String) : ChannelUi
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@ package com.pubnub.components.chat.ui.component.member

import com.pubnub.framework.data.UserId

sealed class MemberUi {
interface MemberUi {
data class Data(
val id: UserId,
val name: String?,
val type: String = "default",
val email: String? = null,
val externalId: String? = null,
val profileUrl: String? = null,
val description: String? = null,
) : MemberUi()
val status: String? = null,
val custom: Any? = null,
) : MemberUi

data class Separator(val text: String) : MemberUi()
data class Separator(val text: String) : MemberUi
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.pubnub.framework.data.ChannelId
import com.pubnub.framework.data.MessageId
import com.pubnub.framework.util.Timetoken

sealed class MessageUi {
interface MessageUi {
data class Data(
val uuid: MessageId,
val publisher: MemberUi.Data,
Expand All @@ -21,9 +21,9 @@ sealed class MessageUi {
val contentType: String = "default",
val content: Any? = null,
val custom: Any? = null,
) : MessageUi()
) : MessageUi

data class Separator(val text: String) : MessageUi()
data class Separator(val text: String) : MessageUi
}

val List<Attachment>.images
Expand Down

0 comments on commit a710499

Please sign in to comment.