Skip to content
This repository has been archived by the owner on Oct 22, 2023. It is now read-only.

Commit

Permalink
Adapt to new Chat request field names
Browse files Browse the repository at this point in the history
  • Loading branch information
cyb3rko committed Jul 22, 2022
1 parent 3677f24 commit b390cc1
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 60 deletions.
60 changes: 30 additions & 30 deletions src/main/kotlin/com/cyb3rko/m3okotlin/data/Chat.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,83 +11,83 @@ internal data class ChatCreateRequest(
val name: String,
val private: Boolean,
@SerialName("user_ids")
val userIDs: List<String>
val userIds: List<String>
)

@Serializable
data class ChatCreateResponse(val room: ChatRoom)
data class ChatCreateResponse(val group: ChatGroup)

@Serializable
internal data class ChatDeleteRequest(@SerialName("room_id") val roomID: String)
internal data class ChatDeleteRequest(@SerialName("group_id") val groupId: String)

@Serializable
data class ChatDeleteResponse(val room: ChatRoom)
data class ChatDeleteResponse(val group: ChatGroup)

@Serializable
internal data class ChatHistoryRequest(@SerialName("room_id") val roomID: String)
internal data class ChatHistoryRequest(@SerialName("group_id") val groupId: String)

@Serializable
data class ChatHistoryResponse(val messages: List<ChatMessage>)

@Serializable
internal data class ChatInviteRequest(
@SerialName("room_id")
val roomID: String,
@SerialName("group_id")
val groupId: String,
@SerialName("user_id")
val userID: String
val userId: String
)

@Serializable
data class ChatInviteResponse(val room: ChatRoom)
data class ChatInviteResponse(val group: ChatGroup)

@Serializable
internal data class ChatJoinRequest(
@SerialName("room_id")
val roomID: String,
@SerialName("group_id")
val groupId: String,
@SerialName("user_id")
val userID: String
val userId: String
)

@Serializable
data class ChatJoinResponse(val message: ChatMessage)

@Serializable
internal data class ChatKickRequest(
@SerialName("room_id")
val roomID: String,
@SerialName("group_id")
val groupId: String,
@SerialName("user_id")
val userID: String
val userId: String
)

@Serializable
data class ChatKickResponse(val room: ChatRoom)
data class ChatKickResponse(val group: ChatGroup)

@Serializable
internal data class ChatLeaveRequest(
@SerialName("room_id")
val roomID: String,
@SerialName("group_id")
val groupId: String,
@SerialName("user_id")
val userID: String
val userId: String
)

@Serializable
data class ChatLeaveResponse(val room: ChatRoom)
data class ChatLeaveResponse(val group: ChatGroup)

@Serializable
internal data class ChatListRequest(@SerialName("user_id") val userID: String)
internal data class ChatListRequest(@SerialName("user_id") val userId: String)

@Serializable
data class ChatListResponse(val rooms: List<ChatRoom>)
data class ChatListResponse(val groups: List<ChatGroup>)

@Serializable
internal data class ChatSendRequest(
val client: String,
@SerialName("room_id")
val roomID: String,
@SerialName("group_id")
val groupId: String,
val subject: String,
val text: String,
@SerialName("user_id")
val userID: String
val userId: String
)

@Serializable
Expand All @@ -99,24 +99,24 @@ data class ChatSendResponse(val message: ChatMessage)
data class ChatMessage(
val client: String,
val id: String,
@SerialName("room_id")
val roomID: String,
@SerialName("group_id")
val groupId: String,
@SerialName("sent_at")
val sentAt: String,
val subject: String,
val text: String,
@SerialName("user_id")
val userID: String
val userId: String
)

