Skip to content

[BUG] onAuthenticated not working because of wrong implementation of JsonElement.isStatusMessage() #297

@ahsetiaki

Description

@ahsetiaki
@Throws(SerializationException::class)
    private fun parseStatusMessageForAuthenticationResult(message: JsonElement): Boolean {
        if (message.isStatusMessage()) {
            val status = serializer.decodeFromJsonElement(StatusMessage.serializer(), message)
            if (status.message == "authenticated") {
                activeConnection?.isAuthenticated = true
                listener.onAuthenticated(this)
                return true
            }
        }

        return false
    }

    /**
     * If the first byte in the message is an open square bracket, this frame is housing an array
     */
    private fun JsonElement.isStatusMessage() =
            this is JsonObject && JsonPrimitive(EVENT_TYPE_MESSAGE_KEY).contentOrNull == "status"

JsonPrimitive(EVENT_TYPE_MESSAGE_KEY).contentOrNull == "status" will always false because instead of comparing incoming ev, this creates a new JsonPrimitive EVENT_TYPE_MESSAGE_KEY as the content
.contentOrNull - This immediately extracts the content from that newly created JsonPrimitive

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions