@Override public void SendMessage(String name, String message) { if (connection == null) return; if (connection.isConnected() == true) { Chat chat = connection .getChatManager() .createChat( name + "@" + serverName, new MessageListener() { public void processMessage(Chat chat, Message message) { System.out.println("Received message: " + message); System.out.println( "message body:" + message != null ? message.getBody() : "NULL"); } }); try { chat.sendMessage(message); this.sessionMessage.add("send to:`" + name + "` message:" + message); } catch (XMPPException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
/** * @see net.sf.kraken.session.TransportSession#sendChatState(org.xmpp.packet.JID, * net.sf.kraken.type.ChatStateType) */ @Override public void sendChatState(JID jid, ChatStateType chatState) { final Presence presence = conn.getRoster().getPresence(jid.toString()); if (presence == null || presence.getType().equals(Presence.Type.unavailable)) { // don't send chat state to contacts that are offline. return; } Chat chat = conn.getChatManager().createChat(getTransport().convertJIDToID(jid), listener); try { ChatState state = ChatState.active; switch (chatState) { case active: state = ChatState.active; break; case composing: state = ChatState.composing; break; case paused: state = ChatState.paused; break; case inactive: state = ChatState.inactive; break; case gone: state = ChatState.gone; break; } Message message = new Message(); message.addExtension(new ChatStateExtension(state)); chat.sendMessage(message); } catch (XMPPException e) { // Ignore } }
public void removeFromConnectionList(String participant) { for (Chat c : connectionList) { if (c.getParticipant().equalsIgnoreCase(participant)) { connectionList.remove(c); } } }
private boolean chatExactlyExists(Chat chat) { for (Chat c : connectionList) { if (c.getParticipant().equalsIgnoreCase(chat.getParticipant())) { return true; } } return false; }
public Chat chat(String participantName) { for (Chat c : connectionList) { if (c.getParticipant().equalsIgnoreCase(participantName)) { return c; } } return null; }
public void sendAll(String message) { for (Chat c : connectionList) { try { c.sendMessage(message); } catch (XMPPException ex) { Logger.getLogger(XMPPManager.class.getName()).log(Level.SEVERE, null, ex); } } }
/** @see net.sf.kraken.session.TransportSession#sendMessage(org.xmpp.packet.JID, String) */ @Override public void sendMessage(JID jid, String message) { Chat chat = conn.getChatManager().createChat(getTransport().convertJIDToID(jid), listener); try { chat.sendMessage(message); } catch (XMPPException e) { // Ignore } }
public boolean chatExists(Chat chat) { for (Chat c : connectionList) { if (correctAdress(c.getParticipant()) .equalsIgnoreCase(correctAdress(chat.getParticipant()))) { return true; } } return false; }
public void sendAllExcept(String message, String exceptionName) { for (Chat c : connectionList) { if (!c.getParticipant().equalsIgnoreCase(exceptionName)) { try { c.sendMessage(message); } catch (XMPPException ex) { Logger.getLogger(XMPPManager.class.getName()).log(Level.SEVERE, null, ex); } } } }
/** * @see net.sf.kraken.session.TransportSession#sendBuzzNotification(org.xmpp.packet.JID, String) */ @Override public void sendBuzzNotification(JID jid, String message) { Chat chat = conn.getChatManager().createChat(getTransport().convertJIDToID(jid), listener); try { Message m = new Message(); m.setTo(getTransport().convertJIDToID(jid)); m.addExtension(new BuzzExtension()); chat.sendMessage(m); } catch (XMPPException e) { // Ignore } }
@Override public void onCreate(Bundle savedInstanceState) { context = getApplicationContext(); this.connection = Conexion.getInstance(); this.roster = RosterManager.getRosterInstance(); chatMan = ContactsActivity.chatMan; chat = chatMan.chat; super.onCreate(savedInstanceState); setContentView(R.layout.chat); destJid = getIntent().getStringExtra("destJid"); myJid = this.connection.getUser(); cipher = RosterManager.isSecure(destJid); Bundle bundle = getIntent().getExtras(); passPhrase = bundle.getString(AndroidRsaConstants.PASSPHRASE); String parsedDest = StringUtils.parseBareAddress(destJid); Log.d(TAG, "Creado chat con " + roster.getEntry(parsedDest).getName() + " cifrado=" + cipher); if (chat == null) { chatMan.createChat(destJid, messageListener); chat = chatMan.getChat(); if (cipher) { Message m = new Message(destJid); try { chat.sendMessage(m); } catch (XMPPException e) { e.printStackTrace(); } } } else { chat.addMessageListener(messageListener); } adapter = new ChatAdapter(this, listMessages); setListAdapter(adapter); myListView = getListView(); myListView.setDivider(null); if (cipher) { Bitmap bm = AvatarsCache.getAvatar(destJid); try { cert = Decode.decode(bm); } catch (IOException e) { e.printStackTrace(); } catch (CertificateException e) { e.printStackTrace(); } } }
private void sendMessage(String message) { try { chat.sendMessage(message); } catch (XMPPException e) { e.printStackTrace(); } }
/* * (non-Javadoc) * * @see * fr.univartois.ili.fsnet.commons.talk.ITalk#sendMessage(java.lang.String, * java.lang.String, org.jivesoftware.smack.Chat) */ @Override public void sendMessage(String msg, String friendPseudo, Chat chat) throws TalkException { try { chat.sendMessage(msg); } catch (Exception e) { Logger.getAnonymousLogger().log(Level.SEVERE, "", e); } }
public static void sendViaXMPP(String message) { String userHome = System.getProperty("user.home"); try { String jabberConfig = FileUtils.readFileToString(new File(userHome + "/.nexmpp")); String[] xmppParams = jabberConfig.split(" "); if (xmppParams.length != 4) { System.err.println( "Wrong .nexmpp format, should be: server server_login server_password jabber_id"); return; } String server = xmppParams[0]; String serverLogin = xmppParams[1]; String serverPassword = xmppParams[2]; String jabberId = xmppParams[3].split("\n")[0]; Calendar cal = Calendar.getInstance(); int hour24 = cal.get(Calendar.HOUR_OF_DAY); if (hour24 <= 9) { // do not wake me up :) return; } try { String hostName = InetAddress.getLocalHost().getHostName(); // if (hostName.endsWith(".local") || hostName.startsWith("eduroam") || // hostName.startsWith("dhcp")) { // return; // } message = hostName + ": " + message; XMPPConnection connection = new XMPPConnection(server); connection.connect(); connection.login(serverLogin, serverPassword); ChatManager chatmanager = connection.getChatManager(); Chat chat = chatmanager.createChat(jabberId, null); chat.sendMessage(message); connection.disconnect(); } catch (XMPPException e) { e.printStackTrace(); } catch (UnknownHostException e) { e.printStackTrace(); } } catch (IOException e) { System.err.println("No " + userHome + "/.nexmpp file."); return; } }
/** @param message 聊天信息 */ public void chat(String jid, String message) { Chat chat = connection.getChatManager().getThreadChat(jid); if (chat == null) { try { connection.getChatManager().createChat(jid, null).sendMessage(message); } catch (XMPPException e) { e.printStackTrace(); } } else { try { chat.sendMessage(message); } catch (XMPPException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
public void handleSpeech(List<String> matches) { String response = matches.get(0); if (response.startsWith("talk to")) { // "talk to <person>" String name = response.split(" ")[2].toLowerCase(); setActiveChatByName(name); } else { // sends "<message>" to the active chat if (activeChat == null) { Log.i("Chat", "Attempted to send chat with no active recipient."); speak("No chat active. Start one by saying talk to , then a name."); } else { try { Log.i("Chat", "Sending message to " + activeChat.getParticipant() + ": " + response); activeChat.sendMessage(response); } catch (XMPPException e) { e.printStackTrace(); } } } }
/** {@inheritDoc} */ @Override public void outgoingBroadcast(Object message) { if (message instanceof String) { try { channel.sendMessage(message.toString()); } catch (XMPPException e) { logger.debug("failed to send message on channel", e); } } }
public void sendMessage(String message) { try { if (chat != null) { chat.sendMessage(message); } if (muc2 != null) { muc2.sendMessage(message); } } catch (XMPPException e) { e.printStackTrace(); } }
/** 发送消息 */ public void sendMessage(String sessionJID, String sessionName, String message, String type) throws RemoteException { ChatManager chatManager = ChatManager.getInstanceFor(connection); Chat chat; // 查找Chat对策 if (jidChats.containsKey(sessionJID)) { chat = jidChats.get(sessionJID); // 创建Chat } else { chat = chatManager.createChat(sessionJID, null); // 添加到集合 jidChats.put(sessionJID, chat); } if (chat != null) { try { // 发送消息 chat.sendMessage(message); // 保存聊天记录 ContentValues values = new ContentValues(); values.put(SMSProvider.SMSColumns.BODY, message); values.put(SMSProvider.SMSColumns.TYPE, type); values.put(SMSProvider.SMSColumns.TIME, System.currentTimeMillis()); values.put(SMSProvider.SMSColumns.WHO_ID, IM.getString(IM.ACCOUNT_JID)); values.put(SMSProvider.SMSColumns.SESSION_ID, sessionJID); values.put(SMSProvider.SMSColumns.SESSION_NAME, sessionName); imService.getContentResolver().insert(SMSProvider.SMS_URI, values); } catch (XMPPException e) { e.printStackTrace(); } catch (SmackException.NotConnectedException e) { e.printStackTrace(); } } }
// TODO: figure out what determines the presence of a RosterEntry's name field public void setActiveChatByName(String name) { Roster roster = connection.getRoster(); String activeUser = null; if (activeChat != null) { activeUser = activeChat.getParticipant(); int index = activeUser.indexOf("/"); // Log.d("Jane", "index: " + index); if (index >= 0) { activeUser = activeUser.substring(0, index); } if (!chatCache.containsKey(activeUser)) { Log.d("Jane", "Caching " + activeUser); chatCache.put(activeUser, activeChat); } } for (RosterEntry entry : roster.getEntries()) { String potentialName = entry.getName(); String email = entry.getUser(); Log.i("Chat", "Checking desired recipient: " + name + " against: " + potentialName); if (potentialName != null && potentialName.regionMatches(true, 0, name, 0, name.length())) { Log.i("Chat", "Setting active chat to " + potentialName + "/" + email); speak("Now talking to " + potentialName); if (chatCache.containsKey(email)) { activeChat = chatCache.get(email); } else { Log.d("Chat", "Chat cache did not contain key " + email); activeChat = connection.getChatManager().createChat(email, null); } return; } else if (email.contains(name)) { // maybe emails will be ok... Log.i("Chat", "Setting active chat to " + email); speak("Now talking to " + email); if (chatCache.containsKey(email)) { activeChat = chatCache.get(email); } else { activeChat = connection.getChatManager().createChat(email, null); } return; } } Log.i("Chat", "No friend matches " + name); speak("Sorry, but I couldn't find a friend named " + name); }
// 发送消息 public void sendMessage() { EditText text = (EditText) this.findViewById(R.id.et_sendmessage); String message = text.getText().toString(); if (message == null || message == "") { return; } // 刷新内容 refresh(message, false); // 保存到sqlite InMessageStore.saveOrUpdate(userId, friendId, message, false, this); try { chat.sendMessage(message); } catch (XMPPException e) { System.out.println(e.getMessage() + "exception"); } // 发送完消息后清空原来的数据 text.setText(""); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.singlechat); send = (Button) findViewById(R.id.send); record = (TextView) findViewById(R.id.record); message = (EditText) findViewById(R.id.message); send.setOnClickListener( new OnClickListener() { @Override public void onClick(View arg0) { try { newChat.sendMessage(message.getText().toString()); } catch (XMPPException e) { e.printStackTrace(); } } }); ChatManager chatmanager = ActivityMain.connection.getChatManager(); // get user Intent intent = getIntent(); String user = intent.getStringExtra("user"); System.out.println("user:"******"im bird man"); } catch (XMPPException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
protected UMOMessage doSend(UMOEvent event) throws Exception { sendMessage(event); if (useRemoteSync(event)) { Message response; if (groupChat != null) { response = groupChat.nextMessage(event.getTimeout()); } else { response = chat.nextMessage(event.getTimeout()); } if (response != null) { if (logger.isDebugEnabled()) { logger.debug("Got a response from chat: " + chat); } return new MuleMessage(connector.getMessageAdapter(response)); } } return null; }
protected void sendMessage(UMOEvent event) throws Exception { if (chat == null && groupChat == null) { UMOMessage msg = event.getMessage(); boolean group = msg.getBooleanProperty(XmppConnector.XMPP_GROUP_CHAT, false); String nickname = msg.getStringProperty(XmppConnector.XMPP_NICKNAME, "mule"); String recipient = event.getEndpoint().getEndpointURI().getPath().substring(1); if (group) { groupChat = new GroupChat(xmppConnection, recipient); if (!groupChat.isJoined()) { groupChat.join(nickname); } } else { chat = new Chat(xmppConnection, recipient); } } Object msgObj = event.getMessage().getPayload(); Message message; // avoid duplicate transformation if (!(msgObj instanceof Message)) { message = (Message) event.getTransformedMessage(); } else { message = (Message) msgObj; } if (logger.isTraceEnabled()) { logger.trace("Transformed packet: " + message.toXML()); } if (chat != null) { chat.sendMessage(message); } else { groupChat.sendMessage(message); } if (logger.isDebugEnabled()) { logger.debug("Packet successfully sent"); } }
@Override public void performInternal(Chat chat, Message message) { SparqlQuery query = new SparqlQuery(message.getBody().substring(6)); endpoints.process(query); for (SparqlEndpointIdentifier ident : query.getResults().keySet()) { if (query.getResults().get(ident).getErrorMsg() == null || query.getResults().get(ident).getErrorMsg().isEmpty()) { try { chat.sendMessage( "RDF-Store " + ident.getName() + " (" + ident.getType() + ") " + "answered:" + transform.transformXML(query.getResults().get(ident).getAnswer())); } catch (XMPPException e) { log.error(e); } } } }
@Override public void chatCreated(Chat chat, boolean createdLocally) { // Set listener for incoming messages. chat.addMessageListener(messageListener); muc2.addMessageListener(packetListener); }
public void announceClosed() throws XMPPException { currentChat.sendMessage("SOLVersion: 1.1; Event: CLOSE;"); }
private void recievesAMessageMatching(String sniperId, Matcher<? super String> messageMatcher) throws InterruptedException { messageListener.receivesAMessage(messageMatcher); assertThat(currentChat.getParticipant(), equalTo(sniperId)); }
// @Override public void processMessage(Chat chat, Message message) { System.out.println(chat.getParticipant() + ": " + message.getBody()); myChat.setChat(chat); }
private void createAndAddToChat(Chat chat) { connectionList.add( chatManager.createChat(correctAdress(chat.getParticipant()), new InboundHandler())); }