Utilize lombok in entity
This commit is contained in:
parent
c52ff7ed25
commit
44d066117d
|
@ -84,8 +84,8 @@ dependencies {
|
|||
implementation "com.google.dagger:dagger:$daggerVersion"
|
||||
annotationProcessor "com.google.dagger:dagger-compiler:$daggerVersion"
|
||||
|
||||
compileOnly 'org.projectlombok:lombok:1.18.10'
|
||||
annotationProcessor 'org.projectlombok:lombok:1.18.10'
|
||||
compileOnly "org.projectlombok:lombok:$lombokVersion"
|
||||
annotationProcessor "org.projectlombok:lombok:$lombokVersion"
|
||||
|
||||
// ViewModel and LiveData
|
||||
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycleVersion"
|
||||
|
|
|
@ -16,6 +16,12 @@ import com.google.android.material.floatingactionbutton.ExtendedFloatingActionBu
|
|||
|
||||
import org.mercury_im.messenger.R;
|
||||
import org.mercury_im.messenger.entity.Account;
|
||||
import org.mercury_im.messenger.xmpp.MercuryConnection;
|
||||
import org.mercury_im.messenger.xmpp.state.ConnectionState;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
@ -58,7 +64,14 @@ public class AccountsFragment extends Fragment {
|
|||
}
|
||||
|
||||
private void observeViewModel() {
|
||||
viewModel.getConnectionPool().observe(this, adapter::setValues);
|
||||
viewModel.getConnectionPool().observe(this, pool -> {
|
||||
Collection<ConnectionState> connectionStateList = pool.getConnectionStates().values();
|
||||
List<MercuryConnection> connections = new ArrayList<>(connectionStateList.size());
|
||||
for (ConnectionState state : connectionStateList) {
|
||||
connections.add(state.getConnection());
|
||||
}
|
||||
adapter.setValues(connections);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -68,10 +68,6 @@ public class AccountsRecyclerViewAdapter extends RecyclerView.Adapter<AccountsRe
|
|||
holder.enabled.setOnCheckedChangeListener((compoundButton, checked) ->
|
||||
viewModel.setAccountEnabled(account, checked));
|
||||
|
||||
viewModel.getDisposable().add(connection.getState()
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(state -> holder.status.setText(state.toString())));
|
||||
|
||||
setClickListenersOnViewHolder(holder);
|
||||
}
|
||||
|
||||
|
@ -116,7 +112,7 @@ public class AccountsRecyclerViewAdapter extends RecyclerView.Adapter<AccountsRe
|
|||
|
||||
@Override
|
||||
public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) {
|
||||
return oldItems.get(oldItemPosition).getAccountId().equals(newItems.get(newItemPosition).getAccountId());
|
||||
return oldItems.get(oldItemPosition).getAccount().getId().equals(newItems.get(newItemPosition).getAccount().getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -16,7 +16,6 @@ import org.mercury_im.messenger.MercuryImApplication;
|
|||
import org.mercury_im.messenger.Messenger;
|
||||
import org.mercury_im.messenger.R;
|
||||
import org.mercury_im.messenger.entity.Account;
|
||||
import org.mercury_im.messenger.entity.IAccount;
|
||||
import org.mercury_im.messenger.xmpp.MercuryConnection;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
@ -25,7 +24,6 @@ import java.util.logging.Logger;
|
|||
import javax.inject.Inject;
|
||||
|
||||
import io.reactivex.Completable;
|
||||
import io.reactivex.Scheduler;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
@ -86,7 +84,7 @@ public class LoginViewModel extends AndroidViewModel {
|
|||
return;
|
||||
}
|
||||
loginButtonEnabled.setValue(false);
|
||||
Account account = new IAccount();
|
||||
Account account = new Account();
|
||||
account.setAddress(username.asUnescapedString());
|
||||
account.setPassword(password);
|
||||
MercuryConnection connection = messenger.getConnectionManager().createConnection(account);
|
||||
|
|
|
@ -12,8 +12,8 @@ dependencies {
|
|||
implementation project(":entity")
|
||||
implementation project(':domain')
|
||||
|
||||
compileOnly 'org.projectlombok:lombok:1.18.10'
|
||||
annotationProcessor 'org.projectlombok:lombok:1.18.10'
|
||||
compileOnly "org.projectlombok:lombok:$lombokVersion"
|
||||
annotationProcessor "org.projectlombok:lombok:$lombokVersion"
|
||||
|
||||
// RxJava2
|
||||
implementation "io.reactivex.rxjava2:rxjava:$rxJava2Version"
|
||||
|
|
|
@ -2,7 +2,6 @@ package org.mercury_im.messenger.data.mapping;
|
|||
|
||||
import org.mercury_im.messenger.data.model.AccountModel;
|
||||
import org.mercury_im.messenger.entity.Account;
|
||||
import org.mercury_im.messenger.entity.IAccount;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
|
@ -15,7 +14,7 @@ public class AccountMapping extends AbstractMapping<Account, AccountModel> {
|
|||
|
||||
@Override
|
||||
public Account newEntity(AccountModel model) {
|
||||
return new IAccount();
|
||||
return new Account();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -2,7 +2,6 @@ package org.mercury_im.messenger.data.mapping;
|
|||
|
||||
import org.mercury_im.messenger.data.model.DirectChatModel;
|
||||
import org.mercury_im.messenger.entity.chat.DirectChat;
|
||||
import org.mercury_im.messenger.entity.chat.IDirectChat;
|
||||
import org.mercury_im.messenger.entity.contact.Peer;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
@ -18,7 +17,7 @@ public class DirectChatMapping extends AbstractMapping<DirectChat, DirectChatMod
|
|||
|
||||
@Override
|
||||
public DirectChat newEntity(DirectChatModel model) {
|
||||
return new IDirectChat();
|
||||
return new DirectChat();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -2,7 +2,6 @@ package org.mercury_im.messenger.data.mapping;
|
|||
|
||||
import org.mercury_im.messenger.data.model.EntityCapsModel;
|
||||
import org.mercury_im.messenger.entity.caps.EntityCapsRecord;
|
||||
import org.mercury_im.messenger.entity.caps.IEntityCapsRecord;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
|
@ -17,7 +16,7 @@ public class EntityCapsMapping extends AbstractMapping<EntityCapsRecord, EntityC
|
|||
|
||||
@Override
|
||||
protected EntityCapsRecord newEntity(@NonNull EntityCapsModel model) {
|
||||
return new IEntityCapsRecord();
|
||||
return new EntityCapsRecord();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -2,7 +2,6 @@ package org.mercury_im.messenger.data.mapping;
|
|||
|
||||
import org.mercury_im.messenger.data.model.GroupChatModel;
|
||||
import org.mercury_im.messenger.entity.chat.GroupChat;
|
||||
import org.mercury_im.messenger.entity.chat.IGroupChat;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
|
@ -17,7 +16,7 @@ public class GroupChatMapping extends AbstractMapping<GroupChat, GroupChatModel>
|
|||
|
||||
@Override
|
||||
public GroupChat newEntity(GroupChatModel model) {
|
||||
return new IGroupChat();
|
||||
return new GroupChat();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -2,7 +2,6 @@ package org.mercury_im.messenger.data.mapping;
|
|||
|
||||
import org.mercury_im.messenger.data.model.MessageModel;
|
||||
import org.mercury_im.messenger.data.model.MessagePayloadContainerModel;
|
||||
import org.mercury_im.messenger.entity.message.IMessage;
|
||||
import org.mercury_im.messenger.entity.message.Message;
|
||||
import org.mercury_im.messenger.entity.message.PayloadContainer;
|
||||
|
||||
|
@ -22,7 +21,7 @@ public class MessageMapping extends AbstractMapping<Message, MessageModel> {
|
|||
|
||||
@Override
|
||||
public Message newEntity(MessageModel model) {
|
||||
return new IMessage();
|
||||
return new Message();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -2,7 +2,6 @@ package org.mercury_im.messenger.data.mapping;
|
|||
|
||||
import org.mercury_im.messenger.data.model.MessagePayloadModel;
|
||||
import org.mercury_im.messenger.data.model.MessagePayloadContainerModel;
|
||||
import org.mercury_im.messenger.entity.message.IPayloadContainer;
|
||||
import org.mercury_im.messenger.entity.message.PayloadContainer;
|
||||
import org.mercury_im.messenger.entity.message.content.Payload;
|
||||
|
||||
|
@ -22,7 +21,7 @@ public class MessagePayloadContainerMapping extends AbstractMapping<PayloadConta
|
|||
|
||||
@Override
|
||||
public PayloadContainer newEntity(MessagePayloadContainerModel model) {
|
||||
return new IPayloadContainer();
|
||||
return new PayloadContainer();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package org.mercury_im.messenger.data.mapping;
|
||||
|
||||
import org.mercury_im.messenger.data.model.PeerModel;
|
||||
import org.mercury_im.messenger.entity.contact.IPeer;
|
||||
import org.mercury_im.messenger.entity.contact.Peer;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
@ -17,7 +16,7 @@ public class PeerMapping extends AbstractMapping<Peer, PeerModel> {
|
|||
|
||||
@Override
|
||||
public Peer newEntity(PeerModel model) {
|
||||
return new IPeer();
|
||||
return new Peer();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -5,7 +5,6 @@ import org.mercury_im.messenger.data.model.DirectChatModel;
|
|||
import org.mercury_im.messenger.data.repository.dao.DirectChatDao;
|
||||
import org.mercury_im.messenger.util.Optional;
|
||||
import org.mercury_im.messenger.entity.chat.DirectChat;
|
||||
import org.mercury_im.messenger.entity.chat.IDirectChat;
|
||||
import org.mercury_im.messenger.entity.contact.Peer;
|
||||
import org.mercury_im.messenger.util.ThreadUtils;
|
||||
|
||||
|
@ -24,7 +23,6 @@ import io.reactivex.Single;
|
|||
import io.requery.Persistable;
|
||||
import io.requery.query.ResultDelegate;
|
||||
import io.requery.reactivex.ReactiveEntityStore;
|
||||
import io.requery.reactivex.ReactiveResult;
|
||||
|
||||
public class XmppDirectChatRepository
|
||||
extends RequeryRepository
|
||||
|
@ -77,7 +75,7 @@ public class XmppDirectChatRepository
|
|||
@Override
|
||||
public Single<DirectChat> getOrCreateChatWithPeer(Peer peer) {
|
||||
return getDirectChatByPeer(peer)
|
||||
.switchIfEmpty(Single.just(new IDirectChat())
|
||||
.switchIfEmpty(Single.just(new DirectChat())
|
||||
.map(chat -> {
|
||||
chat.setAccount(peer.getAccount());
|
||||
chat.setPeer(peer);
|
||||
|
|
|
@ -6,7 +6,6 @@ import org.mercury_im.messenger.data.repository.dao.GroupChatDao;
|
|||
import org.mercury_im.messenger.util.Optional;
|
||||
import org.mercury_im.messenger.entity.Account;
|
||||
import org.mercury_im.messenger.entity.chat.GroupChat;
|
||||
import org.mercury_im.messenger.entity.chat.IGroupChat;
|
||||
import org.mercury_im.messenger.util.ThreadUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -74,7 +73,7 @@ public class XmppGroupChatRepository
|
|||
@Override
|
||||
public Single<GroupChat> getOrCreateGroupChat(Account account, String roomAddress) {
|
||||
return getGroupChatByRoomAddress(account, roomAddress)
|
||||
.switchIfEmpty(Single.just(new IGroupChat())
|
||||
.switchIfEmpty(Single.just(new GroupChat())
|
||||
.map(chat -> {
|
||||
chat.setAccount(account);
|
||||
chat.setRoomAddress(roomAddress);
|
||||
|
|
|
@ -3,7 +3,6 @@ package org.mercury_im.messenger.data.repository;
|
|||
import org.mercury_im.messenger.data.mapping.PeerMapping;
|
||||
import org.mercury_im.messenger.data.model.PeerModel;
|
||||
import org.mercury_im.messenger.entity.Account;
|
||||
import org.mercury_im.messenger.entity.contact.IPeer;
|
||||
import org.mercury_im.messenger.entity.contact.Peer;
|
||||
import org.mercury_im.messenger.entity.contact.SubscriptionDirection;
|
||||
import org.mercury_im.messenger.util.Optional;
|
||||
|
@ -59,7 +58,7 @@ public class XmppPeerRepository
|
|||
return data().select(PeerModel.class)
|
||||
.where(PeerModel.ID.eq(peerId))
|
||||
.get().observableResult()
|
||||
.map(result -> new Optional<>(peerMapping.toEntity(result.firstOrNull(), new IPeer())))
|
||||
.map(result -> new Optional<>(peerMapping.toEntity(result.firstOrNull(), new Peer())))
|
||||
.subscribeOn(subscriberScheduler())
|
||||
.observeOn(observerScheduler());
|
||||
}
|
||||
|
@ -69,7 +68,7 @@ public class XmppPeerRepository
|
|||
return data().select(PeerModel.class)
|
||||
.where(PeerModel.ID.eq(peerId))
|
||||
.get().maybe()
|
||||
.map(model -> peerMapping.toEntity(model, new IPeer()))
|
||||
.map(model -> peerMapping.toEntity(model, new Peer()))
|
||||
.subscribeOn(subscriberScheduler())
|
||||
.observeOn(observerScheduler());
|
||||
}
|
||||
|
@ -107,7 +106,7 @@ public class XmppPeerRepository
|
|||
public Single<Peer> getOrCreatePeer(Account account, String address) {
|
||||
return getPeerByAddress(account, address)
|
||||
.switchIfEmpty(Single
|
||||
.just(new IPeer())
|
||||
.just(new Peer())
|
||||
.map(peer -> {
|
||||
peer.setAccount(account);
|
||||
peer.setAddress(address);
|
||||
|
|
|
@ -4,14 +4,9 @@ import org.junit.Test;
|
|||
import org.mercury_im.messenger.data.di.DaggerMappingTestComponent;
|
||||
import org.mercury_im.messenger.data.model.AccountModel;
|
||||
import org.mercury_im.messenger.entity.Account;
|
||||
import org.mercury_im.messenger.entity.IAccount;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import io.requery.proxy.EntityProxy;
|
||||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
import static junit.framework.TestCase.assertNotSame;
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@ import org.junit.Test;
|
|||
import org.mercury_im.messenger.data.di.DaggerMappingTestComponent;
|
||||
import org.mercury_im.messenger.data.model.EntityCapsModel;
|
||||
import org.mercury_im.messenger.entity.caps.EntityCapsRecord;
|
||||
import org.mercury_im.messenger.entity.caps.IEntityCapsRecord;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@ import org.junit.Test;
|
|||
import org.mercury_im.messenger.data.di.DaggerMappingTestComponent;
|
||||
import org.mercury_im.messenger.data.model.AccountModel;
|
||||
import org.mercury_im.messenger.data.model.PeerModel;
|
||||
import org.mercury_im.messenger.entity.contact.IPeer;
|
||||
import org.mercury_im.messenger.entity.contact.Peer;
|
||||
import org.mercury_im.messenger.entity.contact.SubscriptionDirection;
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@ import org.junit.Test;
|
|||
import org.mercury_im.messenger.data.di.DaggerInMemoryDatabaseComponent;
|
||||
import org.mercury_im.messenger.data.di.InMemoryDatabaseComponent;
|
||||
import org.mercury_im.messenger.entity.Account;
|
||||
import org.mercury_im.messenger.entity.IAccount;
|
||||
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.UUID;
|
||||
|
|
|
@ -21,8 +21,8 @@ dependencies {
|
|||
implementation "com.google.dagger:dagger:$daggerVersion"
|
||||
annotationProcessor "com.google.dagger:dagger-compiler:$daggerVersion"
|
||||
|
||||
compileOnly 'org.projectlombok:lombok:1.18.10'
|
||||
annotationProcessor 'org.projectlombok:lombok:1.18.10'
|
||||
compileOnly "org.projectlombok:lombok:$lombokVersion"
|
||||
annotationProcessor "org.projectlombok:lombok:$lombokVersion"
|
||||
|
||||
// JUnit for testing
|
||||
testImplementation "junit:junit:$junitVersion"
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.mercury_im.messenger;
|
||||
|
||||
import org.mercury_im.messenger.data.repository.Repositories;
|
||||
import org.mercury_im.messenger.entity.Account;
|
||||
import org.mercury_im.messenger.xmpp.MercuryConnectionManager;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
@ -41,4 +42,11 @@ public class Messenger {
|
|||
.subscribe(connectionManager::registerConnections));
|
||||
}
|
||||
|
||||
public Account createAccount(String username, String service, String password) {
|
||||
Account account = new Account();
|
||||
account.setAddress(username + "@" + service);
|
||||
account.setPassword(password);
|
||||
return account;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package org.mercury_im.messenger.data.repository;
|
||||
|
||||
import org.mercury_im.messenger.entity.caps.EntityCapsRecord;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@ import org.jivesoftware.smackx.caps.cache.EntityCapsPersistentCache;
|
|||
import org.jivesoftware.smackx.disco.packet.DiscoverInfo;
|
||||
import org.mercury_im.messenger.data.repository.EntityCapsRepository;
|
||||
import org.mercury_im.messenger.entity.caps.EntityCapsRecord;
|
||||
import org.mercury_im.messenger.entity.caps.IEntityCapsRecord;
|
||||
import org.mercury_im.messenger.logging.Tags;
|
||||
|
||||
import java.io.StringReader;
|
||||
|
@ -34,7 +33,7 @@ public class MercuryEntityCapsStore implements EntityCapsPersistentCache {
|
|||
@Override
|
||||
public void addDiscoverInfoByNodePersistent(String nodeVer, DiscoverInfo info) {
|
||||
LOGGER.log(Level.INFO, "MercuryEntityCapsStore: addDiscoverInfoByNodePersistent: " + nodeVer);
|
||||
EntityCapsRecord record = new IEntityCapsRecord();
|
||||
EntityCapsRecord record = new EntityCapsRecord();
|
||||
record.setNodeVer(nodeVer);
|
||||
record.setXml(info.toXML().toString());
|
||||
|
||||
|
|
|
@ -50,14 +50,14 @@ public class LogIntoAccount {
|
|||
doAuthenticateIfNecessary();
|
||||
return ConnectionResult.success;
|
||||
} catch (SASLErrorException e) {
|
||||
LOGGER.log(Level.WARNING, "SASL Error while connecting to account " + connection.getAccountId(), e);
|
||||
LOGGER.log(Level.WARNING, "SASL Error while connecting to account " + connection.getAccount().getId(), e);
|
||||
return ConnectionResult.credential_error;
|
||||
} catch (SmackException.ConnectionException e) {
|
||||
LOGGER.log(Level.WARNING, "Connectivity error while connecting to account " + connection.getAccountId(), e);
|
||||
LOGGER.log(Level.WARNING, "Connectivity error while connecting to account " + connection.getAccount().getId(), e);
|
||||
return ConnectionResult.server_error;
|
||||
}
|
||||
catch (IOException | XMPPException | SmackException | InterruptedException e) {
|
||||
LOGGER.log(Level.WARNING, "Error connecting to account " + connection.getAccountId(), e);
|
||||
LOGGER.log(Level.WARNING, "Error connecting to account " + connection.getAccount().getId(), e);
|
||||
return ConnectionResult.other_error;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ public class RosterStoreBinder {
|
|||
|
||||
public void setRosterStoreOn(MercuryConnection connection) {
|
||||
MercuryRosterStore store =
|
||||
createRosterStore(connection.getAccountId(), accountRepository, peerRepository);
|
||||
createRosterStore(connection.getAccount().getId(), accountRepository, peerRepository);
|
||||
Roster roster = Roster.getInstanceFor(connection.getConnection());
|
||||
roster.setRosterStore(store);
|
||||
}
|
||||
|
|
|
@ -28,18 +28,21 @@ public class MercuryConnection {
|
|||
private XMPPConnection connection;
|
||||
|
||||
@Getter
|
||||
private final UUID accountId;
|
||||
private final Account account;
|
||||
|
||||
private final BehaviorSubject<ConnectionState> state;
|
||||
|
||||
public MercuryConnection(XMPPConnection connection, Account account) {
|
||||
this.connection = connection;
|
||||
this.accountId = account.getId();
|
||||
this.account = account;
|
||||
|
||||
this.state = BehaviorSubject.createDefault(new ConnectionState(accountId,
|
||||
this.state = BehaviorSubject.createDefault(new ConnectionState(account.getId(), this,
|
||||
ConnectivityState.disconnected, false, false));
|
||||
}
|
||||
|
||||
public UUID getAccountId() {
|
||||
return getAccount().getId();
|
||||
}
|
||||
|
||||
public Observable<ConnectionState> observeConnection() {
|
||||
return state;
|
||||
|
@ -78,7 +81,7 @@ public class MercuryConnection {
|
|||
connect();
|
||||
((AbstractXMPPConnection) getConnection()).login();
|
||||
} catch (SASLErrorException e) {
|
||||
throw new InvalidCredentialsException("Credentials of account " + accountId + " are invalid.", e);
|
||||
throw new InvalidCredentialsException("Credentials of account " + account.getId() + " are invalid.", e);
|
||||
} catch (InterruptedException | XMPPException | SmackException | IOException e) {
|
||||
throw new AssertionError("Unexpected exception.", e);
|
||||
}
|
||||
|
|
|
@ -4,6 +4,9 @@ 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.smack.packet.MessageBuilder;
|
||||
import org.jivesoftware.smack.packet.id.StandardStanzaIdSource;
|
||||
import org.jivesoftware.smack.packet.id.UuidStanzaIdSource;
|
||||
import org.jivesoftware.smackx.sid.element.OriginIdElement;
|
||||
import org.jxmpp.jid.EntityBareJid;
|
||||
import org.jxmpp.jid.impl.JidCreate;
|
||||
|
@ -16,9 +19,8 @@ import org.mercury_im.messenger.data.repository.PeerRepository;
|
|||
import org.mercury_im.messenger.data.repository.Repositories;
|
||||
import org.mercury_im.messenger.entity.Account;
|
||||
import org.mercury_im.messenger.entity.chat.DirectChat;
|
||||
import org.mercury_im.messenger.entity.message.IMessage;
|
||||
import org.mercury_im.messenger.entity.message.IMessageMetadata;
|
||||
import org.mercury_im.messenger.entity.message.Message;
|
||||
import org.mercury_im.messenger.entity.message.MessageMetadata;
|
||||
import org.mercury_im.messenger.listener.IncomingDirectMessageListener;
|
||||
|
||||
import java.util.LinkedHashSet;
|
||||
|
@ -72,15 +74,15 @@ public class XmppDirectMessageCenter
|
|||
EntityBareJid peerAddress =
|
||||
JidCreate.entityBareFromOrThrowUnchecked(chat.getPeer().getAddress());
|
||||
|
||||
org.jivesoftware.smack.packet.Message smackMessage = new org.jivesoftware.smack.packet.Message();
|
||||
smackMessage.setFrom(accountAddress);
|
||||
smackMessage.setTo(peerAddress);
|
||||
smackMessage.setType(org.jivesoftware.smack.packet.Message.Type.chat);
|
||||
MessageBuilder messageBuilder = MessageBuilder.buildMessage()
|
||||
.from(accountAddress)
|
||||
.to(peerAddress)
|
||||
.ofType(org.jivesoftware.smack.packet.Message.Type.chat);
|
||||
|
||||
String originId = OriginIdElement.addOriginId(smackMessage).getId();
|
||||
String legacyStanzaId = smackMessage.getStanzaId();
|
||||
String originId = OriginIdElement.addOriginId(messageBuilder).getId();
|
||||
String legacyStanzaId = messageBuilder.getStanzaId();
|
||||
|
||||
IMessageMetadata metadata = new IMessageMetadata();
|
||||
MessageMetadata metadata = new MessageMetadata();
|
||||
metadata.setLegacyStanzaId(legacyStanzaId);
|
||||
metadata.setOriginId(originId);
|
||||
|
||||
|
@ -89,7 +91,7 @@ public class XmppDirectMessageCenter
|
|||
Chat smackChat = chatManager.chatWith(peerAddress);
|
||||
return messageRepository.insertMessage(chat, message)
|
||||
.ignoreElement()
|
||||
.andThen(Completable.fromAction(() -> smackChat.send(smackMessage)));
|
||||
.andThen(Completable.fromAction(() -> smackChat.send(messageBuilder.build())));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -112,7 +114,7 @@ public class XmppDirectMessageCenter
|
|||
// notify listeners
|
||||
.subscribe(chatEntity -> {
|
||||
for (IncomingDirectMessageListener listener : messageListeners) {
|
||||
listener.onIncomingDirectMessage(account, chatEntity, new IMessage());
|
||||
listener.onIncomingDirectMessage(account, chatEntity, new Message());
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.mercury_im.messenger.xmpp.state;
|
||||
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.mercury_im.messenger.xmpp.MercuryConnection;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
|
@ -13,7 +14,7 @@ import lombok.With;
|
|||
public class ConnectionState {
|
||||
|
||||
UUID id;
|
||||
XMPPConnection connection;
|
||||
MercuryConnection connection;
|
||||
@With
|
||||
ConnectivityState connectivity;
|
||||
@With
|
||||
|
@ -21,7 +22,7 @@ public class ConnectionState {
|
|||
@With
|
||||
boolean resumed;
|
||||
|
||||
public ConnectionState(UUID id, XMPPConnection connection, ConnectivityState connectivity, boolean authenticated, boolean resumed) {
|
||||
public ConnectionState(UUID id, MercuryConnection connection, ConnectivityState connectivity, boolean authenticated, boolean resumed) {
|
||||
this.id = id;
|
||||
this.connection = connection;
|
||||
this.connectivity = connectivity;
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
apply plugin: 'java-library'
|
||||
|
||||
dependencies {
|
||||
|
||||
compileOnly "org.projectlombok:lombok:$lombokVersion"
|
||||
annotationProcessor "org.projectlombok:lombok:$lombokVersion"
|
||||
}
|
||||
|
||||
sourceCompatibility = "8"
|
||||
|
|
|
@ -2,40 +2,17 @@ package org.mercury_im.messenger.entity;
|
|||
|
||||
import java.util.UUID;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* User Account entity.
|
||||
*
|
||||
* An implementation of this entity can be found as {@link IAccount}.
|
||||
*/
|
||||
public interface Account {
|
||||
|
||||
UUID UNASSIGNED = UUID.fromString("00000000-0000-0000-0000-000000000000");
|
||||
|
||||
void setId(UUID id);
|
||||
|
||||
UUID getId();
|
||||
|
||||
void setAddress(String address);
|
||||
|
||||
String getAddress();
|
||||
|
||||
void setPassword(String password);
|
||||
|
||||
String getPassword();
|
||||
|
||||
void setHost(String host);
|
||||
|
||||
String getHost();
|
||||
|
||||
void setPort(int port);
|
||||
|
||||
int getPort();
|
||||
|
||||
void setEnabled(boolean enabled);
|
||||
|
||||
boolean isEnabled();
|
||||
|
||||
default String displayName() {
|
||||
return getAddress();
|
||||
}
|
||||
@Data
|
||||
public class Account {
|
||||
UUID id;
|
||||
String address;
|
||||
String password;
|
||||
String host;
|
||||
int port;
|
||||
boolean enabled;
|
||||
}
|
||||
|
|
|
@ -1,85 +0,0 @@
|
|||
package org.mercury_im.messenger.entity;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class IAccount implements Account {
|
||||
|
||||
protected UUID id;
|
||||
protected String address;
|
||||
protected String password;
|
||||
protected String host;
|
||||
protected int port;
|
||||
protected boolean enabled;
|
||||
|
||||
public IAccount() {
|
||||
this(UUID.randomUUID());
|
||||
}
|
||||
|
||||
public IAccount(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public static Account createUnassignedAccount() {
|
||||
return new IAccount(Account.UNASSIGNED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setId(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAddress(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHost(String host) {
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHost() {
|
||||
return host;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPort(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
}
|
|
@ -1,12 +1,9 @@
|
|||
package org.mercury_im.messenger.entity.caps;
|
||||
|
||||
public interface EntityCapsRecord {
|
||||
import lombok.Data;
|
||||
|
||||
String getNodeVer();
|
||||
|
||||
void setNodeVer(String nodeVer);
|
||||
|
||||
String getXml();
|
||||
|
||||
void setXml(String xml);
|
||||
@Data
|
||||
public class EntityCapsRecord {
|
||||
String nodeVer;
|
||||
String xml;
|
||||
}
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
package org.mercury_im.messenger.entity.caps;
|
||||
|
||||
public class IEntityCapsRecord implements EntityCapsRecord {
|
||||
|
||||
private String nodeVer;
|
||||
private String xml;
|
||||
|
||||
@Override
|
||||
public String getNodeVer() {
|
||||
return nodeVer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNodeVer(String nodeVer) {
|
||||
this.nodeVer = nodeVer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getXml() {
|
||||
return xml;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setXml(String xml) {
|
||||
this.xml = xml;
|
||||
}
|
||||
}
|
|
@ -4,22 +4,16 @@ import org.mercury_im.messenger.entity.Account;
|
|||
|
||||
import java.util.UUID;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* Generic interface defining shared properties of chats.
|
||||
*
|
||||
* Child interfaces of {@link Chat} are {@link DirectChat} and {@link GroupChat}.
|
||||
*/
|
||||
public interface Chat {
|
||||
|
||||
UUID getId();
|
||||
|
||||
void setId(UUID id);
|
||||
|
||||
Account getAccount();
|
||||
|
||||
void setAccount(Account account);
|
||||
|
||||
ChatPreferences getChatPreferences();
|
||||
|
||||
void setChatPreferences(ChatPreferences chatPreferences);
|
||||
@Data
|
||||
public abstract class Chat {
|
||||
UUID id;
|
||||
Account account;
|
||||
ChatPreferences chatPreferences;
|
||||
}
|
||||
|
|
|
@ -1,41 +1,21 @@
|
|||
package org.mercury_im.messenger.entity.chat;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* Interface that describes typical preferences in the context of a chat.
|
||||
*
|
||||
* An implementation can be found as {@link IChatPreferences}.
|
||||
*/
|
||||
public interface ChatPreferences {
|
||||
@Data
|
||||
public class ChatPreferences {
|
||||
NotificationPreferences notificationPreferences;
|
||||
boolean typingNotificationsSupported;
|
||||
boolean sendTypingNotificationsEnabled;
|
||||
boolean readNotificationsSupported;
|
||||
boolean sendReadNotificationsEnabled;
|
||||
|
||||
NotificationPreferences getNotificationPreference();
|
||||
|
||||
void setNotificationPreference(NotificationPreferences notificationPreferences);
|
||||
|
||||
boolean isTypingNotificationsSupported();
|
||||
|
||||
void setTypingNotificationsSupported(boolean typingNotificationsSupported);
|
||||
|
||||
boolean isSendTypingNotificationsEnabled();
|
||||
|
||||
void setSendTypingNotificationsEnabled(boolean sendTypingNotifications);
|
||||
|
||||
boolean isReadNotificationsSupported();
|
||||
|
||||
void setReadNotificationsSupported(boolean readNotificationsSupported);
|
||||
|
||||
boolean isSendReadNotifications();
|
||||
|
||||
void setSendReadNotifications(boolean sendReadNotifications);
|
||||
|
||||
|
||||
interface NotificationPreferences {
|
||||
|
||||
boolean isNotifyOnMessage();
|
||||
|
||||
void setNotifyOnMessage(boolean notify);
|
||||
|
||||
boolean isNotifyOnMention();
|
||||
|
||||
void setNotifyOnMention(boolean notify);
|
||||
@Data
|
||||
public static class NotificationPreferences {
|
||||
boolean notifyOnMessage;
|
||||
boolean notifyOnMention;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,15 +2,14 @@ package org.mercury_im.messenger.entity.chat;
|
|||
|
||||
import org.mercury_im.messenger.entity.contact.Peer;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* Interface that describes a direct chat between the user and another one.
|
||||
*
|
||||
* An implementation can be found in {@link IDirectChat}.
|
||||
*/
|
||||
public interface DirectChat extends Chat {
|
||||
|
||||
Peer getPeer();
|
||||
|
||||
void setPeer(Peer peer);
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class DirectChat extends Chat {
|
||||
Peer peer;
|
||||
}
|
||||
|
|
|
@ -4,22 +4,14 @@ import org.mercury_im.messenger.entity.contact.Peer;
|
|||
|
||||
import java.util.Set;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* An interface that describes a group chat entity.
|
||||
*
|
||||
* An implementation can be found as {@link IGroupChat}.
|
||||
*/
|
||||
public interface GroupChat extends Chat {
|
||||
|
||||
Set<Peer> getParticipants();
|
||||
|
||||
void setParticipants(Set<Peer> participants);
|
||||
|
||||
String getRoomAddress();
|
||||
|
||||
void setRoomAddress(String roomAddress);
|
||||
|
||||
String getRoomName();
|
||||
|
||||
void setRoomName(String roomName);
|
||||
@Data
|
||||
public class GroupChat extends Chat {
|
||||
Set<Peer> participants;
|
||||
String roomAddress;
|
||||
String roomName;
|
||||
}
|
||||
|
|
|
@ -1,60 +0,0 @@
|
|||
package org.mercury_im.messenger.entity.chat;
|
||||
|
||||
public class IChatPreferences implements ChatPreferences {
|
||||
|
||||
protected NotificationPreferences notificationPreferences;
|
||||
protected boolean typingNotificationsSupported;
|
||||
protected boolean sendTypingNotificationsEnabled;
|
||||
protected boolean readNotificationsSupported;
|
||||
protected boolean sendReadNotificationsEnabled;
|
||||
|
||||
@Override
|
||||
public NotificationPreferences getNotificationPreference() {
|
||||
return notificationPreferences;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNotificationPreference(NotificationPreferences notificationPreferences) {
|
||||
this.notificationPreferences = notificationPreferences;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTypingNotificationsSupported() {
|
||||
return typingNotificationsSupported;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTypingNotificationsSupported(boolean typingNotificationsSupported) {
|
||||
this.typingNotificationsSupported = typingNotificationsSupported;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSendTypingNotificationsEnabled() {
|
||||
return sendTypingNotificationsEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSendTypingNotificationsEnabled(boolean sendTypingNotifications) {
|
||||
this.sendTypingNotificationsEnabled = sendTypingNotifications;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isReadNotificationsSupported() {
|
||||
return readNotificationsSupported;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setReadNotificationsSupported(boolean readNotificationsSupported) {
|
||||
this.readNotificationsSupported = readNotificationsSupported;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSendReadNotifications() {
|
||||
return sendReadNotificationsEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSendReadNotifications(boolean sendReadNotifications) {
|
||||
this.sendReadNotificationsEnabled = sendReadNotifications;
|
||||
}
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
package org.mercury_im.messenger.entity.chat;
|
||||
|
||||
import org.mercury_im.messenger.entity.Account;
|
||||
import org.mercury_im.messenger.entity.contact.Peer;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class IDirectChat implements DirectChat {
|
||||
|
||||
protected UUID id;
|
||||
protected Peer peer;
|
||||
protected Account account;
|
||||
protected ChatPreferences preferences;
|
||||
|
||||
public IDirectChat() {
|
||||
this(UUID.randomUUID());
|
||||
}
|
||||
|
||||
public IDirectChat(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Peer getPeer() {
|
||||
return peer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPeer(Peer peer) {
|
||||
this.peer = peer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setId(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Account getAccount() {
|
||||
return account;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAccount(Account account) {
|
||||
this.account = account;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChatPreferences getChatPreferences() {
|
||||
return preferences;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setChatPreferences(ChatPreferences chatPreferences) {
|
||||
this.preferences = chatPreferences;
|
||||
}
|
||||
}
|
|
@ -1,87 +0,0 @@
|
|||
package org.mercury_im.messenger.entity.chat;
|
||||
|
||||
import org.mercury_im.messenger.entity.Account;
|
||||
import org.mercury_im.messenger.entity.contact.Peer;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
public class IGroupChat implements GroupChat {
|
||||
|
||||
private UUID id;
|
||||
private Account account;
|
||||
private String roomAddress;
|
||||
private String roomName;
|
||||
protected ChatPreferences preferences;
|
||||
protected Set<Peer> participants;
|
||||
|
||||
public IGroupChat() {
|
||||
this(UUID.randomUUID());
|
||||
}
|
||||
|
||||
public IGroupChat(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Peer> getParticipants() {
|
||||
return participants;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setParticipants(Set<Peer> participants) {
|
||||
this.participants = participants;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRoomAddress() {
|
||||
return roomAddress;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRoomAddress(String roomAddress) {
|
||||
this.roomAddress = roomAddress;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRoomName() {
|
||||
return roomName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRoomName(String roomName) {
|
||||
this.roomName = roomName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setId(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Account getAccount() {
|
||||
return account;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAccount(Account account) {
|
||||
this.account = account;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ChatPreferences getChatPreferences() {
|
||||
return preferences;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setChatPreferences(ChatPreferences chatPreferences) {
|
||||
this.preferences = chatPreferences;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
package org.mercury_im.messenger.entity.chat;
|
||||
|
||||
public class INotificationPreferences implements ChatPreferences.NotificationPreferences {
|
||||
|
||||
protected boolean notifyOnMessage;
|
||||
protected boolean notifyOnMention;
|
||||
|
||||
@Override
|
||||
public boolean isNotifyOnMessage() {
|
||||
return notifyOnMessage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNotifyOnMessage(boolean notify) {
|
||||
this.notifyOnMessage = notify;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNotifyOnMention() {
|
||||
return notifyOnMention;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNotifyOnMention(boolean notify) {
|
||||
this.notifyOnMention = notify;
|
||||
}
|
||||
}
|
|
@ -1,100 +0,0 @@
|
|||
package org.mercury_im.messenger.entity.contact;
|
||||
|
||||
import org.mercury_im.messenger.entity.Account;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class IPeer implements Peer {
|
||||
|
||||
protected UUID id;
|
||||
protected Account account;
|
||||
protected String address;
|
||||
protected String name;
|
||||
protected SubscriptionDirection subscriptionDirection;
|
||||
protected boolean pending;
|
||||
protected boolean approved;
|
||||
|
||||
public IPeer() {
|
||||
this(UUID.randomUUID());
|
||||
}
|
||||
|
||||
public IPeer(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setId(UUID 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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SubscriptionDirection getSubscriptionDirection() {
|
||||
return subscriptionDirection;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSubscriptionDirection(SubscriptionDirection mode) {
|
||||
this.subscriptionDirection = mode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSubscriptionPending() {
|
||||
return pending;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSubscriptionPending(boolean pending) {
|
||||
this.pending = pending;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSubscriptionApproved() {
|
||||
return approved;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSubscriptionApproved(boolean approved) {
|
||||
this.approved = approved;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isContact() {
|
||||
return subscriptionDirection != SubscriptionDirection.none
|
||||
&& subscriptionDirection != SubscriptionDirection.from;
|
||||
}
|
||||
}
|
|
@ -4,45 +4,27 @@ import org.mercury_im.messenger.entity.Account;
|
|||
|
||||
import java.util.UUID;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.With;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* An implementation can be found as {@link IPeer}.
|
||||
*/
|
||||
public interface Peer {
|
||||
@Data
|
||||
public class Peer {
|
||||
UUID id;
|
||||
Account account;
|
||||
String address;
|
||||
String name;
|
||||
SubscriptionDirection subscriptionDirection;
|
||||
boolean subscriptionPending;
|
||||
boolean subscriptionApproved;
|
||||
|
||||
UUID getId();
|
||||
|
||||
void setId(UUID id);
|
||||
|
||||
Account getAccount();
|
||||
|
||||
void setAccount(Account account);
|
||||
|
||||
String getAddress();
|
||||
|
||||
void setAddress(String address);
|
||||
|
||||
String getName();
|
||||
|
||||
void setName(String name);
|
||||
|
||||
SubscriptionDirection getSubscriptionDirection();
|
||||
|
||||
void setSubscriptionDirection(SubscriptionDirection mode);
|
||||
|
||||
boolean isSubscriptionPending();
|
||||
|
||||
void setSubscriptionPending(boolean pending);
|
||||
|
||||
boolean isSubscriptionApproved();
|
||||
|
||||
void setSubscriptionApproved(boolean approved);
|
||||
|
||||
boolean isContact();
|
||||
|
||||
default String getDisplayName() {
|
||||
return getName() != null ? getName() : getAddress();
|
||||
public String getDisplayName() {
|
||||
if (name != null) {
|
||||
return name;
|
||||
}
|
||||
return address;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
package org.mercury_im.messenger.entity.event;
|
||||
|
||||
import org.mercury_im.messenger.entity.contact.Peer;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class ITypingEvent implements TypingEvent {
|
||||
|
||||
public Map<Peer, TypingState> typingStates;
|
||||
|
||||
@Override
|
||||
public Map<Peer, TypingState> getTypingStates() {
|
||||
return typingStates;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTypingStates(Map<Peer, TypingState> typingStates) {
|
||||
this.typingStates = typingStates;
|
||||
}
|
||||
}
|
|
@ -4,14 +4,13 @@ import org.mercury_im.messenger.entity.contact.Peer;
|
|||
|
||||
import java.util.Map;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.Value;
|
||||
|
||||
/**
|
||||
* Event of someone typing in a chat.
|
||||
*
|
||||
* An implementation can be found as {@link ITypingEvent}.
|
||||
*/
|
||||
public interface TypingEvent {
|
||||
|
||||
Map<Peer, TypingState> getTypingStates();
|
||||
|
||||
void setTypingStates(Map<Peer, TypingState> typingStates);
|
||||
@Value
|
||||
public class TypingEvent {
|
||||
Map<Peer, TypingState> typingStates;
|
||||
}
|
||||
|
|
|
@ -1,105 +0,0 @@
|
|||
package org.mercury_im.messenger.entity.message;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class IMessage implements Message {
|
||||
|
||||
protected UUID id;
|
||||
protected String sender;
|
||||
protected String recipient;
|
||||
protected Date timestamp;
|
||||
protected List<PayloadContainer> payloads;
|
||||
protected MessageDeliveryState deliveryState;
|
||||
protected MessageMetadata metadata;
|
||||
protected MessageDirection direction;
|
||||
|
||||
public IMessage() {
|
||||
this(UUID.randomUUID());
|
||||
}
|
||||
|
||||
public IMessage(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setId(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSender() {
|
||||
return sender;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSender(String address) {
|
||||
this.sender = address;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRecipient() {
|
||||
return recipient;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRecipient(String recipient) {
|
||||
this.recipient = recipient;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTimestamp(Date timestamp) {
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MessageDirection getDirection() {
|
||||
return direction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDirection(MessageDirection direction) {
|
||||
this.direction = direction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PayloadContainer> getMessagePayloads() {
|
||||
return payloads;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMessagePayloads(List<PayloadContainer> list) {
|
||||
this.payloads = list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MessageDeliveryState getDeliveryState() {
|
||||
return deliveryState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDeliveryState(MessageDeliveryState deliveryState) {
|
||||
this.deliveryState = deliveryState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MessageMetadata getMetadata() {
|
||||
return metadata;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMetadata(MessageMetadata metadata) {
|
||||
this.metadata = metadata;
|
||||
}
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
package org.mercury_im.messenger.entity.message;
|
||||
|
||||
public class IMessageMetadata implements MessageMetadata {
|
||||
|
||||
private long id;
|
||||
private String legacyStanzaId;
|
||||
private String originId;
|
||||
private String stanzaId;
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void setLegacyStanzaId(String legacyStanzaId) {
|
||||
this.legacyStanzaId = legacyStanzaId;
|
||||
}
|
||||
|
||||
public void setOriginId(String originId) {
|
||||
this.originId = originId;
|
||||
}
|
||||
|
||||
public void setStanzaId(String stanzaId) {
|
||||
this.stanzaId = stanzaId;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getLegacyStanzaId() {
|
||||
return legacyStanzaId;
|
||||
}
|
||||
|
||||
public String getOriginId() {
|
||||
return originId;
|
||||
}
|
||||
|
||||
public String getStanzaId() {
|
||||
return stanzaId;
|
||||
}
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
package org.mercury_im.messenger.entity.message;
|
||||
|
||||
import org.mercury_im.messenger.entity.message.content.Payload;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class IPayloadContainer implements PayloadContainer {
|
||||
|
||||
protected long id;
|
||||
protected List<Payload> contents;
|
||||
|
||||
@Override
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Payload> getMessageContents() {
|
||||
return contents;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMessageContents(List<Payload> payloads) {
|
||||
this.contents = payloads;
|
||||
}
|
||||
}
|
|
@ -4,41 +4,22 @@ import java.util.Date;
|
|||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public interface Message {
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.With;
|
||||
|
||||
UUID getId();
|
||||
@Data
|
||||
public class Message {
|
||||
UUID id;
|
||||
String sender;
|
||||
String recipient;
|
||||
Date timestamp;
|
||||
MessageDirection direction;
|
||||
List<PayloadContainer> messagePayloads;
|
||||
MessageDeliveryState deliveryState;
|
||||
MessageMetadata metadata;
|
||||
|
||||
void setId(UUID id);
|
||||
|
||||
String getSender();
|
||||
|
||||
void setSender(String address);
|
||||
|
||||
String getRecipient();
|
||||
|
||||
void setRecipient(String recipient);
|
||||
|
||||
Date getTimestamp();
|
||||
|
||||
void setTimestamp(Date timestamp);
|
||||
|
||||
MessageDirection getDirection();
|
||||
|
||||
void setDirection(MessageDirection direction);
|
||||
|
||||
default boolean isIncoming() {
|
||||
public boolean isIncoming() {
|
||||
return getDirection() == MessageDirection.incoming;
|
||||
}
|
||||
|
||||
List<PayloadContainer> getMessagePayloads();
|
||||
|
||||
void setMessagePayloads(List<PayloadContainer> payloadContainers);
|
||||
|
||||
MessageDeliveryState getDeliveryState();
|
||||
|
||||
void setDeliveryState(MessageDeliveryState deliveryState);
|
||||
|
||||
MessageMetadata getMetadata();
|
||||
|
||||
void setMetadata(MessageMetadata metadata);
|
||||
}
|
||||
|
|
|
@ -1,9 +1,15 @@
|
|||
package org.mercury_im.messenger.entity.message;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* Interface to allow additional, protocol specific metadata to be attached to the message.
|
||||
* In case of XMPP this might be origin/stanza id, encryption information etc.
|
||||
*/
|
||||
public interface MessageMetadata {
|
||||
|
||||
@Data
|
||||
public class MessageMetadata {
|
||||
private long id;
|
||||
private String legacyStanzaId;
|
||||
private String originId;
|
||||
private String stanzaId;
|
||||
}
|
|
@ -4,6 +4,8 @@ import org.mercury_im.messenger.entity.message.content.Payload;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* Defines a certain set of {@link Payload Payloads} of a message.
|
||||
* A {@link PayloadContainer} can either be a plaintext container or an encrypted container and contains
|
||||
|
@ -12,15 +14,8 @@ import java.util.List;
|
|||
* A message may contain encrypted and unencrypted payloads. Those could then be represented by
|
||||
* two different {@link PayloadContainer PayloadContainers}.
|
||||
*/
|
||||
public interface PayloadContainer {
|
||||
|
||||
long getId();
|
||||
|
||||
void setId(long id);
|
||||
|
||||
List<Payload> getMessageContents();
|
||||
|
||||
void setMessageContents(List<Payload> payloads);
|
||||
|
||||
|
||||
@Data
|
||||
public class PayloadContainer {
|
||||
long id;
|
||||
List<Payload> messageContents;
|
||||
}
|
||||
|
|
|
@ -1,27 +1,9 @@
|
|||
package org.mercury_im.messenger.entity.message.content;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class TextPayload implements Payload.Body {
|
||||
|
||||
private long id;
|
||||
private String body;
|
||||
|
||||
@Override
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBody() {
|
||||
return body;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBody(String body) {
|
||||
this.body = body;
|
||||
}
|
||||
long id;
|
||||
String body;
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit e6e8547f7b29e9c961cb23020c0f0fe2ea1b0f14
|
||||
Subproject commit e79710840be6d6b3301e078a23688eafaa06013c
|
|
@ -88,6 +88,9 @@ ext {
|
|||
// Dagger 2
|
||||
daggerVersion = '2.25.4'
|
||||
|
||||
// Lombok
|
||||
lombokVersion = '1.18.12'
|
||||
|
||||
// Android Support Library
|
||||
supportLibVersion = "28.0.0"
|
||||
|
||||
|
|
Loading…
Reference in New Issue