iosxmppxmppframework

How to set the delayedDeliveryDate property of an XMPPMessage by XMPPFramework?


I'm implementing receiving archived XMPP messages according to XEP-0313 (Message Archive Management) with XMPPFramework. In my XMPPMessageArchiveManagementDelegate I receive messages one by one using the appropriate delegate method:

public func xmppMessageArchiveManagement(_ xmppMessageArchiveManagement: XMPPMessageArchiveManagement, didReceiveMAMMessage message: XMPPMessage) { }

Inside the received XMPP message I have an XML element for the message itself and another XML element for the delayed delivery date which I'm able to convert to a timestamp:

guard let timestamp = delayElement.attribute(forName: "stamp") else { return }

let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZ"

guard let delayedDeliveryDate = dateFormatter.date(from:timestamp.stringValue)

I'm also able to successfully create an XMPPMessage object from the message XMPP element:

let xmppMessage = XMPPMessage(from: messageElement)

The problem is that I don't understand how to set the delayed delivery date to the XMPPMessage object. The last one has a property delayedDeliveryDate, but I'm not able just to set it because of its get-only status:

// xmppMessage.delayedDeliveryDate = delayedDeliveryDate
// It doesn't work because 'delayedDeliveryDate' is a get-only property

I tried to find an initialiser which I can pass the delayed delivery date to, but I can't find exactly this parameter in available initialisers of the class XMPPMessage and I don't understand how to use available parameters to provide the date without which I'm not able to sort my messages correctly.


Solution

  • Finally I was able to solve my problem bypassing the necessity to set the delayedDeliveryDate property of XMPPMessage. I just set the appropriate property of my database message object and it's enough for the sorting purposes:

    let dbMessage = DBMessage(xmppMessage: xmppMessage, date: delayedDeliveryDate)