Temporary commit
This commit is contained in:
parent
78d5376724
commit
baeabc0602
|
@ -0,0 +1,33 @@
|
||||||
|
package org.mercury_im.core.usecase;
|
||||||
|
|
||||||
|
import org.mercury_im.messenger.core.entity.Account;
|
||||||
|
import org.mercury_im.messenger.core.entity.Address;
|
||||||
|
import org.mercury_im.messenger.core.entity.chat.DirectChat;
|
||||||
|
import org.mercury_im.messenger.core.entity.contact.Interlocutor;
|
||||||
|
import org.mercury_im.messenger.core.entity.message.Message;
|
||||||
|
import org.mercury_im.messenger.core.entity.message.MessageMetadata;
|
||||||
|
|
||||||
|
public class SendDirectMessage<
|
||||||
|
M extends Message<AD, MM>,
|
||||||
|
C extends DirectChat<IL, AC, AD>,
|
||||||
|
AD extends Address.UserAddress,
|
||||||
|
MM extends MessageMetadata,
|
||||||
|
IL extends Interlocutor<AC, AD, AD>,
|
||||||
|
AC extends Account<AD, ?>> {
|
||||||
|
|
||||||
|
private final M message;
|
||||||
|
private final C chat;
|
||||||
|
|
||||||
|
public SendDirectMessage(M message, C chat) {
|
||||||
|
this.message = message;
|
||||||
|
this.chat = chat;
|
||||||
|
}
|
||||||
|
|
||||||
|
public M getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public C getChat() {
|
||||||
|
return chat;
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,9 +3,7 @@ package org.mercury_im.messenger.xmpp.entity.message;
|
||||||
import org.mercury_im.messenger.core.entity.message.AbstractMessage;
|
import org.mercury_im.messenger.core.entity.message.AbstractMessage;
|
||||||
import org.mercury_im.messenger.xmpp.entity.XmppAddress;
|
import org.mercury_im.messenger.xmpp.entity.XmppAddress;
|
||||||
|
|
||||||
public final class XmppMessage extends AbstractMessage<
|
public final class XmppMessage {
|
||||||
XmppAddress,
|
|
||||||
XmppMessageMetadata> {
|
|
||||||
|
|
||||||
private XmppMessage() {
|
private XmppMessage() {
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ include ':entity',
|
||||||
':transport_xmpp',
|
':transport_xmpp',
|
||||||
':app',
|
':app',
|
||||||
':thread_utils',
|
':thread_utils',
|
||||||
':core-old'
|
':core-old',
|
||||||
|
':view_entity'
|
||||||
|
|
||||||
includeBuild 'libs/Smack'
|
includeBuild 'libs/Smack'
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
package org.mercury_im.core.message;
|
||||||
|
|
||||||
|
import org.mercury_im.messenger.core.entity.Account;
|
||||||
|
import org.mercury_im.messenger.core.entity.Address;
|
||||||
|
import org.mercury_im.messenger.core.entity.chat.Chat;
|
||||||
|
import org.mercury_im.messenger.core.entity.message.Message;
|
||||||
|
import org.mercury_im.messenger.core.entity.message.MessageMetadata;
|
||||||
|
|
||||||
|
import io.reactivex.Completable;
|
||||||
|
|
||||||
|
public interface MessageCenter<
|
||||||
|
M extends Message<AD, MM>,
|
||||||
|
C extends Chat<AC, AD>,
|
||||||
|
AD extends Address.UserAddress,
|
||||||
|
MM extends MessageMetadata,
|
||||||
|
AC extends Account<AD, ?>> {
|
||||||
|
|
||||||
|
Completable sendMessage(M message, C chat);
|
||||||
|
|
||||||
|
void addIncomingMessageListener();
|
||||||
|
}
|
|
@ -4,6 +4,14 @@ dependencies {
|
||||||
implementation project(":repository_xmpp")
|
implementation project(":repository_xmpp")
|
||||||
implementation project(":entity_xmpp")
|
implementation project(":entity_xmpp")
|
||||||
implementation project(":transport")
|
implementation project(":transport")
|
||||||
|
|
||||||
|
// Smack
|
||||||
|
// Not all of those are needed, but it may be a good idea to define those versions explicitly
|
||||||
|
api "org.igniterealtime.smack:smack-core:$smackCoreVersion"
|
||||||
|
api "org.igniterealtime.smack:smack-experimental:$smackExperimentalVersion"
|
||||||
|
api "org.igniterealtime.smack:smack-extensions:$smackExtensionsVersion"
|
||||||
|
api "org.igniterealtime.smack:smack-im:$smackImVersion"
|
||||||
|
api "org.igniterealtime.smack:smack-tcp:$smackTcpVersion"
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceCompatibility = "8"
|
sourceCompatibility = "8"
|
||||||
|
|
|
@ -1,14 +1,20 @@
|
||||||
package org.mercury_im.xmpp.connection;
|
package org.mercury_im.xmpp.connection;
|
||||||
|
|
||||||
|
import org.jivesoftware.smack.ConnectionConfiguration;
|
||||||
|
import org.jivesoftware.smack.XMPPConnection;
|
||||||
import org.mercury_im.core.ConnectionFactory;
|
import org.mercury_im.core.ConnectionFactory;
|
||||||
import org.mercury_im.core.Messenger;
|
import org.mercury_im.core.Messenger;
|
||||||
import org.mercury_im.messenger.xmpp.entity.XmppAccount;
|
import org.mercury_im.messenger.xmpp.entity.XmppAccount;
|
||||||
import org.mercury_im.messenger.xmpp.entity.XmppAddress;
|
import org.mercury_im.messenger.xmpp.entity.XmppAddress;
|
||||||
import org.mercury_im.messenger.xmpp.entity.XmppAuthMethod;
|
import org.mercury_im.messenger.xmpp.entity.XmppAuthMethod;
|
||||||
|
|
||||||
public class XmppConnectionFactory implements ConnectionFactory<XmppConnectionMethod, XmppAccount, XmppAddress.XmppUserAddress, XmppAuthMethod> {
|
public abstract class XmppConnectionFactory implements ConnectionFactory<XmppConnectionMethod, XmppAccount, XmppAddress.XmppUserAddress, XmppAuthMethod> {
|
||||||
|
|
||||||
protected Messenger messenger;
|
protected final Messenger messenger;
|
||||||
|
|
||||||
|
public XmppConnectionFactory(Messenger messenger) {
|
||||||
|
this.messenger = messenger;
|
||||||
|
}
|
||||||
|
|
||||||
public Messenger getMessenger() {
|
public Messenger getMessenger() {
|
||||||
return messenger;
|
return messenger;
|
||||||
|
@ -16,6 +22,8 @@ public class XmppConnectionFactory implements ConnectionFactory<XmppConnectionMe
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public XmppConnectionMethod provideConnection(XmppAccount account) {
|
public XmppConnectionMethod provideConnection(XmppAccount account) {
|
||||||
return new XmppConnectionMethod(account, getMessenger());
|
return new XmppConnectionMethod(account, getMessenger(), createXmppConnection());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected abstract XMPPConnection createXmppConnection(ConnectionConfiguration connectionConfiguration);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package org.mercury_im.xmpp.connection;
|
package org.mercury_im.xmpp.connection;
|
||||||
|
|
||||||
|
import org.jivesoftware.smack.AbstractXMPPConnection;
|
||||||
|
import org.jivesoftware.smack.XMPPConnection;
|
||||||
import org.mercury_im.core.Messenger;
|
import org.mercury_im.core.Messenger;
|
||||||
import org.mercury_im.core.connection.AbstractConnectionMethod;
|
import org.mercury_im.core.connection.AbstractConnectionMethod;
|
||||||
import org.mercury_im.messenger.xmpp.entity.XmppAccount;
|
import org.mercury_im.messenger.xmpp.entity.XmppAccount;
|
||||||
|
@ -9,12 +11,19 @@ import io.reactivex.Completable;
|
||||||
|
|
||||||
public class XmppConnectionMethod extends AbstractConnectionMethod<XmppAccount, XmppAddress.XmppUserAddress> {
|
public class XmppConnectionMethod extends AbstractConnectionMethod<XmppAccount, XmppAddress.XmppUserAddress> {
|
||||||
|
|
||||||
public XmppConnectionMethod(XmppAccount account, Messenger messenger) {
|
private XMPPConnection connection;
|
||||||
|
|
||||||
|
public XmppConnectionMethod(XmppAccount account, Messenger messenger, XMPPConnection connection) {
|
||||||
super(account, messenger);
|
super(account, messenger);
|
||||||
|
this.connection = connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Completable connect() {
|
public Completable connect() {
|
||||||
return null;
|
if (connection.isConnected()) {
|
||||||
|
return Completable.complete();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Completable.fromAction(() -> ((AbstractXMPPConnection) connection).connect().login());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
package org.mercury_im.xmpp.connection;
|
||||||
|
|
||||||
|
import org.jivesoftware.smack.ConnectionConfiguration;
|
||||||
|
import org.jivesoftware.smack.XMPPConnection;
|
||||||
|
import org.jivesoftware.smack.tcp.XMPPTCPConnection;
|
||||||
|
import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration;
|
||||||
|
import org.mercury_im.core.Messenger;
|
||||||
|
|
||||||
|
public class XmppTcpConnectionFactory extends XmppConnectionFactory {
|
||||||
|
|
||||||
|
public XmppTcpConnectionFactory(Messenger messenger) {
|
||||||
|
super(messenger);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected XMPPConnection createXmppConnection(ConnectionConfiguration configuration) {
|
||||||
|
XMPPTCPConnectionConfiguration tcpConfiguration = (XMPPTCPConnectionConfiguration) configuration;
|
||||||
|
return new XMPPTCPConnection(tcpConfiguration);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,50 @@
|
||||||
|
package org.mercury_im.xmpp.connection.message;
|
||||||
|
|
||||||
|
import org.jivesoftware.smack.chat2.Chat;
|
||||||
|
import org.jivesoftware.smack.chat2.ChatManager;
|
||||||
|
import org.jivesoftware.smack.packet.Message;
|
||||||
|
import org.jivesoftware.smackx.sid.element.OriginIdElement;
|
||||||
|
import org.mercury_im.core.message.MessageCenter;
|
||||||
|
import org.mercury_im.messenger.xmpp.entity.XmppAccount;
|
||||||
|
import org.mercury_im.messenger.xmpp.entity.XmppAddress;
|
||||||
|
import org.mercury_im.messenger.xmpp.entity.chat.XmppDirectChat;
|
||||||
|
import org.mercury_im.messenger.xmpp.entity.message.XmppMessage;
|
||||||
|
import org.mercury_im.messenger.xmpp.entity.message.XmppMessageMetadata;
|
||||||
|
|
||||||
|
import io.reactivex.Completable;
|
||||||
|
|
||||||
|
public class XmppDirectMessageCenter
|
||||||
|
implements MessageCenter<
|
||||||
|
XmppMessage.DirectMessage,
|
||||||
|
XmppDirectChat,
|
||||||
|
XmppAddress.XmppUserAddress,
|
||||||
|
XmppMessageMetadata,
|
||||||
|
XmppAccount> {
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Completable sendMessage(XmppMessage.DirectMessage message, XmppDirectChat chat) {
|
||||||
|
ChatManager chatManager = getChatManager(chat);
|
||||||
|
|
||||||
|
Message smackMessage = new Message();
|
||||||
|
smackMessage.setFrom(chat.getAccount().getAddress().getJid());
|
||||||
|
smackMessage.setTo(chat.getInterlocutor().getAddress().getJid());
|
||||||
|
smackMessage.setType(Message.Type.chat);
|
||||||
|
|
||||||
|
OriginIdElement.addOriginId(smackMessage);
|
||||||
|
|
||||||
|
|
||||||
|
Chat smackChat = chatManager.chatWith(chat.getInterlocutor().getAddress().getJid());
|
||||||
|
return Completable.fromAction(
|
||||||
|
() -> smackChat.send(smackMessage));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addIncomingMessageListener() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ChatManager getChatManager(XmppDirectChat chat) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
/build
|
|
@ -0,0 +1,8 @@
|
||||||
|
apply plugin: 'java-library'
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation project(':entity')
|
||||||
|
}
|
||||||
|
|
||||||
|
sourceCompatibility = "8"
|
||||||
|
targetCompatibility = "8"
|
|
@ -0,0 +1,134 @@
|
||||||
|
package org.mercury_im.messenger.view.entity;
|
||||||
|
|
||||||
|
import org.mercury_im.messenger.core.entity.contact.Contact;
|
||||||
|
import org.mercury_im.messenger.view.entity.definition.InterlocutorViewEntity;
|
||||||
|
|
||||||
|
public class ViewInterlocutor<A> implements InterlocutorViewEntity {
|
||||||
|
|
||||||
|
private final String name;
|
||||||
|
private final String address;
|
||||||
|
private final String accountAddress;
|
||||||
|
private final Contact.SubscriptionMode subscriptionMode;
|
||||||
|
private final String lastActivity;
|
||||||
|
private final boolean isTyping;
|
||||||
|
private final String status;
|
||||||
|
private final A avatar;
|
||||||
|
|
||||||
|
private ViewInterlocutor(String name,
|
||||||
|
String address,
|
||||||
|
String accountAddress,
|
||||||
|
Contact.SubscriptionMode subscriptionMode,
|
||||||
|
String lastActivity,
|
||||||
|
boolean isTyping,
|
||||||
|
String status,
|
||||||
|
A avatar) {
|
||||||
|
this.name = name;
|
||||||
|
this.address = address;
|
||||||
|
this.accountAddress = accountAddress;
|
||||||
|
this.subscriptionMode = subscriptionMode;
|
||||||
|
this.lastActivity = lastActivity;
|
||||||
|
this.isTyping = isTyping;
|
||||||
|
this.status = status;
|
||||||
|
this.avatar = avatar;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getAddress() {
|
||||||
|
return address;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getAccountAddress() {
|
||||||
|
return accountAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Contact.SubscriptionMode getSubscriptionMode() {
|
||||||
|
return subscriptionMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getLastActivity() {
|
||||||
|
return lastActivity;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isTyping() {
|
||||||
|
return isTyping;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public A getAvatar() {
|
||||||
|
return avatar;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <A> Builder<A> builder() {
|
||||||
|
return new Builder<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class Builder<A> {
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
private String address;
|
||||||
|
private String accountAddress;
|
||||||
|
private Contact.SubscriptionMode subscriptionMode;
|
||||||
|
private String lastActivity;
|
||||||
|
private boolean isTyping;
|
||||||
|
private String status;
|
||||||
|
private A avatar;
|
||||||
|
|
||||||
|
public Builder setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder setAddress(String address) {
|
||||||
|
this.address = address;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder setAccountAddress(String accountAddress) {
|
||||||
|
this.accountAddress = accountAddress;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder setSubscriptionMode(Contact.SubscriptionMode subscriptionMode) {
|
||||||
|
this.subscriptionMode = subscriptionMode;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder setLastActivity(String lastActivity) {
|
||||||
|
this.lastActivity = lastActivity;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder setIsTyping(boolean isTyping) {
|
||||||
|
this.isTyping = isTyping;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder setStatus(String status) {
|
||||||
|
this.status = status;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder setAvatar(A avatar) {
|
||||||
|
this.avatar = avatar;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ViewInterlocutor<A> build() {
|
||||||
|
return new ViewInterlocutor<>(name, address, accountAddress, subscriptionMode,
|
||||||
|
lastActivity, isTyping, status, avatar);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
package org.mercury_im.messenger.view.entity.definition;
|
||||||
|
|
||||||
|
import org.mercury_im.messenger.core.entity.contact.Contact;
|
||||||
|
|
||||||
|
public interface InterlocutorViewEntity {
|
||||||
|
|
||||||
|
String getName();
|
||||||
|
|
||||||
|
String getAddress();
|
||||||
|
|
||||||
|
String getAccountAddress();
|
||||||
|
|
||||||
|
Contact.SubscriptionMode getSubscriptionMode();
|
||||||
|
|
||||||
|
String getLastActivity();
|
||||||
|
|
||||||
|
boolean isTyping();
|
||||||
|
|
||||||
|
String getStatus();
|
||||||
|
}
|
Loading…
Reference in New Issue