org.jivesoftware.smack.packet.Presence.Type Java Examples

The following examples show how to use org.jivesoftware.smack.packet.Presence.Type. 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: RosterEntry.java    From Smack with Apache License 2.0 6 votes vote down vote up
/**
 * Sets the name associated with this entry.
 *
 * @param name the name.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws XMPPErrorException if there was an XMPP error returned.
 * @throws NoResponseException if there was no response from the remote entity.
 * @throws InterruptedException if the calling thread was interrupted.
 */
public synchronized void setName(String name) throws NotConnectedException, NoResponseException, XMPPErrorException, InterruptedException {
    // Do nothing if the name hasn't changed.
    if (name != null && name.equals(getName())) {
        return;
    }

    RosterPacket packet = new RosterPacket();
    packet.setType(IQ.Type.set);

    // Create a new roster item with the current RosterEntry and the *new* name. Note that we can't set the name of
    // RosterEntry right away, as otherwise the updated event wont get fired, because equalsDeep would return true.
    packet.addRosterItem(toRosterItem(this, name));
    connection().createStanzaCollectorAndSend(packet).nextResultOrThrow();

    // We have received a result response to the IQ set, the name was successfully changed
    item.setName(name);
}
 
Example #2
Source File: XmppVcard.java    From yiim_v2 with GNU General Public License v2.0 6 votes vote down vote up
public void updatePresence() {
	try {
		Connection connection = XmppConnectionUtils.getInstance()
				.getConnection();
		if (connection != null && connection.isConnected()
				&& connection.isAuthenticated()) {
			// 在线状态获取
			Presence presence = connection.getRoster().getPresence(mUserId);
			if (presence.getType() != Type.unavailable) {
				setPresence("online");
			} else {
				setPresence("unavailable");
			}
			saveToDatabase();
		}
	} catch (Exception e) {
		// TODO: handle exception
	}
}
 
Example #3
Source File: SubscriptionHandler.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
private boolean sendUnsubscribedPresence(JID jid) {
  boolean success = true;

  try {
    sendPresence(Presence.Type.unsubscribed, jid.getBase());
  } catch (IllegalStateException e) {
    log.error("failed to send unsubscribed message, not connected to a XMPP server", e);

    success = false;
  }

  return success;
}
 
Example #4
Source File: SubscriptionHandler.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
private boolean sendSubscribedPresence(JID jid) {
  boolean success = true;

  try {
    sendPresence(Presence.Type.subscribed, jid.getBase());
  } catch (IllegalStateException e) {
    log.error("failed to send subscribe message, not connected to a XMPP server", e);

    success = false;
  }

  return success;
}
 
Example #5
Source File: RosterEntry.java    From Smack with Apache License 2.0 5 votes vote down vote up
/**
 * Cancel the presence subscription the XMPP entity representing this roster entry has with us.
 *
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 * @since 4.2
 */
public void cancelSubscription() throws NotConnectedException, InterruptedException {
    XMPPConnection connection = connection();
    Presence unsubscribed = connection.getStanzaFactory().buildPresenceStanza()
            .to(item.getJid())
            .ofType(Type.unsubscribed)
            .build();
    connection.sendStanza(unsubscribed);
}
 
Example #6
Source File: XmppLoginRunnable.java    From yiim_v2 with GNU General Public License v2.0 4 votes vote down vote up
public XmppLoginRunnable(XmppListener listener) {
	super(listener);
	mType = Type.available;
	mMode = Mode.available;
	mStatus = null;
}
 
Example #7
Source File: SubscriptionHandler.java    From saros with GNU General Public License v2.0 4 votes vote down vote up
private void sendPresence(Presence.Type type, String to) {
  Presence presence = new Presence(type);
  presence.setTo(to);
  presence.setFrom(connection.getUser());
  connection.sendPacket(presence);
}
 
Example #8
Source File: PresenceTypeFilter.java    From Smack with Apache License 2.0 4 votes vote down vote up
private PresenceTypeFilter(Presence.Type type) {
    super(Presence.class);
    this.type = Objects.requireNonNull(type, "type must not be null");
}
 
Example #9
Source File: XmppLoginRunnable.java    From yiim_v2 with GNU General Public License v2.0 4 votes vote down vote up
public void setType(Type type) {
	this.mType = type;
}
 
Example #10
Source File: XmppVcard.java    From yiim_v2 with GNU General Public License v2.0 4 votes vote down vote up
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 #11
Source File: ClientHelper.java    From olat with Apache License 2.0 4 votes vote down vote up
/**
 * send a presence packet "unavailable" to all buddies
 */
public void sendPresenceUnavailable() {
    imc.sendPresence(Presence.Type.unavailable, null, 0, null);
}
 
Example #12
Source File: ClientHelper.java    From olat with Apache License 2.0 4 votes vote down vote up
/**
 * send a presence packet "unavailable" to all buddies
 */
public void sendPresenceUnavailable() {
    imc.sendPresence(Presence.Type.unavailable, null, 0, null);
}
 
Example #13
Source File: ClientHelper.java    From olat with Apache License 2.0 2 votes vote down vote up
/**
 * @param type
 * @param status
 * @param priority
 * @param mode
 */
public void sendPresence(final Type type, final String status, final int priority, final Mode mode) {
    imc.sendPresence(type, status, priority, mode);
}
 
Example #14
Source File: Friend.java    From League-of-Legends-XMPP-Chat-Library with MIT License 2 votes vote down vote up
/**
 * Returns true if this friend is online.
 * 
 * @return true if online, false if offline
 */
public boolean isOnline() {
	return con.getRoster().getPresence(getUserId()).getType() == Type.available;
}
 
Example #15
Source File: ClientHelper.java    From olat with Apache License 2.0 2 votes vote down vote up
/**
 * send a presence packet "available" with a certain mode e.g. "away" to all buddies
 * 
 * @param mode
 */
public void sendPresenceAvailable(final Presence.Mode mode) {
    imc.sendPresence(Presence.Type.available, null, 0, mode);
}
 
Example #16
Source File: ClientHelper.java    From olat with Apache License 2.0 2 votes vote down vote up
/**
 * @param type
 * @param status
 * @param priority
 * @param mode
 */
public void sendPresence(final Type type, final String status, final int priority, final Mode mode) {
    imc.sendPresence(type, status, priority, mode);
}
 
Example #17
Source File: ClientHelper.java    From olat with Apache License 2.0 2 votes vote down vote up
/**
 * send a presence packet "available" with a certain mode e.g. "away" to all buddies
 * 
 * @param mode
 */
public void sendPresenceAvailable(final Presence.Mode mode) {
    imc.sendPresence(Presence.Type.available, null, 0, mode);
}