public void updateTypingStatus(final ChatState chatState, final String jid, final int chatType) { if (!Preferences.isTesting()) { new Thread(new Runnable() { @Override public void run() { try { Message message = new Message(JidCreate.from(jid)); message.addExtension(new ChatStateExtension(chatState)); if (chatType == Chat.TYPE_1_T0_1) { message.setType(Message.Type.chat); } else { message.setType(Message.Type.groupchat); } sendMessageDependingOnType(message, jid, chatType); } catch (Exception e) { e.printStackTrace(); } } }).start(); } }
@Override public void processStanza(Stanza p) { // NOTE: the packet is not the acknowledgement itself but the packet // that is acknowledged if (!(p instanceof Message)) { // we are only interested in acks for messages return; } Message m = (Message) p; LOGGER.config("for message: "+m); if (DeliveryReceipt.from(m) != null) { // this is an ack for a 'received' message (XEP-0184) send by // KonMessageListener, ignore return; } if (m.getBody() == null && m.getExtensions().size() == 1 && m.getExtension(ChatStateExtension.NAMESPACE) != null) { // this is an ack for a chat state notification (XEP-0085), ignore return; } mControl.onMessageSent(MessageIDs.to(m)); }
/** * Sets the current state of the provided chat. This method will send an empty bodied Message * stanza(/packet) with the state attached as a {@link org.jivesoftware.smack.packet.ExtensionElement}, if * and only if the new chat state is different than the last state. * * @param newState the new state of the chat * @param chat the chat. * @throws NotConnectedException */ public void setCurrentState(ChatState newState, Chat chat) throws NotConnectedException { if(chat == null || newState == null) { throw new IllegalArgumentException("Arguments cannot be null."); } if(!updateChatState(chat, newState)) { return; } Message message = new Message(); ChatStateExtension extension = new ChatStateExtension(newState); message.addExtension(extension); chat.sendMessage(message); }
@Override public void processMessage(Message message) { Chat chat = chatManager.getThreadChat(message.getThread()); if (chat == null) { return; } if (updateChatState(chat, ChatState.active)) { message.addExtension(new ChatStateExtension(ChatState.active)); } }
public void sendChatState(JID jid, String threadID, ChatState state) { Message message = new Message(jid.toBareSmack(), Message.Type.chat); if (!threadID.isEmpty()) message.setThread(threadID); message.addExtension(new ChatStateExtension(state)); this.sendPacket(message); }
private void processChatMessage(Message m) { LOGGER.config("message: "+m); // note: thread and subject are null if message comes from the Kontalk // Android client MessageIDs ids = MessageIDs.from(m); Date delayDate = getDelay(m); // process possible chat state notification (XEP-0085) ExtensionElement csExt = m.getExtension(ChatStateExtension.NAMESPACE); ChatState chatState = null; if (csExt != null) { chatState = ((ChatStateExtension) csExt).getChatState(); mControl.onChatStateNotification(ids, Optional.ofNullable(delayDate), chatState); } // must be an incoming message // get content/text from body and/or encryption/url extension MessageContent content = ClientUtils.parseMessageContent(m, false); // make sure not to save a message without content if (content.isEmpty()) { if (chatState == null) { LOGGER.warning("can't find any content in message"); } else if (chatState == ChatState.active) { LOGGER.info("only active chat state"); } return; } // add message mControl.onNewInMessage(ids, Optional.ofNullable(delayDate), content); // send a 'received' for a receipt request (XEP-0184) DeliveryReceiptRequest request = DeliveryReceiptRequest.from(m); if (request != null && !ids.xmppID.isEmpty()) { Message received = new Message(m.getFrom(), Message.Type.chat); received.addExtension(new DeliveryReceipt(ids.xmppID)); mClient.sendPacket(received); } }