Search in sources :

Example 6 with PseudoRosterItem

use of net.sf.kraken.pseudoroster.PseudoRosterItem in project Openfire by igniterealtime.

the class YahooSession 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) {
    // OpenYMSG requires a user to be in at least one group.
    if (groups == null) {
        groups = new ArrayList<String>();
    }
    if (groups.isEmpty()) {
        // add the default Yahoo group
        groups.add(DEFAULT_GROUPNAME);
    }
    // Syncing will take care of add.
    String contact = getTransport().convertJIDToID(jid);
    PseudoRosterItem rosterItem;
    if (pseudoRoster.hasItem(contact)) {
        rosterItem = pseudoRoster.getItem(contact);
        rosterItem.setNickname(nickname);
    } else {
        rosterItem = pseudoRoster.createItem(contact, nickname, groups);
    }
    YahooUser yUser = new YahooUser(contact);
    for (String grp : groups) {
        yUser.addGroupId(grp);
    }
    yahooSession.getRoster().add(yUser);
    YahooBuddy yBuddy = new YahooBuddy(getBuddyManager(), yUser, nickname, groups, rosterItem);
    getBuddyManager().storeBuddy(yBuddy);
}
Also used : YahooUser(org.openymsg.network.YahooUser) PseudoRosterItem(net.sf.kraken.pseudoroster.PseudoRosterItem)

Example 7 with PseudoRosterItem

use of net.sf.kraken.pseudoroster.PseudoRosterItem in project Openfire by igniterealtime.

the class YahooSession method updateContact.

/**
     * @see net.sf.kraken.session.TransportSession#updateContact(net.sf.kraken.roster.TransportBuddy)
     */
@Override
public void updateContact(YahooBuddy contact) {
    // Yahoo requires each user to be in at least one group.
    if (contact.getGroups() == null || contact.getGroups().isEmpty()) {
        List<String> defaultGroup = new ArrayList<String>();
        defaultGroup.add(DEFAULT_GROUPNAME);
        contact.setGroups(defaultGroup);
    }
    String yahooContact = getTransport().convertJIDToID(contact.getJID());
    PseudoRosterItem rosterItem;
    if (pseudoRoster.hasItem(yahooContact)) {
        rosterItem = pseudoRoster.getItem(yahooContact);
        rosterItem.setNickname(contact.getNickname());
    } else {
        rosterItem = pseudoRoster.createItem(yahooContact, contact.getNickname(), null);
    }
    try {
        YahooBuddy yBuddy = getBuddyManager().getBuddy(contact.getJID());
        yBuddy.pseudoRosterItem = rosterItem;
        for (String newGroup : yBuddy.getGroups()) {
            if (!yBuddy.yahooUser.getGroupIds().contains(newGroup)) {
                // Add new group to user
                yBuddy.yahooUser.addGroupId(newGroup);
            }
        }
        for (String oldGroup : yBuddy.yahooUser.getGroupIds()) {
            if (!yBuddy.getGroups().contains(oldGroup)) {
            // Remove group from user
            // TODO: This needs to be implemented...
            //yBuddy.yahooUser.removeGroupId(oldGroup);
            }
        }
    } catch (NotFoundException e) {
        Log.debug("Yahoo: Updated buddy not found in buddy manager: " + yahooContact);
    }
}
Also used : ArrayList(java.util.ArrayList) PseudoRosterItem(net.sf.kraken.pseudoroster.PseudoRosterItem) NotFoundException(org.jivesoftware.util.NotFoundException) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException)

Example 8 with PseudoRosterItem

use of net.sf.kraken.pseudoroster.PseudoRosterItem in project Openfire by igniterealtime.

the class SimpleSession method updateContact.

/**
     * @see net.sf.kraken.session.TransportSession#updateContact(net.sf.kraken.roster.TransportBuddy)
     */
@Override
public void updateContact(SimpleBuddy contact) {
    Log.debug("SimpleSession(" + jid.getNode() + ").updateContact:  I was called!");
    JID destJid = contact.getJID();
    String destId = getTransport().convertJIDToID(destJid);
    PseudoRosterItem rosterItem;
    if (pseudoRoster.hasItem(destId)) {
        rosterItem = pseudoRoster.getItem(destId);
        rosterItem.setNickname(contact.getNickname());
    } else {
        rosterItem = pseudoRoster.createItem(destId, contact.getNickname(), null);
    }
    try {
        SimpleBuddy simpleBuddy = getBuddyManager().getBuddy(destJid);
        simpleBuddy.pseudoRosterItem = rosterItem;
    } catch (NotFoundException e) {
        Log.debug("SIMPLE: Newly added buddy not found in buddy manager: " + destId);
    }
}
Also used : JID(org.xmpp.packet.JID) PseudoRosterItem(net.sf.kraken.pseudoroster.PseudoRosterItem) NotFoundException(org.jivesoftware.util.NotFoundException) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException)

Example 9 with PseudoRosterItem

use of net.sf.kraken.pseudoroster.PseudoRosterItem 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)

Example 10 with PseudoRosterItem

use of net.sf.kraken.pseudoroster.PseudoRosterItem in project Openfire by igniterealtime.

the class GaduGaduSession method updateContact.

/**
     * @see net.sf.kraken.session.TransportSession#updateContact(net.sf.kraken.roster.TransportBuddy)
     */
@Override
public void updateContact(GaduGaduBuddy contact) {
    String ggContact = getTransport().convertJIDToID(contact.getJID());
    if (pseudoRoster.hasItem(ggContact)) {
        PseudoRosterItem rosterItem = pseudoRoster.getItem(ggContact);
        rosterItem.setNickname(contact.getNickname());
        rosterItem.setGroups((List<String>) contact.getGroups());
    } else {
        PseudoRosterItem rosterItem = pseudoRoster.createItem(ggContact, contact.getNickname(), (List<String>) contact.getGroups());
        getBuddyManager().storeBuddy(new GaduGaduBuddy(getBuddyManager(), rosterItem));
    }
}
Also used : PseudoRosterItem(net.sf.kraken.pseudoroster.PseudoRosterItem)

Aggregations

PseudoRosterItem (net.sf.kraken.pseudoroster.PseudoRosterItem)10 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)4 NotFoundException (org.jivesoftware.util.NotFoundException)3 ArrayList (java.util.ArrayList)2 YahooUser (org.openymsg.network.YahooUser)2 GGException (pl.mn.communicator.GGException)2 LocalUser (pl.mn.communicator.LocalUser)2 User (pl.mn.communicator.User)2 ParseException (java.text.ParseException)1 TooManyListenersException (java.util.TooManyListenersException)1 InvalidArgumentException (javax.sip.InvalidArgumentException)1 SipException (javax.sip.SipException)1 Request (javax.sip.message.Request)1 JID (org.xmpp.packet.JID)1 IUser (pl.mn.communicator.IUser)1