Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ <h1>
<ul>
<li>[<a href="https://github.com/igniterealtime/openfire-restAPI-plugin/issues/213">#213</a>] - Improve setting a subject in a chat room</li>
<li>[<a href="https://github.com/igniterealtime/openfire-restAPI-plugin/issues/217">#217</a>] - Add Hurl e2e tests, and CI to run them</li>
<li>Ensure cross-database compatibility for unread message count query</li>
</ul>

<p><b>1.12.0</b> July 4, 2025</p>
Expand Down
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<description>Allows administration over a RESTful API.</description>
<author>Roman Soldatow</author>
<version>${project.version}</version>
<date>2025-10-02</date>
<date>2025-10-09</date>
<minServerVersion>5.0.0</minServerVersion>
<adminconsole>
<tab id="tab-server">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.sql.SQLException;

import org.jivesoftware.database.DbConnectionManager;
import org.jivesoftware.database.DbConnectionManager.DatabaseType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xmpp.packet.JID;
Expand All @@ -36,12 +37,29 @@ public class MsgArchiveController {

/** The Constant INSTANCE. */
public static final MsgArchiveController INSTANCE = new MsgArchiveController();
/**
* Builds the SQL query for counting unread messages based on the underlying database type.
*
* @param databaseType the database connection used to detect the database product name
* @return the database-specific SQL query string for counting unread messages
*/
private String buildUserMessageCountQuery(DatabaseType databaseType) {
String castExpr;
switch (databaseType) {
case mysql:
castExpr = "CAST(p.offlineDate AS SIGNED)"; break;
case oracle:
castExpr = "CAST(p.offlineDate AS NUMBER)"; break;
default:
// PostgreSQL, SQL Server, Sybase — all understand BIGINT in CAST
castExpr = "CAST(p.offlineDate AS BIGINT)";
break;
}

/** The Constant USER_MESSAGE_COUNT. */
private static final String USER_MESSAGE_COUNT = "select COUNT(1) from ofMessageArchive a " +
"join ofPresence p on (a.sentDate > p.offlineDate) " +
return "SELECT COUNT(1) FROM ofMessageArchive a " +
"JOIN ofPresence p ON (a.sentDate > " + castExpr + ") " +
"WHERE a.toJID = ? AND p.username = ?";

}
/**
* Gets the single instance of MsgArchiveController.
*
Expand Down Expand Up @@ -70,7 +88,9 @@ public int getUnReadMessagesCount(JID jid) {
ResultSet rs = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(USER_MESSAGE_COUNT);
DatabaseType databaseType = DbConnectionManager.getDatabaseType();
String userMessageCountQuery = buildUserMessageCountQuery(databaseType);
pstmt = con.prepareStatement(userMessageCountQuery);
pstmt.setString(1, jid.toBareJID());
pstmt.setString(2, jid.getNode());
rs = pstmt.executeQuery();
Expand Down
Loading