use of org.jivesoftware.smackx.muc.MultiUserChatManager in project Spark by igniterealtime.
the class CurrentActivity method checkPopup.
private void checkPopup(MouseEvent e) {
if (e.isPopupTrigger()) {
// Check if monitor
try {
boolean isMonitor = FastpathPlugin.getAgentSession().hasMonitorPrivileges(SparkManager.getConnection());
if (isMonitor) {
JPopupMenu menu = new JPopupMenu();
int location = list.locationToIndex(e.getPoint());
list.setSelectedIndex(location);
ConversationItem item = (ConversationItem) list.getSelectedValue();
final String sessionID = item.getSessionID();
Action joinAction = new AbstractAction() {
private static final long serialVersionUID = -3198414924157880065L;
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;
final 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 = 7292337790553806820L;
public void actionPerformed(ActionEvent actionEvent) {
// Make user an owner.
try {
FastpathPlugin.getAgentSession().makeRoomOwner(SparkManager.getConnection(), sessionID);
MultiUserChatManager manager = MultiUserChatManager.getInstanceFor(SparkManager.getConnection());
Collection<String> col = manager.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 = manager.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