本文整理汇总了Java中org.jivesoftware.smack.Roster.getPresence方法的典型用法代码示例。如果您正苦于以下问题:Java Roster.getPresence方法的具体用法?Java Roster.getPresence怎么用?Java Roster.getPresence使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jivesoftware.smack.Roster
的用法示例。
在下文中一共展示了Roster.getPresence方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isAvailable
import org.jivesoftware.smack.Roster; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*
* @param username
* Has to be in the messagers format.
*/
@Override
public boolean isAvailable(String username) {
if (connection.isConnected()) {
Roster roster = connection.getRoster();
if (roster != null) {
Presence presence = roster.getPresence(username + XMPPPatternUtils.getUserSuffix());
return presence.isAvailable();
} else {
LOG.debug("XMPP connection did not return a roster for communote bot");
}
} else {
LOG.debug("Cannot check availability of user because XMPP connector is disconnected");
}
return false;
}
示例2: transEntryToUser
import org.jivesoftware.smack.Roster; //导入方法依赖的package包/类
/**
* ����RosterEntry����һ��User
*
* @param entry
* @return
*/
public static User transEntryToUser(RosterEntry entry, Roster roster) {
User user = new User();
if (entry.getName() == null) {
user.setName(StringUtil.getUserNameByJid(entry.getUser()));
} else {
user.setName(entry.getName());
}
user.setJID(entry.getUser());
System.out.println(entry.getUser());
Presence presence = roster.getPresence(entry.getUser());
user.setFrom(presence.getFrom());
user.setStatus(presence.getStatus());
user.setSize(entry.getGroups().size());
user.setAvailable(presence.isAvailable());
user.setType(entry.getType());
return user;
}
示例3: getByUserJid
import org.jivesoftware.smack.Roster; //导入方法依赖的package包/类
/**
* �����û�jid�õ��û�
*
* @param userJid
* @param nickname
*/
public static User getByUserJid(String userJId, XMPPConnection connection) {
Roster roster = connection.getRoster();
RosterEntry entry = connection.getRoster().getEntry(userJId);
if (null == entry) {
return null;
}
User user = new User();
if (entry.getName() == null) {
user.setName(StringUtil.getUserNameByJid(entry.getUser()));
} else {
user.setName(entry.getName());
}
user.setJID(entry.getUser());
System.out.println(entry.getUser());
Presence presence = roster.getPresence(entry.getUser());
user.setFrom(presence.getFrom());
user.setStatus(presence.getStatus());
user.setSize(entry.getGroups().size());
user.setAvailable(presence.isAvailable());
user.setType(entry.getType());
return user;
}
示例4: displayfrndslist
import org.jivesoftware.smack.Roster; //导入方法依赖的package包/类
public void displayfrndslist()
{
Roster rster = conn.getRoster();
Collection<RosterEntry> records = rster.getEntries();
System.out.println("\nTotal friends: "+records.size());
int i = 1;
String status = null;
for(RosterEntry r:records)
{
Presence presence = rster.getPresence(r.getUser());
if ((presence != null)){
if(rster.getPresence(r.getUser()).toString().contains("away"))
status = "idle";
else if (rster.getPresence(r.getUser()).toString().contains("unavailable"))
status = "offline";
else if (rster.getPresence(r.getUser()).toString().contains("dnd"))
status = "busy";
else
status = "available";
System.out.println("(#" + i + ")"+r.getUser()+"---"+status);
i++;
}
}
}
示例5: transEntryToUser
import org.jivesoftware.smack.Roster; //导入方法依赖的package包/类
/**
* 根据RosterEntry创建一个User
*/
public static IMUser transEntryToUser(RosterEntry entry, Roster roster) {
IMUser user = new IMUser();
if (entry.getName() == null) {
user.setName(getUserNameByJid(entry.getUser()));
} else {
user.setName(entry.getName());
}
user.setJid(entry.getUser());
Presence presence = roster.getPresence(entry.getUser());
user.setAvailable(presence.isAvailable());
return user;
}
示例6: getImage
import org.jivesoftware.smack.Roster; //导入方法依赖的package包/类
private void getImage(String requestAgent, String workgroup, HttpServletRequest request, HttpServletResponse response) {
ChatManager chatManager = ChatManager.getInstance();
boolean isOnline = WorkgroupStatus.isOnline(workgroup);
final SettingsManager imageManager = SettingsManager.getInstance();
final Roster roster = chatManager.getGlobalConnection().getRoster();
final Presence presence = roster.getPresence(requestAgent);
isOnline = isOnline && presence != null && presence.getType() == Presence.Type.available;
if (!isOnline) {
Object o = roster.getEntry(requestAgent);
if (o == null) {
try {
roster.createEntry(requestAgent, requestAgent, null);
}
catch (XMPPException e) {
WebLog.logError("Error creating new roster entry:", e);
}
}
}
byte[] image;
if (isOnline) {
image = imageManager.getImage("personalonline", workgroup, getServletContext());
}
else {
image = imageManager.getImage("personaloffline", workgroup, getServletContext());
}
imageManager.writeBytesToStream(image, response);
}
示例7: getRosterEntries
import org.jivesoftware.smack.Roster; //导入方法依赖的package包/类
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>();
}
}
示例8: getPresence
import org.jivesoftware.smack.Roster; //导入方法依赖的package包/类
/**
* Returns the presence of a user.
*
* @param jid the users jid.
* @return the users presence.
*/
public static Presence getPresence(String jid) {
if (jid!= null && jid.equals(SparkManager.getSessionManager().getBareAddress())) {
return SparkManager.getWorkspace().getStatusBar().getPresence();
} else {
final Roster roster = SparkManager.getConnection().getRoster();
return roster.getPresence(jid);
}
}
示例9: authenticate
import org.jivesoftware.smack.Roster; //导入方法依赖的package包/类
/**
* Authenticating a particular user
*
* @return true if authentication is successful, and false otherwise.
*/
public boolean authenticate() {
//creating the connection
XMPPConnection connection = createConnection();
//connecting to the server
boolean connectionStatus = connect(connection);
if (!connectionStatus) {
log.info("Failed to connect to the Server");
return false;
}
//signing in
boolean loginStatus = login(connection);
if (!loginStatus) {
log.info("login failed");
return false;
}
Roster roster = connection.getRoster();
Presence presence = roster.getPresence(userXmppId);
boolean isAvailable = false;
if (!presence.isAvailable()) {
isAvailable = checkforUserAvailability(roster, userXmppId);
}
if (!isAvailable) {
log.info("user is not online");
return false;
}
boolean validation = getUserResponse(connection, userXmppId);
// Giving a second chance to provide the PIN
if (!validation && !pinDisabledResponse) {
validation = getUserResponse(connection, userXmppId);
}
return validation;
}
示例10: checkforUserAvailability
import org.jivesoftware.smack.Roster; //导入方法依赖的package包/类
/**
* Checking whether the user is available in the contact list.
*
* @param roster
* @param userXmppId
* @return
*/
public boolean checkforUserAvailability(Roster roster, String userXmppId) {
boolean isAvailable = false;
XmppSubscriptionListener listener = new XmppSubscriptionListener(userXmppId);
roster.addRosterListener(listener);
Presence presence = roster.getPresence(userXmppId);
boolean status = isAvailable(roster, userXmppId);
try {
if (!status) {
if (log.isInfoEnabled()) {
log.info("The User is not subscribed.");
}
boolean contactAddStatus = new XmppSubscriber().addContact(roster, userXmppId);
if (contactAddStatus) {
if (log.isInfoEnabled()) {
log.info("User's Contact is added successfully..");
}
} else {
if (log.isInfoEnabled()) {
log.info("Failed to add contact.");
}
}
if (!presence.isAvailable()) {
while (!listener.isOnline()) {
Thread.sleep(5000);
}
}
isAvailable = true;
} else {
if (log.isInfoEnabled()) {
log.info("User is not online..");
}
while (!listener.isOnline()) {
Thread.sleep(5000);
}
isAvailable = true;
}
} catch (InterruptedException e) {
log.error("Error while checking user availability", e);
} finally {
roster.removeRosterListener(listener);
}
return isAvailable;
}
示例11: loadByVcard
import org.jivesoftware.smack.Roster; //导入方法依赖的package包/类
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;
}
示例12: getUsers
import org.jivesoftware.smack.Roster; //导入方法依赖的package包/类
public List<UserInfo> getUsers(){
Roster roster = getConnection().getRoster();
Collection<RosterGroup> groups = roster.getGroups();
Collection<RosterEntry> entries = roster.getEntries();
List<UserInfo> users = null;
if(entries != null && !entries.isEmpty()){
users = new ArrayList<UserInfo>();
for (RosterEntry rosterEntry : entries) {
Presence presence = roster.getPresence(rosterEntry.getUser());
UserInfo user = new UserInfo();
user.setName(rosterEntry.getName());
user.setUser(rosterEntry.getUser());
user.setStatus(presence.getStatus());
user.setFrom(presence.getFrom());
users.add(user);
}
}
return users;
}
示例13: isOnline
import org.jivesoftware.smack.Roster; //导入方法依赖的package包/类
/**
* Returns true if the user is online.
*
* @param jid the jid of the user.
* @return true if online.
*/
public static boolean isOnline(String jid) {
final Roster roster = SparkManager.getConnection().getRoster();
Presence presence = roster.getPresence(jid);
return presence.isAvailable();
}
示例14: isAvailable
import org.jivesoftware.smack.Roster; //导入方法依赖的package包/类
/**
* Returns true if the user is online and their status is available or free to chat.
*
* @param jid the jid of the user.
* @return true if the user is online and available.
*/
public static boolean isAvailable(String jid) {
final Roster roster = SparkManager.getConnection().getRoster();
Presence presence = roster.getPresence(jid);
return presence.isAvailable() && !presence.isAway();
}
示例15: getFullyQualifiedJID
import org.jivesoftware.smack.Roster; //导入方法依赖的package包/类
/**
* Returns the fully qualified jid of a user.
*
* @param jid the users bare jid (ex. [email protected])
* @return the fully qualified jid of a user (ex. [email protected] --> [email protected]/spark)
*/
public static String getFullyQualifiedJID(String jid) {
final Roster roster = SparkManager.getConnection().getRoster();
Presence presence = roster.getPresence(jid);
return presence.getFrom();
}