Remove Contact classes in favor of extended Peer logic
This commit is contained in:
parent
3cb2d79724
commit
d4de49e25b
|
@ -11,7 +11,7 @@ import org.mercury_im.messenger.xmpp.model.ChatModel;
|
|||
import org.mercury_im.messenger.xmpp.model.ContactModel;
|
||||
import org.mercury_im.messenger.xmpp.model.EntityModel;
|
||||
import org.mercury_im.messenger.xmpp.model.MessageModel;
|
||||
import org.mercury_im.messenger.data.repository.XmppContactRepository;
|
||||
import org.mercury_im.messenger.data.repository.XmppPeerRepository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -29,7 +29,7 @@ public class ChatViewModel extends ViewModel {
|
|||
MessageRepository messageRepository;
|
||||
|
||||
@Inject
|
||||
XmppContactRepository xmppContactRepository;
|
||||
XmppPeerRepository xmppContactRepository;
|
||||
|
||||
@Inject
|
||||
ChatRepository chatRepository;
|
||||
|
|
|
@ -7,14 +7,14 @@ import androidx.lifecycle.AndroidViewModel;
|
|||
import androidx.lifecycle.LiveData;
|
||||
|
||||
import org.mercury_im.messenger.xmpp.model.ContactModel;
|
||||
import org.mercury_im.messenger.data.repository.XmppContactRepository;
|
||||
import org.mercury_im.messenger.data.repository.XmppPeerRepository;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
public class ContactListItemViewModel extends AndroidViewModel {
|
||||
|
||||
@Inject
|
||||
XmppContactRepository contactRepository;
|
||||
XmppPeerRepository contactRepository;
|
||||
|
||||
private LiveData<ContactModel> contact;
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ import androidx.lifecycle.ViewModel;
|
|||
|
||||
import org.mercury_im.messenger.MercuryImApplication;
|
||||
import org.mercury_im.messenger.xmpp.model.ContactModel;
|
||||
import org.mercury_im.messenger.data.repository.XmppContactRepository;
|
||||
import org.mercury_im.messenger.data.repository.XmppPeerRepository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -22,7 +22,7 @@ import io.reactivex.schedulers.Schedulers;
|
|||
public class ContactListViewModel extends ViewModel {
|
||||
|
||||
@Inject
|
||||
XmppContactRepository xmppContactRepository;
|
||||
XmppPeerRepository xmppContactRepository;
|
||||
|
||||
private final MutableLiveData<List<ContactModel>> rosterEntryList = new MutableLiveData<>();
|
||||
private final CompositeDisposable compositeDisposable = new CompositeDisposable();
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package org.mercury_im.messenger.data.di;
|
||||
|
||||
import org.mercury_im.messenger.data.mapping.AccountMapping;
|
||||
import org.mercury_im.messenger.data.mapping.ContactMapping;
|
||||
import org.mercury_im.messenger.data.mapping.DirectChatMapping;
|
||||
import org.mercury_im.messenger.data.mapping.GroupChatMapping;
|
||||
import org.mercury_im.messenger.data.mapping.MessageContentMapping;
|
||||
|
@ -29,12 +28,6 @@ public class MappingModule {
|
|||
return new PeerMapping(provideAccountMapping());
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
static ContactMapping provideContactMapping() {
|
||||
return new ContactMapping(provideAccountMapping());
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
static DirectChatMapping provideDirectChatMapping() {
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
package org.mercury_im.messenger.data.di;
|
||||
|
||||
import org.mercury_im.messenger.data.repository.AccountRepository;
|
||||
import org.mercury_im.messenger.data.repository.ContactRepository;
|
||||
import org.mercury_im.messenger.data.repository.PeerRepository;
|
||||
import org.mercury_im.messenger.data.repository.DirectChatRepository;
|
||||
import org.mercury_im.messenger.data.repository.EntityCapsRepository;
|
||||
import org.mercury_im.messenger.data.repository.XmppAccountRepository;
|
||||
import org.mercury_im.messenger.data.repository.XmppDirectChatRepository;
|
||||
import org.mercury_im.messenger.data.repository.XmppContactRepository;
|
||||
import org.mercury_im.messenger.data.repository.XmppPeerRepository;
|
||||
import org.mercury_im.messenger.util.ThreadUtils;
|
||||
|
||||
import javax.inject.Named;
|
||||
|
@ -50,10 +50,10 @@ public class RepositoryModule {
|
|||
|
||||
@Provides
|
||||
@Singleton
|
||||
public static ContactRepository provideRosterRepository(
|
||||
public static PeerRepository provideRosterRepository(
|
||||
ReactiveEntityStore<Persistable> data,
|
||||
@Named(value = ThreadUtils.SCHEDULER_IO) Scheduler ioScheduler,
|
||||
@Named(value = ThreadUtils.SCHEDULER_UI) Scheduler uiScheduler) {
|
||||
return new XmppContactRepository(data, ioScheduler, uiScheduler);
|
||||
return new XmppPeerRepository(data, ioScheduler, uiScheduler);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,32 +0,0 @@
|
|||
package org.mercury_im.messenger.data.mapping;
|
||||
|
||||
import org.mercury_im.messenger.data.model.ContactModel;
|
||||
import org.mercury_im.messenger.entity.contact.Contact;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
public class ContactMapping implements Mapping<Contact, ContactModel> {
|
||||
|
||||
private final AccountMapping accountMapping;
|
||||
|
||||
@Inject
|
||||
public ContactMapping(AccountMapping accountMapping) {
|
||||
this.accountMapping = accountMapping;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContactModel entityToModel(Contact entity, ContactModel model) {
|
||||
if (entity == null) {
|
||||
return null;
|
||||
}
|
||||
if (model == null) {
|
||||
model = new ContactModel();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Contact modelToEntity(ContactModel model, Contact entity) {
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
package org.mercury_im.messenger.data.mapping;
|
||||
|
||||
import org.mercury_im.messenger.data.enums.SubscriptionDirection;
|
||||
import org.mercury_im.messenger.data.model.PeerModel;
|
||||
import org.mercury_im.messenger.entity.contact.IPeer;
|
||||
import org.mercury_im.messenger.entity.contact.Peer;
|
||||
|
@ -25,6 +26,10 @@ public class PeerMapping implements Mapping<Peer, PeerModel> {
|
|||
}
|
||||
model.setAccount(accountMapping.entityToModel(entity.getAccount(), model.getAccount()));
|
||||
model.setAddress(entity.getAddress());
|
||||
model.setName(entity.getName());
|
||||
|
||||
// TODO: sub direction
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
|
@ -39,6 +44,76 @@ public class PeerMapping implements Mapping<Peer, PeerModel> {
|
|||
entity.setAccount(accountMapping.modelToEntity(model.getAccount(), entity.getAccount()));
|
||||
entity.setAddress(model.getAddress());
|
||||
entity.setId(model.getId());
|
||||
|
||||
// TODO: Sub direction
|
||||
return entity;
|
||||
}
|
||||
|
||||
private void setSubscriptionDirectionInModel(PeerModel model, Peer entity) {
|
||||
switch (entity.getSubscriptionMode()) {
|
||||
case NONE:
|
||||
model.setSubscriptionDirection(SubscriptionDirection.none);
|
||||
model.setSubscriptionPreApproved(false);
|
||||
model.setSubscriptionPending(false);
|
||||
break;
|
||||
|
||||
case NONE_PREAPPROVED:
|
||||
model.setSubscriptionDirection(SubscriptionDirection.none);
|
||||
model.setSubscriptionPreApproved(true);
|
||||
model.setSubscriptionPending(false);
|
||||
break;
|
||||
|
||||
case TO_THEM_PENDING:
|
||||
model.setSubscriptionDirection(SubscriptionDirection.to);
|
||||
model.setSubscriptionPending(true);
|
||||
model.setSubscriptionPreApproved(false);
|
||||
break;
|
||||
case TO_THEM_PENDING_PREAPPROVED:
|
||||
model.setSubscriptionDirection(SubscriptionDirection.to);
|
||||
model.setSubscriptionPending(true);
|
||||
model.setSubscriptionPreApproved(true);
|
||||
break;
|
||||
case TO_THEM_ACCEPTED:
|
||||
model.setSubscriptionDirection(SubscriptionDirection.to);
|
||||
model.setSubscriptionPending(false);
|
||||
model.setSubscriptionPreApproved(false);
|
||||
break;
|
||||
case TO_THEM_ACCEPTED_PREAPPROVED:
|
||||
model.setSubscriptionDirection(SubscriptionDirection.to);
|
||||
model.setSubscriptionPending(false);
|
||||
model.setSubscriptionPreApproved(true);
|
||||
break;
|
||||
case FROM_THEM_PENDING:
|
||||
model.setSubscriptionDirection(SubscriptionDirection.from);
|
||||
model.setSubscriptionPending(true);
|
||||
model.setSubscriptionPreApproved(false);
|
||||
break;
|
||||
case FROM_THEM_ACCEPTED:
|
||||
model.setSubscriptionDirection(SubscriptionDirection.from);
|
||||
model.setSubscriptionPending(false);
|
||||
model.setSubscriptionPreApproved(false);
|
||||
break;
|
||||
case BIDIRECTIONAL:
|
||||
model.setSubscriptionDirection(SubscriptionDirection.both);
|
||||
model.setSubscriptionPending(false);
|
||||
model.setSubscriptionPreApproved(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void setSubscriptionDirectionInEntity(Peer entity, PeerModel model) {
|
||||
|
||||
switch (model.getSubscriptionDirection()) {
|
||||
case none:
|
||||
break;
|
||||
case to:
|
||||
break;
|
||||
case from:
|
||||
break;
|
||||
case both:
|
||||
break;
|
||||
case remove:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,45 +0,0 @@
|
|||
package org.mercury_im.messenger.data.model;
|
||||
|
||||
import org.mercury_im.messenger.data.converter.SubscriptionDirectionConverter;
|
||||
import org.mercury_im.messenger.data.enums.SubscriptionDirection;
|
||||
|
||||
import io.requery.Convert;
|
||||
import io.requery.Entity;
|
||||
import io.requery.ForeignKey;
|
||||
import io.requery.Generated;
|
||||
import io.requery.Key;
|
||||
import io.requery.OneToOne;
|
||||
import io.requery.Persistable;
|
||||
import io.requery.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name = "contacts")
|
||||
public abstract class AbstractContactModel implements Persistable {
|
||||
|
||||
@Key
|
||||
@Generated
|
||||
long id;
|
||||
|
||||
@OneToOne
|
||||
@ForeignKey(referencedColumn = "id")
|
||||
PeerModel entity;
|
||||
|
||||
String rostername;
|
||||
|
||||
@Convert(SubscriptionDirectionConverter.class)
|
||||
SubscriptionDirection sub_direction;
|
||||
|
||||
boolean sub_pending;
|
||||
|
||||
boolean sub_approved;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Contact[" + id + ", " +
|
||||
rostername + ", " +
|
||||
entity + ", " +
|
||||
sub_direction + ", " +
|
||||
(sub_pending ? "pending" : "not pending") + ", " +
|
||||
(sub_approved ? "approved" : "not approved") + "]";
|
||||
}
|
||||
}
|
|
@ -1,6 +1,10 @@
|
|||
package org.mercury_im.messenger.data.model;
|
||||
|
||||
import org.mercury_im.messenger.data.converter.SubscriptionDirectionConverter;
|
||||
import org.mercury_im.messenger.data.enums.SubscriptionDirection;
|
||||
|
||||
import io.requery.Column;
|
||||
import io.requery.Convert;
|
||||
import io.requery.Entity;
|
||||
import io.requery.ForeignKey;
|
||||
import io.requery.Generated;
|
||||
|
@ -10,7 +14,7 @@ import io.requery.Persistable;
|
|||
import io.requery.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name = "peers")
|
||||
@Table(name = "contacts")
|
||||
public abstract class AbstractPeerModel implements Persistable {
|
||||
|
||||
@Key @Generated
|
||||
|
@ -23,9 +27,20 @@ public abstract class AbstractPeerModel implements Persistable {
|
|||
@Column(nullable = false)
|
||||
String address;
|
||||
|
||||
@Column
|
||||
String name;
|
||||
|
||||
@Convert(SubscriptionDirectionConverter.class)
|
||||
SubscriptionDirection subscriptionDirection;
|
||||
|
||||
boolean subscriptionPending;
|
||||
|
||||
boolean subscriptionPreApproved;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Entity[" + id + ", " +
|
||||
return "Peer[" + id + ", " +
|
||||
name + ", " +
|
||||
address + ", " +
|
||||
account + "]";
|
||||
}
|
||||
|
|
|
@ -1,75 +0,0 @@
|
|||
package org.mercury_im.messenger.data.repository;
|
||||
|
||||
import org.mercury_im.messenger.data.util.Optional;
|
||||
import org.mercury_im.messenger.entity.contact.Contact;
|
||||
import org.mercury_im.messenger.util.ThreadUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
import io.reactivex.Completable;
|
||||
import io.reactivex.Maybe;
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.Scheduler;
|
||||
import io.reactivex.Single;
|
||||
import io.requery.Persistable;
|
||||
import io.requery.reactivex.ReactiveEntityStore;
|
||||
|
||||
public class XmppContactRepository
|
||||
extends RequeryRepository
|
||||
implements ContactRepository {
|
||||
|
||||
@Inject
|
||||
public XmppContactRepository(ReactiveEntityStore<Persistable> data,
|
||||
@Named(value = ThreadUtils.SCHEDULER_IO) Scheduler subscriberScheduler,
|
||||
@Named(value = ThreadUtils.SCHEDULER_UI) Scheduler observerScheduler) {
|
||||
super(data, subscriberScheduler, observerScheduler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Single<Contact> insertContact(Contact contact) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Observable<Optional<Contact>> observeContact(long contactId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Maybe<Contact> getContact(long contactId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Observable<Optional<Contact>> observeContactByAddress(String address) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Maybe<Contact> getContactByAddress(String address) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Observable<List<Contact>> observeAllContacts() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Single<Contact> updateContact(Contact contact) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Single<Contact> upsertContact(Contact contact) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Completable deleteContact(Contact contact) {
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
package org.mercury_im.messenger.data.repository;
|
||||
|
||||
import org.mercury_im.messenger.data.util.Optional;
|
||||
import org.mercury_im.messenger.entity.contact.Peer;
|
||||
import org.mercury_im.messenger.util.ThreadUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
import io.reactivex.Completable;
|
||||
import io.reactivex.Maybe;
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.Scheduler;
|
||||
import io.reactivex.Single;
|
||||
import io.requery.Persistable;
|
||||
import io.requery.reactivex.ReactiveEntityStore;
|
||||
|
||||
public class XmppPeerRepository
|
||||
extends RequeryRepository
|
||||
implements PeerRepository {
|
||||
|
||||
@Inject
|
||||
public XmppPeerRepository(ReactiveEntityStore<Persistable> data,
|
||||
@Named(value = ThreadUtils.SCHEDULER_IO) Scheduler subscriberScheduler,
|
||||
@Named(value = ThreadUtils.SCHEDULER_UI) Scheduler observerScheduler) {
|
||||
super(data, subscriberScheduler, observerScheduler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Single<Peer> insertPeer(Peer contact) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Observable<Optional<Peer>> observePeer(long contactId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Maybe<Peer> getPeer(long contactId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Observable<Optional<Peer>> observePeerByAddress(String address) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Maybe<Peer> getPeerByAddress(String address) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Observable<List<Peer>> observeAllPeers() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Single<Peer> updatePeer(Peer contact) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Single<Peer> upsertPeer(Peer contact) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Completable deletePeer(Peer contact) {
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -30,7 +30,7 @@ public class AccountRepositoryTest {
|
|||
XmppDirectChatRepository directChatRepository;
|
||||
|
||||
@Inject
|
||||
XmppContactRepository contactRepository;
|
||||
XmppPeerRepository contactRepository;
|
||||
|
||||
@Inject
|
||||
public AccountRepositoryTest() {
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
package org.mercury_im.messenger;
|
||||
|
||||
import org.mercury_im.messenger.data.repository.PeerRepository;
|
||||
import org.mercury_im.messenger.entity.Account;
|
||||
import org.mercury_im.messenger.entity.contact.Peer;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
public class DataStore {
|
||||
|
||||
@Inject
|
||||
PeerRepository peerRepository;
|
||||
|
||||
@Inject
|
||||
public DataStore() {
|
||||
|
||||
}
|
||||
|
||||
public Peer getPeer(Account account, String address) {
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -17,5 +17,4 @@ public class Messenger {
|
|||
public ConnectionMethod getConnection(Account account) {
|
||||
return connections.get(account.getId());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,32 +0,0 @@
|
|||
package org.mercury_im.messenger.data.repository;
|
||||
|
||||
import org.mercury_im.messenger.entity.contact.Contact;
|
||||
import org.mercury_im.messenger.data.util.Optional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.reactivex.Completable;
|
||||
import io.reactivex.Maybe;
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.Single;
|
||||
|
||||
public interface ContactRepository {
|
||||
|
||||
Single<Contact> insertContact(Contact contact);
|
||||
|
||||
Observable<Optional<Contact>> observeContact(long contactId);
|
||||
|
||||
Maybe<Contact> getContact(long contactId);
|
||||
|
||||
Observable<Optional<Contact>> observeContactByAddress(String address);
|
||||
|
||||
Maybe<Contact> getContactByAddress(String address);
|
||||
|
||||
Observable<List<Contact>> observeAllContacts();
|
||||
|
||||
Single<Contact> updateContact(Contact contact);
|
||||
|
||||
Single<Contact> upsertContact(Contact contact);
|
||||
|
||||
Completable deleteContact(Contact contact);
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package org.mercury_im.messenger.data.repository;
|
||||
|
||||
import org.mercury_im.messenger.entity.contact.Peer;
|
||||
import org.mercury_im.messenger.data.util.Optional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.reactivex.Completable;
|
||||
import io.reactivex.Maybe;
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.Single;
|
||||
|
||||
public interface PeerRepository {
|
||||
|
||||
Single<Peer> insertPeer(Peer Peer);
|
||||
|
||||
Observable<Optional<Peer>> observePeer(long PeerId);
|
||||
|
||||
Maybe<Peer> getPeer(long PeerId);
|
||||
|
||||
Observable<Optional<Peer>> observePeerByAddress(String address);
|
||||
|
||||
Maybe<Peer> getPeerByAddress(String address);
|
||||
|
||||
Observable<List<Peer>> observeAllPeers();
|
||||
|
||||
Single<Peer> updatePeer(Peer Peer);
|
||||
|
||||
Single<Peer> upsertPeer(Peer Peer);
|
||||
|
||||
Completable deletePeer(Peer Peer);
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
package org.mercury_im.messenger.entity.contact;
|
||||
|
||||
public interface Contact extends Peer {
|
||||
|
||||
SubscriptionMode getSubscriptionMode();
|
||||
|
||||
void setSubscriptionMode(SubscriptionMode mode);
|
||||
|
||||
enum SubscriptionMode {
|
||||
/**
|
||||
* No subscription between us an them.
|
||||
*/
|
||||
NONE,
|
||||
|
||||
/**
|
||||
* We sent a subscription request, which is now pending to be accepted.
|
||||
*/
|
||||
TO_THEM_PENDING,
|
||||
|
||||
/**
|
||||
* We sent a subscription request and they accepted it.
|
||||
*/
|
||||
TO_THEM_ACCEPTED,
|
||||
|
||||
/**
|
||||
* They sent us a subscription request, but we did not yet accept it.
|
||||
*/
|
||||
FROM_THEM_PENDING,
|
||||
|
||||
/**
|
||||
* They sent us a subscription request and we accepted it.
|
||||
*/
|
||||
FROM_THEM_ACCEPTED,
|
||||
|
||||
/**
|
||||
* They accepted us and we accepted them.
|
||||
*/
|
||||
BIDIRECTIONAL
|
||||
}
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
package org.mercury_im.messenger.entity.contact;
|
||||
|
||||
import org.mercury_im.messenger.entity.Account;
|
||||
|
||||
public class IContact implements Contact {
|
||||
|
||||
protected long id;
|
||||
protected Account account;
|
||||
protected String address;
|
||||
protected String name;
|
||||
protected SubscriptionMode subscriptionMode;
|
||||
|
||||
@Override
|
||||
public SubscriptionMode getSubscriptionMode() {
|
||||
return subscriptionMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSubscriptionMode(SubscriptionMode mode) {
|
||||
this.subscriptionMode = mode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Account getAccount() {
|
||||
return account;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAccount(Account account) {
|
||||
this.account = account;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAddress(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
|
@ -8,6 +8,7 @@ public class IPeer implements Peer {
|
|||
protected Account account;
|
||||
protected String address;
|
||||
protected String name;
|
||||
protected SubscriptionMode subscriptionMode;
|
||||
|
||||
@Override
|
||||
public long getId() {
|
||||
|
@ -48,4 +49,20 @@ public class IPeer implements Peer {
|
|||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SubscriptionMode getSubscriptionMode() {
|
||||
return subscriptionMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSubscriptionMode(SubscriptionMode mode) {
|
||||
this.subscriptionMode = mode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isContact() {
|
||||
return subscriptionMode != SubscriptionMode.NONE
|
||||
&& subscriptionMode != SubscriptionMode.FROM_THEM_PENDING;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,4 +23,10 @@ public interface Peer {
|
|||
String getName();
|
||||
|
||||
void setName(String name);
|
||||
|
||||
SubscriptionMode getSubscriptionMode();
|
||||
|
||||
void setSubscriptionMode(SubscriptionMode mode);
|
||||
|
||||
boolean isContact();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
package org.mercury_im.messenger.entity.contact;
|
||||
|
||||
public enum SubscriptionMode {
|
||||
/**
|
||||
* No subscription between us an them.
|
||||
*/
|
||||
NONE,
|
||||
|
||||
/**
|
||||
* No subscription between us and them.
|
||||
* However, we pre-approved their subscription, should they decide to subscribe to us.
|
||||
*/
|
||||
NONE_PREAPPROVED,
|
||||
|
||||
/**
|
||||
* We sent a subscription request, which is now pending to be accepted.
|
||||
* We do not pre-approve their subscription to us.
|
||||
*/
|
||||
TO_THEM_PENDING,
|
||||
|
||||
/**
|
||||
* We sent a subscription request, which is now pending to be accepted.
|
||||
* Also, we pre-approved their subscription to us.
|
||||
*/
|
||||
TO_THEM_PENDING_PREAPPROVED,
|
||||
|
||||
/**
|
||||
* We sent a subscription request and they approved it.
|
||||
*/
|
||||
TO_THEM_ACCEPTED,
|
||||
|
||||
/**
|
||||
* We sent a subscription request and they approved it.
|
||||
* Also, we pre-approved their subscription, should they decide to subscribe back.
|
||||
*/
|
||||
TO_THEM_ACCEPTED_PREAPPROVED,
|
||||
|
||||
/**
|
||||
* They sent us a subscription request, but we did not yet accept it.
|
||||
*/
|
||||
FROM_THEM_PENDING,
|
||||
|
||||
/**
|
||||
* They sent us a subscription request and we accepted it.
|
||||
*/
|
||||
FROM_THEM_ACCEPTED,
|
||||
|
||||
/**
|
||||
* They accepted us and we accepted them.
|
||||
*/
|
||||
BIDIRECTIONAL
|
||||
}
|
|
@ -1,26 +1,44 @@
|
|||
package org.mercury_im.messenger.domain.xmpp;
|
||||
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smack.chat2.Chat;
|
||||
import org.jivesoftware.smack.chat2.ChatManager;
|
||||
import org.jivesoftware.smack.chat2.IncomingChatMessageListener;
|
||||
import org.jivesoftware.smackx.sid.element.OriginIdElement;
|
||||
import org.jxmpp.jid.EntityBareJid;
|
||||
import org.jxmpp.jid.impl.JidCreate;
|
||||
import org.mercury_im.messenger.Messenger;
|
||||
import org.mercury_im.messenger.entity.Account;
|
||||
import org.mercury_im.messenger.entity.contact.Peer;
|
||||
import org.mercury_im.messenger.transport.listener.IncomingDirectMessageListener;
|
||||
import org.mercury_im.messenger.entity.message.Message;
|
||||
import org.mercury_im.messenger.MessageCenter;
|
||||
import org.mercury_im.messenger.entity.chat.DirectChat;
|
||||
import org.mercury_im.messenger.transport.xmpp.XmppTcpConnectionMethod;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import io.reactivex.Completable;
|
||||
import sun.reflect.generics.tree.Tree;
|
||||
|
||||
public class XmppDirectMessageCenter
|
||||
implements MessageCenter<DirectChat> {
|
||||
|
||||
private final Messenger messenger;
|
||||
private final Account account;
|
||||
|
||||
public XmppDirectMessageCenter(Messenger messenger) {
|
||||
private Set<IncomingDirectMessageListener> messageListeners = new LinkedHashSet<>();
|
||||
|
||||
public XmppDirectMessageCenter(Account account, Messenger messenger) {
|
||||
this.messenger = messenger;
|
||||
this.account = account;
|
||||
XMPPConnection connection = ((XmppTcpConnectionMethod) getMessenger()
|
||||
.getConnection(account)).getConnection();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -52,7 +70,7 @@ public class XmppDirectMessageCenter
|
|||
|
||||
@Override
|
||||
public void addIncomingMessageListener(IncomingDirectMessageListener listener) {
|
||||
|
||||
messageListeners.add(listener);
|
||||
}
|
||||
|
||||
protected ChatManager getChatManager(DirectChat chat) {
|
||||
|
|
Loading…
Reference in New Issue