XMPPFramework icon indicating copy to clipboard operation
XMPPFramework copied to clipboard

Duplicate entry in XMPPMessageArchiving Database

Open blulion opened this issue 8 years ago • 1 comments

I am implementing MUC with default core data (XMPPMessageArchivingCoreDataStorage) using XMPPFramework. Messages are getting saved as expected. But when i send a message, i am getting two entries of same message in the database with Outgoing as 0 and 1.

screen shot 2016-11-05 at 5 10 40 pm

Message 1:

<message xmlns="jabber:client" id="9A120717-0D51-4BB3-BF33-7C738690A67A" to="[email protected]/iphone" type="groupchat" from="[email protected]/anish"><request xmlns="urn:xmpp:receipts"/><body>{
  "mediaItem" : "0",
  "body" : "A3"
}</body><thread>854CB335-35DA-43FB-9D63-B4015364CDF4</thread></message>

Is this expected behaviour?

Whenever i close and restart the app (or re establish the xmppstream), i am getting the same message with 'delay' tag but it is also getting inserted in the database.

screen shot 2016-11-05 at 5 24 47 pm

Message 2:

<message xmlns="jabber:client" id="9A120717-0D51-4BB3-BF33-7C738690A67A" to="[email protected]/iphone" type="groupchat" from="[email protected]/anish"><request xmlns="urn:xmpp:receipts"/><body>{
  "mediaItem" : "0",
  "body" : "A3"
}</body><thread>854CB335-35DA-43FB-9D63-B4015364CDF4</thread><delay xmlns="urn:xmpp:delay" stamp="2016-11-05T13:53:00.172Z" from="[email protected]/iphone"/></message>

I dig into XMPPMessageArchivingCoreDataStorage.m class. Here in "composingMessageWithJid:" method, there is a predicate

NSString *predicateFrmt = @"composing == YES AND bareJidStr == %@ AND outgoing == %@ AND streamBareJidStr == %@";
 
NSPredicate *predicate = [NSPredicate predicateWithFormat:predicateFrmt,
                                                            [messageJid bare], @(isOutgoing),
                                                            [streamJid bare]];

In the above predicate, the result will be always empty array. So every message which is received will be inserted into the database even if the entry is already there. Refer Fig 1 and Fig 2. How can i avoid duplicate entry.

blulion avatar Nov 05 '16 14:11 blulion

`

let entityDescription = NSEntityDescription.entity(forEntityName: "XMPPRoomMessageCoreDataStorageObject", in: moc)
    let request = NSFetchRequest<XMPPRoomMessageCoreDataStorageObject>()
    let predicate = NSPredicate(format: "roomJIDStr like %@", argumentArray: [roomJID])`
    `
    This seems to solve the issue by using `XMPPRoomMessageCoreDataStorageObject ` instead of `XMPPMessageArchivingCoreDataStorage

WUNIGLOBAL avatar Apr 11 '21 08:04 WUNIGLOBAL