@Serializable
data class ChatRoom(
data class ChatGroup(
@SerialName("created_at")
val createdAt: String,
val description: String,
val id: String,
val name: String,
val private: Boolean,
@SerialName("user_ids")
val userIDs: List<String>
val userIds: List<String>
)
60 changes: 30 additions & 30 deletions src/main/kotlin/com/cyb3rko/m3okotlin/services/ChatService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,40 +28,40 @@ object ChatService {
description: String,
name: String,
private: Boolean = false,
userIDs: List<String> = listOf()
userIds: List<String> = listOf()
): ChatCreateResponse {
return M3O.ktorHttpClient.post(M3O.getUrl(SERVICE, "Create")) {
body = ChatCreateRequest(description, name, private, userIDs)
body = ChatCreateRequest(description, name, private, userIds)
}
}

/**
* Delete a chat room
* @since 0.1.0
*/
suspend fun delete(roomID: String): ChatDeleteResponse {
suspend fun delete(groupId: String): ChatDeleteResponse {
return M3O.ktorHttpClient.post(M3O.getUrl(SERVICE, "Delete")) {
body = ChatDeleteRequest(roomID)
body = ChatDeleteRequest(groupId)
}
}

/**
* List the messages in a chat
* @since 0.1.0
*/
suspend fun history(roomID: String): ChatHistoryResponse {
suspend fun history(groupId: String): ChatHistoryResponse {
return M3O.ktorHttpClient.post(M3O.getUrl(SERVICE, "History")) {
body = ChatHistoryRequest(roomID)
body = ChatHistoryRequest(groupId)
}
}

/**
* Invite a user to a chat room
* @since 0.1.0
*/
suspend fun invite(roomID: String, userID: String): ChatInviteResponse {
suspend fun invite(groupId: String, userId: String): ChatInviteResponse {
return M3O.ktorHttpClient.post(M3O.getUrl(SERVICE, "Invite")) {
body = ChatInviteRequest(roomID, userID)
body = ChatInviteRequest(groupId, userId)
}
}

Expand All @@ -70,14 +70,14 @@ object ChatService {
* @since 0.1.0
*/
fun join(
roomID: String,
userID: String,
groupId: String,
userId: String,
action: (Exception?, ChatJoinResponse?) -> Unit
): WebSocket {
val url = M3O.getUrl(SERVICE, "Join", true)
val socket = WebSocket(
url,
Json.encodeToString(ChatJoinRequest(roomID, userID))
Json.encodeToString(ChatJoinRequest(groupId, userId))
) { e, response ->
action(
e,
Expand All @@ -92,29 +92,29 @@ object ChatService {
* Kick a user from a chat room
* @since 0.1.0
*/
suspend fun kick(roomID: String, userID: String): ChatKickResponse {
suspend fun kick(groupId: String, userId: String): ChatKickResponse {
return M3O.ktorHttpClient.post(M3O.getUrl(SERVICE, "Kick")) {
body = ChatKickRequest(roomID, userID)
body = ChatKickRequest(groupId, userId)
}
}

/**
* Leave a chat room
* @since 0.1.0
*/
suspend fun leave(roomID: String, userID: String): ChatLeaveResponse {
suspend fun leave(groupId: String, userId: String): ChatLeaveResponse {
return M3O.ktorHttpClient.post(M3O.getUrl(SERVICE, "Leave")) {
body = ChatLeaveRequest(roomID, userID)
body = ChatLeaveRequest(groupId, userId)
}
}

/**
* List available chats
* @since 0.1.0
*/
suspend fun list(userID: String = ""): ChatListResponse {
suspend fun list(userId: String = ""): ChatListResponse {
return M3O.ktorHttpClient.post(M3O.getUrl(SERVICE, "List")) {
body = ChatListRequest(userID)
body = ChatListRequest(userId)
}
}

Expand All @@ -125,34 +125,34 @@ object ChatService {
*/
suspend fun send(
client: String,
roomID: String,
groupId: String,
subject: String,
text: String,
userID: String
userId: String
): ChatSendResponse {
return M3O.ktorHttpClient.post(M3O.getUrl(SERVICE, "Send")) {
body = ChatSendRequest(client, roomID, subject, text, userID)
body = ChatSendRequest(client, groupId, subject, text, userId)
}
}

suspend fun ChatRoom.delete() = delete(this.id)
suspend fun ChatGroup.delete() = delete(this.id)

suspend fun ChatRoom.history() = history(this.id)
suspend fun ChatGroup.history() = history(this.id)

suspend fun ChatRoom.invite(userID: String) = invite(this.id, userID)
suspend fun ChatGroup.invite(userId: String) = invite(this.id, userId)

fun ChatRoom.join(userID: String, action: (Exception?, ChatJoinResponse?) -> Unit) = join(
this.id, userID, action
fun ChatGroup.join(userId: String, action: (Exception?, ChatJoinResponse?) -> Unit) = join(
this.id, userId, action
)

suspend fun ChatRoom.kick(userID: String) = kick(this.id, userID)
suspend fun ChatGroup.kick(userId: String) = kick(this.id, userId)

suspend fun ChatRoom.leave(userID: String) = leave(this.id, userID)
suspend fun ChatGroup.leave(userId: String) = leave(this.id, userId)

suspend fun ChatRoom.send(
suspend fun ChatGroup.send(
client: String,
subject: String,
text: String,
userID: String
) = send(client, this.id, subject, text, userID)
userId: String
) = send(client, this.id, subject, text, userId)
}

0 comments on commit b390cc1

Please sign in to comment.