use of org.jivesoftware.spark.ui.ChatRoomNotFoundException in project Spark by igniterealtime.
the class BroadcastPlugin method userToUserBroadcast.
/**
* Handles Broadcasts made from a user to another user
*
* @param message
* the message
* @param type
* the message type
* @param from
* the sender
*/
private void userToUserBroadcast(Message message, Type type, String from) {
String jid = XmppStringUtils.parseBareJid(from);
String nickname = SparkManager.getUserManager().getUserNicknameFromJID(jid);
ChatManager chatManager = SparkManager.getChatManager();
ChatContainer container = chatManager.getChatContainer();
ChatRoomImpl chatRoom;
try {
chatRoom = (ChatRoomImpl) container.getChatRoom(jid);
} catch (ChatRoomNotFoundException e) {
chatRoom = new ChatRoomImpl(jid, nickname, nickname);
SparkManager.getChatManager().getChatContainer().addChatRoom(chatRoom);
}
Message m = new Message();
m.setBody(message.getBody());
m.setTo(message.getTo());
String broadcasttype = type == Message.Type.normal ? Res.getString("broadcast") : Res.getString("message.alert.notify");
// m.setFrom(name +" "+broadcasttype);
m.setFrom(nickname + " - " + broadcasttype);
chatRoom.getTranscriptWindow().insertMessage(m.getFrom(), message, ChatManager.FROM_COLOR);
chatRoom.addToTranscript(m, true);
chatRoom.increaseUnreadMessageCount();
broadcastRooms.add(chatRoom);
LocalPreferences pref = SettingsManager.getLocalPreferences();
if (pref.getShowToasterPopup()) {
SparkToaster toaster = new SparkToaster();
toaster.setDisplayTime(30000);
toaster.setBorder(BorderFactory.createBevelBorder(0));
toaster.setTitle(nickname + " - " + broadcasttype);
toaster.showToaster(message.getBody());
}
SparkManager.getChatManager().fireGlobalMessageReceievedListeners(chatRoom, message);
DelayInformation inf = message.getExtension("delay", "urn:xmpp:delay");
if (inf == null) {
SoundPreference soundPreference = (SoundPreference) SparkManager.getPreferenceManager().getPreference(new SoundPreference().getNamespace());
SoundPreferences preferences = soundPreference.getPreferences();
if (preferences.isPlayIncomingSound()) {
File incomingFile = new File(preferences.getIncomingSound());
SparkManager.getSoundManager().playClip(incomingFile);
}
}
chatRoom.addMessageListener(new MessageListener() {
boolean waiting = true;
public void messageReceived(ChatRoom room, Message message) {
removeAsBroadcast(room);
}
public void messageSent(ChatRoom room, Message message) {
removeAsBroadcast(room);
}
private void removeAsBroadcast(ChatRoom room) {
if (waiting) {
broadcastRooms.remove(room);
// Notify decorators
SparkManager.getChatManager().notifySparkTabHandlers(room);
waiting = false;
}
}
});
}
use of org.jivesoftware.spark.ui.ChatRoomNotFoundException in project Spark by igniterealtime.
the class InviteSwingWorker method finished.
@Override
public void finished() {
final String roomName = XmppStringUtils.parseBareJid(roomJID);
try {
final ChatRoom room = SparkManager.getChatManager().getChatContainer().getChatRoom(roomName);
final TranscriptWindow transcriptWindow = room.getTranscriptWindow();
for (final String jid : (Set<String>) getValue()) {
final String notification = Res.getString("message.waiting.for.user.to.join", jid);
transcriptWindow.insertNotificationMessage(notification, ChatManager.NOTIFICATION_COLOR);
}
} catch (ChatRoomNotFoundException e) {
Log.error("Unable to identify chat room tab by name: " + roomName);
}
}
use of org.jivesoftware.spark.ui.ChatRoomNotFoundException in project Spark by igniterealtime.
the class ConferenceUtils method createPrivateConference.
/**
* Creates a private conference.
*
* @param serviceName the service name to use for the private conference.
* @param message the message sent to each individual invitee.
* @param roomName the name of the room to create.
* @param jids a collection of the user JIDs to invite.
* @throws SmackException thrown if an error occurs during room creation.
*/
public static void createPrivateConference(String serviceName, String message, String roomName, Collection<String> jids) throws SmackException {
final String roomJID = XmppStringUtils.escapeLocalpart(roomName) + "@" + serviceName;
final MultiUserChat multiUserChat = MultiUserChatManager.getInstanceFor(SparkManager.getConnection()).getMultiUserChat(roomJID);
final LocalPreferences pref = SettingsManager.getLocalPreferences();
final GroupChatRoom room = UIComponentRegistry.createGroupChatRoom(multiUserChat);
try {
// Attempt to create room.
multiUserChat.create(pref.getNickname());
} catch (XMPPException | SmackException e) {
throw new SmackException(e);
}
try {
// Since this is a private room, make the room not public and set user as owner of the room.
Form submitForm = multiUserChat.getConfigurationForm().createAnswerForm();
submitForm.setAnswer("muc#roomconfig_publicroom", false);
submitForm.setAnswer("muc#roomconfig_roomname", roomName);
final List<String> owners = new ArrayList<>();
owners.add(SparkManager.getSessionManager().getBareAddress());
submitForm.setAnswer("muc#roomconfig_roomowners", owners);
multiUserChat.sendConfigurationForm(submitForm);
} catch (XMPPException | SmackException e1) {
Log.error("Unable to send conference room chat configuration form.", e1);
}
ChatManager chatManager = SparkManager.getChatManager();
// Check if room already is open
try {
chatManager.getChatContainer().getChatRoom(room.getRoomname());
} catch (ChatRoomNotFoundException e) {
chatManager.getChatContainer().addChatRoom(room);
chatManager.getChatContainer().activateChatRoom(room);
}
for (String jid : jids) {
multiUserChat.invite(jid, message);
room.getTranscriptWindow().insertNotificationMessage(Res.getString("message.waiting.for.user.to.join", jid), ChatManager.NOTIFICATION_COLOR);
}
}
use of org.jivesoftware.spark.ui.ChatRoomNotFoundException in project Spark by igniterealtime.
the class OnlineAgents method activateChat.
/**
* Activate a chat room with the selected user.
*/
private void activateChat(final String userJID, final String nickname) {
if (!ModelUtil.hasLength(userJID)) {
return;
}
SwingWorker worker = new SwingWorker() {
final ChatManager chatManager = SparkManager.getChatManager();
ChatRoom chatRoom;
public Object construct() {
try {
Thread.sleep(50);
} catch (InterruptedException e) {
Log.error("Error in activate chat.", e);
}
ChatContainer chatRooms = chatManager.getChatContainer();
try {
chatRoom = chatRooms.getChatRoom(userJID);
} catch (ChatRoomNotFoundException e) {
Log.warning("Room not found for jid: " + userJID, e);
}
return chatRoom;
}
public void finished() {
if (chatRoom == null) {
chatRoom = new ChatRoomImpl(userJID, nickname, nickname);
chatManager.getChatContainer().addChatRoom(chatRoom);
}
chatManager.getChatContainer().activateChatRoom(chatRoom);
}
};
worker.start();
}
use of org.jivesoftware.spark.ui.ChatRoomNotFoundException in project Spark by igniterealtime.
the class GroupChatParticipantList method startChat.
protected void startChat(ChatRoom groupChat, String groupJID) {
String userNickname = XmppStringUtils.parseResource(groupJID);
String roomTitle = userNickname + " - " + XmppStringUtils.parseLocalpart(groupChat.getRoomname());
String nicknameOfUser = XmppStringUtils.parseResource(groupJID);
String nickname = groupChat.getNickname();
if (nicknameOfUser.equals(nickname)) {
return;
}
ChatRoom chatRoom;
try {
chatRoom = chatManager.getChatContainer().getChatRoom(groupJID);
} catch (ChatRoomNotFoundException e) {
Log.debug("Could not find chat room - " + groupJID);
// Create new room
chatRoom = new ChatRoomImpl(groupJID, nicknameOfUser, roomTitle);
chatManager.getChatContainer().addChatRoom(chatRoom);
}
chatManager.getChatContainer().activateChatRoom(chatRoom);
}
Aggregations