/** * send an xmpp message to a specified Chat Room. * * @param xmppChatRoom room to send message to. * @param xmppMessage text to be sent in the body of the message * @return true if message is sent, false otherwise */ public boolean sendGroupChat(String xmppChatRoom, String xmppMessage) { MultiUserChat groupChat; if (rooms.containsKey(xmppChatRoom)) { groupChat = rooms.get(xmppChatRoom); } else { LOG.debug("Adding room: {}", xmppChatRoom); groupChat = new MultiUserChat(xmpp, xmppChatRoom); rooms.put(xmppChatRoom, groupChat); } if (!groupChat.isJoined()) { LOG.debug("Joining room: {}", xmppChatRoom); try { groupChat.join(xmppUser); } catch (XMPPException e) { LOG.error("XMPP Exception joining chat room ", e); return false; } } try { groupChat.sendMessage(xmppMessage); LOG.debug("XMPP Manager sent message to: {}", xmppChatRoom); } catch (XMPPException e) { LOG.error("XMPP Exception sending message to Chat room", e); return false; } return true; }
public void onClick(View v) { FQRoomName = getText(R.id.room_name) == null || getText(R.id.room_name).equals("") ? "*****@*****.**" : getText(R.id.room_name); String nickname = getText(R.id.nickname) == null || getText(R.id.nickname).equals("") ? "curtis" : getText(R.id.nickname); MultiUserChat muc = new MultiUserChat(xmppClient.getConnection(), FQRoomName); // MultiUserChat muc = new MultiUserChat(xmppClient.getConnection(), room_name + // "@talk.google.com"); try { if (muc != null) { Log.i("TestXMPPClient", "MUC is not null!"); muc.create(nickname); muc.sendConfigurationForm(new Form(Form.TYPE_SUBMIT)); xmppClient.setMUC(muc); if (!muc.isJoined()) muc.join(nickname); if (!muc.isJoined()) throw new XMPPException("Failed to join room!"); else { // } } else { Log.i("TestXMPPClient", "Failed to create MUC"); } } catch (XMPPException ex) { Log.e("TestXMPPClient", "[RoomCreateDialog] Failed to create room " + FQRoomName); // Log.e("TestXMPPClient", "Exception", ex); Log.e("TestXMPPClient", ex.toString()); xmppClient.setMUC(null); } dismiss(); }
/** * leaves the muc and deletes its record from the db * * @param muc */ private void leaveRoom(MultiUserChat muc) throws SmackException.NotConnectedException { mMucHelper.deleteMUC(muc.getRoom()); if (muc.isJoined()) { muc.leave(); } // Remove the room if mRooms contains it if (mRooms.size() > 0) { Integer i = getRoomInt(muc.getRoom()); String number = mMucHelper.getNumber(muc.getRoom()); mRoomNumbers.remove(i); mRooms.remove(number); } }