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

Moving shared MAM Query representation into abstract class #384

Merged
merged 1 commit into from
Nov 22, 2024
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
* Copyright (C) 2024 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.reucon.openfire.plugin.archive.impl;

import org.jivesoftware.openfire.muc.MUCRoom;
import org.xmpp.packet.JID;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Date;

/**
* Representation of a MAM query that is querying a multi-user chat-based archive.
*
* @author Guus der Kinderen, [email protected]
*/
public abstract class AbstractPaginatedMamMucQuery extends AbstractPaginatedMamQuery
{
/**
* The MUC room instance that owns the message archive.
*/
@Nonnull
protected final MUCRoom room;

/**
* To be able to return not only the public messages exchanged in the room, but also the private messages that are
* relevant for the user that performs this query, an additional JID is provided as the 'messageOwner' argument.
* This identifies the user for which to retrieve the (private) messages.
*/
@Nonnull
protected final JID messageOwner;

/**
* Creates a query for messages from a message archive.
* <p>
* To be able to return not only the public messages exchanged in the room, but also the private messages that are
* relevant for the user that performs this query, an additional JID is provided as the 'messageOwner' argument.
* This identifies the user for which to retrieve the (private) messages.
*
* @param startDate Start (inclusive) of period for which to return messages. EPOCH will be used if no value is provided.
* @param endDate End (inclusive) of period for which to return messages. 'now' will be used if no value is provided.
* @param room The multi-user chat room that is the message archive owner.
* @param messageOwner The entity for which to return messages (typically the JID of the entity making the request).
* @param with An optional conversation partner
*/
public AbstractPaginatedMamMucQuery(@Nullable final Date startDate, @Nullable final Date endDate, @Nonnull final MUCRoom room, @Nonnull final JID messageOwner, @Nullable final JID with)
{
super(startDate, endDate, room.getJID(), with);
this.messageOwner = messageOwner;
this.room = room;
}

/**
* Creates a query for messages from a message archive.
* <p>
* To be able to return not only the public messages exchanged in the room, but also the private messages that are
* relevant for the user that performs this query, an additional JID is provided as the 'messageOwner' argument.
* This identifies the user for which to retrieve the (private) messages.
*
* @param startDate Start (inclusive) of period for which to return messages. EPOCH will be used if no value is provided.
* @param endDate End (inclusive) of period for which to return messages. 'now' will be used if no value is provided.
* @param room The multi-user chat room that is the message archive owner.
* @param messageOwner The entity for which to return messages (typically the JID of the entity making the request).
* @param with An optional conversation partner
* @param query A search string to be used for text-based search.
*/
public AbstractPaginatedMamMucQuery(@Nullable final Date startDate, @Nullable final Date endDate, @Nonnull final MUCRoom room, @Nonnull final JID messageOwner, @Nullable final JID with, @Nonnull final String query)
{
super(startDate, endDate, room.getJID(), with, query);
this.messageOwner = messageOwner;
this.room = room;
}

@Nonnull
public MUCRoom getRoom()
{
return room;
}

@Nonnull
public JID getMessageOwner()
{
return messageOwner;
}

@Override
public String toString()
{
return "AbstractPaginatedMamMucQuery{" +
"messageOwner=" + messageOwner +
", startDate=" + startDate +
", endDate=" + endDate +
", archiveOwner=" + archiveOwner +
", with=" + with +
", query='" + query + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
/*
* Copyright (C) 2024 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.reucon.openfire.plugin.archive.impl;

import com.reucon.openfire.plugin.archive.model.ArchivedMessage;
import org.xmpp.packet.JID;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Date;
import java.util.List;

/**
* Representation of a MAM query.
*
* @author Guus der Kinderen, [email protected]
*/
public abstract class AbstractPaginatedMamQuery
{
/**
* Start (inclusive) of period for which to return messages.
*/
@Nonnull
protected final Date startDate;

/**
* End (inclusive) of period for which to return messages.
*/
@Nonnull
protected final Date endDate;

/**
* The message archive owner.
*/
@Nonnull
protected final JID archiveOwner;

/**
* An optional conversation partner.
*/
@Nullable
protected final JID with;

/**
* A search filter to be used for text-based search.
*/
@Nullable
protected final String query;

/**
* Creates a query for messages from a message archive.
*
* @param startDate Start (inclusive) of period for which to return messages. EPOCH will be used if no value is provided.
* @param endDate End (inclusive) of period for which to return messages. 'now' will be used if no value is provided.
* @param archiveOwner The message archive owner.
* @param with An optional conversation partner
*/
public AbstractPaginatedMamQuery(@Nullable final Date startDate, @Nullable final Date endDate, @Nonnull final JID archiveOwner, @Nullable final JID with)
{
this.startDate = startDate == null ? new Date( 0L ) : startDate ;
this.endDate = endDate == null ? new Date() : endDate;
this.archiveOwner = archiveOwner;
this.with = with;
this.query = null;
}

/**
* Creates a query for messages from a message archive.
*
* @param startDate Start (inclusive) of period for which to return messages. EPOCH will be used if no value is provided.
* @param endDate End (inclusive) of period for which to return messages. 'now' will be used if no value is provided.
* @param archiveOwner The message archive owner.
* @param with An optional conversation partner
* @param query A search string to be used for text-based search.
*/
public AbstractPaginatedMamQuery(@Nullable final Date startDate, @Nullable final Date endDate, @Nonnull final JID archiveOwner, @Nullable final JID with, @Nonnull final String query)
{
this.startDate = startDate == null ? new Date( 0L ) : startDate ;
this.endDate = endDate == null ? new Date() : endDate;
this.archiveOwner = archiveOwner;
this.with = with;
this.query = query;
}

/**
* Get a page of a potentially larger list of archived messages that are the result of this query.
*
* @param after an optional message identifier that acts as a starting point (exclusive) of the messages to be returned.
* @param before an optional message identifier that acts as an end point (exclusive) of the messages to be returned.
* @param maxResults The maximum number of archived messages to return
* @param isPagingBackwards true if the order of the messages is from new to old, otherwise false.
* @return A list of archived messages
* @throws DataRetrievalException On any problem that occurs while retrieving the page of archived messages.
*/
abstract protected List<ArchivedMessage> getPage(@Nullable final Long after, @Nullable final Long before, final int maxResults, final boolean isPagingBackwards) throws DataRetrievalException;

/**
* Returns the amount of messages that are in the entire, unlimited/unpaged, result set.
* <p>
* The returned number is allowed to be an approximation.
*
* @return A message count, or -1 if unavailable.
*/
abstract protected int getTotalCount();

@Nonnull
public Date getStartDate()
{
return startDate;
}

@Nonnull
public Date getEndDate()
{
return endDate;
}

@Nonnull
public JID getArchiveOwner()
{
return archiveOwner;
}

@Nullable
public JID getWith()
{
return with;
}

@Nullable
public String getQuery() {
return query;
}

@Override
public String toString()
{
return "AbstractPaginatedMamQuery{" +
"startDate=" + startDate +
", endDate=" + endDate +
", archiveOwner=" + archiveOwner +
", with=" + with +
", query='" + query + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public Collection<ArchivedMessage> findMessages(Date startDate, Date endDate, JI
}
} else {
Log.debug("Using Monitoring plugin tables");
final PaginatedMucMessageDatabaseQuery paginatedMessageDatabaseQuery = new PaginatedMucMessageDatabaseQuery(startDate, endDate, room.getJID(), messageOwner, with);
final PaginatedMucMessageDatabaseQuery paginatedMessageDatabaseQuery = new PaginatedMucMessageDatabaseQuery(startDate, endDate, room, messageOwner, with);
Log.debug("Request for message archive of room '{}' resulted in the following query data: {}", room.getJID(), paginatedMessageDatabaseQuery);
totalCount = paginatedMessageDatabaseQuery.getTotalCount();
if (totalCount == 0) {
Expand Down Expand Up @@ -174,7 +174,7 @@ public Collection<ArchivedMessage> findMessages(Date startDate, Date endDate, JI
final PaginatedMucMessageFromOpenfireDatabaseQuery paginatedMucMessageFromOpenfireDatabaseQuery = new PaginatedMucMessageFromOpenfireDatabaseQuery(startDate, endDate, room, with);
nextPage = paginatedMucMessageFromOpenfireDatabaseQuery.getPage(afterForNextPage, beforeForNextPage, 1, isPagingBackwards);
} else {
final PaginatedMucMessageDatabaseQuery paginatedMessageDatabaseQuery = new PaginatedMucMessageDatabaseQuery(startDate, endDate, room.getJID(), messageOwner, with);
final PaginatedMucMessageDatabaseQuery paginatedMessageDatabaseQuery = new PaginatedMucMessageDatabaseQuery(startDate, endDate, room, messageOwner, with);
nextPage = paginatedMessageDatabaseQuery.getPage(afterForNextPage, beforeForNextPage, 1, isPagingBackwards);
}
}
Expand Down
Loading
Loading