Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inform ourselves of presence info. #538

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -947,15 +947,18 @@ public RosterEntry getEntry(BareJid jid) {
}

/**
* Returns true if the specified XMPP address is an entry in the roster.
* Returns true if the specified XMPP address is an entry in the roster, or is
* a resource of the logged in user.
*
* @param jid the XMPP address of the user (eg "jsmith@example.com"). The
* address must be a bare JID e.g. "domain/resource" or
* "user@domain".
* @return true if the XMPP address is an entry in the roster.
*/
public boolean contains(BareJid jid) {
return getEntry(jid) != null;
RosterEntry entry = getEntry(jid);
EntityFullJid user = connection().getUser();
return entry != null || (user != null && jid.isParentOf(user));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,32 @@ public void testEmptyGroupRosterPush() throws Throwable {
assertSame("Wrong number of roster entries.", 4, roster.getEntries().size());
}

@Test
public void testContactBelongsToRoster() throws Exception {
assertNotNull("Can't get the roster from the provided connection!", roster);
initRoster();

// Verify the contact belongs to roster
final BareJid contactJID = JidCreate.entityBareFrom("romeo@example.net");
assertTrue("Contact doesn't belong to the roster.", roster.contains(contactJID));

// Verify the non-existent contact does not belong to roster
final BareJid nonExistentContactJID = JidCreate.entityBareFrom("juliet@example.net");
assertFalse("Non-existent contact found in the roster.", roster.contains(nonExistentContactJID));
}

@Test
public void testAccountBelongsToRoster() {
// Verify the connection account belongs to roster
final BareJid accountJID = connection.getUser().asBareJid();
assertTrue("Connection account doesn't belong to the connected roster.", roster.contains(accountJID));

connection.instantShutdown();

// Verify the connection account no longer belongs to the roster now it has been disconnected.
assertFalse("Connection account erroneously belongs to the disconnected roster.", roster.contains(accountJID));
}

/**
* Remove all roster entries by iterating trough {@link Roster#getEntries()}
* and simulating receiving roster pushes from the server.
Expand Down