more refactoring for presence selection. removed getTo, getFrom and getJid from Element
This commit is contained in:
parent
26b4788733
commit
89ee999e1b
|
@ -67,18 +67,14 @@ public class Message extends AbstractEntity {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Message(Conversation conversation, String body, int encryption) {
|
public Message(Conversation conversation, String body, int encryption) {
|
||||||
this(java.util.UUID.randomUUID().toString(), conversation.getUuid(),
|
this(conversation,body,encryption,STATUS_UNSEND);
|
||||||
conversation.getContactJid(), null, body, System
|
|
||||||
.currentTimeMillis(), encryption,
|
|
||||||
Message.STATUS_UNSEND, TYPE_TEXT, null);
|
|
||||||
this.conversation = conversation;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Message(final Conversation conversation, final Jid counterpart, final String body,
|
public Message(Conversation conversation, String body, int encryption, int status) {
|
||||||
final int encryption, final int status) {
|
|
||||||
this(java.util.UUID.randomUUID().toString(), conversation.getUuid(),
|
this(java.util.UUID.randomUUID().toString(), conversation.getUuid(),
|
||||||
counterpart, null, body, System.currentTimeMillis(),
|
conversation.getContactJid().toBareJid(), null, body, System
|
||||||
encryption, status, TYPE_TEXT, null);
|
.currentTimeMillis(), encryption,
|
||||||
|
status, TYPE_TEXT, null);
|
||||||
this.conversation = conversation;
|
this.conversation = conversation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
package eu.siacs.conversations.parser;
|
package eu.siacs.conversations.parser;
|
||||||
|
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import net.java.otr4j.session.Session;
|
import net.java.otr4j.session.Session;
|
||||||
import net.java.otr4j.session.SessionStatus;
|
import net.java.otr4j.session.SessionStatus;
|
||||||
|
|
||||||
|
import eu.siacs.conversations.Config;
|
||||||
import eu.siacs.conversations.entities.Account;
|
import eu.siacs.conversations.entities.Account;
|
||||||
import eu.siacs.conversations.entities.Contact;
|
import eu.siacs.conversations.entities.Contact;
|
||||||
import eu.siacs.conversations.entities.Conversation;
|
import eu.siacs.conversations.entities.Conversation;
|
||||||
|
@ -30,10 +33,10 @@ public class MessageParser extends AbstractParser implements
|
||||||
String pgpBody = getPgpBody(packet);
|
String pgpBody = getPgpBody(packet);
|
||||||
Message finishedMessage;
|
Message finishedMessage;
|
||||||
if (pgpBody != null) {
|
if (pgpBody != null) {
|
||||||
finishedMessage = new Message(conversation, packet.getFrom(),
|
finishedMessage = new Message(conversation,
|
||||||
pgpBody, Message.ENCRYPTION_PGP, Message.STATUS_RECEIVED);
|
pgpBody, Message.ENCRYPTION_PGP, Message.STATUS_RECEIVED);
|
||||||
} else {
|
} else {
|
||||||
finishedMessage = new Message(conversation, packet.getFrom(),
|
finishedMessage = new Message(conversation,
|
||||||
packet.getBody(), Message.ENCRYPTION_NONE,
|
packet.getBody(), Message.ENCRYPTION_NONE,
|
||||||
Message.STATUS_RECEIVED);
|
Message.STATUS_RECEIVED);
|
||||||
}
|
}
|
||||||
|
@ -110,12 +113,12 @@ public class MessageParser extends AbstractParser implements
|
||||||
conversation.setSymmetricKey(CryptoHelper.hexToBytes(key));
|
conversation.setSymmetricKey(CryptoHelper.hexToBytes(key));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Message finishedMessage = new Message(conversation,
|
Message finishedMessage = new Message(conversation, body, Message.ENCRYPTION_OTR,
|
||||||
packet.getFrom(), body, Message.ENCRYPTION_OTR,
|
|
||||||
Message.STATUS_RECEIVED);
|
Message.STATUS_RECEIVED);
|
||||||
finishedMessage.setTime(getTimestamp(packet));
|
finishedMessage.setTime(getTimestamp(packet));
|
||||||
finishedMessage.setRemoteMsgId(packet.getId());
|
finishedMessage.setRemoteMsgId(packet.getId());
|
||||||
finishedMessage.markable = isMarkable(packet);
|
finishedMessage.markable = isMarkable(packet);
|
||||||
|
finishedMessage.setCounterpart(from);
|
||||||
return finishedMessage;
|
return finishedMessage;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
String receivedId = packet.getId();
|
String receivedId = packet.getId();
|
||||||
|
@ -158,14 +161,15 @@ public class MessageParser extends AbstractParser implements
|
||||||
String pgpBody = getPgpBody(packet);
|
String pgpBody = getPgpBody(packet);
|
||||||
Message finishedMessage;
|
Message finishedMessage;
|
||||||
if (pgpBody == null) {
|
if (pgpBody == null) {
|
||||||
finishedMessage = new Message(conversation, from,
|
finishedMessage = new Message(conversation,
|
||||||
packet.getBody(), Message.ENCRYPTION_NONE, status);
|
packet.getBody(), Message.ENCRYPTION_NONE, status);
|
||||||
} else {
|
} else {
|
||||||
finishedMessage = new Message(conversation, from, pgpBody,
|
finishedMessage = new Message(conversation, pgpBody,
|
||||||
Message.ENCRYPTION_PGP, status);
|
Message.ENCRYPTION_PGP, status);
|
||||||
}
|
}
|
||||||
finishedMessage.setRemoteMsgId(packet.getId());
|
finishedMessage.setRemoteMsgId(packet.getId());
|
||||||
finishedMessage.markable = isMarkable(packet);
|
finishedMessage.markable = isMarkable(packet);
|
||||||
|
finishedMessage.setCounterpart(from);
|
||||||
if (status == Message.STATUS_RECEIVED) {
|
if (status == Message.STATUS_RECEIVED) {
|
||||||
finishedMessage.setTrueCounterpart(conversation.getMucOptions()
|
finishedMessage.setTrueCounterpart(conversation.getMucOptions()
|
||||||
.getTrueCounterpart(from.getResourcepart()));
|
.getTrueCounterpart(from.getResourcepart()));
|
||||||
|
@ -206,7 +210,7 @@ public class MessageParser extends AbstractParser implements
|
||||||
parseNonMessage(message, account);
|
parseNonMessage(message, account);
|
||||||
} else if (status == Message.STATUS_SEND
|
} else if (status == Message.STATUS_SEND
|
||||||
&& message.hasChild("displayed", "urn:xmpp:chat-markers:0")) {
|
&& message.hasChild("displayed", "urn:xmpp:chat-markers:0")) {
|
||||||
final Jid to = message.getTo();
|
final Jid to = message.getAttributeAsJid("to");
|
||||||
if (to != null) {
|
if (to != null) {
|
||||||
final Conversation conversation = mXmppConnectionService.find(
|
final Conversation conversation = mXmppConnectionService.find(
|
||||||
mXmppConnectionService.getConversations(), account,
|
mXmppConnectionService.getConversations(), account,
|
||||||
|
@ -219,14 +223,14 @@ public class MessageParser extends AbstractParser implements
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (status == Message.STATUS_RECEIVED) {
|
if (status == Message.STATUS_RECEIVED) {
|
||||||
fullJid = message.getFrom();
|
fullJid = message.getAttributeAsJid("from");
|
||||||
if (fullJid == null) {
|
if (fullJid == null) {
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
updateLastseen(message, account, true);
|
updateLastseen(message, account, true);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fullJid = message.getTo();
|
fullJid = message.getAttributeAsJid("to");
|
||||||
if (fullJid == null) {
|
if (fullJid == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -236,20 +240,20 @@ public class MessageParser extends AbstractParser implements
|
||||||
String pgpBody = getPgpBody(message);
|
String pgpBody = getPgpBody(message);
|
||||||
Message finishedMessage;
|
Message finishedMessage;
|
||||||
if (pgpBody != null) {
|
if (pgpBody != null) {
|
||||||
finishedMessage = new Message(conversation, fullJid, pgpBody,
|
finishedMessage = new Message(conversation, pgpBody,
|
||||||
Message.ENCRYPTION_PGP, status);
|
Message.ENCRYPTION_PGP, status);
|
||||||
} else {
|
} else {
|
||||||
String body = message.findChild("body").getContent();
|
String body = message.findChild("body").getContent();
|
||||||
finishedMessage = new Message(conversation, fullJid, body,
|
finishedMessage = new Message(conversation, body,
|
||||||
Message.ENCRYPTION_NONE, status);
|
Message.ENCRYPTION_NONE, status);
|
||||||
}
|
}
|
||||||
finishedMessage.setTime(getTimestamp(message));
|
finishedMessage.setTime(getTimestamp(message));
|
||||||
finishedMessage.setRemoteMsgId(message.getAttribute("id"));
|
finishedMessage.setRemoteMsgId(message.getAttribute("id"));
|
||||||
finishedMessage.markable = isMarkable(message);
|
finishedMessage.markable = isMarkable(message);
|
||||||
|
finishedMessage.setCounterpart(fullJid);
|
||||||
if (conversation.getMode() == Conversation.MODE_MULTI
|
if (conversation.getMode() == Conversation.MODE_MULTI
|
||||||
&& !fullJid.isBareJid()) {
|
&& !fullJid.isBareJid()) {
|
||||||
finishedMessage.setType(Message.TYPE_PRIVATE);
|
finishedMessage.setType(Message.TYPE_PRIVATE);
|
||||||
finishedMessage.setCounterpart(fullJid);
|
|
||||||
finishedMessage.setTrueCounterpart(conversation.getMucOptions()
|
finishedMessage.setTrueCounterpart(conversation.getMucOptions()
|
||||||
.getTrueCounterpart(fullJid.getResourcepart()));
|
.getTrueCounterpart(fullJid.getResourcepart()));
|
||||||
if (conversation.hasDuplicateMessage(finishedMessage)) {
|
if (conversation.hasDuplicateMessage(finishedMessage)) {
|
||||||
|
@ -266,7 +270,7 @@ public class MessageParser extends AbstractParser implements
|
||||||
}
|
}
|
||||||
|
|
||||||
private void parseNonMessage(Element packet, Account account) {
|
private void parseNonMessage(Element packet, Account account) {
|
||||||
final Jid from = packet.getFrom();
|
final Jid from = packet.getAttributeAsJid("from");
|
||||||
if (packet.hasChild("event", "http://jabber.org/protocol/pubsub#event")) {
|
if (packet.hasChild("event", "http://jabber.org/protocol/pubsub#event")) {
|
||||||
Element event = packet.findChild("event",
|
Element event = packet.findChild("event",
|
||||||
"http://jabber.org/protocol/pubsub#event");
|
"http://jabber.org/protocol/pubsub#event");
|
||||||
|
@ -299,7 +303,7 @@ public class MessageParser extends AbstractParser implements
|
||||||
if (x.hasChild("invite")) {
|
if (x.hasChild("invite")) {
|
||||||
Conversation conversation = mXmppConnectionService
|
Conversation conversation = mXmppConnectionService
|
||||||
.findOrCreateConversation(account,
|
.findOrCreateConversation(account,
|
||||||
packet.getFrom(), true);
|
packet.getAttributeAsJid("from"), true);
|
||||||
if (!conversation.getMucOptions().online()) {
|
if (!conversation.getMucOptions().online()) {
|
||||||
if (x.hasChild("password")) {
|
if (x.hasChild("password")) {
|
||||||
Element password = x.findChild("password");
|
Element password = x.findChild("password");
|
||||||
|
@ -479,6 +483,7 @@ public class MessageParser extends AbstractParser implements
|
||||||
&& conversation.getOtrSession() != null
|
&& conversation.getOtrSession() != null
|
||||||
&& !conversation.getOtrSession().getSessionID().getUserID()
|
&& !conversation.getOtrSession().getSessionID().getUserID()
|
||||||
.equals(message.getCounterpart().getResourcepart())) {
|
.equals(message.getCounterpart().getResourcepart())) {
|
||||||
|
Log.d(Config.LOGTAG, "ending because of reasons");
|
||||||
conversation.endOtrIfNeeded();
|
conversation.endOtrIfNeeded();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,40 @@
|
||||||
package eu.siacs.conversations.services;
|
package eu.siacs.conversations.services;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
|
import android.app.AlarmManager;
|
||||||
|
import android.app.PendingIntent;
|
||||||
|
import android.app.Service;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.database.ContentObserver;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.net.ConnectivityManager;
|
||||||
|
import android.net.NetworkInfo;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.os.Binder;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.FileObserver;
|
||||||
|
import android.os.IBinder;
|
||||||
|
import android.os.PowerManager;
|
||||||
|
import android.os.PowerManager.WakeLock;
|
||||||
|
import android.os.SystemClock;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
|
import android.provider.ContactsContract;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.util.LruCache;
|
||||||
|
|
||||||
|
import net.java.otr4j.OtrException;
|
||||||
|
import net.java.otr4j.session.Session;
|
||||||
|
import net.java.otr4j.session.SessionID;
|
||||||
|
import net.java.otr4j.session.SessionStatus;
|
||||||
|
|
||||||
|
import org.openintents.openpgp.util.OpenPgpApi;
|
||||||
|
import org.openintents.openpgp.util.OpenPgpServiceConnection;
|
||||||
|
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStream;
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -12,15 +47,7 @@ import java.util.Locale;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
|
|
||||||
import org.openintents.openpgp.util.OpenPgpApi;
|
|
||||||
import org.openintents.openpgp.util.OpenPgpServiceConnection;
|
|
||||||
|
|
||||||
import de.duenndns.ssl.MemorizingTrustManager;
|
import de.duenndns.ssl.MemorizingTrustManager;
|
||||||
|
|
||||||
import net.java.otr4j.OtrException;
|
|
||||||
import net.java.otr4j.session.Session;
|
|
||||||
import net.java.otr4j.session.SessionID;
|
|
||||||
import net.java.otr4j.session.SessionStatus;
|
|
||||||
import eu.siacs.conversations.Config;
|
import eu.siacs.conversations.Config;
|
||||||
import eu.siacs.conversations.R;
|
import eu.siacs.conversations.R;
|
||||||
import eu.siacs.conversations.crypto.PgpEngine;
|
import eu.siacs.conversations.crypto.PgpEngine;
|
||||||
|
@ -65,63 +92,23 @@ import eu.siacs.conversations.xmpp.pep.Avatar;
|
||||||
import eu.siacs.conversations.xmpp.stanzas.IqPacket;
|
import eu.siacs.conversations.xmpp.stanzas.IqPacket;
|
||||||
import eu.siacs.conversations.xmpp.stanzas.MessagePacket;
|
import eu.siacs.conversations.xmpp.stanzas.MessagePacket;
|
||||||
import eu.siacs.conversations.xmpp.stanzas.PresencePacket;
|
import eu.siacs.conversations.xmpp.stanzas.PresencePacket;
|
||||||
import android.annotation.SuppressLint;
|
|
||||||
import android.app.AlarmManager;
|
|
||||||
import android.app.PendingIntent;
|
|
||||||
import android.app.Service;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.database.ContentObserver;
|
|
||||||
import android.graphics.Bitmap;
|
|
||||||
import android.net.ConnectivityManager;
|
|
||||||
import android.net.NetworkInfo;
|
|
||||||
import android.net.Uri;
|
|
||||||
import android.os.Binder;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.os.FileObserver;
|
|
||||||
import android.os.IBinder;
|
|
||||||
import android.os.PowerManager;
|
|
||||||
import android.os.PowerManager.WakeLock;
|
|
||||||
import android.os.SystemClock;
|
|
||||||
import android.preference.PreferenceManager;
|
|
||||||
import android.provider.ContactsContract;
|
|
||||||
import android.util.Log;
|
|
||||||
import android.util.LruCache;
|
|
||||||
|
|
||||||
public class XmppConnectionService extends Service {
|
public class XmppConnectionService extends Service {
|
||||||
|
|
||||||
public DatabaseBackend databaseBackend;
|
|
||||||
private FileBackend fileBackend = new FileBackend(this);
|
|
||||||
|
|
||||||
private static String ACTION_MERGE_PHONE_CONTACTS = "merge_phone_contacts";
|
|
||||||
public static String ACTION_CLEAR_NOTIFICATION = "clear_notification";
|
public static String ACTION_CLEAR_NOTIFICATION = "clear_notification";
|
||||||
|
private static String ACTION_MERGE_PHONE_CONTACTS = "merge_phone_contacts";
|
||||||
private MemorizingTrustManager mMemorizingTrustManager;
|
private ContentObserver contactObserver = new ContentObserver(null) {
|
||||||
|
@Override
|
||||||
private NotificationService mNotificationService = new NotificationService(
|
public void onChange(boolean selfChange) {
|
||||||
this);
|
super.onChange(selfChange);
|
||||||
|
Intent intent = new Intent(getApplicationContext(),
|
||||||
private MessageParser mMessageParser = new MessageParser(this);
|
XmppConnectionService.class);
|
||||||
private PresenceParser mPresenceParser = new PresenceParser(this);
|
intent.setAction(ACTION_MERGE_PHONE_CONTACTS);
|
||||||
private IqParser mIqParser = new IqParser(this);
|
startService(intent);
|
||||||
private MessageGenerator mMessageGenerator = new MessageGenerator(this);
|
}
|
||||||
private PresenceGenerator mPresenceGenerator = new PresenceGenerator(this);
|
};
|
||||||
|
private final IBinder mBinder = new XmppConnectionBinder();
|
||||||
private List<Account> accounts;
|
public DatabaseBackend databaseBackend;
|
||||||
private CopyOnWriteArrayList<Conversation> conversations = null;
|
|
||||||
private JingleConnectionManager mJingleConnectionManager = new JingleConnectionManager(
|
|
||||||
this);
|
|
||||||
private HttpConnectionManager mHttpConnectionManager = new HttpConnectionManager(
|
|
||||||
this);
|
|
||||||
private AvatarService mAvatarService = new AvatarService(this);
|
|
||||||
|
|
||||||
private OnConversationUpdate mOnConversationUpdate = null;
|
|
||||||
private Integer convChangedListenerCount = 0;
|
|
||||||
private OnAccountUpdate mOnAccountUpdate = null;
|
|
||||||
private Integer accountChangedListenerCount = 0;
|
|
||||||
private OnRosterUpdate mOnRosterUpdate = null;
|
|
||||||
private Integer rosterChangedListenerCount = 0;
|
|
||||||
public OnContactStatusChanged onContactStatusChanged = new OnContactStatusChanged() {
|
public OnContactStatusChanged onContactStatusChanged = new OnContactStatusChanged() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -139,32 +126,25 @@ public class XmppConnectionService extends Service {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
private FileBackend fileBackend = new FileBackend(this);
|
||||||
private SecureRandom mRandom;
|
private MemorizingTrustManager mMemorizingTrustManager;
|
||||||
|
private NotificationService mNotificationService = new NotificationService(
|
||||||
private ContentObserver contactObserver = new ContentObserver(null) {
|
this);
|
||||||
@Override
|
private MessageParser mMessageParser = new MessageParser(this);
|
||||||
public void onChange(boolean selfChange) {
|
private PresenceParser mPresenceParser = new PresenceParser(this);
|
||||||
super.onChange(selfChange);
|
private IqParser mIqParser = new IqParser(this);
|
||||||
Intent intent = new Intent(getApplicationContext(),
|
private MessageGenerator mMessageGenerator = new MessageGenerator(this);
|
||||||
XmppConnectionService.class);
|
private PresenceGenerator mPresenceGenerator = new PresenceGenerator(this);
|
||||||
intent.setAction(ACTION_MERGE_PHONE_CONTACTS);
|
private List<Account> accounts;
|
||||||
startService(intent);
|
private CopyOnWriteArrayList<Conversation> conversations = null;
|
||||||
}
|
private JingleConnectionManager mJingleConnectionManager = new JingleConnectionManager(
|
||||||
};
|
this);
|
||||||
|
private HttpConnectionManager mHttpConnectionManager = new HttpConnectionManager(
|
||||||
private FileObserver fileObserver = new FileObserver(
|
this);
|
||||||
FileBackend.getConversationsDirectory()) {
|
private AvatarService mAvatarService = new AvatarService(this);
|
||||||
|
private OnConversationUpdate mOnConversationUpdate = null;
|
||||||
@Override
|
private Integer convChangedListenerCount = 0;
|
||||||
public void onEvent(int event, String path) {
|
private OnAccountUpdate mOnAccountUpdate = null;
|
||||||
if (event == FileObserver.DELETE) {
|
|
||||||
markFileDeleted(path.split("\\.")[0]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private final IBinder mBinder = new XmppConnectionBinder();
|
|
||||||
private OnStatusChanged statusListener = new OnStatusChanged() {
|
private OnStatusChanged statusListener = new OnStatusChanged() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -225,7 +205,20 @@ public class XmppConnectionService extends Service {
|
||||||
getAccounts());
|
getAccounts());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
private Integer accountChangedListenerCount = 0;
|
||||||
|
private OnRosterUpdate mOnRosterUpdate = null;
|
||||||
|
private Integer rosterChangedListenerCount = 0;
|
||||||
|
private SecureRandom mRandom;
|
||||||
|
private FileObserver fileObserver = new FileObserver(
|
||||||
|
FileBackend.getConversationsDirectory()) {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEvent(int event, String path) {
|
||||||
|
if (event == FileObserver.DELETE) {
|
||||||
|
markFileDeleted(path.split("\\.")[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
private OnJinglePacketReceived jingleListener = new OnJinglePacketReceived() {
|
private OnJinglePacketReceived jingleListener = new OnJinglePacketReceived() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -276,6 +269,8 @@ public class XmppConnectionService extends Service {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
private LruCache<String, Bitmap> mBitmapCache;
|
private LruCache<String, Bitmap> mBitmapCache;
|
||||||
|
private OnRenameListener renameListener = null;
|
||||||
|
private IqGenerator mIqGenerator = new IqGenerator(this);
|
||||||
|
|
||||||
public PgpEngine getPgpEngine() {
|
public PgpEngine getPgpEngine() {
|
||||||
if (pgpServiceConnection.isBound()) {
|
if (pgpServiceConnection.isBound()) {
|
||||||
|
@ -339,12 +334,6 @@ public class XmppConnectionService extends Service {
|
||||||
return find(getConversations(), account, jid);
|
return find(getConversations(), account, jid);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class XmppConnectionBinder extends Binder {
|
|
||||||
public XmppConnectionService getService() {
|
|
||||||
return XmppConnectionService.this;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||||
if (intent != null && intent.getAction() != null) {
|
if (intent != null && intent.getAction() != null) {
|
||||||
|
@ -412,6 +401,10 @@ public class XmppConnectionService extends Service {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
PowerManager pm = (PowerManager) this.getSystemService(Context.POWER_SERVICE);
|
||||||
|
if (!pm.isScreenOn()) {
|
||||||
|
removeStaleListeners();
|
||||||
|
}
|
||||||
if (wakeLock.isHeld()) {
|
if (wakeLock.isHeld()) {
|
||||||
try {
|
try {
|
||||||
wakeLock.release();
|
wakeLock.release();
|
||||||
|
@ -586,12 +579,6 @@ public class XmppConnectionService extends Service {
|
||||||
conv.startOtrSession(this, message.getCounterpart().getResourcepart(), true);
|
conv.startOtrSession(this, message.getCounterpart().getResourcepart(), true);
|
||||||
message.setStatus(Message.STATUS_WAITING);
|
message.setStatus(Message.STATUS_WAITING);
|
||||||
} else if (conv.hasValidOtrSession()) {
|
} else if (conv.hasValidOtrSession()) {
|
||||||
SessionID id = conv.getOtrSession().getSessionID();
|
|
||||||
try {
|
|
||||||
message.setCounterpart(Jid.fromString(id.getAccountID() + "/" + id.getUserID()));
|
|
||||||
} catch (final InvalidJidException e) {
|
|
||||||
message.setCounterpart(null);
|
|
||||||
}
|
|
||||||
if (conv.getOtrSession().getSessionStatus() == SessionStatus.ENCRYPTED) {
|
if (conv.getOtrSession().getSessionStatus() == SessionStatus.ENCRYPTED) {
|
||||||
packet = mMessageGenerator.generateOtrChat(message);
|
packet = mMessageGenerator.generateOtrChat(message);
|
||||||
send = true;
|
send = true;
|
||||||
|
@ -631,14 +618,7 @@ public class XmppConnectionService extends Service {
|
||||||
message.setBody(decryptedBody);
|
message.setBody(decryptedBody);
|
||||||
message.setEncryption(Message.ENCRYPTION_DECRYPTED);
|
message.setEncryption(Message.ENCRYPTION_DECRYPTED);
|
||||||
} else if (message.getEncryption() == Message.ENCRYPTION_OTR) {
|
} else if (message.getEncryption() == Message.ENCRYPTION_OTR) {
|
||||||
if (conv.hasValidOtrSession()) {
|
if (!conv.hasValidOtrSession()
|
||||||
SessionID id = conv.getOtrSession().getSessionID();
|
|
||||||
try {
|
|
||||||
message.setCounterpart(Jid.fromString(id.getAccountID() + "/" + id.getUserID()));
|
|
||||||
} catch (final InvalidJidException e) {
|
|
||||||
message.setCounterpart(null);
|
|
||||||
}
|
|
||||||
} else if (!conv.hasValidOtrSession()
|
|
||||||
&& message.getCounterpart() != null) {
|
&& message.getCounterpart() != null) {
|
||||||
conv.startOtrSession(this, message.getCounterpart().getResourcepart(), false);
|
conv.startOtrSession(this, message.getCounterpart().getResourcepart(), false);
|
||||||
}
|
}
|
||||||
|
@ -1058,6 +1038,46 @@ public class XmppConnectionService extends Service {
|
||||||
UIHelper.showErrorNotification(getApplicationContext(), getAccounts());
|
UIHelper.showErrorNotification(getApplicationContext(), getAccounts());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void removeStaleListeners() {
|
||||||
|
boolean removedListener = false;
|
||||||
|
synchronized (this.convChangedListenerCount) {
|
||||||
|
if (this.mOnConversationUpdate != null) {
|
||||||
|
this.mOnConversationUpdate = null;
|
||||||
|
this.convChangedListenerCount = 0;
|
||||||
|
this.mNotificationService.setIsInForeground(false);
|
||||||
|
removedListener = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
synchronized (this.accountChangedListenerCount) {
|
||||||
|
if (this.mOnAccountUpdate != null) {
|
||||||
|
this.mOnAccountUpdate = null;
|
||||||
|
this.accountChangedListenerCount = 0;
|
||||||
|
removedListener = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
synchronized (this.rosterChangedListenerCount) {
|
||||||
|
if (this.mOnRosterUpdate != null) {
|
||||||
|
this.mOnRosterUpdate = null;
|
||||||
|
this.rosterChangedListenerCount = 0;
|
||||||
|
removedListener = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (removedListener) {
|
||||||
|
final String msg = "removed stale listeners";
|
||||||
|
Log.d(Config.LOGTAG, msg);
|
||||||
|
checkListeners();
|
||||||
|
try {
|
||||||
|
OutputStream os = openFileOutput("stacktrace.txt", MODE_PRIVATE);
|
||||||
|
os.write(msg.getBytes());
|
||||||
|
os.flush();
|
||||||
|
os.close();
|
||||||
|
} catch (final FileNotFoundException ignored) {
|
||||||
|
|
||||||
|
} catch (final IOException ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void setOnConversationListChangedListener(
|
public void setOnConversationListChangedListener(
|
||||||
OnConversationUpdate listener) {
|
OnConversationUpdate listener) {
|
||||||
if (!isScreenOn()) {
|
if (!isScreenOn()) {
|
||||||
|
@ -1232,9 +1252,6 @@ public class XmppConnectionService extends Service {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private OnRenameListener renameListener = null;
|
|
||||||
private IqGenerator mIqGenerator = new IqGenerator(this);
|
|
||||||
|
|
||||||
public void setOnRenameListener(OnRenameListener listener) {
|
public void setOnRenameListener(OnRenameListener listener) {
|
||||||
this.renameListener = listener;
|
this.renameListener = listener;
|
||||||
}
|
}
|
||||||
|
@ -1898,18 +1915,6 @@ public class XmppConnectionService extends Service {
|
||||||
return this.mJingleConnectionManager;
|
return this.mJingleConnectionManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface OnConversationUpdate {
|
|
||||||
public void onConversationUpdate();
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface OnAccountUpdate {
|
|
||||||
public void onAccountUpdate();
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface OnRosterUpdate {
|
|
||||||
public void onRosterUpdate();
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Contact> findContacts(String jid) {
|
public List<Contact> findContacts(String jid) {
|
||||||
ArrayList<Contact> contacts = new ArrayList<>();
|
ArrayList<Contact> contacts = new ArrayList<>();
|
||||||
for (Account account : getAccounts()) {
|
for (Account account : getAccounts()) {
|
||||||
|
@ -1931,6 +1936,41 @@ public class XmppConnectionService extends Service {
|
||||||
return this.mHttpConnectionManager;
|
return this.mHttpConnectionManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void resendFailedMessages(Message message) {
|
||||||
|
List<Message> messages = new ArrayList<>();
|
||||||
|
Message current = message;
|
||||||
|
while (current.getStatus() == Message.STATUS_SEND_FAILED) {
|
||||||
|
messages.add(current);
|
||||||
|
if (current.mergeable(current.next())) {
|
||||||
|
current = current.next();
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (Message msg : messages) {
|
||||||
|
markMessage(msg, Message.STATUS_WAITING);
|
||||||
|
this.resendMessage(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface OnConversationUpdate {
|
||||||
|
public void onConversationUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface OnAccountUpdate {
|
||||||
|
public void onAccountUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface OnRosterUpdate {
|
||||||
|
public void onRosterUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public class XmppConnectionBinder extends Binder {
|
||||||
|
public XmppConnectionService getService() {
|
||||||
|
return XmppConnectionService.this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private class DeletedDownloadable implements Downloadable {
|
private class DeletedDownloadable implements Downloadable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1949,21 +1989,4 @@ public class XmppConnectionService extends Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resendFailedMessages(Message message) {
|
|
||||||
List<Message> messages = new ArrayList<>();
|
|
||||||
Message current = message;
|
|
||||||
while(current.getStatus() == Message.STATUS_SEND_FAILED) {
|
|
||||||
messages.add(current);
|
|
||||||
if (current.mergeable(current.next())) {
|
|
||||||
current = current.next();
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for(Message msg: messages) {
|
|
||||||
markMessage(msg, Message.STATUS_WAITING);
|
|
||||||
this.resendMessage(msg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -825,10 +825,6 @@ public class ConversationFragment extends Fragment {
|
||||||
protected void sendOtrMessage(final Message message) {
|
protected void sendOtrMessage(final Message message) {
|
||||||
final ConversationActivity activity = (ConversationActivity) getActivity();
|
final ConversationActivity activity = (ConversationActivity) getActivity();
|
||||||
final XmppConnectionService xmppService = activity.xmppConnectionService;
|
final XmppConnectionService xmppService = activity.xmppConnectionService;
|
||||||
if (conversation.hasValidOtrSession()) {
|
|
||||||
activity.xmppConnectionService.sendMessage(message);
|
|
||||||
messageSent();
|
|
||||||
} else {
|
|
||||||
activity.selectPresence(message.getConversation(),
|
activity.selectPresence(message.getConversation(),
|
||||||
new OnPresenceSelected() {
|
new OnPresenceSelected() {
|
||||||
|
|
||||||
|
@ -840,7 +836,6 @@ public class ConversationFragment extends Fragment {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void appendText(String text) {
|
public void appendText(String text) {
|
||||||
String previous = this.mEditMessage.getText().toString();
|
String previous = this.mEditMessage.getText().toString();
|
||||||
|
|
|
@ -48,6 +48,8 @@ import com.google.zxing.common.BitMatrix;
|
||||||
import com.google.zxing.qrcode.QRCodeWriter;
|
import com.google.zxing.qrcode.QRCodeWriter;
|
||||||
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
|
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
|
||||||
|
|
||||||
|
import net.java.otr4j.session.SessionID;
|
||||||
|
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
|
@ -452,7 +454,17 @@ public abstract class XmppActivity extends Activity {
|
||||||
public void selectPresence(final Conversation conversation,
|
public void selectPresence(final Conversation conversation,
|
||||||
final OnPresenceSelected listener) {
|
final OnPresenceSelected listener) {
|
||||||
final Contact contact = conversation.getContact();
|
final Contact contact = conversation.getContact();
|
||||||
if (!contact.showInRoster()) {
|
if (conversation.hasValidOtrSession()) {
|
||||||
|
SessionID id = conversation.getOtrSession().getSessionID();
|
||||||
|
Jid jid;
|
||||||
|
try {
|
||||||
|
jid = Jid.fromString(id.getAccountID() + "/" + id.getUserID());
|
||||||
|
} catch (InvalidJidException e) {
|
||||||
|
jid = null;
|
||||||
|
}
|
||||||
|
conversation.setNextCounterpart(jid);
|
||||||
|
listener.onPresenceSelected();
|
||||||
|
} else if (!contact.showInRoster()) {
|
||||||
showAddToRosterDialog(conversation);
|
showAddToRosterDialog(conversation);
|
||||||
} else {
|
} else {
|
||||||
Presences presences = contact.getPresences();
|
Presences presences = contact.getPresences();
|
||||||
|
|
|
@ -31,6 +31,8 @@ public class ExceptionHandler implements UncaughtExceptionHandler {
|
||||||
OutputStream os = context.openFileOutput("stacktrace.txt",
|
OutputStream os = context.openFileOutput("stacktrace.txt",
|
||||||
Context.MODE_PRIVATE);
|
Context.MODE_PRIVATE);
|
||||||
os.write(stacktrace.getBytes());
|
os.write(stacktrace.getBytes());
|
||||||
|
os.flush();
|
||||||
|
os.close();
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
|
@ -105,8 +105,8 @@ public class Element {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Jid getJid() {
|
public Jid getAttributeAsJid(String name) {
|
||||||
final String jid = this.getAttribute("jid");
|
final String jid = this.getAttribute(name);
|
||||||
if (jid != null && !jid.isEmpty()) {
|
if (jid != null && !jid.isEmpty()) {
|
||||||
try {
|
try {
|
||||||
return Jid.fromString(jid);
|
return Jid.fromString(jid);
|
||||||
|
@ -117,30 +117,6 @@ public class Element {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Jid getTo() {
|
|
||||||
final String to = this.getAttribute("to");
|
|
||||||
if (to != null && !to.isEmpty()) {
|
|
||||||
try {
|
|
||||||
return Jid.fromString(to);
|
|
||||||
} catch (final InvalidJidException e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Jid getFrom() {
|
|
||||||
final String from = this.getAttribute("from");
|
|
||||||
if (from != null && !from.isEmpty()) {
|
|
||||||
try {
|
|
||||||
return Jid.fromString(from);
|
|
||||||
} catch (final InvalidJidException e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Hashtable<String, String> getAttributes() {
|
public Hashtable<String, String> getAttributes() {
|
||||||
return this.attributes;
|
return this.attributes;
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,7 +109,7 @@ public class JingleCandidate {
|
||||||
JingleCandidate parsedCandidate = new JingleCandidate(
|
JingleCandidate parsedCandidate = new JingleCandidate(
|
||||||
candidate.getAttribute("cid"), false);
|
candidate.getAttribute("cid"), false);
|
||||||
parsedCandidate.setHost(candidate.getAttribute("host"));
|
parsedCandidate.setHost(candidate.getAttribute("host"));
|
||||||
parsedCandidate.setJid(candidate.getJid());
|
parsedCandidate.setJid(candidate.getAttributeAsJid("jid"));
|
||||||
parsedCandidate.setType(candidate.getAttribute("type"));
|
parsedCandidate.setType(candidate.getAttribute("type"));
|
||||||
parsedCandidate.setPriority(Integer.parseInt(candidate
|
parsedCandidate.setPriority(Integer.parseInt(candidate
|
||||||
.getAttribute("priority")));
|
.getAttribute("priority")));
|
||||||
|
|
Loading…
Reference in New Issue