Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CHAT-4902] feat: add chat room skeleton and default implementations for main classes #11

Merged
merged 2 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ trim_trailing_whitespace = true
charset = utf-8

[*.{kt,kts}]
ij_kotlin_imports_layout = android.**,androidx.**,*,java.**,javax.**,kotlin.**,kotlinx.**,io.ably.**,com.ably.**,^
ij_kotlin_imports_layout = *,^
47 changes: 1 addition & 46 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ plugins {
alias(libs.plugins.android.application) apply false
alias(libs.plugins.android.kotlin) apply false
alias(libs.plugins.compose.compiler) apply false
alias(libs.plugins.build.config) apply false
}

dependencies {
Expand Down
9 changes: 9 additions & 0 deletions chat-android/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
plugins {
alias(libs.plugins.android.library)
alias(libs.plugins.android.kotlin)
alias(libs.plugins.build.config)
}

val version = libs.versions.ably.chat.get()

android {
namespace = "com.ably.chat"
compileSdk = 34
Expand Down Expand Up @@ -33,6 +36,12 @@ android {
}
}

buildConfig {
packageName("com.ably.chat")
useKotlinOutput { internalVisibility = true }
buildConfigField("APP_VERSION", provider { "\"${version}\"" })
}

dependencies {
api(libs.ably.android)
implementation(libs.gson)
Expand Down
25 changes: 24 additions & 1 deletion chat-android/src/main/java/com/ably/chat/ChatClient.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
@file:Suppress("StringLiteralDuplication", "NotImplementedDeclaration")

package com.ably.chat

import io.ably.lib.realtime.AblyRealtime
import io.ably.lib.types.ClientOptions

typealias RealtimeClient = AblyRealtime

Expand Down Expand Up @@ -35,3 +36,25 @@ interface ChatClient {
*/
val clientOptions: ClientOptions
}

fun ChatClient(realtimeClient: RealtimeClient, clientOptions: ClientOptions): ChatClient = DefaultChatClient(realtimeClient, clientOptions)

internal class DefaultChatClient(
override val realtime: RealtimeClient,
override val clientOptions: ClientOptions,
) : ChatClient {

private val chatApi = ChatApi(realtime, clientId)

override val rooms: Rooms = DefaultRooms(
realtimeClient = realtime,
chatApi = chatApi,
clientOptions = clientOptions,
)

override val connection: Connection
get() = TODO("Not yet implemented")

override val clientId: String
get() = realtime.auth.clientId
}
ttypic marked this conversation as resolved.
Show resolved Hide resolved
39 changes: 39 additions & 0 deletions chat-android/src/main/java/com/ably/chat/Messages.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@file:Suppress("StringLiteralDuplication", "NotImplementedDeclaration")

package com.ably.chat

import io.ably.lib.realtime.Channel
Expand Down Expand Up @@ -173,3 +175,40 @@ data class SendMessageParams(
*/
val headers: MessageHeaders? = null,
)

class DefaultMessages(
private val roomId: String,
private val realtimeClient: RealtimeClient,
private val chatApi: ChatApi,
) : Messages {

/**
* the channel name for the chat messages channel.
*/
private val messagesChannelName = "$roomId::\$chat::\$chatMessages"

override val channel: Channel
get() = realtimeClient.channels.get(messagesChannelName, ChatChannelOptions())

override fun subscribe(listener: Messages.Listener) {
TODO("Not yet implemented")
}

override fun unsubscribe(listener: Messages.Listener) {
TODO("Not yet implemented")
}

override suspend fun get(options: QueryOptions): PaginatedResult<Message> {
TODO("Not yet implemented")
}

override suspend fun send(params: SendMessageParams): Message = chatApi.sendMessage(roomId, params)

override fun onDiscontinuity(listener: EmitsDiscontinuities.Listener) {
TODO("Not yet implemented")
}

override fun offDiscontinuity(listener: EmitsDiscontinuities.Listener) {
TODO("Not yet implemented")
}
ttypic marked this conversation as resolved.
Show resolved Hide resolved
}
29 changes: 29 additions & 0 deletions chat-android/src/main/java/com/ably/chat/Occupancy.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@file:Suppress("StringLiteralDuplication", "NotImplementedDeclaration")

package com.ably.chat

import io.ably.lib.realtime.Channel
Expand Down Expand Up @@ -63,3 +65,30 @@ data class OccupancyEvent(
*/
val presenceMembers: Int,
)

internal class DefaultOccupancy(
private val messages: Messages,
) : Occupancy {
override val channel: Channel
get() = messages.channel

override fun subscribe(listener: Occupancy.Listener) {
TODO("Not yet implemented")
}

override fun unsubscribe(listener: Occupancy.Listener) {
TODO("Not yet implemented")
}

override suspend fun get(): OccupancyEvent {
TODO("Not yet implemented")
}

override fun onDiscontinuity(listener: EmitsDiscontinuities.Listener) {
TODO("Not yet implemented")
}

override fun offDiscontinuity(listener: EmitsDiscontinuities.Listener) {
TODO("Not yet implemented")
}
ttypic marked this conversation as resolved.
Show resolved Hide resolved
}
46 changes: 46 additions & 0 deletions chat-android/src/main/java/com/ably/chat/Presence.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@file:Suppress("StringLiteralDuplication", "NotImplementedDeclaration")

package com.ably.chat

import android.text.PrecomputedText.Params
Expand Down Expand Up @@ -132,3 +134,47 @@ data class PresenceEvent(
*/
val data: PresenceData,
)

internal class DefaultPresence(
private val messages: Messages,
) : Presence {

override val channel: Channel
get() = messages.channel

override suspend fun get(params: List<Params>): List<PresenceMember> {
TODO("Not yet implemented")
}

override suspend fun isUserPresent(clientId: String): Boolean {
TODO("Not yet implemented")
}

override suspend fun enter(data: PresenceData?) {
TODO("Not yet implemented")
}

override suspend fun update(data: PresenceData?) {
TODO("Not yet implemented")
}

override suspend fun leave(data: PresenceData?) {
TODO("Not yet implemented")
}

override fun subscribe(listener: Presence.Listener) {
TODO("Not yet implemented")
}

override fun unsubscribe(listener: Presence.Listener) {
TODO("Not yet implemented")
}

override fun onDiscontinuity(listener: EmitsDiscontinuities.Listener) {
TODO("Not yet implemented")
}

override fun offDiscontinuity(listener: EmitsDiscontinuities.Listener) {
TODO("Not yet implemented")
}
ttypic marked this conversation as resolved.
Show resolved Hide resolved
}
51 changes: 51 additions & 0 deletions chat-android/src/main/java/com/ably/chat/Room.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@file:Suppress("StringLiteralDuplication", "NotImplementedDeclaration")

package com.ably.chat

/**
Expand Down Expand Up @@ -80,3 +82,52 @@ interface Room {
*/
suspend fun detach()
}

internal class DefaultRoom(
override val roomId: String,
override val options: RoomOptions,
realtimeClient: RealtimeClient,
chatApi: ChatApi,
) : Room {

override val messages: Messages = DefaultMessages(
roomId = roomId,
realtimeClient = realtimeClient,
chatApi = chatApi,
)

override val presence: Presence = DefaultPresence(
messages = messages,
)

override val reactions: RoomReactions = DefaultRoomReactions(
roomId = roomId,
realtimeClient = realtimeClient,
)

override val typing: Typing = DefaultTyping(
roomId = roomId,
realtimeClient = realtimeClient,
)

override val occupancy: Occupancy = DefaultOccupancy(
messages = messages,
)

override val status: RoomStatus
get() {
TODO("Not yet implemented")
}

override suspend fun attach() {
messages.channel.attachCoroutine()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to check - the room lifecycle will be a separate PR?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, of course

typing.channel.attachCoroutine()
reactions.channel.attachCoroutine()
}

override suspend fun detach() {
messages.channel.detachCoroutine()
typing.channel.detachCoroutine()
reactions.channel.detachCoroutine()
}
ttypic marked this conversation as resolved.
Show resolved Hide resolved
}
32 changes: 32 additions & 0 deletions chat-android/src/main/java/com/ably/chat/RoomReactions.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@file:Suppress("StringLiteralDuplication", "NotImplementedDeclaration")

package com.ably.chat

import io.ably.lib.realtime.Channel
Expand Down Expand Up @@ -100,3 +102,33 @@ data class SendReactionParams(
*/
val headers: ReactionHeaders? = null,
)

internal class DefaultRoomReactions(
roomId: String,
private val realtimeClient: RealtimeClient,
) : RoomReactions {
private val roomReactionsChannelName = "$roomId::\$chat::\$reactions"

override val channel: Channel
get() = realtimeClient.channels.get(roomReactionsChannelName, ChatChannelOptions())

override suspend fun send(params: SendReactionParams) {
TODO("Not yet implemented")
}

override fun subscribe(listener: RoomReactions.Listener) {
TODO("Not yet implemented")
}

override fun unsubscribe(listener: RoomReactions.Listener) {
TODO("Not yet implemented")
}

override fun onDiscontinuity(listener: EmitsDiscontinuities.Listener) {
TODO("Not yet implemented")
}

override fun offDiscontinuity(listener: EmitsDiscontinuities.Listener) {
TODO("Not yet implemented")
}
ttypic marked this conversation as resolved.
Show resolved Hide resolved
}
Loading