Skip to content
This repository was archived by the owner on Oct 30, 2025. It is now read-only.

Commit 567fce9

Browse files
authored
Merge pull request #255 from RocketChat/beta
[RELEASE] Merge BETA into MASTER
2 parents b4aa0a4 + 76dbff1 commit 567fce9

File tree

7 files changed

+325
-75
lines changed

7 files changed

+325
-75
lines changed

core/src/main/kotlin/chat/rocket/core/internal/model/ChatRoomPayload.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ data class ChatRoomPayload(@Json(name = "rid") val roomId: String)
99
@JsonSerializable
1010
data class ChatRoomUnreadPayload(val roomId: String)
1111

12+
@JsonSerializable
13+
data class ChatRoomIdUserPayload(@Json(name = "rid") val roomId: String, val userId: String)
14+
15+
@JsonSerializable
16+
data class ChatRoomUserIgnorePayload(@Json(name = "rid") val roomId: String, val userId: String, val ignore: Boolean)
17+
18+
@JsonSerializable
19+
data class ChatRoomUserPayload(val roomId: String, val userId: String)
20+
1221
@JsonSerializable
1322
data class ChatRoomNamePayload(val roomId: String, val name: String?)
1423

@@ -27,8 +36,14 @@ data class ChatRoomReadOnlyPayload(val roomId: String, val readOnly: Boolean)
2736
@JsonSerializable
2837
data class ChatRoomTypePayload(val roomId: String, val type: String)
2938

39+
@JsonSerializable
40+
data class ChatRoomInvitePayload(val roomId: String, val userId: String)
41+
3042
@JsonSerializable
3143
data class ChatRoomJoinCodePayload(val roomId: String, val joinCode: String)
3244

45+
@JsonSerializable
46+
data class ChatRoomKickPayload(val roomId: String, val userId: String)
47+
3348
@JsonSerializable
3449
data class ChatRoomFavoritePayload(val roomId: String, val favorite: Boolean)

core/src/main/kotlin/chat/rocket/core/internal/realtime/socket/Socket.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,9 @@ class Socket(
175175
return
176176
}
177177

178-
reschedulePing(message.type)
178+
message.type?.let {
179+
reschedulePing(message.type)
180+
}
179181

