Skip to content

Commit

Permalink
Fixed RoomStatusEventEmitter typo,
Browse files Browse the repository at this point in the history
Refactored DefaultStatus, using composition over inheritance for RoomStatusEventEmitter
  • Loading branch information
sacOO7 committed Nov 8, 2024
1 parent b5a5e54 commit ce9c0ba
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions chat-android/src/main/java/com/ably/chat/RoomStatus.kt
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ data class RoomStatusChange(
val error: ErrorInfo? = null,
)

open class RoomStatusEvenEmitter : EventEmitter<RoomLifecycle, RoomStatus.Listener>() {
class RoomStatusEventEmitter : EventEmitter<RoomLifecycle, RoomStatus.Listener>() {

override fun apply(listener: RoomStatus.Listener?, event: RoomLifecycle?, vararg args: Any?) {
try {
Expand All @@ -174,7 +174,7 @@ open class RoomStatusEvenEmitter : EventEmitter<RoomLifecycle, RoomStatus.Listen
}
}

class DefaultStatus(private val logger: LogHandler?) : InternalRoomStatus, RoomStatusEvenEmitter() {
class DefaultStatus(private val logger: LogHandler?) : InternalRoomStatus {

private val _logger = logger

Expand All @@ -186,17 +186,18 @@ class DefaultStatus(private val logger: LogHandler?) : InternalRoomStatus, RoomS
override val error: ErrorInfo?
get() = _error

private val internalEmitter = RoomStatusEvenEmitter()
private val externalEmitter = RoomStatusEventEmitter()
private val internalEmitter = RoomStatusEventEmitter()

override fun onChange(listener: RoomStatus.Listener): Subscription {
this.on(listener)
externalEmitter.on(listener)
return Subscription {
this.off(listener)
externalEmitter.off(listener)
}
}

override fun offAll() {
this.offAll()
externalEmitter.off()
}

override fun onChangeOnce(listener: RoomStatus.Listener) {
Expand All @@ -205,10 +206,10 @@ class DefaultStatus(private val logger: LogHandler?) : InternalRoomStatus, RoomS

override fun setStatus(params: NewRoomStatus) {
val change = RoomStatusChange(params.status, current, params.error)
this._state = change.current
this._error = change.error
this.internalEmitter.emit(change.current, change)
this.emit(change.current, change)
_state = change.current
_error = change.error
internalEmitter.emit(change.current, change)
externalEmitter.emit(change.current, change)
}

fun setStatus(status: RoomLifecycle, error: ErrorInfo? = null) {
Expand Down

0 comments on commit ce9c0ba

Please sign in to comment.