mirror of
https://codeberg.org/Mercury-IM/Mercury-IM
synced 2024-06-27 22:14:52 +02:00
Temp
This commit is contained in:
parent
273788b11f
commit
184c0777c1
|
@ -4,7 +4,7 @@ apply plugin: 'checkstyle'
|
||||||
android {
|
android {
|
||||||
compileSdkVersion 28
|
compileSdkVersion 28
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId "org.olomono.messenger"
|
applicationId "org.mercury_im.messenger"
|
||||||
minSdkVersion 19
|
minSdkVersion 19
|
||||||
targetSdkVersion 28
|
targetSdkVersion 28
|
||||||
versionCode 1
|
versionCode 1
|
||||||
|
|
|
@ -33,6 +33,9 @@ public class RoomPlainMessageHandler implements PlainMessageHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void newIncomingMessage(EntityBareJid from, Message message, Chat chat) {
|
public void newIncomingMessage(EntityBareJid from, Message message, Chat chat) {
|
||||||
|
if (message.getBody() == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
MessageModel messageModel = new RoomMessageModel();
|
MessageModel messageModel = new RoomMessageModel();
|
||||||
messageModel.setAccountId(accountId);
|
messageModel.setAccountId(accountId);
|
||||||
messageModel.setFrom(chat.getXmppAddressOfChatPartner());
|
messageModel.setFrom(chat.getXmppAddressOfChatPartner());
|
||||||
|
@ -60,6 +63,9 @@ public class RoomPlainMessageHandler implements PlainMessageHandler {
|
||||||
@Override
|
@Override
|
||||||
public void onCarbonCopyReceived(CarbonExtension.Direction direction, Message carbonCopy, Message wrappingMessage) {
|
public void onCarbonCopyReceived(CarbonExtension.Direction direction, Message carbonCopy, Message wrappingMessage) {
|
||||||
Log.d(TAG, "onCarbonReceived:" + carbonCopy.toXML());
|
Log.d(TAG, "onCarbonReceived:" + carbonCopy.toXML());
|
||||||
|
if (carbonCopy.getBody() == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
MessageModel messageModel = new RoomMessageModel();
|
MessageModel messageModel = new RoomMessageModel();
|
||||||
messageModel.setAccountId(accountId);
|
messageModel.setAccountId(accountId);
|
||||||
messageModel.setFrom(carbonCopy.getFrom() != null ? carbonCopy.getFrom().asEntityBareJidIfPossible() : null);
|
messageModel.setFrom(carbonCopy.getFrom() != null ? carbonCopy.getFrom().asEntityBareJidIfPossible() : null);
|
||||||
|
|
|
@ -17,6 +17,7 @@ import org.jivesoftware.smack.SmackException;
|
||||||
import org.jivesoftware.smack.XMPPConnection;
|
import org.jivesoftware.smack.XMPPConnection;
|
||||||
import org.jivesoftware.smack.XMPPException;
|
import org.jivesoftware.smack.XMPPException;
|
||||||
import org.jivesoftware.smack.tcp.XMPPTCPConnection;
|
import org.jivesoftware.smack.tcp.XMPPTCPConnection;
|
||||||
|
import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration;
|
||||||
import org.jivesoftware.smackx.ping.android.ServerPingWithAlarmManager;
|
import org.jivesoftware.smackx.ping.android.ServerPingWithAlarmManager;
|
||||||
import org.jxmpp.stringprep.XmppStringprepException;
|
import org.jxmpp.stringprep.XmppStringprepException;
|
||||||
import org.mercury_im.messenger.MercuryImApplication;
|
import org.mercury_im.messenger.MercuryImApplication;
|
||||||
|
@ -194,12 +195,17 @@ public class XmppConnectionService extends Service implements ConnectionHolder {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
XMPPTCPConnectionConfiguration configuration = XMPPTCPConnectionConfiguration.builder()
|
||||||
|
.setHost(accountModel.getJid().getDomain().toString())
|
||||||
|
.setXmppAddressAndPassword(accountModel.getJid(), accountModel.getPassword())
|
||||||
|
.setConnectTimeout(2 * 60 * 1000)
|
||||||
|
.build();
|
||||||
|
|
||||||
new Thread() {
|
new Thread() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
XMPPTCPConnection connection = new XMPPTCPConnection(accountModel.getJid().getLocalpart().asUnescapedString(),
|
XMPPTCPConnection connection = new XMPPTCPConnection(configuration);
|
||||||
accountModel.getPassword(), accountModel.getJid().getDomain().toString());
|
|
||||||
connection.setUseStreamManagement(true);
|
connection.setUseStreamManagement(true);
|
||||||
connection.setUseStreamManagementResumption(true);
|
connection.setUseStreamManagementResumption(true);
|
||||||
MercuryConnection mercuryConnection = new AndroidMercuryConnection(connection, accountModel.getId());
|
MercuryConnection mercuryConnection = new AndroidMercuryConnection(connection, accountModel.getId());
|
||||||
|
|
|
@ -122,12 +122,16 @@ public class ChatActivity extends BindingActivity implements ChatInputFragment.O
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onComposingBodySend(String body) {
|
public void onComposingBodySend(String body) {
|
||||||
|
String msg = body.trim();
|
||||||
|
if (msg.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
new Thread() {
|
new Thread() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
ChatManager.getInstanceFor(connectionService.getConnection(accountId).getConnection())
|
ChatManager.getInstanceFor(connectionService.getConnection(accountId).getConnection())
|
||||||
.chatWith(jid).send(body);
|
.chatWith(jid).send(msg);
|
||||||
} catch (SmackException.NotConnectedException e) {
|
} catch (SmackException.NotConnectedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
|
|
|
@ -17,6 +17,7 @@ import com.google.android.material.textfield.TextInputEditText;
|
||||||
import org.jivesoftware.smack.SmackException;
|
import org.jivesoftware.smack.SmackException;
|
||||||
import org.jivesoftware.smack.XMPPException;
|
import org.jivesoftware.smack.XMPPException;
|
||||||
import org.jivesoftware.smack.tcp.XMPPTCPConnection;
|
import org.jivesoftware.smack.tcp.XMPPTCPConnection;
|
||||||
|
import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration;
|
||||||
import org.jxmpp.jid.EntityBareJid;
|
import org.jxmpp.jid.EntityBareJid;
|
||||||
import org.jxmpp.jid.impl.JidCreate;
|
import org.jxmpp.jid.impl.JidCreate;
|
||||||
import org.jxmpp.stringprep.XmppStringprepException;
|
import org.jxmpp.stringprep.XmppStringprepException;
|
||||||
|
@ -145,12 +146,16 @@ public class LoginActivity extends BindingActivity implements TextView.OnEditorA
|
||||||
}
|
}
|
||||||
|
|
||||||
private void attemptLogin(AccountModel accountModel) {
|
private void attemptLogin(AccountModel accountModel) {
|
||||||
|
XMPPTCPConnectionConfiguration configuration = XMPPTCPConnectionConfiguration.builder()
|
||||||
|
.setHost(accountModel.getJid().getDomain().toString())
|
||||||
|
.setXmppAddressAndPassword(accountModel.getJid(), accountModel.getPassword())
|
||||||
|
.setConnectTimeout(2 * 60 * 1000)
|
||||||
|
.build();
|
||||||
new Thread() {
|
new Thread() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
XMPPTCPConnection connection = new XMPPTCPConnection(accountModel.getJid().getLocalpart().asUnescapedString(),
|
XMPPTCPConnection connection = new XMPPTCPConnection(configuration);
|
||||||
accountModel.getPassword(), accountModel.getJid().getDomain().toString());
|
|
||||||
connection.setUseStreamManagementResumption(true);
|
connection.setUseStreamManagementResumption(true);
|
||||||
connection.setUseStreamManagement(true);
|
connection.setUseStreamManagement(true);
|
||||||
MercuryConnection mercuryConnection = new AndroidMercuryConnection(connection, accountModel.getId());
|
MercuryConnection mercuryConnection = new AndroidMercuryConnection(connection, accountModel.getId());
|
||||||
|
|
|
@ -13,6 +13,7 @@ import androidx.appcompat.app.AppCompatActivity;
|
||||||
import androidx.core.app.ActivityOptionsCompat;
|
import androidx.core.app.ActivityOptionsCompat;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
|
import org.jivesoftware.smackx.colors.ConsistentColor;
|
||||||
import org.jxmpp.jid.EntityBareJid;
|
import org.jxmpp.jid.EntityBareJid;
|
||||||
import org.mercury_im.messenger.R;
|
import org.mercury_im.messenger.R;
|
||||||
import org.mercury_im.messenger.persistence.room.model.RoomContactAndEntityModel;
|
import org.mercury_im.messenger.persistence.room.model.RoomContactAndEntityModel;
|
||||||
|
@ -84,7 +85,7 @@ public class RosterRecyclerViewAdapter
|
||||||
nicknameView.setText(nick != null ? nick : "");
|
nicknameView.setText(nick != null ? nick : "");
|
||||||
EntityBareJid jid = contactModel.getEntity().getJid();
|
EntityBareJid jid = contactModel.getEntity().getJid();
|
||||||
jidView.setText(jid.toString());
|
jidView.setText(jid.toString());
|
||||||
jidView.setTextColor(ColorUtil.consistentColor(jid.toString()));
|
jidView.setTextColor(ColorUtil.consistentColor(jid.toString(), new ConsistentColor.ConsistentColorSettings(ConsistentColor.Deficiency.none)));
|
||||||
view.setOnClickListener(new View.OnClickListener() {
|
view.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
|
|
|
@ -1,15 +1,27 @@
|
||||||
package org.mercury_im.messenger.xmpp_core;
|
package org.mercury_im.messenger.xmpp_core;
|
||||||
|
|
||||||
|
import org.jivesoftware.smack.AbstractXMPPConnection;
|
||||||
import org.jivesoftware.smack.ConnectionListener;
|
import org.jivesoftware.smack.ConnectionListener;
|
||||||
|
import org.jivesoftware.smack.ReconnectionListener;
|
||||||
|
import org.jivesoftware.smack.ReconnectionManager;
|
||||||
|
import org.jivesoftware.smack.SmackException;
|
||||||
import org.jivesoftware.smack.XMPPConnection;
|
import org.jivesoftware.smack.XMPPConnection;
|
||||||
|
import org.jivesoftware.smack.XMPPException;
|
||||||
import org.jivesoftware.smack.chat2.ChatManager;
|
import org.jivesoftware.smack.chat2.ChatManager;
|
||||||
|
import org.jivesoftware.smack.iqrequest.AbstractIqRequestHandler;
|
||||||
|
import org.jivesoftware.smack.iqrequest.IQRequestHandler;
|
||||||
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smack.roster.Roster;
|
import org.jivesoftware.smack.roster.Roster;
|
||||||
import org.jivesoftware.smack.sm.packet.StreamManagement;
|
import org.jivesoftware.smack.sm.packet.StreamManagement;
|
||||||
import org.jivesoftware.smack.tcp.XMPPTCPConnection;
|
import org.jivesoftware.smack.tcp.XMPPTCPConnection;
|
||||||
import org.jivesoftware.smackx.carbons.CarbonManager;
|
import org.jivesoftware.smackx.carbons.CarbonManager;
|
||||||
import org.jivesoftware.smackx.csi.ClientStateIndicationManager;
|
import org.jivesoftware.smackx.csi.ClientStateIndicationManager;
|
||||||
|
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
||||||
|
import org.jivesoftware.smackx.disco.packet.DiscoverInfo;
|
||||||
|
import org.jivesoftware.smackx.iqversion.packet.Version;
|
||||||
import org.jivesoftware.smackx.sid.StableUniqueStanzaIdManager;
|
import org.jivesoftware.smackx.sid.StableUniqueStanzaIdManager;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
public abstract class MercuryConnection implements ConnectionListener {
|
public abstract class MercuryConnection implements ConnectionListener {
|
||||||
|
@ -21,10 +33,12 @@ public abstract class MercuryConnection implements ConnectionListener {
|
||||||
protected final XMPPConnection connection;
|
protected final XMPPConnection connection;
|
||||||
protected final long accountId;
|
protected final long accountId;
|
||||||
|
|
||||||
|
protected final ReconnectionManager reconnectionManager;
|
||||||
protected final Roster roster;
|
protected final Roster roster;
|
||||||
protected final ChatManager chatManager;
|
protected final ChatManager chatManager;
|
||||||
protected final CarbonManager carbonManager;
|
protected final CarbonManager carbonManager;
|
||||||
protected final StableUniqueStanzaIdManager stanzaIdManager;
|
protected final StableUniqueStanzaIdManager stanzaIdManager;
|
||||||
|
protected final ServiceDiscoveryManager serviceDiscoveryManager;
|
||||||
|
|
||||||
protected ConnectionStateHolder stateHolder;
|
protected ConnectionStateHolder stateHolder;
|
||||||
|
|
||||||
|
@ -33,13 +47,24 @@ public abstract class MercuryConnection implements ConnectionListener {
|
||||||
connection.addConnectionListener(this);
|
connection.addConnectionListener(this);
|
||||||
this.accountId = accountId;
|
this.accountId = accountId;
|
||||||
|
|
||||||
|
reconnectionManager = ReconnectionManager.getInstanceFor((AbstractXMPPConnection) connection);
|
||||||
|
reconnectionManager.enableAutomaticReconnection();
|
||||||
|
|
||||||
this.roster = Roster.getInstanceFor(connection);
|
this.roster = Roster.getInstanceFor(connection);
|
||||||
this.chatManager = ChatManager.getInstanceFor(connection);
|
this.chatManager = ChatManager.getInstanceFor(connection);
|
||||||
this.carbonManager = CarbonManager.getInstanceFor(connection);
|
this.carbonManager = CarbonManager.getInstanceFor(connection);
|
||||||
this.stanzaIdManager = StableUniqueStanzaIdManager.getInstanceFor(connection);
|
this.stanzaIdManager = StableUniqueStanzaIdManager.getInstanceFor(connection);
|
||||||
stanzaIdManager.enable();
|
stanzaIdManager.enable();
|
||||||
|
|
||||||
|
this.serviceDiscoveryManager = ServiceDiscoveryManager.getInstanceFor(connection);
|
||||||
|
serviceDiscoveryManager.setIdentity(new DiscoverInfo.Identity("client", "Mercury", "phone"));
|
||||||
|
|
||||||
|
connection.registerIQRequestHandler(new AbstractIqRequestHandler(Version.ELEMENT, Version.NAMESPACE, IQ.Type.get, IQRequestHandler.Mode.async) {
|
||||||
|
@Override
|
||||||
|
public IQ handleIQRequest(IQ iqRequest) {
|
||||||
|
return Version.createResultFor(iqRequest, new Version("Mercury", "stealth", "Android"));
|
||||||
|
}
|
||||||
|
});
|
||||||
roster.setRosterLoadedAtLogin(true);
|
roster.setRosterLoadedAtLogin(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,7 +119,6 @@ public abstract class MercuryConnection implements ConnectionListener {
|
||||||
@Override
|
@Override
|
||||||
public void connectionClosedOnError(Exception e) {
|
public void connectionClosedOnError(Exception e) {
|
||||||
LOGGER.severe("Connection closed on error: " + e.getMessage());
|
LOGGER.severe("Connection closed on error: " + e.getMessage());
|
||||||
e.printStackTrace();
|
|
||||||
getState().updateConnectionState(ConnectionState.DISCONNECTED);
|
getState().updateConnectionState(ConnectionState.DISCONNECTED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue