Skip to content

Commit ce9c0ba

Browse files
committed
Fixed RoomStatusEventEmitter typo,
Refactored DefaultStatus, using composition over inheritance for RoomStatusEventEmitter
1 parent b5a5e54 commit ce9c0ba

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

chat-android/src/main/java/com/ably/chat/RoomStatus.kt

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ data class RoomStatusChange(
163163
val error: ErrorInfo? = null,
164164
)
165165

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

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

177-
class DefaultStatus(private val logger: LogHandler?) : InternalRoomStatus, RoomStatusEvenEmitter() {
177+
class DefaultStatus(private val logger: LogHandler?) : InternalRoomStatus {
178178

179179
private val _logger = logger
180180

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

189-
private val internalEmitter = RoomStatusEvenEmitter()
189+
private val externalEmitter = RoomStatusEventEmitter()
190+
private val internalEmitter = RoomStatusEventEmitter()
190191

191192
override fun onChange(listener: RoomStatus.Listener): Subscription {
192-
this.on(listener)
193+
externalEmitter.on(listener)
193194
return Subscription {
194-
this.off(listener)
195+
externalEmitter.off(listener)
195196
}
196197
}
197198

198199
override fun offAll() {
199-
this.offAll()
200+
externalEmitter.off()
200201
}
201202

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

206207
override fun setStatus(params: NewRoomStatus) {
207208
val change = RoomStatusChange(params.status, current, params.error)
208-
this._state = change.current
209-
this._error = change.error
210-
this.internalEmitter.emit(change.current, change)
211-
this.emit(change.current, change)
209+
_state = change.current
210+
_error = change.error
211+
internalEmitter.emit(change.current, change)
212+
externalEmitter.emit(change.current, change)
212213
}
213214

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

0 commit comments

Comments
 (0)