public static void customerIsTyping(String chatID) { ChatSession chatSession = getChatSession(chatID); if (chatSession == null) { return; } final MultiUserChat chat = chatSession.getGroupChat(); final Iterator iter = chat.getOccupants(); while (iter.hasNext()) { String from = (String)iter.next(); String tFrom = StringUtils.parseResource(from); String nickname = chat.getNickname(); if (tFrom != null && !tFrom.equals(nickname)) { MessageEventManager messageEventManager = chatSession.getMessageEventManager(); messageEventManager.sendComposingNotification(from, "l0k1"); } } }
@Override public Message textMessage2XMPPMessage(TextMessage textMessage, String thread, String to, Message.Type messageType) throws Exception { Message message = new Message(to, messageType); message.setThread(thread); message.setPacketID(textMessage.getMessageId() + ""); MessageEventManager.addNotificationsRequests(message, true, true, true, true); String buddyKey = null; if (edProvider != null && (buddyKey = edProvider.getKeyStorage().get(textMessage.getContactUid())) != null){ EncryptedMessage ems = new EncryptedMessage(); ems.setAndEncrypt(textMessage.getText(), buddyKey); //TODO message.setBody("Encrypted message"); message.addExtension(ems); } else { message.setBody(textMessage.getText()); } return message; }
/** * Notifies all MessageEventHandlers that the customer is typing a message. */ public void customerIsTyping() { final MultiUserChat chat = chatSession.getGroupChat(); final Iterator iter = chat.getOccupants(); while (iter.hasNext()) { String from = (String) iter.next(); String tFrom = StringUtils.parseResource(from); String nickname = chat.getNickname(); if (tFrom != null && !tFrom.equals(nickname)) { MessageEventManager messageEventManager = chatSession.getMessageEventManager(); messageEventManager.sendComposingNotification(from, "l0k1"); } } }
/** * @param messageEventManager the messageEventManager to set */ public void setMessageEventManager(MessageEventManager messageEventManager) { this.messageEventManager = messageEventManager; if (messageEventManager == null){ return; } if (getInternalService().getOnlineInfo().getFeatures().getByte(ApiConstants.FEATURE_STATUS, (byte) 0) != XMPPEntityAdapter.INVISIBLE_STATUS_ID) { messageEventManager.addMessageEventRequestListener(messageEventListener); } messageEventManager.addMessageEventNotificationListener(this); }
public Message textMessage2XMPPMessage(TextMessage textMessage, String thread, String to, Message.Type messageType) throws Exception { Message message = new Message(to, messageType); message.setThread(thread); message.setPacketID(textMessage.getMessageId() + ""); MessageEventManager.addNotificationsRequests(message, true, true, true, true); message.setBody(textMessage.getText()); return message; }
private void send(Message message) { GroupChatRoom groupChatRoom = (GroupChatRoom)chatRoom; try { message.setTo(groupChatRoom.getRoomname()); message.setType(Message.Type.groupchat); MessageEventManager.addNotificationsRequests(message, true, true, true, true); groupChatRoom.getMultiUserChat().sendMessage(message); } catch (XMPPException ex) { Log.error("Unable to send message in conference chat.", ex); } }
/** * Joins the specified room and removes from queue. * * @param roomName the name of the room to join. */ public void joinRoom(String roomName) { // Set the last check now lastCheck = System.currentTimeMillis(); try { groupChat = new MultiUserChat(connection, roomName); if (name != null) { try { AndFilter presenceFilter = new AndFilter(new PacketTypeFilter(Presence.class), new FromContainsFilter(groupChat.getRoom())); connection.addPacketListener(this, presenceFilter); groupChat.join(name); } // Catch any join exceptions and attempt to join again // using an altered name (since exception is most likely // due to a conflict of names). catch (XMPPException xe) { String conflictName = name + " (Visitor)"; groupChat.join(conflictName); nickname = conflictName; } } else { nickname = "Visitor"; groupChat.join(nickname); } groupChat.addParticipantListener(new PacketListener() { public void processPacket(Packet packet) { final Presence p = (Presence)packet; final String from = p.getFrom(); String user = StringUtils.parseResource(from); if (p.getType() != Presence.Type.available) { lastAgent = user; } final Timer timer = new Timer(); timer.schedule(new TimerTask() { public void run() { checkForEmptyRoom(); } }, 5000); } }); messageEventManager = new MessageEventManager(connection); messageEventManager.addMessageEventNotificationListener(this); } catch (Exception e) { WebLog.logError("Error joining room:", e); } this.roomName = roomName; listenForMessages(connection, groupChat); }
private void sendMessageTo(Bundle bundle) { if (!connection.isConnected()) { addPendingAction(ACTION_SEND_MSG, bundle); } else { String to = bundle.getString("to"); String message = bundle.getString("message"); to = "-" + to + "@chat.facebook.com"; Log.d(TAG, "sendMessage to " + to + " " + message); Chat toChat = null; for (Chat chat : chats) { if (chat.getParticipant().equals(to)) { toChat = chat; } } if (toChat == null) { toChat = createChat(to); } org.jivesoftware.smack.packet.Message msg = new org.jivesoftware.smack.packet.Message(); msg.setBody(message); msg.setTo(to); msg.setType(org.jivesoftware.smack.packet.Message.Type.chat); msg.setThread(toChat.getThreadID()); // Add to the message all the notifications requests (offline, delivered, displayed, composing) MessageEventManager.addNotificationsRequests(msg, true, true, true, true); DeliveryReceiptManager.addDeliveryReceiptRequest(msg); try { toChat.sendMessage(msg); } catch (XMPPException e) { e.printStackTrace(); } } }
/** * Gets the MessageEventManager. * * @return the MessageEventManager used in this ChatSession. */ public MessageEventManager getMessageEventManager() { return messageEventManager; }