Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#369 and #370: Add support for the clear chat room history event #411

Merged
merged 9 commits into from
Jan 7, 2025
Merged
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
3 changes: 3 additions & 0 deletions changelog.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,12 @@ <h1>
<p><b>2.7.0</b> -- To be determined</p>
<ul>
<li>Requires Openfire 5.0.0</li>
<li>Note: Chat rooms can, in certain circumstances, be destroyed, and then be recreated using the same name. For data recorded by previous versions of this plugin, the plugin will associate all room history with the latest 'reincarnation' of a room. Starting with this version, new data will be associated to the correct 'incarnation' of the room.</li>
<li>[<a href='https://github.com/igniterealtime/openfire-monitoring-plugin/issues/401'>Issue #401</a>] - Fixes: Update Jersey from 2.35 to 2.45</li>
<li>[<a href='https://github.com/igniterealtime/openfire-monitoring-plugin/issues/398'>Issue #398</a>] - Fixes: Missing translation for system property</li>
<li>[<a href='https://github.com/igniterealtime/openfire-monitoring-plugin/issues/392'>Issue #392</a>] - Fixes: Compatibility issue with Openfire 5.0.0</li>
<li>[<a href='https://github.com/igniterealtime/openfire-monitoring-plugin/issues/370'>Issue #370</a>] - Add option to delete history on room deletion</li>
<li>[<a href='https://github.com/igniterealtime/openfire-monitoring-plugin/issues/369'>Issue #369</a>] - Add option to clear history for a given MUC</li>
<li>[<a href='https://github.com/igniterealtime/openfire-monitoring-plugin/issues/363'>Issue #363</a>] - Fixes SQL Server error: An expression of non-boolean type specified in a context where a condition is expected, near 'RowNum'</li>
<li>[<a href='https://github.com/igniterealtime/openfire-monitoring-plugin/issues/357'>Issue #357</a>] - Fixes: Error on admin console after user session expired.</li>
<li>[<a href='https://github.com/igniterealtime/openfire-monitoring-plugin/issues/354'>Issue #354</a>] - Allow full-text search / indexing to be disabled</li>
Expand Down
6 changes: 3 additions & 3 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
<description>Monitors conversations and statistics of the server.</description>
<author>Ignite Realtime</author>
<version>${project.version}</version>
<date>2024-11-22</date>
<date>2025-01-03</date>
<minServerVersion>5.0.0</minServerVersion>
<databaseKey>monitoring</databaseKey>
<databaseVersion>8</databaseVersion>
<databaseVersion>9</databaseVersion>

<adminconsole>
<tab id="tab-server">
Expand All @@ -33,7 +33,7 @@
url="conversations.jsp"
description="${admin.item.active-conversations.description}"/>
</sidebar>

</tab>

</adminconsole>
</plugin>
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<artifactId>plugins</artifactId>
<groupId>org.igniterealtime.openfire</groupId>
<version>5.0.0-SNAPSHOT</version>
<version>5.0.0-alpha</version>
</parent>
<groupId>org.igniterealtime.openfire.plugins</groupId>
<artifactId>monitoring</artifactId>
Expand Down
4 changes: 3 additions & 1 deletion src/database/monitoring_db2.sql
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@

INSERT INTO ofVersion (name, version) VALUES ('monitoring', 8);
INSERT INTO ofVersion (name, version) VALUES ('monitoring', 9);

CREATE TABLE ofConversation (
conversationID INTEGER NOT NULL,
roomID INTEGER,
room VARCHAR(512),
isExternal INTEGER NOT NULL,
startDate BIGINT NOT NULL,
Expand All @@ -13,6 +14,7 @@ CREATE TABLE ofConversation (
CREATE INDEX ofConversation_ext_idx ON ofConversation (isExternal);
CREATE INDEX ofConversation_start_idx ON ofConversation (startDate);
CREATE INDEX ofConversation_last_idx ON ofConversation (lastActivity);
CREATE INDEX ofConversation_room_idx ON ofConversation (roomID);

CREATE TABLE ofConParticipant (
conversationID INTEGER NOT NULL,
Expand Down
4 changes: 3 additions & 1 deletion src/database/monitoring_hsqldb.sql
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@

INSERT INTO ofVersion (name, version) VALUES ('monitoring', 8);
INSERT INTO ofVersion (name, version) VALUES ('monitoring', 9);

CREATE TABLE ofConversation (
conversationID BIGINT NOT NULL,
roomID BIGINT NULL,
room VARCHAR(1024) NULL,
isExternal INT NOT NULL,
startDate BIGINT NOT NULL,
Expand All @@ -13,6 +14,7 @@ CREATE TABLE ofConversation (
CREATE INDEX ofConversation_ext_idx ON ofConversation (isExternal);
CREATE INDEX ofConversation_start_idx ON ofConversation (startDate);
CREATE INDEX ofConversation_last_idx ON ofConversation (lastActivity);
CREATE INDEX ofConversation_room_idx ON ofConversation (roomID);

CREATE TABLE ofConParticipant (
conversationID BIGINT NOT NULL,
Expand Down
6 changes: 4 additions & 2 deletions src/database/monitoring_mysql.sql
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@

INSERT INTO ofVersion (name, version) VALUES ('monitoring', 8);
INSERT INTO ofVersion (name, version) VALUES ('monitoring', 9);

CREATE TABLE ofConversation (
conversationID BIGINT NOT NULL,
roomID BIGINT NULL,
room VARCHAR(255) NULL,
isExternal TINYINT NOT NULL,
startDate BIGINT NOT NULL,
Expand All @@ -11,7 +12,8 @@ CREATE TABLE ofConversation (
PRIMARY KEY (conversationID),
INDEX ofConversation_ext_idx (isExternal),
INDEX ofConversation_start_idx (startDate),
INDEX ofConversation_last_idx (lastActivity)
INDEX ofConversation_last_idx (lastActivity),
INDEX ofConversation_room_idx (roomID)
);

CREATE TABLE ofConParticipant (
Expand Down
4 changes: 3 additions & 1 deletion src/database/monitoring_oracle.sql
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@

INSERT INTO ofVersion (name, version) VALUES ('monitoring', 8);
INSERT INTO ofVersion (name, version) VALUES ('monitoring', 9);

CREATE TABLE ofConversation (
conversationID INTEGER NOT NULL,
roomID INTEGER NULL,
room VARCHAR2(1024) NULL,
isExternal NUMBER(2) NOT NULL,
startDate INTEGER NOT NULL,
Expand All @@ -13,6 +14,7 @@ CREATE TABLE ofConversation (
CREATE INDEX ofConversation_ext_idx ON ofConversation (isExternal);
CREATE INDEX ofConversation_start_idx ON ofConversation (startDate);
CREATE INDEX ofConversation_last_idx ON ofConversation (lastActivity);
CREATE INDEX ofConversation_room_idx ON ofConversation (roomID);

CREATE TABLE ofConParticipant (
conversationID INTEGER NOT NULL,
Expand Down
4 changes: 3 additions & 1 deletion src/database/monitoring_postgresql.sql
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@

INSERT INTO ofVersion (name, version) VALUES ('monitoring', 8);
INSERT INTO ofVersion (name, version) VALUES ('monitoring', 9);

CREATE TABLE ofConversation (
conversationID INTEGER NOT NULL,
roomID INTEGER NULL,
room VARCHAR(1024) NULL,
isExternal SMALLINT NOT NULL,
startDate BIGINT NOT NULL,
Expand All @@ -13,6 +14,7 @@ CREATE TABLE ofConversation (
CREATE INDEX ofConversation_ext_idx ON ofConversation (isExternal);
CREATE INDEX ofConversation_start_idx ON ofConversation (startDate);
CREATE INDEX ofConversation_last_idx ON ofConversation (lastActivity);
CREATE INDEX ofConversation_room_idx ON ofConversation (roomID);

CREATE TABLE ofConParticipant (
conversationID INTEGER NOT NULL,
Expand Down
4 changes: 3 additions & 1 deletion src/database/monitoring_sqlserver.sql
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@

INSERT INTO ofVersion (name, version) VALUES ('monitoring', 8);
INSERT INTO ofVersion (name, version) VALUES ('monitoring', 9);

CREATE TABLE ofConversation (
conversationID BIGINT NOT NULL,
roomID BIGINT NULL,
room NVARCHAR(1024) NULL,
isExternal TINYINT NOT NULL,
startDate BIGINT NOT NULL,
Expand All @@ -13,6 +14,7 @@ CREATE TABLE ofConversation (
CREATE INDEX ofConversation_ext_idx ON ofConversation (isExternal);
CREATE INDEX ofConversation_start_idx ON ofConversation (startDate);
CREATE INDEX ofConversation_last_idx ON ofConversation (lastActivity);
CREATE INDEX ofConversation_room_idx ON ofConversation (roomID);

CREATE TABLE ofConParticipant (
conversationID BIGINT NOT NULL,
Expand Down
17 changes: 17 additions & 0 deletions src/database/upgrade/9/monitoring_db2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-- Add column that will contain the unique numeric ID of a room.
ALTER TABLE ofConversation ADD COLUMN roomID INTEGER NULL;

-- Populate the new column with the numeric ID of the room from the ofMucRoom table.
UPDATE ofConversation SET roomID = (
SELECT ofMucRoom.roomID FROM ofMucRoom
JOIN ofMucService ON ofMucRoom.serviceID = ofMucService.serviceID
CROSS JOIN ofProperty
WHERE ofProperty.name = 'xmpp.domain'
AND ofMucRoom.name || '@' || ofMucService.subdomain || '.' || ofProperty.propValue = ofConversation.room
)
WHERE room IS NOT NULL AND room <> '';

CREATE INDEX ofConversation_room_idx ON ofConversation (roomID);

-- Update database version
UPDATE ofVersion SET version = 9 WHERE name = 'monitoring';
17 changes: 17 additions & 0 deletions src/database/upgrade/9/monitoring_hsqldb.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-- Add column that will contain the unique numeric ID of a room.
ALTER TABLE ofConversation ADD COLUMN roomID BIGINT NULL;

-- Populate the new column with the numeric ID of the room from the ofMucRoom table.
UPDATE ofConversation SET roomID = (
SELECT ofMucRoom.roomID FROM ofMucRoom
JOIN ofMucService ON ofMucRoom.serviceID = ofMucService.serviceID
CROSS JOIN ofProperty
WHERE ofProperty.name = 'xmpp.domain'
AND ofMucRoom.name || '@' || ofMucService.subdomain || '.' || ofProperty.propValue = ofConversation.room
)
WHERE room IS NOT NULL AND room <> '';

CREATE INDEX ofConversation_room_idx ON ofConversation (roomID);

-- Update database version
UPDATE ofVersion SET version = 9 WHERE name = 'monitoring';
17 changes: 17 additions & 0 deletions src/database/upgrade/9/monitoring_mysql.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-- Add column that will contain the unique numeric ID of a room.
ALTER TABLE ofConversation ADD COLUMN roomID BIGINT NULL;

-- Populate the new column with the numeric ID of the room from the ofMucRoom table.
UPDATE ofConversation SET roomID = (
SELECT ofMucRoom.roomID FROM ofMucRoom
JOIN ofMucService ON ofMucRoom.serviceID = ofMucService.serviceID
CROSS JOIN ofProperty
WHERE ofProperty.name = 'xmpp.domain'
AND CONCAT(ofMucRoom.name, '@', ofMucService.subdomain, '.', ofProperty.propValue) = ofConversation.room
)
WHERE room IS NOT NULL AND room <> '';

ALTER TABLE ofConversation ADD INDEX ofConversation_room_idx (roomID);

-- Update database version
UPDATE ofVersion SET version = 9 WHERE name = 'monitoring';
17 changes: 17 additions & 0 deletions src/database/upgrade/9/monitoring_oracle.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-- Add column that will contain the unique numeric ID of a room.
ALTER TABLE ofConversation ADD roomID INTEGER NULL;

-- Populate the new column with the numeric ID of the room from the ofMucRoom table.
UPDATE ofConversation SET roomID = (
SELECT ofMucRoom.roomID FROM ofMucRoom
JOIN ofMucService ON ofMucRoom.serviceID = ofMucService.serviceID
CROSS JOIN ofProperty
WHERE ofProperty.name = 'xmpp.domain'
AND ofMucRoom.name || '@' || ofMucService.subdomain || '.' || ofProperty.propValue = ofConversation.room
)
WHERE room IS NOT NULL AND room <> '';

CREATE INDEX ofConversation_room_idx ON ofConversation (roomID);

-- Update database version
UPDATE ofVersion SET version = 9 WHERE name = 'monitoring';
17 changes: 17 additions & 0 deletions src/database/upgrade/9/monitoring_postgresql.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-- Add column that will contain the unique numeric ID of a room.
ALTER TABLE ofConversation ADD COLUMN roomID INTEGER NULL;

-- Populate the new column with the numeric ID of the room from the ofMucRoom table.
UPDATE ofConversation SET roomID = (
SELECT ofMucRoom.roomID FROM ofMucRoom
JOIN ofMucService ON ofMucRoom.serviceID = ofMucService.serviceID
CROSS JOIN ofProperty
WHERE ofProperty.name = 'xmpp.domain'
AND ofMucRoom.name || '@' || ofMucService.subdomain || '.' || ofProperty.propValue = ofConversation.room
)
WHERE room IS NOT NULL AND room <> '';

CREATE INDEX ofConversation_room_idx ON ofConversation (roomID);

-- Update database version
UPDATE ofVersion SET version = 9 WHERE name = 'monitoring';
17 changes: 17 additions & 0 deletions src/database/upgrade/9/monitoring_sqlserver.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-- Add column that will contain the unique numeric ID of a room.
ALTER TABLE ofConversation ADD roomID BIGINT NULL;

-- Populate the new column with the numeric ID of the room from the ofMucRoom table.
UPDATE ofConversation SET roomID = (
SELECT ofMucRoom.roomID FROM ofMucRoom
JOIN ofMucService ON ofMucRoom.serviceID = ofMucService.serviceID
CROSS JOIN ofProperty
WHERE ofProperty.name = 'xmpp.domain'
AND CONCAT(ofMucRoom.name, '@', ofMucService.subdomain, '.', ofProperty.propValue) = ofConversation.room
)
WHERE room IS NOT NULL AND room <> '';

CREATE INDEX ofConversation_room_idx ON ofConversation (roomID);

-- Update database version
UPDATE ofVersion SET version = 9 WHERE name = 'monitoring';
36 changes: 34 additions & 2 deletions src/java/com/reucon/openfire/plugin/archive/impl/MucIndexer.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2008 Jive Software, 2024 Ignite Realtime Foundation. All rights reserved.
* Copyright (C) 2008 Jive Software, 2024-2025 Ignite Realtime Foundation. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,6 +17,7 @@

import org.apache.lucene.document.*;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.Term;
import org.jivesoftware.database.DbConnectionManager;
import org.jivesoftware.openfire.archive.ConversationManager;
import org.jivesoftware.openfire.archive.MonitoringConstants;
Expand All @@ -36,6 +37,8 @@
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

/**
* Creates and maintains a Lucene index for messages exchanged in multi-user chat.
Expand All @@ -55,12 +58,27 @@ public class MucIndexer extends LuceneIndexer

private ConversationManager conversationManager;

/**
* A collection of rooms that are to be removed from the index during the next update or rebuild operation.
*/
private final Set<Long> roomsPendingDeletion = new HashSet<>();

public MucIndexer( final TaskEngine taskEngine, final ConversationManager conversationManager )
{
super(taskEngine, JiveGlobals.getHomePath().resolve(Path.of(MonitoringConstants.NAME, "mucsearch")), "MUCSEARCH", SCHEMA_VERSION);
this.conversationManager = conversationManager;
}

/**
* Schedules documents that relate to the provided room for deletion during the next update cycle.
*
* @param roomID Room for which documents are to be removed from the index.
*/
public void scheduleForDeletion(final Long roomID)
{
roomsPendingDeletion.add(roomID);
}

@Override
protected Instant doUpdateIndex( final IndexWriter writer, final Instant lastModified ) throws IOException
{
Expand Down Expand Up @@ -148,6 +166,11 @@ private Instant indexMUCMessages( IndexWriter writer, Instant since )
continue;
}

// Skip rooms that are going to be deleted anyway.
if (roomsPendingDeletion.contains(roomID)) {
continue;
}

// Index message.
final Document document = createDocument(roomID, messageID, sender, logTime, body );
writer.addDocument(document);
Expand All @@ -164,6 +187,15 @@ private Instant indexMUCMessages( IndexWriter writer, Instant since )
}
}
Log.debug( "... finished the entire result set. Processed {} messages in total.", progress );

if (!since.equals( Instant.EPOCH ) && !roomsPendingDeletion.isEmpty()) {
// In case this is an update instead of a rebuild, older documents may still refer to rooms that are deleted. Remove those.
Log.debug( "... removing documents for {} rooms that are pending deletion.", roomsPendingDeletion.size());
for (long roomID : roomsPendingDeletion) {
writer.deleteDocuments(new Term("roomID", Long.toString(roomID)));
}
}
roomsPendingDeletion.clear();
}
catch (SQLException sqle) {
Log.error("An exception occurred while trying to fetch all MUC messages from the database to rebuild the Lucene index.", sqle);
Expand All @@ -179,7 +211,7 @@ private Instant indexMUCMessages( IndexWriter writer, Instant since )
}

/**
* Creates a index document for one particular chat message.
* Creates an index document for one particular chat message.
*
* @param roomID ID of the MUC room in which the message was exchanged.
* @param messageID ID of the message that was exchanged.
Expand Down
Loading
Loading