fix: stabler reconnect, fix message reporting

This commit is contained in:
Infi 2023-02-24 20:16:52 +01:00
parent c38fc51e23
commit 40b85aa880
3 changed files with 14 additions and 4 deletions

View File

@ -33,6 +33,13 @@ object RealtimeSocket {
} }
suspend fun connect(token: String) { suspend fun connect(token: String) {
if (disconnectionState == DisconnectionState.Connected) {
Log.d("RealtimeSocket", "Already connected to websocket. Refusing to connect again.")
return
}
socket?.close(CloseReason(CloseReason.Codes.NORMAL, "Reconnecting to websocket."))
RevoltHttp.ws(REVOLT_WEBSOCKET) { RevoltHttp.ws(REVOLT_WEBSOCKET) {
socket = this socket = this

View File

@ -16,8 +16,9 @@ suspend fun putMessageReport(
) { ) {
val fullMessageReport = FullMessageReport( val fullMessageReport = FullMessageReport(
content = MessageReport( content = MessageReport(
type = "Message",
report_reason = reason, report_reason = reason,
id = messageId, id = messageId
), ),
additional_context = additionalContext, additional_context = additionalContext,
) )
@ -48,6 +49,7 @@ suspend fun putServerReport(
) { ) {
val fullServerReport = FullServerReport( val fullServerReport = FullServerReport(
content = ServerReport( content = ServerReport(
type = "Server",
report_reason = reason, report_reason = reason,
id = serverId, id = serverId,
), ),
@ -80,6 +82,7 @@ suspend fun putUserReport(
) { ) {
val fullUserReport = FullUserReport( val fullUserReport = FullUserReport(
content = UserReport( content = UserReport(
type = "User",
report_reason = reason, report_reason = reason,
id = userId, id = userId,
), ),

View File

@ -80,7 +80,7 @@ enum class UserReportReason(val value: String) {
@Serializable @Serializable
data class MessageReport( data class MessageReport(
val type: String = "Message", val type: String,
val id: String, val id: String,
val report_reason: ContentReportReason, val report_reason: ContentReportReason,
) )
@ -93,7 +93,7 @@ data class FullMessageReport(
@Serializable @Serializable
data class ServerReport( data class ServerReport(
val type: String = "Server", val type: String,
val id: String, val id: String,
val report_reason: ContentReportReason, val report_reason: ContentReportReason,
) )
@ -106,7 +106,7 @@ data class FullServerReport(
@Serializable @Serializable
data class UserReport( data class UserReport(
val type: String = "User", val type: String,
val id: String, val id: String,
val report_reason: UserReportReason, val report_reason: UserReportReason,
) )