Mercury-IM/entity/src/main/java/org/mercury_im/messenger/entity/contact/Peer.java

42 lines
1008 B
Java
Raw Normal View History

2019-11-18 23:51:27 +01:00
package org.mercury_im.messenger.entity.contact;
2020-06-15 17:41:13 +02:00
import org.jxmpp.jid.EntityBareJid;
import org.jxmpp.jid.impl.JidCreate;
2019-11-18 23:51:27 +01:00
import org.mercury_im.messenger.entity.Account;
2020-06-05 13:45:53 +02:00
import java.util.List;
2019-12-21 16:30:14 +01:00
import java.util.UUID;
2020-05-16 15:53:54 +02:00
import lombok.Data;
/**
* Defines a user on the network (eg. a contact, chat partner, group chat member etc).
* Basically anyone that may send you a message is a Peer.
*/
2020-05-16 15:53:54 +02:00
@Data
public class Peer {
UUID id;
Account account;
String address;
String name;
SubscriptionDirection subscriptionDirection;
boolean subscriptionPending;
boolean subscriptionApproved;
2020-06-05 13:45:53 +02:00
List<String> groupNames;
2020-05-16 15:53:54 +02:00
2020-05-31 22:32:33 +02:00
public Peer() {
this.id = UUID.randomUUID();
}
2020-05-16 15:53:54 +02:00
public String getDisplayName() {
if (name != null && !name.trim().isEmpty()) {
2020-05-16 15:53:54 +02:00
return name;
}
return address.substring(0, address.indexOf('@'));
}
2020-06-15 17:41:13 +02:00
public EntityBareJid getJid() {
return JidCreate.entityBareFromOrThrowUnchecked(getAddress());
}
}