Monitoring Plugin (MAM) — doubled/quadrupled messages after relogin

This issue occurs only in Gajim when used with Openfire’s MAM (Message Archive Management) plugin. Other XMPP clients like Spark or Pade do not have this problem.

The key problem is that Gajim and Openfire MAM handle message identification differently, which leads to duplicate or even triplicate messages when retrieving archived conversations.

Why Does This Happen?

To understand the root cause, it’s important to know how XMPP messages are stored and retrieved:
1. How Gajim Sends Messages:
• When Gajim sends a message, it assigns a unique stanza ID (an identifier for each message).
• This stanza ID is generated by Gajim itself and stored in its local database.
2. How Openfire MAM Stores Messages:
• When Openfire’s MAM plugin is enabled, it archives messages server-side.
• However, Openfire generates its own stanza ID when storing these messages in MAM.
• This means Openfire’s archived message has a different stanza ID than what Gajim originally assigned.
3. How Gajim Retrieves Messages from MAM:
• When Gajim reconnects or re-syncs, it fetches archived messages from Openfire’s MAM.
• Since Openfire’s MAM returns messages with different stanza IDs, Gajim treats them as new messages instead of recognizing them as duplicates.
• As a result, you see the same message multiple times—once from Gajim’s local database and once (or more) from Openfire’s MAM archive.

How I Identified the Problem
1. I downloaded Gajim’s source code and examined all Python scripts related to:
• How messages are stored.
• How messages are retrieved.
• How Gajim interacts with the MAM plugin in Openfire.
2. I found that Gajim’s local message storage and Openfire’s MAM storage were using different stanza IDs.
3. I verified this by disabling the MAM plugin in Openfire, and the issue disappeared. This confirmed that the stanza ID mismatch was the root cause.

How I Fixed It

Since I am not a programmer, I used ChatGPT to help analyze and modify the relevant Python scripts in Gajim.
• The fix involved modifying Gajim’s message retrieval system so that it properly handles the stanza IDs assigned by Openfire’s MAM.
• After applying these changes, I recompiled Gajim and tested it.
• With this modified version, Gajim now correctly recognizes archived messages from Openfire, preventing duplicates.

Final Notes
• I do not update Gajim in my company because newer versions still have this problem.
• If anyone needs the modified Gajim executable for Windows, I can provide it.
• This issue likely needs to be addressed by Gajim’s developers for a proper long-term fix.

Edited by GPT.

2 Likes