use of org.jivesoftware.smack.packet.Presence in project intellij-plugins by JetBrains.
the class JabberTransport_ConnectionTest method testUserOnlineOffline.
public void testUserOnlineOffline() throws Throwable {
addEventListener();
String userName = "bob" + System.currentTimeMillis();
XMPPConnection contact = createLocalConnectionWithJabberUser(userName, null);
Roster roster = myTransport.getFacade().getConnection().getRoster();
String jabberUser = getUser(contact);
final User bob = UserImpl.create(jabberUser, myTransport.getName());
myEvents.clear();
roster.createEntry(jabberUser, "Bob", new String[0]);
new WaitFor(TIMEOUT) {
@Override
protected boolean condition() {
return myEvents.size() == 2;
}
};
assertTrue("Bob should be online", bob.isOnline());
assertEquals("/ideTalk/jabber.png", myTransport.getIcon(bob.getPresence()));
assertEquals("One user in UserModel expected:" + Arrays.asList(myUserModel.getAllUsers()), 1, myUserModel.getAllUsers().length);
UserEvent.Online online = ((UserEvent.Online) myEvents.get(1));
assertEquals("Online event expected", bob, online.getUser());
myEvents.clear();
Presence presence = new Presence(Presence.Type.unavailable);
contact.sendPacket(presence);
new WaitFor(TIMEOUT) {
@Override
protected boolean condition() {
return myEvents.size() == 1;
}
};
assertFalse("Should become offline", bob.isOnline());
assertEquals("/ideTalk/offline.png", myTransport.getIcon(myTransport.getUserPresence(bob)));
assertEquals("Bob should go offline", bob, ((UserEvent.Offline) checkEvent(true)).getUser());
}
use of org.jivesoftware.smack.packet.Presence in project intellij-plugins by JetBrains.
the class JabberFacade_ConnectionTest method testPresenceAfterConnection.
public void testPresenceAfterConnection() throws Throwable {
createGoodAccount(myUser, myFacade);
final String me = myFacade.getConnection().getUser();
myFacade.getConnection().getRoster().setSubscriptionMode(Roster.SubscriptionMode.accept_all);
final JabberFacadeImpl another = new JabberFacadeImpl(myIDEFacade);
createGoodAccount("ddd" + System.currentTimeMillis(), another);
another.addUsers("group", Arrays.asList(me));
new WaitFor(3000) {
@Override
protected boolean condition() {
return another.getConnection().getRoster().getPresence(me) != null;
}
};
Presence presence = another.getConnection().getRoster().getPresence(me);
assertNotNull(presence);
assertEquals(Presence.Type.available, presence.getType());
assertEquals(Presence.Mode.available, presence.getMode());
}
use of org.jivesoftware.smack.packet.Presence in project Essentials by drtshock.
the class XMPPManager method disconnect.
public final void disconnect() {
if (loggerThread != null) {
loggerThread.interrupt();
}
if (chatManager != null) {
chatManager.removeChatListener(this);
chatManager = null;
}
if (connection != null) {
connection.disconnect(new Presence(Presence.Type.unavailable));
}
}
use of org.jivesoftware.smack.packet.Presence in project Essentials by drtshock.
the class XMPPManager method updatePresence.
public final void updatePresence() {
final int usercount;
final StringBuilder stringBuilder = new StringBuilder();
usercount = parent.getEss().getOnlinePlayers().size();
if (usercount == 0) {
final String presenceMsg = "No one online.";
connection.sendPacket(new Presence(Presence.Type.available, presenceMsg, 2, Presence.Mode.dnd));
}
if (usercount == 1) {
final String presenceMsg = "1 player online.";
connection.sendPacket(new Presence(Presence.Type.available, presenceMsg, 2, Presence.Mode.available));
}
if (usercount > 1) {
stringBuilder.append(usercount).append(" players online.");
connection.sendPacket(new Presence(Presence.Type.available, stringBuilder.toString(), 2, Presence.Mode.available));
}
}
Aggregations