use of org.jivesoftware.openfire.muc.MultiUserChatService 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.MultiUserChatService in project Openfire by igniterealtime.
the class GetNewMemberRoomsRequest method run.
@Override
public void run() {
rooms = new ArrayList<>();
// Get all services that have local occupants and include them in the reply
for (MultiUserChatService mucService : XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatServices()) {
// Get rooms that have local occupants and include them in the reply
for (MUCRoom room : mucService.getChatRooms()) {
LocalMUCRoom localRoom = (LocalMUCRoom) room;
Collection<MUCRole> localOccupants = new ArrayList<>();
for (MUCRole occupant : room.getOccupants()) {
if (occupant.isLocal()) {
localOccupants.add(occupant);
}
}
if (!localOccupants.isEmpty()) {
rooms.add(new RoomInfo(localRoom, localOccupants));
}
}
}
}
use of org.jivesoftware.openfire.muc.MultiUserChatService in project Openfire by igniterealtime.
the class MUCRoomTask method getRoom.
public LocalMUCRoom getRoom() {
MultiUserChatService mucService = XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService(subdomain);
if (mucService == null) {
throw new IllegalArgumentException("MUC service not found for subdomain: " + subdomain);
}
LocalMUCRoom room = (LocalMUCRoom) mucService.getChatRoom(roomName);
if (room == null) {
throw new IllegalArgumentException("Room not found: " + roomName);
}
return room;
}
use of org.jivesoftware.openfire.muc.MultiUserChatService in project Openfire by igniterealtime.
the class RoomRemovedEvent method run.
@Override
public void run() {
MultiUserChatService mucService = room.getMUCService();
mucService.chatRoomRemoved(room);
}
use of org.jivesoftware.openfire.muc.MultiUserChatService in project Openfire by igniterealtime.
the class OccupantUpdatedTask method run.
@Override
public void run() {
final MultiUserChatService multiUserChatService = XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService(subdomain);
((MultiUserChatServiceImpl) multiUserChatService).getOccupantManager().process(this);
}
Aggregations