From 2db247e6e86d5217b24a098b30c577e4ab321e04 Mon Sep 17 00:00:00 2001 From: Davide Pianca Date: Mon, 16 Mar 2020 15:51:28 +0100 Subject: [PATCH] Fix will retained messages --- src/commonMain/kotlin/mqtt/broker/Broker.kt | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/commonMain/kotlin/mqtt/broker/Broker.kt b/src/commonMain/kotlin/mqtt/broker/Broker.kt index fe82ae7..2f73130 100644 --- a/src/commonMain/kotlin/mqtt/broker/Broker.kt +++ b/src/commonMain/kotlin/mqtt/broker/Broker.kt @@ -74,7 +74,7 @@ class Broker( properties.responseTopic = will.responseTopic properties.correlationData = will.correlationData properties.userProperty += will.userProperty - publish(session.clientId, will.retain, will.topic, will.qos, false, properties, will.payload) + publish(session.clientId, will.retain, will.topic, will.qos, properties, will.payload) // The will must be removed after sending session.will = null } @@ -160,7 +160,8 @@ class Broker( } } - fun publish( + private fun publish( + publisherClientId: String, retain: Boolean, topicName: String, qos: Qos, @@ -185,10 +186,20 @@ class Broker( ) setRetained(topicName, packet, "") } - publish("", retain, topicName, qos, false, properties, payload) + publish(publisherClientId, retain, topicName, qos, false, properties, payload) return true } + fun publish( + retain: Boolean, + topicName: String, + qos: Qos, + properties: MQTTProperties, + payload: UByteArray? + ): Boolean { + return publish("", retain, topicName, qos, properties, payload) + } + internal fun setRetained(topicName: String, message: MQTTPublish, clientId: String) { if (retainedAvailable) { if (message.payload?.isNotEmpty() == true)