blob: 7ce0412eedcc9daf1dc8f912a5faed38b25b03a4 [file] [log] [blame]
/****************************************************************************
* Copyright (c) 2006, 2007 Remy Suen, Composent Inc., and others.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* Contributors:
* Remy Suen <remy.suen@gmail.com> - initial API and implementation
*
* SPDX-License-Identifier: EPL-2.0
*****************************************************************************/
package org.eclipse.ecf.internal.provider.msn;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.ecf.core.identity.ID;
import org.eclipse.ecf.core.identity.IDCreateException;
import org.eclipse.ecf.core.identity.Namespace;
import org.eclipse.ecf.core.user.IUser;
import org.eclipse.ecf.presence.IPresence;
import org.eclipse.ecf.presence.roster.IRoster;
import org.eclipse.ecf.presence.roster.IRosterEntry;
import org.eclipse.ecf.presence.roster.IRosterItem;
import org.eclipse.ecf.protocol.msn.Contact;
import org.eclipse.ecf.protocol.msn.Status;
final class MSNRosterEntry implements IPresence, IRosterEntry, IUser {
private static final long serialVersionUID = 5358415024505371809L;
private Collection groups;
private IRosterItem parent;
private final Contact contact;
private MSNID id;
private IRoster roster;
private Map properties;
MSNRosterEntry(IRoster roster, Contact contact, Namespace namespace) {
this.roster = roster;
this.contact = contact;
groups = Collections.EMPTY_LIST;
properties = new HashMap(1);
try {
id = (MSNID) namespace.createInstance(new Object[] { contact
.getEmail() });
} catch (IDCreateException e) {
// ignored since this is not possible
}
}
void updatePersonalMessage() {
String message = contact.getPersonalMessage();
if (message.equals("")) { //$NON-NLS-1$
properties.remove(Messages.MSNRosterEntry_Message);
} else {
properties.put(Messages.MSNRosterEntry_Message, message);
}
}
Contact getContact() {
return contact;
}
public String getName() {
return contact.getDisplayName();
}
public Mode getMode() {
Status status = contact.getStatus();
if (status == Status.ONLINE) {
return Mode.AVAILABLE;
} else if (status == Status.BUSY) {
return Mode.DND;
} else if (status == Status.APPEAR_OFFLINE) {
return Mode.INVISIBLE;
} else {
return Mode.AWAY;
}
}
public Map getProperties() {
return properties;
}
public String getStatus() {
return contact.getPersonalMessage();
}
public Type getType() {
return contact.getStatus() == Status.OFFLINE ? Type.UNAVAILABLE
: Type.AVAILABLE;
}
public Object getAdapter(Class adapter) {
if (adapter != null && adapter.isInstance(this)) {
return this;
} else {
return null;
}
}
public Collection getGroups() {
return groups;
}
public IPresence getPresence() {
return this;
}
public IUser getUser() {
return this;
}
void setParent(IRosterItem parent) {
this.parent = parent;
if (parent instanceof IRoster) {
groups = Collections.EMPTY_LIST;
} else {
ArrayList list = new ArrayList(1);
list.add(parent);
groups = Collections.unmodifiableCollection(list);
}
}
public IRosterItem getParent() {
return parent;
}
public byte[] getPictureData() {
// TODO: update this when avatars have been implemented
return new byte[0];
}
public ID getID() {
return id;
}
public String getNickname() {
return contact.getDisplayName();
}
public IRoster getRoster() {
return roster;
}
}