Java Code Examples for org.jivesoftware.smack.packet.Presence#getFrom()

The following examples show how to use org.jivesoftware.smack.packet.Presence#getFrom() . 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: GroupChatJoinTask.java    From olat with Apache License 2.0 6 votes vote down vote up
/**
 * listen to new people joining the room in realtime and and set the new content which sets the component to dirty which forces it to redraw
 */
void addParticipationsListener() {
    participationsListener = new PacketListener() {

        @Override
        public void processPacket(final Packet packet) {
            final Presence presence = (Presence) packet;
            if (log.isDebugEnabled()) {
                log.debug("processPacket Presence: to=" + presence.getTo() + " , ");
            }
            if (presence.getFrom() != null) {
                listeningController.event(new InstantMessagingEvent(presence, "participant"));
            }
        }
    };
    muc.addParticipantListener(participationsListener);

}
 
Example 2
Source File: GroupChatJoinTask.java    From olat with Apache License 2.0 6 votes vote down vote up
/**
 * listen to new people joining the room in realtime and and set the new content which sets the component to dirty which forces it to redraw
 */
void addParticipationsListener() {
    participationsListener = new PacketListener() {

        @Override
        public void processPacket(final Packet packet) {
            final Presence presence = (Presence) packet;
            if (log.isDebugEnabled()) {
                log.debug("processPacket Presence: to=" + presence.getTo() + " , ");
            }
            if (presence.getFrom() != null) {
                listeningController.event(new InstantMessagingEvent(presence, "participant"));
            }
        }
    };
    muc.addParticipantListener(participationsListener);

}
 
Example 3
Source File: XMPPContactsService.java    From saros with GNU General Public License v2.0 6 votes vote down vote up
private void contactResourceChangedPresence(Presence presence) {
  if (roster == null) return;

  String address = presence.getFrom();
  XMPPContact contact = contacts.get(address);
  if (contact == null) {
    log.error("Should not happen: Contact " + address + " for presence update not found!");
    return;
  }

  JID fullJid = new JID(address);
  if (presence.isAvailable()) {
    handleContactResourceAvailable(contact, fullJid, presence);
  } else {
    handleContactResourceUnavailable(contact, fullJid);
  }
}
 
Example 4
Source File: XmppSubscriptionListener.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * Listennig for a change in presence of the user, eg: unavailable => available
 *
 * @param presence
 */
@Override
public void presenceChanged(Presence presence) {
    String user = presence.getFrom();
    if (user.contains(xmppUserId) && presence.isAvailable()) {
        isOnline = true;
    }
}
 
Example 5
Source File: SubscriptionHandler.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
private void processPresence(Presence presence) {
  if (presence.getFrom() == null) return;

  JID jid = new JID(presence.getFrom());

  switch (presence.getType()) {
    case error:
      String message =
          MessageFormat.format(
              "received error presence package from {0}, condition: {1}, message: {2}",
              presence.getFrom(),
              presence.getError().getCondition(),
              presence.getError().getMessage());
      log.warn(message);
      return;

    case subscribed:
      log.debug("contact subscribed to us: " + jid);
      break;

    case unsubscribed:
      log.debug("contact unsubscribed from us: " + jid);
      notifySubscriptionCanceled(jid);
      break;

    case subscribe:
      log.debug("contact requests to subscribe to us: " + jid);
      notifySubscriptionReceived(jid);
      break;

    case unsubscribe:
      log.debug("contact requests to unsubscribe from us: " + jid);
      removeSubscription(jid);
      break;

    default:
      // do nothing
  }
}
 
Example 6
Source File: PresenceManager.java    From Spark with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the fully qualified jid of a user. May return {@code null}.
 *
 * @param jidString the users bare jid (ex. [email protected])
 * @return the fully qualified jid of a user (ex. [email protected] --> [email protected]/spark) or {@code null}.
 */
public static EntityFullJid getFullyQualifiedJID(BareJid jid) {
    final Roster roster = Roster.getInstanceFor( SparkManager.getConnection() );
    Presence presence = roster.getPresence(jid);
    Jid result = presence.getFrom();
    EntityFullJid entityFullJid = result.asEntityFullJidIfPossible();
    return entityFullJid;
}
 
Example 7
Source File: NotificationPlugin.java    From Spark with Apache License 2.0 5 votes vote down vote up
@Override
public void processStanza(Stanza stanza) {
    final Presence presence = (Presence)stanza;
    Jid jid = presence.getFrom();
    if (jid == null) {
        return;
    }

    // Make sure the user is in the contact list.
    ContactItem contactItem = SparkManager.getWorkspace().getContactList().getContactItemByJID(jid);
    if (contactItem == null) {
        return;
    }

    BareJid bareJid = jid.asBareJid();
    boolean isOnline = onlineUsers.contains(jid);

    if (presence.isAvailable()) {
        if (preferences.isOnlineNotificationsOn()) {
            if (!isOnline) {
                notifyUserOnline(bareJid, presence);
            }
        }

        onlineUsers.add(bareJid);
    }
    else {
        if (preferences.isOfflineNotificationsOn() && isOnline) {
            notifyUserOffline(bareJid, presence);
        }

        onlineUsers.remove(bareJid);
    }
}
 
Example 8
Source File: UserManager.java    From Spark with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the full jid (with resource) based on the user's jid.
 *
 * @param jid the users bare jid.
 * @return the full jid with resource.
 */
public EntityFullJid getFullJID(BareJid bareJid) {
    Presence presence = PresenceManager.getPresence(bareJid);
    Jid jid =  presence.getFrom();
    return jid.asEntityFullJidIfPossible();
}