Search in sources :

Example 1 with GGException

use of pl.mn.communicator.GGException in project Openfire by igniterealtime.

the class GaduGaduListener method contactListReceived.

@SuppressWarnings("unchecked")
public void contactListReceived(Collection collection) {
    Log.debug("GaduGadu: Contact list received: " + collection);
    for (Object localUserObj : collection) {
        LocalUser localUser = (LocalUser) localUserObj;
        if (localUser.getUin() > 0) {
            String ggContact = Integer.toString(localUser.getUin());
            String nickname = localUser.getDisplayName();
            List<String> groups = new ArrayList<String>();
            groups.add(localUser.getGroup());
            if (getSession().getPseudoRoster().hasItem(ggContact)) {
                PseudoRosterItem rosterItem = getSession().getPseudoRoster().getItem(ggContact);
                rosterItem.setNickname(nickname);
                rosterItem.setGroups(groups);
            } else {
                PseudoRosterItem rosterItem = getSession().getPseudoRoster().createItem(ggContact, nickname, groups);
                getSession().getBuddyManager().storeBuddy(new GaduGaduBuddy(getSession().getBuddyManager(), localUser, rosterItem));
            }
            try {
                getSession().iSession.getPresenceService().addMonitoredUser(new User(localUser.getUin()));
            } catch (GGException e) {
                Log.debug("GaduGadu: Error while setting up user to be monitored:", e);
            }
        } else {
            Log.debug("GaduGadu: Ignoring user with UIN less than -1: " + localUser);
        }
    }
}
Also used : GGException(pl.mn.communicator.GGException) LocalUser(pl.mn.communicator.LocalUser) User(pl.mn.communicator.User) IUser(pl.mn.communicator.IUser) ArrayList(java.util.ArrayList) PseudoRosterItem(net.sf.kraken.pseudoroster.PseudoRosterItem) LocalUser(pl.mn.communicator.LocalUser)

Example 2 with GGException

use of pl.mn.communicator.GGException in project Openfire by igniterealtime.

the class GaduGaduSession method removeContact.

/**
     * @see net.sf.kraken.session.TransportSession#removeContact(net.sf.kraken.roster.TransportBuddy)
     */
@Override
public void removeContact(GaduGaduBuddy contact) {
    String ggContact = getTransport().convertJIDToID(contact.getJID());
    pseudoRoster.removeItem(ggContact);
    for (GaduGaduBuddy buddy : getBuddyManager().getBuddies()) {
        if (buddy.getJID().equals(contact.getJID())) {
            LocalUser byeUser = buddy.toLocalUser();
            try {
                iSession.getPresenceService().removeMonitoredUser(new User(byeUser.getUin()));
            } catch (GGException e) {
                Log.debug("GaduGadu: Error while removing user from being monitored during delete:", e);
            }
            break;
        }
    }
}
Also used : GGException(pl.mn.communicator.GGException) User(pl.mn.communicator.User) LocalUser(pl.mn.communicator.LocalUser) LocalUser(pl.mn.communicator.LocalUser)

Example 3 with GGException

use of pl.mn.communicator.GGException in project Openfire by igniterealtime.

the class GaduGaduSession method logIn.

/**
     * @see net.sf.kraken.session.TransportSession#logIn(net.sf.kraken.type.PresenceType, String)
     */
@Override
public void logIn(PresenceType presenceType, String verboseStatus) {
    setPendingPresenceAndStatus(presenceType, verboseStatus);
    if (!isLoggedIn()) {
        loginContext = new LoginContext(idNumber, registration.getPassword());
        listener = new GaduGaduListener(this);
        iSession = new Session(new GGConfiguration());
        iSession.getConnectionService().addConnectionListener(listener);
        iSession.getLoginService().addLoginListener(listener);
        iSession.getMessageService().addMessageListener(listener);
        iSession.getContactListService().addContactListListener(listener);
        iSession.getPresenceService().addUserListener(listener);
        try {
            IServer iServer = iSession.getConnectionService().lookupServer(idNumber);
            iSession.getConnectionService().connect(iServer);
        } catch (GGException e) {
            Log.debug("GaduGadu: Unable to establish connection:", e);
            setFailureStatus(ConnectionFailureReason.CAN_NOT_CONNECT);
            sessionDisconnected("Unable to establish connection.");
        }
    }
}
Also used : IServer(pl.mn.communicator.IServer) GGException(pl.mn.communicator.GGException) LoginContext(pl.mn.communicator.LoginContext) GGConfiguration(pl.mn.communicator.GGConfiguration) TransportSession(net.sf.kraken.session.TransportSession) Session(pl.mn.communicator.Session) ISession(pl.mn.communicator.ISession)

