use of org.jivesoftware.spark.ui.ChatRoomNotFoundException in project Spark by igniterealtime.
the class BroadcastPlugin method broadcastInChat.
/**
* Displays the Serverbroadcast like all other messages
* in its on chatcontainer with transcript history
* @param message
* @param from
*/
private void broadcastInChat(Message message) {
String from = message.getFrom() != null ? message.getFrom() : "";
ChatManager chatManager = SparkManager.getChatManager();
ChatContainer container = chatManager.getChatContainer();
ChatRoomImpl chatRoom;
try {
chatRoom = (ChatRoomImpl) container.getChatRoom(from);
} catch (ChatRoomNotFoundException e) {
String windowtitle = message.getSubject() != null ? message.getSubject() : Res.getString("administrator");
chatRoom = new ChatRoomImpl("serveralert@" + from, Res.getString("broadcast"), windowtitle);
chatRoom.getBottomPanel().setVisible(false);
chatRoom.hideToolbar();
SparkManager.getChatManager().getChatContainer().addChatRoom(chatRoom);
}
chatRoom.getTranscriptWindow().insertNotificationMessage(message.getBody(), ChatManager.NOTIFICATION_COLOR);
broadcastRooms.add(chatRoom);
}
use of org.jivesoftware.spark.ui.ChatRoomNotFoundException in project Spark by igniterealtime.
the class BuzzPlugin method shakeWindow.
private void shakeWindow(Message message) {
String bareJID = XmppStringUtils.parseBareJid(message.getFrom());
ContactItem contact = SparkManager.getWorkspace().getContactList().getContactItemByJID(bareJID);
String nickname = XmppStringUtils.parseLocalpart(bareJID);
if (contact != null) {
nickname = contact.getDisplayName();
}
ChatRoom room;
try {
room = SparkManager.getChatManager().getChatContainer().getChatRoom(bareJID);
} catch (ChatRoomNotFoundException e) {
// Create the room if it does not exist.
room = SparkManager.getChatManager().createChatRoom(bareJID, nickname, nickname);
}
ChatFrame chatFrame = SparkManager.getChatManager().getChatContainer().getChatFrame();
if (chatFrame != null) {
if (SettingsManager.getLocalPreferences().isBuzzEnabled()) {
chatFrame.buzz();
SparkManager.getChatManager().getChatContainer().activateChatRoom(room);
}
}
// Insert offline message
room.getTranscriptWindow().insertNotificationMessage(Res.getString("message.buzz.message", nickname), ChatManager.NOTIFICATION_COLOR);
room.scrollToBottom();
}
use of org.jivesoftware.spark.ui.ChatRoomNotFoundException in project Spark by igniterealtime.
the class RoarMessageListener method messageReceived.
@Override
public void messageReceived(ChatRoom room, Message message) {
try {
ChatRoom activeroom = SparkManager.getChatManager().getChatContainer().getActiveChatRoom();
int framestate = SparkManager.getChatManager().getChatContainer().getChatFrame().getState();
if (framestate == JFrame.NORMAL && activeroom.equals(room) && room.isShowing() && (isOldGroupChat(room) || isMessageFromRoom(room, message))) {
// Do Nothing
} else {
decideForRoomAndMessage(room, message);
}
} catch (ChatRoomNotFoundException e) {
// i dont care
}
}
use of org.jivesoftware.spark.ui.ChatRoomNotFoundException in project Spark by igniterealtime.
the class Workspace method handleIncomingPacket.
private void handleIncomingPacket(Stanza stanza) throws SmackException.NotConnectedException {
// We only handle message packets here.
if (stanza instanceof Message) {
final Message message = (Message) stanza;
boolean isGroupChat = message.getType() == Message.Type.groupchat;
// Check if Conference invite. If so, do not handle here.
if (message.getExtension("x", "jabber:x:conference") != null) {
return;
}
final String body = message.getBody();
final JivePropertiesExtension extension = ((JivePropertiesExtension) message.getExtension(JivePropertiesExtension.NAMESPACE));
final boolean broadcast = extension != null && extension.getProperty("broadcast") != null;
// Handle offline message.
DelayInformation offlineInformation = message.getExtension("delay", "urn:xmpp:delay");
if (offlineInformation != null && (Message.Type.chat == message.getType() || Message.Type.normal == message.getType())) {
handleOfflineMessage(message);
}
if (body == null || isGroupChat || broadcast || message.getType() == Message.Type.normal || message.getType() == Message.Type.headline || message.getType() == Message.Type.error) {
return;
}
// Create new chat room for Agent Invite.
final String from = stanza.getFrom();
final String host = SparkManager.getSessionManager().getServerAddress();
// Don't allow workgroup notifications to come through here.
final String bareJID = XmppStringUtils.parseBareJid(from);
if (host.equalsIgnoreCase(from) || from == null) {
return;
}
ChatRoom room = null;
try {
room = SparkManager.getChatManager().getChatContainer().getChatRoom(bareJID);
} catch (ChatRoomNotFoundException e) {
// Ignore
}
// Check for non-existent rooms.
if (room == null) {
createOneToOneRoom(bareJID, message);
}
}
}
use of org.jivesoftware.spark.ui.ChatRoomNotFoundException in project Spark by igniterealtime.
the class Workspace method createOneToOneRoom.
/**
* Creates a new room based on an anonymous user.
*
* @param bareJID the bareJID of the anonymous user.
* @param message the message from the anonymous user.
*/
private void createOneToOneRoom(String bareJID, Message message) {
ContactItem contact = contactList.getContactItemByJID(bareJID);
String nickname = XmppStringUtils.parseLocalpart(bareJID);
if (contact != null) {
nickname = contact.getDisplayName();
} else {
// Attempt to load VCard from users who we are not subscribed to.
VCard vCard = SparkManager.getVCardManager().getVCard(bareJID);
if (vCard != null && vCard.getError() == null) {
String firstName = vCard.getFirstName();
String lastName = vCard.getLastName();
String userNickname = vCard.getNickName();
if (ModelUtil.hasLength(userNickname)) {
nickname = userNickname;
} else if (ModelUtil.hasLength(firstName) && ModelUtil.hasLength(lastName)) {
nickname = firstName + " " + lastName;
} else if (ModelUtil.hasLength(firstName)) {
nickname = firstName;
}
}
}
SparkManager.getChatManager().createChatRoom(bareJID, nickname, nickname);
try {
insertMessage(bareJID, message);
} catch (ChatRoomNotFoundException e) {
Log.error("Could not find chat room.", e);
}
}
Aggregations