use of org.jivesoftware.openfire.muc.MultiUserChatManager in project Openfire by igniterealtime.
the class MucMamPersistenceManager method findMessages.
@Override
public Collection<ArchivedMessage> findMessages(Date startDate, Date endDate, String owner, String with, XmppResultSet xmppResultSet) {
JID mucRoom = new JID(owner);
MultiUserChatManager manager = XMPPServer.getInstance().getMultiUserChatManager();
MultiUserChatService service = manager.getMultiUserChatService(mucRoom);
MUCRoom room = service.getChatRoom(mucRoom.getNode());
Connection connection = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
// If logging isn't enabled, do nothing.
if (!room.isLogEnabled())
return null;
List<ArchivedMessage> msgs = new LinkedList<>();
if (startDate == null) {
startDate = new Date(0L);
}
if (endDate == null) {
endDate = new Date();
}
int max = xmppResultSet.getMax();
// TODO: Suppress this, since we don't yet have requestor information for access control.
with = null;
try {
connection = DbConnectionManager.getConnection();
StringBuilder sql = new StringBuilder(LOAD_HISTORY);
if (with != null) {
sql.append(WHERE_SENDER);
}
if (xmppResultSet.getAfter() != null) {
sql.append(WHERE_AFTER);
}
if (xmppResultSet.getBefore() != null) {
sql.append(WHERE_BEFORE);
}
sql.append(ORDER_BY);
pstmt = connection.prepareStatement(sql.toString());
pstmt.setString(1, StringUtils.dateToMillis(startDate));
pstmt.setString(2, StringUtils.dateToMillis(endDate));
pstmt.setLong(3, room.getID());
int pos = 3;
if (with != null) {
pstmt.setString(++pos, with);
}
if (xmppResultSet.getAfter() != null) {
pstmt.setLong(++pos, xmppResultSet.getAfter());
}
if (xmppResultSet.getBefore() != null) {
pstmt.setLong(++pos, xmppResultSet.getBefore());
}
rs = pstmt.executeQuery();
while (rs.next()) {
String senderJID = rs.getString(1);
String nickname = rs.getString(2);
Date sentDate = new Date(Long.parseLong(rs.getString(3).trim()));
String subject = rs.getString(4);
String body = rs.getString(5);
String stanza = rs.getString(6);
long id = rs.getLong(7);
if (stanza == null) {
Message message = new Message();
message.setType(Message.Type.groupchat);
message.setSubject(subject);
message.setBody(body);
// Set the sender of the message
if (nickname != null && nickname.trim().length() > 0) {
JID roomJID = room.getRole().getRoleAddress();
// Recreate the sender address based on the nickname and room's JID
message.setFrom(new JID(roomJID.getNode(), roomJID.getDomain(), nickname, true));
} else {
// Set the room as the sender of the message
message.setFrom(room.getRole().getRoleAddress());
}
stanza = message.toString();
}
ArchivedMessage archivedMessage = new ArchivedMessage(sentDate, ArchivedMessage.Direction.from, null, null);
archivedMessage.setStanza(stanza);
archivedMessage.setId(id);
msgs.add(archivedMessage);
}
} catch (SQLException e) {
Log.error("SQL failure during MAM-MUC: ", e);
} finally {
DbConnectionManager.closeConnection(rs, pstmt, connection);
}
// TODO - Not great, really should be done by suitable LIMIT stuff.
// Would need to reverse ordering in some cases and then reverse results.
boolean complete = true;
xmppResultSet.setCount(msgs.size());
while (msgs.size() > max) {
msgs.remove(msgs.size() - 1);
complete = false;
}
xmppResultSet.setComplete(complete);
if (msgs.size() > 0) {
xmppResultSet.setFirst(msgs.get(0).getId());
if (msgs.size() > 1) {
xmppResultSet.setLast(msgs.get(msgs.size() - 1).getId());
}
}
return msgs;
}
use of org.jivesoftware.openfire.muc.MultiUserChatManager in project Openfire by igniterealtime.
the class AbstractXepSupport method start.
public void start() {
for (IQHandler iqHandler : iqHandlers) {
try {
iqHandler.initialize(server);
iqHandler.start();
} catch (Exception e) {
Log.error("Unable to initialize and start " + iqHandler.getClass());
continue;
}
element2Handlers.put(iqHandler.getInfo().getName(), iqHandler);
if (iqHandler instanceof ServerFeaturesProvider) {
for (Iterator<String> i = ((ServerFeaturesProvider) iqHandler).getFeatures(); i.hasNext(); ) {
server.getIQDiscoInfoHandler().addServerFeature(i.next());
}
}
if (muc) {
MultiUserChatManager manager = server.getMultiUserChatManager();
for (MultiUserChatService mucService : manager.getMultiUserChatServices()) {
mucService.addIQHandler(iqHandler);
mucService.addExtraFeature(namespace);
}
}
}
server.getIQDiscoInfoHandler().addServerFeature(namespace);
server.getIQRouter().addHandler(iqDispatcher);
}
use of org.jivesoftware.openfire.muc.MultiUserChatManager in project Openfire by igniterealtime.
the class AbstractXepSupport method stop.
public void stop() {
IQRouter iqRouter = server.getIQRouter();
IQDiscoInfoHandler iqDiscoInfoHandler = server.getIQDiscoInfoHandler();
for (IQHandler iqHandler : iqHandlers) {
element2Handlers.remove(iqHandler.getInfo().getName());
try {
iqHandler.stop();
iqHandler.destroy();
} catch (Exception e) {
Log.warn("Unable to stop and destroy " + iqHandler.getClass());
}
if (iqHandler instanceof ServerFeaturesProvider) {
for (Iterator<String> i = ((ServerFeaturesProvider) iqHandler).getFeatures(); i.hasNext(); ) {
if (iqDiscoInfoHandler != null) {
iqDiscoInfoHandler.removeServerFeature(i.next());
}
}
}
if (muc) {
MultiUserChatManager manager = server.getMultiUserChatManager();
for (MultiUserChatService mucService : manager.getMultiUserChatServices()) {
mucService.removeIQHandler(iqHandler);
mucService.removeExtraFeature(namespace);
}
}
}
if (iqRouter != null) {
iqRouter.removeHandler(iqDispatcher);
}
}
Aggregations