2014-05-19 09:15:09 -04:00
|
|
|
package eu.siacs.conversations.entities;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2014-07-04 10:22:19 -04:00
|
|
|
import java.util.Locale;
|
2014-06-01 13:17:05 -04:00
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
2014-05-19 09:15:09 -04:00
|
|
|
|
|
|
|
public class Roster {
|
|
|
|
Account account;
|
2014-06-01 13:17:05 -04:00
|
|
|
ConcurrentHashMap<String, Contact> contacts = new ConcurrentHashMap<String, Contact>();
|
2014-05-19 09:15:09 -04:00
|
|
|
private String version = null;
|
2014-08-31 10:28:21 -04:00
|
|
|
|
2014-05-19 09:15:09 -04:00
|
|
|
public Roster(Account account) {
|
|
|
|
this.account = account;
|
|
|
|
}
|
2014-08-31 10:28:21 -04:00
|
|
|
|
2014-05-19 09:15:09 -04:00
|
|
|
public boolean hasContact(String jid) {
|
|
|
|
String cleanJid = jid.split("/")[0];
|
|
|
|
return contacts.containsKey(cleanJid);
|
|
|
|
}
|
2014-08-31 10:28:21 -04:00
|
|
|
|
2014-05-19 09:15:09 -04:00
|
|
|
public Contact getContact(String jid) {
|
2014-07-04 10:22:19 -04:00
|
|
|
String cleanJid = jid.split("/")[0].toLowerCase(Locale.getDefault());
|
2014-05-19 09:15:09 -04:00
|
|
|
if (contacts.containsKey(cleanJid)) {
|
|
|
|
return contacts.get(cleanJid);
|
|
|
|
} else {
|
|
|
|
Contact contact = new Contact(cleanJid);
|
|
|
|
contact.setAccount(account);
|
|
|
|
contacts.put(cleanJid, contact);
|
|
|
|
return contact;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void clearPresences() {
|
2014-08-31 10:28:21 -04:00
|
|
|
for (Contact contact : getContacts()) {
|
2014-05-22 06:57:47 -04:00
|
|
|
contact.clearPresences();
|
|
|
|
}
|
2014-05-19 09:15:09 -04:00
|
|
|
}
|
2014-08-31 10:28:21 -04:00
|
|
|
|
2014-05-19 09:15:09 -04:00
|
|
|
public void markAllAsNotInRoster() {
|
2014-08-31 10:28:21 -04:00
|
|
|
for (Contact contact : getContacts()) {
|
2014-05-22 06:57:47 -04:00
|
|
|
contact.resetOption(Contact.Options.IN_ROSTER);
|
|
|
|
}
|
|
|
|
}
|
2014-08-31 10:28:21 -04:00
|
|
|
|
2014-05-22 06:57:47 -04:00
|
|
|
public void clearSystemAccounts() {
|
2014-08-31 10:28:21 -04:00
|
|
|
for (Contact contact : getContacts()) {
|
2014-05-22 06:57:47 -04:00
|
|
|
contact.setPhotoUri(null);
|
|
|
|
contact.setSystemName(null);
|
|
|
|
contact.setSystemAccount(null);
|
|
|
|
}
|
2014-05-19 09:15:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public List<Contact> getContacts() {
|
|
|
|
return new ArrayList<Contact>(this.contacts.values());
|
|
|
|
}
|
|
|
|
|
|
|
|
public void initContact(Contact contact) {
|
|
|
|
contact.setAccount(account);
|
|
|
|
contact.setOption(Contact.Options.IN_ROSTER);
|
2014-08-31 10:28:21 -04:00
|
|
|
contacts.put(contact.getJid(), contact);
|
2014-05-19 09:15:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setVersion(String version) {
|
|
|
|
this.version = version;
|
|
|
|
}
|
2014-08-31 10:28:21 -04:00
|
|
|
|
2014-05-19 09:15:09 -04:00
|
|
|
public String getVersion() {
|
|
|
|
return this.version;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Account getAccount() {
|
|
|
|
return this.account;
|
|
|
|
}
|
|
|
|
}
|