0
votes

I am using smack API to accept or reject the contact request sent to a user. Before I render the client (my product has a notification system and I create a notification to the user when he/she is added to somebody's roster), I would like to know the status of the subscription request. So that I can show accept/reject buttons for the user to act upon and if the action already happened would render saying "You have already accepted/rejected" kind of a message.

I understand that if user A had received a request from B and if A accepts the request then the subscription status of the roster entry becomes FROM or BOTH. But how can I figure out whether I have rejected a subscription request from a certain user?

1

1 Answers

0
votes

To listen if user has rejected your add buddy request. You need to register a PacketListener with filtering of packets of Presence class. In it you will get an presence packet of type unsubscribed from the user, who has rejected the request.

public class RequestListener implements PacketListener {
    @Override
    public void processPacket(Packet pack) {
        Presence pres = (Presence) pack;
        if (pres.getType() != null && 
                     pres.getType().equals(Presence.Type.unsubscribed)) {
            // user with jid pres.getFrom() rejected your request.
        }
    }
}

// somewhere in code to register the request listener after login
connection.addPacketListener(new RequestListener(), 
      new PacketTypeFilter(Presence.class));