Example 4 with GGException

use of pl.mn.communicator.GGException in project Openfire by igniterealtime.

the class GaduGaduSession method loadRoster.

/**
     * Loads the stored roster and adds them to have their presence monitored.
     */
void loadRoster() {
    for (String contact : pseudoRoster.getContacts()) {
        User user = new User(Integer.valueOf(contact));
        // Load actual buddy roster
        getBuddyManager().storeBuddy(new GaduGaduBuddy(getBuddyManager(), pseudoRoster.getItem(contact)));
        // Set up each roster item to be monitored for presence
        try {
            iSession.getPresenceService().addMonitoredUser(user);
        } catch (GGException e) {
            Log.debug("GaduGadu: Error while setting up user to be monitored during add:", e);
        }
    }
}
Also used : GGException(pl.mn.communicator.GGException) User(pl.mn.communicator.User) LocalUser(pl.mn.communicator.LocalUser)

Example 5 with GGException

use of pl.mn.communicator.GGException in project Openfire by igniterealtime.

the class GaduGaduSession method addContact.

/**
     * @see net.sf.kraken.session.TransportSession#addContact(org.xmpp.packet.JID, String, java.util.ArrayList)
     */
@Override
public void addContact(JID jid, String nickname, ArrayList<String> groups) {
    String contact = getTransport().convertJIDToID(jid);
    if (nickname == null || nickname.length() < 1) {
        nickname = jid.toBareJID();
    }
    LocalUser newUser = new LocalUser();
    newUser.setUin(Integer.parseInt(contact));
    newUser.setDisplayName(nickname);
    if (groups.size() > 0) {
        newUser.setGroup(groups.get(0));
    }
    PseudoRosterItem rosterItem;
    if (pseudoRoster.hasItem(contact)) {
        rosterItem = pseudoRoster.getItem(contact);
        rosterItem.setNickname(nickname);
        rosterItem.setGroups(groups);
    } else {
        rosterItem = pseudoRoster.createItem(contact, nickname, groups);
    }
    getBuddyManager().storeBuddy(new GaduGaduBuddy(getBuddyManager(), newUser, rosterItem));
    try {
        iSession.getPresenceService().addMonitoredUser(new User(newUser.getUin()));
    } catch (GGException e) {
        Log.debug("GaduGadu: Error while setting up user to be monitored during add:", e);
    }
}
Also used : GGException(pl.mn.communicator.GGException) User(pl.mn.communicator.User) LocalUser(pl.mn.communicator.LocalUser) PseudoRosterItem(net.sf.kraken.pseudoroster.PseudoRosterItem) LocalUser(pl.mn.communicator.LocalUser)

Aggregations

GGException (pl.mn.communicator.GGException)5 LocalUser (pl.mn.communicator.LocalUser)4 User (pl.mn.communicator.User)4 PseudoRosterItem (net.sf.kraken.pseudoroster.PseudoRosterItem)2 ArrayList (java.util.ArrayList)1 TransportSession (net.sf.kraken.session.TransportSession)1 GGConfiguration (pl.mn.communicator.GGConfiguration)1 IServer (pl.mn.communicator.IServer)1 ISession (pl.mn.communicator.ISession)1 IUser (pl.mn.communicator.IUser)1 LoginContext (pl.mn.communicator.LoginContext)1 Session (pl.mn.communicator.Session)1