This repository was archived by the owner on Oct 30, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +47
-3
lines changed
common/src/main/kotlin/chat/rocket/common/model
core/src/main/kotlin/chat/rocket/core
internal/realtime/socket/message/collection Expand file tree Collapse file tree 3 files changed +47
-3
lines changed Original file line number Diff line number Diff line change @@ -39,4 +39,31 @@ fun userStatusOf(status: String): UserStatus {
3939 " offline" -> UserStatus .Offline ()
4040 else -> UserStatus .Unknown (status)
4141 }
42- }
42+ }
43+
44+ @FallbackSealedClass(name = " Unknown" , fieldName = " rawAvatar" )
45+ sealed class UserAvatar {
46+ @Json(name = " upload" )
47+ class Upload : chat.rocket.common.model.UserAvatar ()
48+ @Json(name = " url" )
49+ class Url : chat.rocket.common.model.UserAvatar ()
50+ class Cleared : chat.rocket.common.model.UserAvatar ()
51+ class Unknown (val rawAvatar : String ) : UserAvatar()
52+
53+ override fun toString (): String {
54+ return when (this ) {
55+ is Upload -> " upload"
56+ is Url -> " url"
57+ else -> " cleared"
58+ }
59+ }
60+ }
61+
62+ fun userAvatarOf (avatar : String ): UserAvatar {
63+ return when (avatar) {
64+ " upload" -> UserAvatar .Upload ()
65+ " url" -> UserAvatar .Url ()
66+ " cleared" -> UserAvatar .Cleared ()
67+ else -> UserAvatar .Unknown (avatar)
68+ }
69+ }
Original file line number Diff line number Diff line change 11package chat.rocket.core.internal.realtime.socket.message.collection
22
3+ import chat.rocket.common.model.*
34import chat.rocket.common.model.User
45import chat.rocket.core.internal.realtime.socket.Socket
56import chat.rocket.core.model.Myself
@@ -32,11 +33,25 @@ internal fun Socket.processUserStream(text: String) {
3233@ObsoleteCoroutinesApi
3334@ExperimentalCoroutinesApi
3435private fun Socket.processUserDataStream (json : JSONObject , id : String ) {
35- val fields = json.optJSONObject(" fields" )
36- fields.put(" _id" , id)
36+ var fields: JSONObject ? = JSONObject ()
37+
38+ if (json.has(" fields" )){
39+ fields = json.optJSONObject(" fields" )
40+ }else if (json.has(" cleared" )){
41+ val cleared = json.optJSONArray(" cleared" )
42+
43+ for (i in 0 .. (cleared.length() - 1 )) {
44+ if (cleared.get(i) == " avatarOrigin" ){
45+ fields?.put(" avatarOrigin" , userAvatarOf(" cleared" ))
46+ break
47+ }
48+ }
49+ }
50+ fields?.put(" _id" , id)
3751
3852 val adapter = moshi.adapter<Myself >(Myself ::class .java)
3953 val myself = adapter.fromJson(fields.toString())
54+
4055 myself?.let {
4156 if (! parentJob.isActive) {
4257 logger.debug { " Parent job: $parentJob " }
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package chat.rocket.core.model
22
33import chat.rocket.common.model.BaseUser
44import chat.rocket.common.model.UserStatus
5+ import chat.rocket.common.model.UserAvatar
56import com.squareup.moshi.Json
67import se.ansman.kotshi.JsonSerializable
78
@@ -14,6 +15,7 @@ data class Myself(
1415 val status : UserStatus ? ,
1516 val statusConnection : UserStatus ? ,
1617 val statusDefault : UserStatus ? ,
18+ val avatarOrigin : UserAvatar ? ,
1719 val utcOffset : Float? ,
1820 val emails : List <Email >? ,
1921 val roles : List <String >?
You can’t perform that action at this time.
0 commit comments