This commit is contained in:
Paul Schaub 2019-07-02 00:46:40 +02:00
parent 273788b11f
commit 184c0777c1
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
7 changed files with 54 additions and 8 deletions

View file

@ -4,7 +4,7 @@ apply plugin: 'checkstyle'
android {
compileSdkVersion 28
defaultConfig {
applicationId "org.olomono.messenger"
applicationId "org.mercury_im.messenger"
minSdkVersion 19
targetSdkVersion 28
versionCode 1

View file

@ -33,6 +33,9 @@ public class RoomPlainMessageHandler implements PlainMessageHandler {
@Override
public void newIncomingMessage(EntityBareJid from, Message message, Chat chat) {
if (message.getBody() == null) {
return;
}
MessageModel messageModel = new RoomMessageModel();
messageModel.setAccountId(accountId);
messageModel.setFrom(chat.getXmppAddressOfChatPartner());
@ -60,6 +63,9 @@ public class RoomPlainMessageHandler implements PlainMessageHandler {
@Override
public void onCarbonCopyReceived(CarbonExtension.Direction direction, Message carbonCopy, Message wrappingMessage) {
Log.d(TAG, "onCarbonReceived:" + carbonCopy.toXML());
if (carbonCopy.getBody() == null) {
return;
}
MessageModel messageModel = new RoomMessageModel();
messageModel.setAccountId(accountId);
messageModel.setFrom(carbonCopy.getFrom() != null ? carbonCopy.getFrom().asEntityBareJidIfPossible() : null);

View file

@ -17,6 +17,7 @@ import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.tcp.XMPPTCPConnection;
import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration;
import org.jivesoftware.smackx.ping.android.ServerPingWithAlarmManager;
import org.jxmpp.stringprep.XmppStringprepException;
import org.mercury_im.messenger.MercuryImApplication;
@ -194,12 +195,17 @@ public class XmppConnectionService extends Service implements ConnectionHolder {
return;
}
XMPPTCPConnectionConfiguration configuration = XMPPTCPConnectionConfiguration.builder()
.setHost(accountModel.getJid().getDomain().toString())
.setXmppAddressAndPassword(accountModel.getJid(), accountModel.getPassword())
.setConnectTimeout(2 * 60 * 1000)
.build();
new Thread() {
@Override
public void run() {
try {
XMPPTCPConnection connection = new XMPPTCPConnection(accountModel.getJid().getLocalpart().asUnescapedString(),
accountModel.getPassword(), accountModel.getJid().getDomain().toString());
XMPPTCPConnection connection = new XMPPTCPConnection(configuration);
connection.setUseStreamManagement(true);
connection.setUseStreamManagementResumption(true);
MercuryConnection mercuryConnection = new AndroidMercuryConnection(connection, accountModel.getId());

View file

@ -122,12 +122,16 @@ public class ChatActivity extends BindingActivity implements ChatInputFragment.O
@Override
public void onComposingBodySend(String body) {
String msg = body.trim();
if (msg.isEmpty()) {
return;
}
new Thread() {
@Override
public void run() {
try {
ChatManager.getInstanceFor(connectionService.getConnection(accountId).getConnection())
.chatWith(jid).send(body);
.chatWith(jid).send(msg);
} catch (SmackException.NotConnectedException e) {
e.printStackTrace();
} catch (InterruptedException e) {

View file

@ -17,6 +17,7 @@ import com.google.android.material.textfield.TextInputEditText;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.tcp.XMPPTCPConnection;
import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration;
import org.jxmpp.jid.EntityBareJid;
import org.jxmpp.jid.impl.JidCreate;
import org.jxmpp.stringprep.XmppStringprepException;
@ -145,12 +146,16 @@ public class LoginActivity extends BindingActivity implements TextView.OnEditorA
}
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() {
@Override
public void run() {
try {
XMPPTCPConnection connection = new XMPPTCPConnection(accountModel.getJid().getLocalpart().asUnescapedString(),
accountModel.getPassword(), accountModel.getJid().getDomain().toString());
XMPPTCPConnection connection = new XMPPTCPConnection(configuration);
connection.setUseStreamManagementResumption(true);
connection.setUseStreamManagement(true);
MercuryConnection mercuryConnection = new AndroidMercuryConnection(connection, accountModel.getId());

View file

@ -13,6 +13,7 @@ import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityOptionsCompat;
import androidx.recyclerview.widget.RecyclerView;
import org.jivesoftware.smackx.colors.ConsistentColor;
import org.jxmpp.jid.EntityBareJid;
import org.mercury_im.messenger.R;
import org.mercury_im.messenger.persistence.room.model.RoomContactAndEntityModel;
@ -84,7 +85,7 @@ public class RosterRecyclerViewAdapter
nicknameView.setText(nick != null ? nick : "");
EntityBareJid jid = contactModel.getEntity().getJid();
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() {
@Override
public void onClick(View view) {

View file

@ -1,15 +1,27 @@
package org.mercury_im.messenger.xmpp_core;
import org.jivesoftware.smack.AbstractXMPPConnection;
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.XMPPException;
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.sm.packet.StreamManagement;
import org.jivesoftware.smack.tcp.XMPPTCPConnection;
import org.jivesoftware.smackx.carbons.CarbonManager;
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 java.io.IOException;
import java.util.logging.Logger;
public abstract class MercuryConnection implements ConnectionListener {
@ -21,10 +33,12 @@ public abstract class MercuryConnection implements ConnectionListener {
protected final XMPPConnection connection;
protected final long accountId;
protected final ReconnectionManager reconnectionManager;
protected final Roster roster;
protected final ChatManager chatManager;
protected final CarbonManager carbonManager;
protected final StableUniqueStanzaIdManager stanzaIdManager;
protected final ServiceDiscoveryManager serviceDiscoveryManager;
protected ConnectionStateHolder stateHolder;
@ -33,13 +47,24 @@ public abstract class MercuryConnection implements ConnectionListener {
connection.addConnectionListener(this);
this.accountId = accountId;
reconnectionManager = ReconnectionManager.getInstanceFor((AbstractXMPPConnection) connection);
reconnectionManager.enableAutomaticReconnection();
this.roster = Roster.getInstanceFor(connection);
this.chatManager = ChatManager.getInstanceFor(connection);
this.carbonManager = CarbonManager.getInstanceFor(connection);
this.stanzaIdManager = StableUniqueStanzaIdManager.getInstanceFor(connection);
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);
}
@ -94,7 +119,6 @@ public abstract class MercuryConnection implements ConnectionListener {
@Override
public void connectionClosedOnError(Exception e) {
LOGGER.severe("Connection closed on error: " + e.getMessage());
e.printStackTrace();
getState().updateConnectionState(ConnectionState.DISCONNECTED);
}
}