use of org.jivesoftware.smackx.muc.MultiUserChatManager in project Spark by igniterealtime.
the class ConferenceServices method invitationReceived.
@Override
public void invitationReceived(final XMPPConnection conn, final MultiUserChat room, final String inviter, final String reason, final String password, final Message message) {
SwingUtilities.invokeLater(() -> {
Collection<RoomInvitationListener> listeners = new ArrayList<>(SparkManager.getChatManager().getInvitationListeners());
for (RoomInvitationListener listener : listeners) {
boolean handle = listener.handleInvitation(conn, room, inviter, reason, password, message);
if (handle) {
return;
}
}
// room.
try {
SparkManager.getChatManager().getChatContainer().getChatRoom(room.getRoom());
return;
} catch (ChatRoomNotFoundException e) {
// Ignore :)
}
final GroupChatInvitationUI invitationUI = new GroupChatInvitationUI(room.getRoom(), inviter, password, reason);
String message1 = Res.getString("message.invite.to.groupchat", inviter);
String title = Res.getString("title.group.chat");
String bareJID = XmppStringUtils.parseBareJid(inviter);
if (_localPreferences.isAutoAcceptMucInvite()) {
ConferenceUtils.enterRoomOnSameThread(XmppStringUtils.parseLocalpart(room.getRoom()), room.getRoom(), password);
MultiUserChatManager manager = MultiUserChatManager.getInstanceFor(SparkManager.getConnection());
GroupChatRoom chat = UIComponentRegistry.createGroupChatRoom(manager.getMultiUserChat(room.getRoom()));
showToaster(message1, title, chat);
return;
// Nothing to do here, we want to join the
// room, and stuff
}
try {
ChatRoom chatRoom = SparkManager.getChatManager().getChatContainer().getChatRoom(bareJID);
// If the ChatRoom exists, add an invitationUI.
chatRoom.getTranscriptWindow().addComponent(invitationUI);
// Notify user of incoming invitation.
chatRoom.increaseUnreadMessageCount();
chatRoom.scrollToBottom();
SparkManager.getChatManager().getChatContainer().fireNotifyOnMessage(chatRoom, true, message1, title);
} catch (ChatRoomNotFoundException e) {
// If it doesn't exists. Create a new Group
// Chat Room
// Create the Group Chat Room
final MultiUserChatManager manager = MultiUserChatManager.getInstanceFor(SparkManager.getConnection());
final GroupChatRoom groupChatRoom = UIComponentRegistry.createGroupChatRoom(manager.getMultiUserChat(room.getRoom()));
showToaster(message1, title, groupChatRoom);
groupChatRoom.getSplitPane().setDividerSize(5);
groupChatRoom.getVerticalSlipPane().setDividerLocation(0.6);
groupChatRoom.getSplitPane().setDividerLocation(0.6);
String roomName = XmppStringUtils.parseLocalpart(room.getRoom());
groupChatRoom.setTabTitle(roomName);
groupChatRoom.getToolBar().setVisible(true);
SparkManager.getChatManager().getChatContainer().addChatRoom(groupChatRoom);
groupChatRoom.getTranscriptWindow().addComponent(invitationUI);
// Notify user of incoming invitation.
groupChatRoom.increaseUnreadMessageCount();
groupChatRoom.scrollToBottom();
SparkManager.getChatManager().getChatContainer().fireNotifyOnMessage(groupChatRoom, true, message1, title);
}
// If no listeners handled the invitation,
// default to generic invite.
// new ConversationInvitation(conn, room,
// inviter, reason, password, message);
});
}
use of org.jivesoftware.smackx.muc.MultiUserChatManager in project Spark by igniterealtime.
the class ChatManager method getDefaultConferenceService.
/**
* Returns the default conference service. (ex. conference.jivesoftware.com)
*
* @return the default conference service to interact with MUC.
*/
public String getDefaultConferenceService() {
if (conferenceService == null) {
try {
final MultiUserChatManager multiUserChatManager = MultiUserChatManager.getInstanceFor(SparkManager.getConnection());
Collection<String> col = multiUserChatManager.getServiceNames();
if (col.size() > 0) {
conferenceService = col.iterator().next();
}
} catch (XMPPException | SmackException e) {
Log.error(e);
}
}
return conferenceService;
}
use of org.jivesoftware.smackx.muc.MultiUserChatManager in project Smack by igniterealtime.
the class OmemoService method getMuc.
/**
* Return the joined MUC with EntityBareJid jid, or null if its not a room and/or not joined.
*
* @param connection xmpp connection
* @param jid jid (presumably) of the MUC
* @return MultiUserChat or null if not a MUC.
*/
private static MultiUserChat getMuc(XMPPConnection connection, Jid jid) {
EntityBareJid ebj = jid.asEntityBareJidIfPossible();
if (ebj == null) {
return null;
}
MultiUserChatManager mucm = MultiUserChatManager.getInstanceFor(connection);
Set<EntityBareJid> joinedRooms = mucm.getJoinedRooms();
if (joinedRooms.contains(ebj)) {
return mucm.getMultiUserChat(ebj);
}
return null;
}
use of org.jivesoftware.smackx.muc.MultiUserChatManager in project Payara by payara.
the class XmppNotificationRunnable method run.
@Override
public void run() {
while (queue.size() > 0) {
try {
XmppMessage xmppMessage = queue.getMessage();
MultiUserChatManager manager = MultiUserChatManager.getInstanceFor(connection);
MultiUserChat multiUserChat = manager.getMultiUserChat(executionOptions.getRoomId() + "@" + executionOptions.getServiceName());
if (multiUserChat != null) {
if (!multiUserChat.isJoined()) {
multiUserChat.join(executionOptions.getUsername(), executionOptions.getPassword());
}
Message message = new Message();
message.setSubject(xmppMessage.getSubject());
message.setBody(xmppMessage.getMessage());
multiUserChat.sendMessage(message);
}
logger.log(Level.FINE, "Message sent successfully");
} catch (XMPPException | SmackException e) {
logger.log(Level.SEVERE, "Error occurred while sending message to room", e);
}
}
}
use of org.jivesoftware.smackx.muc.MultiUserChatManager in project Spark by igniterealtime.
the class AgentConversations method checkPopup.
private void checkPopup(MouseEvent e) {
if (e.isPopupTrigger()) {
// Check if monitor
try {
AgentConversation item = (AgentConversation) list.getSelectedValue();
boolean isMonitor = FastpathPlugin.getAgentSession().hasMonitorPrivileges(SparkManager.getConnection());
if (isMonitor) {
JPopupMenu menu = new JPopupMenu();
final String sessionID = item.getSessionID();
Action joinAction = new AbstractAction() {
private static final long serialVersionUID = 8239167390330425891L;
public void actionPerformed(ActionEvent actionEvent) {
// Get Conference
try {
final MultiUserChatManager multiUserChatManager = MultiUserChatManager.getInstanceFor(SparkManager.getConnection());
Collection col = multiUserChatManager.getServiceNames();
if (col.size() == 0) {
return;
}
String serviceName = (String) col.iterator().next();
String roomName = sessionID + "@" + serviceName;
LocalPreferences pref = SettingsManager.getLocalPreferences();
final String nickname = pref.getNickname();
MultiUserChat muc = multiUserChatManager.getMultiUserChat(roomName);
ConferenceUtils.enterRoom(muc, roomName, nickname, null);
if (muc.isJoined()) {
// Try and remove myself as an owner if I am one.
Collection owners = null;
try {
owners = muc.getOwners();
} catch (XMPPException | SmackException e1) {
return;
}
Iterator iter = owners.iterator();
List<String> list = new ArrayList<String>();
while (iter.hasNext()) {
Affiliate affilitate = (Affiliate) iter.next();
String jid = affilitate.getJid();
if (!jid.equals(SparkManager.getSessionManager().getBareAddress())) {
list.add(jid);
}
}
if (list.size() > 0) {
Form form = muc.getConfigurationForm().createAnswerForm();
form.setAnswer("muc#roomconfig_roomowners", list);
// new DataFormDialog(groupChat, form);
muc.sendConfigurationForm(form);
}
}
} catch (Exception e1) {
Log.error(e1);
}
}
};
joinAction.putValue(Action.NAME, FpRes.getString("menuitem.join.chat"));
menu.add(joinAction);
Action monitorAction = new AbstractAction() {
private static final long serialVersionUID = -2072254190661466657L;
public void actionPerformed(ActionEvent actionEvent) {
// Make user an owner.
try {
FastpathPlugin.getAgentSession().makeRoomOwner(SparkManager.getConnection(), sessionID);
final MultiUserChatManager multiUserChatManager = MultiUserChatManager.getInstanceFor(SparkManager.getConnection());
Collection<String> col = multiUserChatManager.getServiceNames();
if (col.size() == 0) {
return;
}
String serviceName = (String) col.iterator().next();
String roomName = sessionID + "@" + serviceName;
LocalPreferences pref = SettingsManager.getLocalPreferences();
final String nickname = pref.getNickname();
MultiUserChat muc = multiUserChatManager.getMultiUserChat(roomName);
ConferenceUtils.enterRoom(muc, roomName, nickname, null);
} catch (XMPPException | SmackException e1) {
Log.error(e1);
}
}
};
monitorAction.putValue(Action.NAME, FpRes.getString("menuitem.monitor.chat"));
menu.add(monitorAction);
menu.show(list, e.getX(), e.getY());
}
} catch (XMPPException | SmackException e1) {
Log.error(e1);
return;
}
}
}
Aggregations