public synchronized JabberRoom getRoomByJID(JabberClient client, String jid, String defaultName) { if (jid == null) { return null; } JabberRoom newRoom = jidToRoom.get(jid); if (newRoom == null) { String roomName = defaultName == null ? "" : defaultName; //$NON-NLS-1$ RoomInfo info = null; try { info = MultiUserChat.getRoomInfo(client.getConnection(), jid); } // FIXME: review error message catch (XMPPException e) { e.printStackTrace(); } newRoom = new JabberRoom(roomName, jid, info, client); jidToRoom.put(jid, newRoom); } return newRoom; }
public static boolean isRoomExist(String roomJid) throws Exception { XMPPConnection connection = XmppConnectionUtils.getInstance() .getRawConnection(); if (connection == null || !connection.isAuthenticated()) { throw new Exception("no connections"); } try { RoomInfo roomInfo = MultiUserChat.getRoomInfo(connection, roomJid); if (roomInfo != null) { return true; } return false; } catch (Exception e) { return false; } }
List<MultiChatRoom> getJoinedChatRooms() { Iterator<String> joinedRooms = MultiUserChat.getJoinedRooms(getInternalService().getConnection(), getInternalService().getService().getProtocolUid()); List<MultiChatRoom> multiChatBuddies = new ArrayList<MultiChatRoom>(); for (; joinedRooms.hasNext();) { String roomJid = joinedRooms.next(); try { RoomInfo info = MultiUserChat.getRoomInfo(getInternalService().getConnection(), roomJid); multiChatBuddies.add(getInternalService().getService().getEntityAdapter().chatRoomInfo2Buddy(info, getInternalService().getService().getProtocolUid(), getInternalService().getService().getServiceId(), true)); } catch (XMPPException e) { Logger.log(e); } } for (final Buddy room : multiChatBuddies) { MultiUserChat chat = new MultiUserChat(getInternalService().getConnection(), room.getProtocolUid()); fillWithListeners(chat); multichats.put(room.getProtocolUid(), chat); } return multiChatBuddies; }
public void displayRoomInformation(final String roomJID) { SwingWorker worker = new SwingWorker() { RoomInfo roomInfo = null; DiscoverItems items = null; public Object construct() { try { roomInfo = MultiUserChat.getRoomInfo(SparkManager.getConnection(), roomJID); ServiceDiscoveryManager manager = ServiceDiscoveryManager.getInstanceFor(SparkManager.getConnection()); items = manager.discoverItems(roomJID); } catch (XMPPException e) { Log.error(e); } return "ok"; } public void finished() { setupRoomInformationUI(roomJID, roomInfo, items); } }; worker.start(); }
private JabberRoom(String name, String jid, RoomInfo info, JabberClient client) { super(name); this.jid = jid; this.info = info; this.client = client; config.clear(); config.put(CONFIG_NAME, name); }
/** * ��ȡHostedrooms * * @return */ public List<MucRoom> getAllHostedRooms() { List<MucRoom> rooms = new ArrayList<MucRoom>(); try { new ServiceDiscoveryManager(connection); Collection<HostedRoom> hrooms = MultiUserChat.getHostedRooms( connection, connection.getServiceName()); if (!hrooms.isEmpty()) { for (HostedRoom r : hrooms) { RoomInfo roominfo = MultiUserChat.getRoomInfo(connection, r.getJid()); SLog.i("������Info", roominfo.toString()); MucRoom mr = new MucRoom(); mr.setDescription(roominfo.getDescription()); mr.setName(r.getName()); mr.setJid(r.getJid()); mr.setOccupants(roominfo.getOccupantsCount()); mr.setSubject(roominfo.getSubject()); rooms.add(mr); } } } catch (XMPPException e) { SLog.e(tag, " ��ȡHosted Rooms ����"); SLog.e(tag, Log.getStackTraceString(e)); } return rooms; }
/** * ��ȡ�����������л����� * @return * @throws XMPPException */ public List<MucRoom> getConferenceRoom() throws XMPPException { List<MucRoom> list = new ArrayList<MucRoom>(); new ServiceDiscoveryManager(connection); if (!MultiUserChat.getHostedRooms(connection, connection.getServiceName()).isEmpty()) { for (HostedRoom k : MultiUserChat.getHostedRooms(connection, connection.getServiceName())) { for (HostedRoom j : MultiUserChat.getHostedRooms(connection, k.getJid())) { RoomInfo info2 = MultiUserChat.getRoomInfo(connection, j.getJid()); if (j.getJid().indexOf("@") > 0) { MucRoom friendrooms = new MucRoom(); friendrooms.setName(j.getName());//�����ҵ����� friendrooms.setJid(j.getJid());//������JID friendrooms.setOccupants(info2.getOccupantsCount());//��������ռ�������� friendrooms.setDescription(info2.getDescription());//�����ҵ����� friendrooms.setSubject(info2.getSubject());//�����ҵ����� list.add(friendrooms); } } } } return list; }
public void onSearchClick(View view) { if (isStringInvalid(mSearchEditText.getText())) { showMsgDialog(getString(R.string.err_empty_search_content), getString(R.string.str_ok)); return; } ArrayList<TabContactsModel> models = new ArrayList<TabContactsModel>(); try { String roomJid = YiHanziToPinyin.getPinYin(mSearchEditText .getText().toString()) + "@conference." + XmppConnectionUtils.getXmppHost(); RoomInfo roomInfo = MultiUserChat.getRoomInfo(getXmppBinder() .getXmppConnection(), roomJid); if (roomInfo != null) { TabContactsModel model = new TabContactsModel(); MultiChatDesc desc = MultiChatDesc.fromString(roomInfo .getDescription()); if (!YiUtils.isStringInvalid(roomInfo.getSubject())) { model.setMsg(roomInfo.getSubject()); } else if (!YiUtils.isStringInvalid(desc.getName())) { model.setMsg(desc.getName()); } else { model.setMsg(roomInfo.getRoom()); } model.setUser(roomInfo.getRoom()); model.setSubMsg(roomInfo.getDescription()); models.add(model); } } catch (Exception e) { // TODO: handle exception }finally { Message message = getHandler().obtainMessage(MSG_UPDATE_LIST, models); message.sendToTarget(); } }
public MultiChatRoom chatRoomInfo2Buddy(RoomInfo info, String ownerJid, byte serviceId, boolean joined) { MultiChatRoom chat = new MultiChatRoom(info.getRoom(), ownerJid, XMPPApiConstants.PROTOCOL_NAME, serviceId); chat.setName((info.getSubject()!= null && info.getSubject().length() > 0) ? info.getSubject() : info.getRoom()); chat.getOnlineInfo().setXstatusName(info.getDescription()); chat.setId(chat.getProtocolUid().hashCode()); if (joined){ chat.getOnlineInfo().getFeatures().putByte(ApiConstants.FEATURE_STATUS, (byte) 0); } return chat; }
public void setInfo(RoomInfo info) { this.info = info; }
private void loadRooms() { getXmppBinder().execute(new Runnable() { @Override public void run() { // TODO Auto-generated method stub try { Collection<HostedRoom> hostedRooms = MultiUserChat .getHostedRooms( getXmppBinder().getXmppConnection(), "conference." + XmppConnectionUtils.getXmppHost()); if (!hostedRooms.isEmpty()) { ArrayList<TabContactsModel> models = new ArrayList<TabContactsModel>(); for (HostedRoom hostedRoom : hostedRooms) { RoomInfo roomInfo = MultiUserChat.getRoomInfo( getXmppBinder().getXmppConnection(), hostedRoom.getJid()); TabContactsModel model = new TabContactsModel(); MultiChatDesc desc = MultiChatDesc .fromString(roomInfo.getDescription()); if (!YiUtils.isStringInvalid(roomInfo.getSubject())) { model.setMsg(roomInfo.getSubject()); } else if (!YiUtils.isStringInvalid(desc.getName())) { model.setMsg(desc.getName()); } else { model.setMsg(roomInfo.getRoom()); } model.setUser(roomInfo.getRoom()); model.setSubMsg(roomInfo.getDescription()); models.add(model); } Message message = getHandler().obtainMessage( MSG_UPDATE_LIST, models); message.sendToTarget(); } } catch (Exception e) { // TODO: handle exception YiLog.getInstance().e(e, "load rooms failed"); } } }); }
public MultiChatRoom xmppRoomInfo2MultiChatRoom(RoomInfo info, String ownerJid, byte serviceId) { MultiChatRoom chat = new MultiChatRoom(info.getRoom(), ownerJid, XMPPApiConstants.PROTOCOL_NAME, serviceId); chat.setName(info.getDescription()); return chat; }
/** * Returns true if the room is password protected or Members only * * @param roomjid * @return */ private boolean isPasswordProtected(String roomjid) { boolean result = false; try { RoomInfo rif = MultiUserChat.getRoomInfo( SparkManager.getConnection(), roomjid); result = rif.isMembersOnly() || rif.isPasswordProtected(); } catch (XMPPException e) { } catch (NumberFormatException nfe) { } return result; }