org.jivesoftware.smack.Roster Java Examples
The following examples show how to use
org.jivesoftware.smack.Roster.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XmppManager.java From weixin with Apache License 2.0 | 6 votes |
/** * 获取所有好友信息 * * @param roster * @return */ public List<User> getAllUser(Roster roster) { List<User> mList_user = new ArrayList<User>(); Collection<RosterEntry> entries = roster.getEntries(); Iterator<RosterEntry> iterator = entries.iterator(); while (iterator.hasNext()) { RosterEntry entry = iterator.next(); User user = new User(); user.setUserAccount(entry.getName()); user.setUserPhote(String.valueOf(R.drawable.user_picture)); // user.setUserImage(getUserImage(entry.getName())); mList_user.add(user); L.i(LOGTAG, "------获取好友-getAllUser----------------------"); L.i(LOGTAG, "getAllUser-getName-->" + entry.getName()); L.i(LOGTAG, "getAllUser-getUser-->" + entry.getUser()); L.i(LOGTAG, "getAllUser-getStatus-->" + entry.getStatus()); } return mList_user; }
Example #2
Source File: XmppTool.java From xmpp with Apache License 2.0 | 6 votes |
/** * 添加到分组 * * @param * @param userName * @param groupName */ public void addUserToGroup(String userName, String groupName) { Roster roster = con.getRoster(); RosterGroup group = roster.getGroup(groupName); if (null == group) { group = roster.createGroup(groupName); } RosterEntry entry = roster.getEntry(userName); if (entry != null) { try { group.addEntry(entry); } catch (XMPPException e) { SLog.e(tag, Log.getStackTraceString(e)); } } }
Example #3
Source File: XmppTool.java From xmpp with Apache License 2.0 | 6 votes |
/** * 获取某一个分组的成员 * * @param * @param groupName * @return */ public List<RosterEntry> getEntrysByGroup(String groupName) { Roster roster = getCon().getRoster(); List<RosterEntry> list = new ArrayList<RosterEntry>(); RosterGroup group = roster.getGroup(groupName); Collection<RosterEntry> rosterEntiry = group.getEntries(); Iterator<RosterEntry> iter = rosterEntiry.iterator(); while (iter.hasNext()) { RosterEntry entry = iter.next(); SLog.i("xmpptool", entry.getUser() + "\t" + entry.getName() + entry.getType().toString()); if (entry.getType().toString().equals("both")) { list.add(entry); } } return list; }
Example #4
Source File: XmppTool.java From xmpp with Apache License 2.0 | 6 votes |
/** * 判断是否是好友 * * @param * @param user * @return */ public boolean isFriendly(String user) { Roster roster = getCon().getRoster(); List<RosterEntry> list = new ArrayList<RosterEntry>(); list.addAll(roster.getEntries()); for (int i = 0; i < list.size(); i++) { Log.i("xmppttttttttt", list.get(i).getUser().toUpperCase() + "\t" + user); if (list.get(i).getUser().contains(user.toLowerCase())) { if (list.get(i).getType().toString().equals("both")) { return true; } else { return false; } } } return false; }
Example #5
Source File: RosterAction.java From jmeter-bzm-plugins with Apache License 2.0 | 6 votes |
@Override public SampleResult perform(JMeterXMPPSampler sampler, SampleResult res) throws Exception { Action action = Action.valueOf(sampler.getPropertyAsString(ACTION, Action.get_roster.toString())); Roster roster = sampler.getXMPPConnection().getRoster(); String entry = sampler.getPropertyAsString(ENTRY); res.setSamplerData(action.toString() + ": " + entry); if (action == Action.get_roster) { res.setResponseData(rosterToString(roster).getBytes()); } else if (action == Action.add_item) { roster.createEntry(entry, entry, new String[0]); } else if (action == Action.delete_item) { RosterEntry rosterEntry = roster.getEntry(entry); if (rosterEntry != null) { roster.removeEntry(rosterEntry); } } return res; }
Example #6
Source File: XmppManager.java From weixin with Apache License 2.0 | 6 votes |
/** * 删除好友 * * @param roster * @param userName * @return */ public boolean removeUser(Roster roster, String userName) { try { if (userName.contains("@")) { userName = userName.split("@")[0]; } RosterEntry entry = roster.getEntry(userName); L.i(LOGTAG, "删除好友--->" + userName); L.d(LOGTAG, "User." + (roster.getEntry(userName) == null)); roster.removeEntry(entry); return true; } catch (Exception e) { e.printStackTrace(); } return false; }
Example #7
Source File: LolChat.java From League-of-Legends-XMPP-Chat-Library with MIT License | 6 votes |
/** * Represents a single connection to a League of Legends chatserver. * * @param server * The chatserver of the region you want to connect to * @param friendRequestPolicy * Determines how new Friend requests are treated. * @param riotApiKey * Your apiKey used to convert summonerId's to name. You can get * your key here <a * href="https://developer.riotgames.com/">developer * .riotgames.com</a> * * @see LolChat#setFriendRequestPolicy(FriendRequestPolicy) * @see LolChat#setFriendRequestListener(FriendRequestListener) */ public LolChat(ChatServer server, FriendRequestPolicy friendRequestPolicy, RiotApiKey riotApiKey) { this.friendRequestPolicy = friendRequestPolicy; this.server = server; if (riotApiKey != null && server.api != null) { this.riotApi = RiotApi.build(riotApiKey, server); } Roster.setDefaultSubscriptionMode(SubscriptionMode.manual); final ConnectionConfiguration config = new ConnectionConfiguration( server.host, 5223, "pvp.net"); config.setSecurityMode(ConnectionConfiguration.SecurityMode.enabled); config.setSocketFactory(SSLSocketFactory.getDefault()); config.setCompressionEnabled(true); connection = new XMPPTCPConnection(config); addListeners(); }
Example #8
Source File: SarosView.java From saros with GNU General Public License v2.0 | 5 votes |
@Override public String getNickname(JID jid) throws RemoteException { Roster roster = getConnectionService().getRoster(); if (roster == null) throw new IllegalStateException("not connected to a xmpp server"); if (roster.getEntry(jid.getBase()) == null) return null; if (roster.getEntry(jid.getBase()).getName() == null) return jid.getBase(); else return roster.getEntry(jid.getBase()).getName(); }
Example #9
Source File: XmppManager.java From weixin with Apache License 2.0 | 5 votes |
/** * 添加好友--无分组 * * @param roster * @param userName * @param name * @return */ public boolean addUser(Roster roster, String userName, String name) { try { roster.createEntry(userName, name, null); return true; } catch (XMPPException e) { e.printStackTrace(); } return false; }
Example #10
Source File: XmppManager.java From weixin with Apache License 2.0 | 5 votes |
/** * 获取所有好友信息 * * @param roster * @return */ public List<RosterEntry> getAllEntries(Roster roster) { List<RosterEntry> entriesList = new ArrayList<RosterEntry>(); Collection<RosterEntry> rosterEntries = roster.getEntries(); Iterator<RosterEntry> i = rosterEntries.iterator(); while (i.hasNext()) { entriesList.add(i.next()); } return entriesList; }
Example #11
Source File: XmppManager.java From weixin with Apache License 2.0 | 5 votes |
/** * 获得某个组里面的所有好友 * * @param roster * @param groupName 组名 * @return */ public List<RosterEntry> getEntriesByGroup(Roster roster, String groupName) { List<RosterEntry> entriesList = new ArrayList<RosterEntry>(); RosterGroup rosterGroup = roster.getGroup(groupName); Collection<RosterEntry> rosterEntries = rosterGroup.getEntries(); Iterator<RosterEntry> i = rosterEntries.iterator(); while (i.hasNext()) { entriesList.add(i.next()); } return entriesList; }
Example #12
Source File: XmppManager.java From weixin with Apache License 2.0 | 5 votes |
/** * 添加分组 * * @param roster * @param groupName 分组名 * @return */ public boolean addGroup(Roster roster, String groupName) { try { roster.createGroup(groupName); return true; } catch (Exception e) { e.printStackTrace(); } return false; }
Example #13
Source File: XmppManager.java From weixin with Apache License 2.0 | 5 votes |
/** * 获得所有组 * * @param roster * @return 所有组集合 */ public List<RosterGroup> getGroups(Roster roster) { List<RosterGroup> groupList = new ArrayList<RosterGroup>(); Collection<RosterGroup> rosterGroups = roster.getGroups(); Iterator<RosterGroup> i = rosterGroups.iterator(); while (i.hasNext()) { groupList.add(i.next()); } return groupList; }
Example #14
Source File: AddressBookFragment.java From weixin with Apache License 2.0 | 5 votes |
/** * 拉取所有好友信息 */ private void pullAllFriends() { Roster roster = XmppManager.getInstance().getConnection().getRoster(); List<User> list = XmppManager.getInstance().getAllUser(roster); if (list.size() == 0) { mHandler.sendEmptyMessage(HandlerTypeUtils.WX_HANDLER_TYPE_LOAD_DATA_EMPTY); } else { // if (list.get(0).getUserAccount() == mList_user.get(0).getUserAccount()) { // mHandler.sendEmptyMessage(HandlerTypeUtils.WX_HANDLER_TYPE_LOAD_DATA_SAME); // } else { mList_user.addAll(list); mHandler.sendEmptyMessage(HandlerTypeUtils.WX_HANDLER_TYPE_LOAD_DATA_SUCCESS); // } } }
Example #15
Source File: XmppLoadRosterRunnable.java From yiim_v2 with GNU General Public License v2.0 | 5 votes |
private void loadRosterEntry(long groupId, Collection<RosterEntry> entries, Roster roster, String owner) throws Exception { try { for (RosterEntry rosterEntry : entries) { String userId = StringUtils.escapeUserResource(rosterEntry .getUser()); XmppVcard vCard = new XmppVcard(mContext); vCard.load(XmppConnectionUtils.getInstance().getConnection(), userId, true); ContentValues enValues = new ContentValues(); enValues.put(RosterColumns.GROUP_ID, groupId); enValues.put(RosterColumns.USERID, userId); enValues.put(RosterColumns.MEMO_NAME, rosterEntry.getName()); enValues.put(RosterColumns.ROSTER_TYPE, rosterEntry.getType() .toString()); enValues.put(RosterColumns.OWNER, owner); mContext.getContentResolver().insert(RosterColumns.CONTENT_URI, enValues); } } catch (Exception e) { throw e; } }
Example #16
Source File: XmppManager.java From weixin with Apache License 2.0 | 5 votes |
/** * 添加好友--有分组 * * @param roster * @param userName * @param name * @param groupName * @return */ public boolean addUser(Roster roster, String userName, String name, String groupName) { try { roster.createEntry(userName, name, new String[] { groupName }); return true; } catch (XMPPException e) { e.printStackTrace(); } return false; }
Example #17
Source File: MessengerService.java From KlyphMessenger with MIT License | 5 votes |
private ArrayList<PRosterEntry> getRosterEntries() { Log.d(TAG, "getRosterEntries"); if (connection != null && connection.isConnected() == true) { Roster roster = connection.getRoster(); Collection<RosterEntry> entries = roster.getEntries(); ArrayList<PRosterEntry> data = new ArrayList<PRosterEntry>(); for (RosterEntry rosterEntry : entries) { PRosterEntry re = new PRosterEntry(); Presence p = roster.getPresence(rosterEntry.getUser()); re.name = rosterEntry.getName(); re.user = rosterEntry.getUser(); re.presence = p.getType().name(); data.add(re); } Log.d(TAG, "getRosterEntries " + data.size()); return data; } else { return new ArrayList<PRosterEntry>(); } }
Example #18
Source File: ContactStore.java From saros with GNU General Public License v2.0 | 5 votes |
/** * This method asks the roster for contacts and fill its store. * * @param roster current Roster */ void init(Roster roster) { addContacts(NO_GROUP, rosterEntriesToXMPPContacts(roster.getUnfiledEntries())); for (RosterGroup group : roster.getGroups()) { addContacts(group.getName(), rosterEntriesToXMPPContacts(group.getEntries())); } }
Example #19
Source File: MPAuthenticationProvider.java From carbon-identity with Apache License 2.0 | 5 votes |
/** * Checking whether the user is avaiable online. * * @param roster * @param userName * @return */ private boolean isAvailable(Roster roster, String userName) { Collection<RosterEntry> entrySet = roster.getEntries(); for (RosterEntry entry : entrySet) { if (entry.getUser().equals(userName)) { return true; } } return false; }
Example #20
Source File: XmppTool.java From xmpp with Apache License 2.0 | 5 votes |
/** * 获取所有分组 * * @param * @return */ public List<RosterGroup> getGroups() { Roster roster = getCon().getRoster(); List<RosterGroup> list = new ArrayList<RosterGroup>(); list.addAll(roster.getGroups()); return list; }
Example #21
Source File: XmppTool.java From xmpp with Apache License 2.0 | 5 votes |
/** * 删除好友 * * @param userName * @return */ public boolean removeUser(String userName) { Roster roster = con.getRoster(); try { RosterEntry entry = roster.getEntry(userName); if (null != entry) { roster.removeEntry(entry); } return true; } catch (XMPPException e) { SLog.e(tag, Log.getStackTraceString(e)); } return false; }
Example #22
Source File: XmppTool.java From xmpp with Apache License 2.0 | 5 votes |
/** * 添加好友 * * @param * @param userName * @param name * @param groupName 是否有分组 * @return */ public boolean addUser(String userName, String name, String groupName) { Roster roster = con.getRoster(); try { roster.createEntry(userName, name, null == groupName ? null : new String[]{groupName}); return true; } catch (XMPPException e) { SLog.e(tag, Log.getStackTraceString(e)); } return false; }
Example #23
Source File: XmppTool.java From xmpp with Apache License 2.0 | 5 votes |
/** * ���һ���� */ public static boolean addGroup(Roster roster, String groupName) { try { roster.createGroup(groupName); return true; } catch (Exception e) { e.printStackTrace(); return false; } }
Example #24
Source File: RosterAction.java From jmeter-bzm-plugins with Apache License 2.0 | 5 votes |
private String rosterToString(Roster roster) { StringBuilder res = new StringBuilder(); for (RosterEntry entry : roster.getEntries()) { res.append(entry.toString()); res.append(':'); res.append(roster.getPresence(entry.getUser()).toString()); res.append('\n'); } return res.toString(); }
Example #25
Source File: Connection.java From HippyJava with MIT License | 4 votes |
public Roster getRoster() { return XMPP.getRoster(); }
Example #26
Source File: XMPPUtils.java From saros with GNU General Public License v2.0 | 4 votes |
/** * @param connectionService network component that should be used to resolve the nickname or * <code>null</code> to use the default one * @param jid the JID to resolve the nickname for * @param alternative nickname to return if no nickname is available, can be <code>null</code> * @return The nickname associated with the given JID in the current roster or the * <tt>alternative</tt> representation if the current roster is not available or the nickname * has not been set. */ public static String getNickname( XMPPConnectionService connectionService, final JID jid, final String alternative) { if (connectionService == null) connectionService = defaultConnectionService; if (connectionService == null) return alternative; Connection connection = connectionService.getConnection(); if (connection == null) return alternative; Roster roster = connection.getRoster(); if (roster == null) return alternative; RosterEntry entry = roster.getEntry(jid.getBase()); if (entry == null) return alternative; String nickName = entry.getName(); if (nickName != null && nickName.trim().length() > 0) return nickName; return alternative; }
Example #27
Source File: XmppDeleteEntryRunnable.java From yiim_v2 with GNU General Public License v2.0 | 4 votes |
@Override public XmppResult execute() { // TODO Auto-generated method stub XmppResult result = createResult(); Cursor mCursor = null; try { // 删除关系表 if (mRosterId != -1) { mCursor = mContext.getContentResolver().query( ContentUris.withAppendedId(RosterColumns.CONTENT_URI, mRosterId), new String[] { RosterColumns.USERID, RosterColumns.GROUP_ID }, null, null, null); if (mCursor != null && mCursor.getCount() == 1) { mCursor.moveToFirst(); mUserId = mCursor.getString(0); mGroupId = mCursor.getInt(1); } } Roster roster = XmppConnectionUtils.getInstance().getConnection() .getRoster(); RosterEntry rosterEntry = roster.getEntry(mUserId); if (rosterEntry != null) { roster.removeEntry(rosterEntry); } mContext.getContentResolver().delete( RosterColumns.CONTENT_URI, RosterColumns.USERID + "='"+mUserId+"' and " + RosterColumns.GROUP_ID + "=" + mGroupId, null); // 删除本地聊天记录 YiIMUtils.deleteChatRecord(mContext, mUserId); // 删除本地会话记录 YiIMUtils.deleteConversation(mContext, mUserId); result.status = Status.SUCCESS; } catch (Exception e) { YiLog.getInstance().e(e, "delete friend failed."); result.obj = e.getMessage(); } finally { if (mCursor != null) { mCursor.close(); mCursor = null; } } return result; }
Example #28
Source File: XmppVcard.java From yiim_v2 with GNU General Public License v2.0 | 4 votes |
public static XmppVcard loadByVcard(Context context, Connection connection, String user, XmppVcard xmppVcard) { XmppVcard ret = null; if (xmppVcard != null) { ret = xmppVcard; } else { ret = new XmppVcard(context); } try { VCard vCard = new VCard(); vCard.load(connection, user); Roster roster = connection.getRoster(); ret.setNickName(vCard.getNickName()); // 在线状态获取 Presence presence = roster.getPresence(user); if (presence.getType() != Type.unavailable) { ret.setPresence("online"); } else { ret.setPresence("unavailable"); } // 加载用户头像 byte[] avatar = vCard.getAvatar(); if (avatar != null) { YiStoreCache.cacheRawData(user, avatar); } ret.setGender(vCard.getField(Const.SEX)); ret.setSign(vCard.getField(Const.SIGN)); ret.setCountry(vCard.getField(Const.COUNTRY)); ret.setProvince(vCard.getField(Const.PROVINCE)); ret.setAddress(vCard.getField(Const.ADDRESS)); ret.setBirthday(Long.valueOf(vCard.getField(Const.BIRTHDAY))); ret.setSecondBirthday(Long.valueOf(vCard .getField(Const.SECOND_BIRTHDAY))); ret.setOnlineTime(Long.valueOf(vCard.getField(Const.ONLINETIME))); ret.setRealName(vCard.getField(Const.REALNAME)); ret.setBloodGroup(vCard.getField(Const.BLOOD_GROUP)); ret.setPhone(vCard.getField(Const.PHONE)); ret.setOccupation(vCard.getField(Const.OCCUPATION)); ret.setEmail(vCard.getField(Const.EMAIL)); //通知重新加载好友列表 Intent intent = new Intent(Const.NOTIFY_RELOAD_ROSTER_ENTRIES); context.sendBroadcast(intent); } catch (Exception e) { } return ret; }
Example #29
Source File: InstantMessagingClient.java From olat with Apache License 2.0 | 4 votes |
/** * @param roster */ public void setRoster(final Roster roster) { this.roster = roster; }
Example #30
Source File: InstantMessagingClient.java From olat with Apache License 2.0 | 4 votes |
/** * @return Returns the roster. */ public Roster getRoster() { return roster; }