Skip to content

Commit a2f6bb0

Browse files
committed
fixes #139: Fix MAM queries using before/after the result ID
The implementation looks for a stanza-id and falls back to a database ID. The XEP-0313 says a client shouldn't rely on the stanza-id as the UID of a message in the archive, but OF is trending towards making that reliable. In the meantime, the result ID is still the database ID. Without this change, searches for the database ID is searched as freetext within the stanza. As a short number in amongst many GUIDs, false positives are more likely than not. This change ensures that a search for a stanza-id is more likely to match exactly that, but it's not foolproof.
1 parent 250b6e9 commit a2f6bb0

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/java/com/reucon/openfire/plugin/archive/impl/MucMamPersistenceManager.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -288,10 +288,11 @@ static Long getMessageIdForStableId( final MUCRoom room, final String value )
288288
try
289289
{
290290
connection = DbConnectionManager.getConnection();
291-
pstmt = connection.prepareStatement( "SELECT messageId, stanza FROM ofMucConversationLog WHERE messageId IS NOT NULL AND roomID=? AND stanza LIKE ? AND stanza LIKE ?" );
291+
pstmt = connection.prepareStatement( "SELECT messageId, stanza FROM ofMucConversationLog WHERE messageId IS NOT NULL AND roomID=? AND (stanza LIKE ? OR stanza LIKE ?) AND stanza LIKE ?" );
292292
pstmt.setLong( 1, room.getID() );
293-
pstmt.setString( 2, "%"+value+"%" );
294-
pstmt.setString( 3, "%urn:xmpp:sid:%" ); // only match stanzas if some kind of XEP-0359 namespace is used.
293+
pstmt.setString( 2, "%id=\""+value+"\"%" );
294+
pstmt.setString( 3, "%id='"+value+"'%" );
295+
pstmt.setString( 4, "%urn:xmpp:sid:%" ); // only match stanzas if some kind of XEP-0359 namespace is used.
295296

296297
rs = pstmt.executeQuery();
297298
while ( rs.next() ) {

0 commit comments

Comments
 (0)