180182
when (currentState) {
181183
is State.Connecting -> {

core/src/main/kotlin/chat/rocket/core/internal/realtime/socket/message/model/SocketMessage.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import se.ansman.kotshi.JsonSerializable
66
@JsonSerializable
77
data class SocketMessage(
88
@Json(name = "msg")
9-
val type: MessageType,
9+
val type: MessageType?,
1010
val id: String?,
1111
val collection: String?,
1212
@Json(name = "reason")

core/src/main/kotlin/chat/rocket/core/internal/rest/Channel.kt

Lines changed: 152 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package chat.rocket.core.internal.rest
33
import chat.rocket.common.model.RoomType
44
import chat.rocket.core.RocketChatClient
55
import chat.rocket.core.internal.RestResult
6+
import chat.rocket.core.internal.model.ChatRoomUserPayload
67
import chat.rocket.core.internal.model.CreateDirectMessagePayload
78
import chat.rocket.core.internal.model.CreateNewChannelPayload
89
import chat.rocket.core.model.DirectMessage
@@ -59,4 +60,154 @@ suspend fun RocketChatClient.createDirectMessage(username: String): DirectMessag
5960
val type = Types.newParameterizedType(RestResult::class.java, DirectMessage::class.java)
6061

6162
return@withContext handleRestCall<RestResult<DirectMessage>>(request, type).result()
62-
}
63+
}
64+
65+
/**
66+
* Add the owner of a chat room.
67+
*
68+
* @param roomId The room id.
69+
* @param roomType The room type.
70+
* @param userId The user id.
71+
*/
72+
suspend fun RocketChatClient.addOwner(
73+
roomId: String,
74+
roomType: RoomType,
75+
userId: String
76+
) {
77+
withContext(Dispatchers.IO) {
78+
val payload = ChatRoomUserPayload(roomId, userId)
79+
val adapter = moshi.adapter(ChatRoomUserPayload::class.java)
80+
val payloadBody = adapter.toJson(payload)
81+
val body = RequestBody.create(MEDIA_TYPE_JSON, payloadBody)
82+
83+
val url = requestUrl(restUrl, getRestApiMethodNameByRoomType(roomType, "addOwner")).build()
84+
85+
val request = requestBuilderForAuthenticatedMethods(url).post(body).build()
86+
87+
handleRestCall<Any>(request, Any::class.java)
88+
}
89+
}
90+
91+
/**
92+
* Adds the leader of a channel.
93+
94+
* @param roomId The room id.
95+
* @param roomType The room type.
96+
* @param userId The user id.
97+
*/
98+
suspend fun RocketChatClient.addLeader(
99+
roomId: String,
100+
roomType: RoomType,
101+
userId: String
102+
) {
103+
withContext(Dispatchers.IO) {
104+
val payload = ChatRoomUserPayload(roomId, userId)
105+
val adapter = moshi.adapter(ChatRoomUserPayload::class.java)
106+
val payloadBody = adapter.toJson(payload)
107+
val body = RequestBody.create(MEDIA_TYPE_JSON, payloadBody)
108+
109+
val url = requestUrl(restUrl, getRestApiMethodNameByRoomType(roomType, "addLeader")).build()
110+
111+
val request = requestBuilderForAuthenticatedMethods(url).post(body).build()
112+
113+
handleRestCall<Any>(request, Any::class.java)
114+
}
115+
}
116+
117+
/**
118+
* Adds the moderator of a channel.
119+
120+
* @param roomId The room id.
121+
* @param roomType The room type.
122+
* @param userId The user id.
123+
*/
124+
suspend fun RocketChatClient.addModerator(
125+
roomId: String,
126+
roomType: RoomType,
127+
userId: String
128+
) {
129+
withContext(Dispatchers.IO) {
130+
val payload = ChatRoomUserPayload(roomId, userId)
131+
val adapter = moshi.adapter(ChatRoomUserPayload::class.java)
132+
val payloadBody = adapter.toJson(payload)
133+
val body = RequestBody.create(MEDIA_TYPE_JSON, payloadBody)
134+
135+
val url = requestUrl(restUrl, getRestApiMethodNameByRoomType(roomType, "addModerator")).build()
136+
137+
val request = requestBuilderForAuthenticatedMethods(url).post(body).build()
138+
139+
handleRestCall<Any>(request, Any::class.java)
140+
}
141+
}
142+
143+
/**
144+
* Removes the owner of a channel.
145+
*
146+
* @param roomId The room id.
147+
* @param roomType The room type.
148+
* @param userId The user id.
149+
*/
150+
suspend fun RocketChatClient.removeOwner(
151+
roomId: String,
152+
roomType: RoomType,
153+
userId: String
154+
) = withContext(Dispatchers.IO) {
155+
val payload = ChatRoomUserPayload(roomId, userId)
156+
val adapter = moshi.adapter(ChatRoomUserPayload::class.java)
157+
val payloadBody = adapter.toJson(payload)
158+
val body = RequestBody.create(MEDIA_TYPE_JSON, payloadBody)
159+
160+
val url = requestUrl(restUrl, getRestApiMethodNameByRoomType(roomType, "removeOwner")).build()
161+
162+
val request = requestBuilderForAuthenticatedMethods(url).post(body).build()
163+
164+
handleRestCall<Any>(request, Any::class.java)
165+
}
166+
167+
/**
168+
* Removes the leader of a channel.
169+
170+
* @param roomId The room id.
171+
* @param roomType The room type.
172+
* @param userId The user id.
173+
*/
174+
suspend fun RocketChatClient.removeLeader(
175+
roomId: String,
176+
roomType: RoomType,
177+
userId: String
178+
) = withContext(Dispatchers.IO) {
179+
val payload = ChatRoomUserPayload(roomId, userId)
180+
val adapter = moshi.adapter(ChatRoomUserPayload::class.java)
181+
val payloadBody = adapter.toJson(payload)
182+
val body = RequestBody.create(MEDIA_TYPE_JSON, payloadBody)
183+
184+
val url = requestUrl(restUrl, getRestApiMethodNameByRoomType(roomType, "removeLeader")).build()
185+
186+
val request = requestBuilderForAuthenticatedMethods(url).post(body).build()
187+
188+
handleRestCall<Any>(request, Any::class.java)
189+
}
190+
191+
/**
192+
* Removes the moderator of a channel.
193+
*
194+
* @param roomId The room id.
195+
* @param roomType The room type.
196+
* @param userId The user id.
197+
*/
198+
suspend fun RocketChatClient.removeModerator(
199+
roomId: String,
200+
roomType: RoomType,
201+
userId: String
202+
) = withContext(Dispatchers.IO) {
203+
val payload = ChatRoomUserPayload(roomId, userId)
204+
val adapter = moshi.adapter(ChatRoomUserPayload::class.java)
205+
val payloadBody = adapter.toJson(payload)
206+
val body = RequestBody.create(MEDIA_TYPE_JSON, payloadBody)
207+
208+
val url = requestUrl(restUrl, getRestApiMethodNameByRoomType(roomType, "removeModerator")).build()
209+
210+
val request = requestBuilderForAuthenticatedMethods(url).post(body).build()
211+
212+
handleRestCall<Any>(request, Any::class.java)
213+
}

0 commit comments

Comments
 (0)