|
|
@ -49,6 +49,7 @@ import eu.siacs.conversations.xml.Element;
|
|
|
|
import eu.siacs.conversations.xmpp.OnBindListener;
|
|
|
|
import eu.siacs.conversations.xmpp.OnBindListener;
|
|
|
|
import eu.siacs.conversations.xmpp.OnContactStatusChanged;
|
|
|
|
import eu.siacs.conversations.xmpp.OnContactStatusChanged;
|
|
|
|
import eu.siacs.conversations.xmpp.OnIqPacketReceived;
|
|
|
|
import eu.siacs.conversations.xmpp.OnIqPacketReceived;
|
|
|
|
|
|
|
|
import eu.siacs.conversations.xmpp.OnMessageAcknowledged;
|
|
|
|
import eu.siacs.conversations.xmpp.OnStatusChanged;
|
|
|
|
import eu.siacs.conversations.xmpp.OnStatusChanged;
|
|
|
|
import eu.siacs.conversations.xmpp.XmppConnection;
|
|
|
|
import eu.siacs.conversations.xmpp.XmppConnection;
|
|
|
|
import eu.siacs.conversations.xmpp.jingle.JingleConnectionManager;
|
|
|
|
import eu.siacs.conversations.xmpp.jingle.JingleConnectionManager;
|
|
|
@ -95,7 +96,7 @@ public class XmppConnectionService extends Service {
|
|
|
|
public static final long CARBON_GRACE_PERIOD = 60000L;
|
|
|
|
public static final long CARBON_GRACE_PERIOD = 60000L;
|
|
|
|
|
|
|
|
|
|
|
|
private static String ACTION_MERGE_PHONE_CONTACTS = "merge_phone_contacts";
|
|
|
|
private static String ACTION_MERGE_PHONE_CONTACTS = "merge_phone_contacts";
|
|
|
|
|
|
|
|
|
|
|
|
private MemorizingTrustManager mMemorizingTrustManager;
|
|
|
|
private MemorizingTrustManager mMemorizingTrustManager;
|
|
|
|
|
|
|
|
|
|
|
|
private MessageParser mMessageParser = new MessageParser(this);
|
|
|
|
private MessageParser mMessageParser = new MessageParser(this);
|
|
|
@ -103,7 +104,7 @@ public class XmppConnectionService extends Service {
|
|
|
|
private IqParser mIqParser = new IqParser(this);
|
|
|
|
private IqParser mIqParser = new IqParser(this);
|
|
|
|
private MessageGenerator mMessageGenerator = new MessageGenerator();
|
|
|
|
private MessageGenerator mMessageGenerator = new MessageGenerator();
|
|
|
|
private PresenceGenerator mPresenceGenerator = new PresenceGenerator();
|
|
|
|
private PresenceGenerator mPresenceGenerator = new PresenceGenerator();
|
|
|
|
|
|
|
|
|
|
|
|
private List<Account> accounts;
|
|
|
|
private List<Account> accounts;
|
|
|
|
private CopyOnWriteArrayList<Conversation> conversations = null;
|
|
|
|
private CopyOnWriteArrayList<Conversation> conversations = null;
|
|
|
|
private JingleConnectionManager mJingleConnectionManager = new JingleConnectionManager(
|
|
|
|
private JingleConnectionManager mJingleConnectionManager = new JingleConnectionManager(
|
|
|
@ -118,7 +119,7 @@ public class XmppConnectionService extends Service {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onContactStatusChanged(Contact contact, boolean online) {
|
|
|
|
public void onContactStatusChanged(Contact contact, boolean online) {
|
|
|
|
Conversation conversation = find(getConversations(),contact);
|
|
|
|
Conversation conversation = find(getConversations(), contact);
|
|
|
|
if (conversation != null) {
|
|
|
|
if (conversation != null) {
|
|
|
|
conversation.endOtrIfNeeded();
|
|
|
|
conversation.endOtrIfNeeded();
|
|
|
|
if (online && (contact.getPresences().size() == 1)) {
|
|
|
|
if (online && (contact.getPresences().size() == 1)) {
|
|
|
@ -146,14 +147,16 @@ public class XmppConnectionService extends Service {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onStatusChanged(Account account) {
|
|
|
|
public void onStatusChanged(Account account) {
|
|
|
|
|
|
|
|
XmppConnection connection = account.getXmppConnection();
|
|
|
|
if (mOnAccountUpdate != null) {
|
|
|
|
if (mOnAccountUpdate != null) {
|
|
|
|
mOnAccountUpdate.onAccountUpdate();;
|
|
|
|
mOnAccountUpdate.onAccountUpdate();
|
|
|
|
|
|
|
|
;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (account.getStatus() == Account.STATUS_ONLINE) {
|
|
|
|
if (account.getStatus() == Account.STATUS_ONLINE) {
|
|
|
|
for(Conversation conversation : account.pendingConferenceLeaves) {
|
|
|
|
for (Conversation conversation : account.pendingConferenceLeaves) {
|
|
|
|
leaveMuc(conversation);
|
|
|
|
leaveMuc(conversation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for(Conversation conversation : account.pendingConferenceJoins) {
|
|
|
|
for (Conversation conversation : account.pendingConferenceJoins) {
|
|
|
|
joinMuc(conversation);
|
|
|
|
joinMuc(conversation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mJingleConnectionManager.cancelInTransmission();
|
|
|
|
mJingleConnectionManager.cancelInTransmission();
|
|
|
@ -164,27 +167,35 @@ public class XmppConnectionService extends Service {
|
|
|
|
sendUnsendMessages(conversations.get(i));
|
|
|
|
sendUnsendMessages(conversations.get(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (connection != null && connection.getFeatures().csi()) {
|
|
|
|
|
|
|
|
if (checkListeners()) {
|
|
|
|
|
|
|
|
Log.d(LOGTAG, account.getJid()
|
|
|
|
|
|
|
|
+ " sending csi//inactive");
|
|
|
|
|
|
|
|
connection.sendInactive();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
Log.d(LOGTAG, account.getJid() + " sending csi//active");
|
|
|
|
|
|
|
|
connection.sendActive();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
syncDirtyContacts(account);
|
|
|
|
syncDirtyContacts(account);
|
|
|
|
scheduleWakeupCall(PING_MAX_INTERVAL, true);
|
|
|
|
scheduleWakeupCall(PING_MAX_INTERVAL, true);
|
|
|
|
} else if (account.getStatus() == Account.STATUS_OFFLINE) {
|
|
|
|
} else if (account.getStatus() == Account.STATUS_OFFLINE) {
|
|
|
|
|
|
|
|
resetSendingToWaiting(account);
|
|
|
|
if (!account.isOptionSet(Account.OPTION_DISABLED)) {
|
|
|
|
if (!account.isOptionSet(Account.OPTION_DISABLED)) {
|
|
|
|
int timeToReconnect = mRandom.nextInt(50) + 10;
|
|
|
|
int timeToReconnect = mRandom.nextInt(50) + 10;
|
|
|
|
scheduleWakeupCall(timeToReconnect, false);
|
|
|
|
scheduleWakeupCall(timeToReconnect, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} else if (account.getStatus() == Account.STATUS_REGISTRATION_SUCCESSFULL) {
|
|
|
|
} else if (account.getStatus() == Account.STATUS_REGISTRATION_SUCCESSFULL) {
|
|
|
|
databaseBackend.updateAccount(account);
|
|
|
|
databaseBackend.updateAccount(account);
|
|
|
|
reconnectAccount(account, true);
|
|
|
|
reconnectAccount(account, true);
|
|
|
|
} else if ((account.getStatus() != Account.STATUS_CONNECTING)
|
|
|
|
} else if ((account.getStatus() != Account.STATUS_CONNECTING)
|
|
|
|
&& (account.getStatus() != Account.STATUS_NO_INTERNET)) {
|
|
|
|
&& (account.getStatus() != Account.STATUS_NO_INTERNET)) {
|
|
|
|
XmppConnection connection = account.getXmppConnection();
|
|
|
|
if (connection != null) {
|
|
|
|
if (connection!=null) {
|
|
|
|
|
|
|
|
int next = connection.getTimeToNextAttempt();
|
|
|
|
int next = connection.getTimeToNextAttempt();
|
|
|
|
Log.d(LOGTAG, account.getJid()
|
|
|
|
Log.d(LOGTAG, account.getJid()
|
|
|
|
+ ": error connecting account. try again in " + next
|
|
|
|
+ ": error connecting account. try again in "
|
|
|
|
+ "s for the "
|
|
|
|
+ next + "s for the "
|
|
|
|
+ (connection.getAttempt() + 1)
|
|
|
|
+ (connection.getAttempt() + 1) + " time");
|
|
|
|
+ " time");
|
|
|
|
|
|
|
|
scheduleWakeupCall((int) (next * 1.2), false);
|
|
|
|
scheduleWakeupCall((int) (next * 1.2), false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -209,19 +220,39 @@ public class XmppConnectionService extends Service {
|
|
|
|
private PowerManager pm;
|
|
|
|
private PowerManager pm;
|
|
|
|
private OnBindListener mOnBindListener = new OnBindListener() {
|
|
|
|
private OnBindListener mOnBindListener = new OnBindListener() {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onBind(final Account account) {
|
|
|
|
public void onBind(final Account account) {
|
|
|
|
account.getRoster().clearPresences();
|
|
|
|
account.getRoster().clearPresences();
|
|
|
|
account.clearPresences(); // self presences
|
|
|
|
account.clearPresences(); // self presences
|
|
|
|
account.pendingConferenceJoins.clear();
|
|
|
|
account.pendingConferenceJoins.clear();
|
|
|
|
account.pendingConferenceLeaves.clear();
|
|
|
|
account.pendingConferenceLeaves.clear();
|
|
|
|
fetchRosterFromServer(account);
|
|
|
|
fetchRosterFromServer(account);
|
|
|
|
fetchBookmarks(account);
|
|
|
|
fetchBookmarks(account);
|
|
|
|
sendPresencePacket(account, mPresenceGenerator.sendPresence(account));
|
|
|
|
sendPresencePacket(account,
|
|
|
|
connectMultiModeConversations(account);
|
|
|
|
mPresenceGenerator.sendPresence(account));
|
|
|
|
updateConversationUi();
|
|
|
|
connectMultiModeConversations(account);
|
|
|
|
|
|
|
|
updateConversationUi();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private OnMessageAcknowledged mOnMessageAcknowledgedListener = new OnMessageAcknowledged() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onMessageAcknowledged(Account account, String uuid) {
|
|
|
|
|
|
|
|
for (Conversation conversation : getConversations()) {
|
|
|
|
|
|
|
|
if (conversation.getAccount() == account) {
|
|
|
|
|
|
|
|
for (Message message : conversation.getMessages()) {
|
|
|
|
|
|
|
|
if ((message.getStatus() == Message.STATUS_UNSEND || message
|
|
|
|
|
|
|
|
.getStatus() == Message.STATUS_WAITING)
|
|
|
|
|
|
|
|
&& message.getUuid().equals(uuid)) {
|
|
|
|
|
|
|
|
markMessage(message, Message.STATUS_SEND);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
public PgpEngine getPgpEngine() {
|
|
|
|
public PgpEngine getPgpEngine() {
|
|
|
|
if (pgpServiceConnection.isBound()) {
|
|
|
|
if (pgpServiceConnection.isBound()) {
|
|
|
@ -274,11 +305,11 @@ public class XmppConnectionService extends Service {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Conversation find(Bookmark bookmark) {
|
|
|
|
public Conversation find(Bookmark bookmark) {
|
|
|
|
return find(bookmark.getAccount(),bookmark.getJid());
|
|
|
|
return find(bookmark.getAccount(), bookmark.getJid());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Conversation find(Account account, String jid) {
|
|
|
|
public Conversation find(Account account, String jid) {
|
|
|
|
return find(getConversations(),account,jid);
|
|
|
|
return find(getConversations(), account, jid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public class XmppConnectionBinder extends Binder {
|
|
|
|
public class XmppConnectionBinder extends Binder {
|
|
|
@ -320,8 +351,10 @@ public class XmppConnectionService extends Service {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (account.getStatus() == Account.STATUS_ONLINE) {
|
|
|
|
if (account.getStatus() == Account.STATUS_ONLINE) {
|
|
|
|
long lastReceived = account.getXmppConnection().getLastPacketReceived();
|
|
|
|
long lastReceived = account.getXmppConnection()
|
|
|
|
long lastSent = account.getXmppConnection().getLastPingSent();
|
|
|
|
.getLastPacketReceived();
|
|
|
|
|
|
|
|
long lastSent = account.getXmppConnection()
|
|
|
|
|
|
|
|
.getLastPingSent();
|
|
|
|
if (lastSent - lastReceived >= PING_TIMEOUT * 1000) {
|
|
|
|
if (lastSent - lastReceived >= PING_TIMEOUT * 1000) {
|
|
|
|
Log.d(LOGTAG, account.getJid() + ": ping timeout");
|
|
|
|
Log.d(LOGTAG, account.getJid() + ": ping timeout");
|
|
|
|
this.reconnectAccount(account, true);
|
|
|
|
this.reconnectAccount(account, true);
|
|
|
@ -369,7 +402,8 @@ public class XmppConnectionService extends Service {
|
|
|
|
ExceptionHelper.init(getApplicationContext());
|
|
|
|
ExceptionHelper.init(getApplicationContext());
|
|
|
|
PRNGFixes.apply();
|
|
|
|
PRNGFixes.apply();
|
|
|
|
this.mRandom = new SecureRandom();
|
|
|
|
this.mRandom = new SecureRandom();
|
|
|
|
this.mMemorizingTrustManager = new MemorizingTrustManager(getApplicationContext());
|
|
|
|
this.mMemorizingTrustManager = new MemorizingTrustManager(
|
|
|
|
|
|
|
|
getApplicationContext());
|
|
|
|
this.databaseBackend = DatabaseBackend
|
|
|
|
this.databaseBackend = DatabaseBackend
|
|
|
|
.getInstance(getApplicationContext());
|
|
|
|
.getInstance(getApplicationContext());
|
|
|
|
this.fileBackend = new FileBackend(getApplicationContext());
|
|
|
|
this.fileBackend = new FileBackend(getApplicationContext());
|
|
|
@ -466,10 +500,11 @@ public class XmppConnectionService extends Service {
|
|
|
|
connection.setOnMessagePacketReceivedListener(this.mMessageParser);
|
|
|
|
connection.setOnMessagePacketReceivedListener(this.mMessageParser);
|
|
|
|
connection.setOnStatusChangedListener(this.statusListener);
|
|
|
|
connection.setOnStatusChangedListener(this.statusListener);
|
|
|
|
connection.setOnPresencePacketReceivedListener(this.mPresenceParser);
|
|
|
|
connection.setOnPresencePacketReceivedListener(this.mPresenceParser);
|
|
|
|
connection
|
|
|
|
connection.setOnUnregisteredIqPacketReceivedListener(this.mIqParser);
|
|
|
|
.setOnUnregisteredIqPacketReceivedListener(this.mIqParser);
|
|
|
|
|
|
|
|
connection.setOnJinglePacketReceivedListener(this.jingleListener);
|
|
|
|
connection.setOnJinglePacketReceivedListener(this.jingleListener);
|
|
|
|
connection.setOnBindListener(this.mOnBindListener);
|
|
|
|
connection.setOnBindListener(this.mOnBindListener);
|
|
|
|
|
|
|
|
connection
|
|
|
|
|
|
|
|
.setOnMessageAcknowledgeListener(this.mOnMessageAcknowledgedListener);
|
|
|
|
return connection;
|
|
|
|
return connection;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -514,8 +549,7 @@ public class XmppConnectionService extends Service {
|
|
|
|
.getUserID());
|
|
|
|
.getUserID());
|
|
|
|
packet = mMessageGenerator.generateOtrChat(message);
|
|
|
|
packet = mMessageGenerator.generateOtrChat(message);
|
|
|
|
send = true;
|
|
|
|
send = true;
|
|
|
|
message.setStatus(Message.STATUS_SEND);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else if (message.getPresence() == null) {
|
|
|
|
} else if (message.getPresence() == null) {
|
|
|
|
message.setStatus(Message.STATUS_WAITING);
|
|
|
|
message.setStatus(Message.STATUS_WAITING);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -523,14 +557,10 @@ public class XmppConnectionService extends Service {
|
|
|
|
message.getConversation().endOtrIfNeeded();
|
|
|
|
message.getConversation().endOtrIfNeeded();
|
|
|
|
failWaitingOtrMessages(message.getConversation());
|
|
|
|
failWaitingOtrMessages(message.getConversation());
|
|
|
|
packet = mMessageGenerator.generatePgpChat(message);
|
|
|
|
packet = mMessageGenerator.generatePgpChat(message);
|
|
|
|
message.setStatus(Message.STATUS_SEND);
|
|
|
|
|
|
|
|
send = true;
|
|
|
|
send = true;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
message.getConversation().endOtrIfNeeded();
|
|
|
|
message.getConversation().endOtrIfNeeded();
|
|
|
|
failWaitingOtrMessages(message.getConversation());
|
|
|
|
failWaitingOtrMessages(message.getConversation());
|
|
|
|
if (message.getConversation().getMode() == Conversation.MODE_SINGLE || message.getType() == Message.TYPE_PRIVATE) {
|
|
|
|
|
|
|
|
message.setStatus(Message.STATUS_SEND);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
packet = mMessageGenerator.generateChat(message);
|
|
|
|
packet = mMessageGenerator.generateChat(message);
|
|
|
|
send = true;
|
|
|
|
send = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -562,11 +592,14 @@ public class XmppConnectionService extends Service {
|
|
|
|
databaseBackend.createMessage(message);
|
|
|
|
databaseBackend.createMessage(message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
conv.getMessages().add(message);
|
|
|
|
conv.getMessages().add(message);
|
|
|
|
updateConversationUi();
|
|
|
|
|
|
|
|
if ((send) && (packet != null)) {
|
|
|
|
if ((send) && (packet != null)) {
|
|
|
|
|
|
|
|
if (!account.getXmppConnection().getFeatures().sm()
|
|
|
|
|
|
|
|
&& conv.getMode() != Conversation.MODE_MULTI) {
|
|
|
|
|
|
|
|
message.setStatus(Message.STATUS_SEND);
|
|
|
|
|
|
|
|
}
|
|
|
|
sendMessagePacket(account, packet);
|
|
|
|
sendMessagePacket(account, packet);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
updateConversationUi();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void sendUnsendMessages(Conversation conversation) {
|
|
|
|
private void sendUnsendMessages(Conversation conversation) {
|
|
|
@ -632,7 +665,7 @@ public class XmppConnectionService extends Service {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (packet != null) {
|
|
|
|
if (packet != null) {
|
|
|
|
sendMessagePacket(account,packet);
|
|
|
|
sendMessagePacket(account, packet);
|
|
|
|
markMessage(message, Message.STATUS_SEND);
|
|
|
|
markMessage(message, Message.STATUS_SEND);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -661,29 +694,31 @@ public class XmppConnectionService extends Service {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void fetchBookmarks(Account account) {
|
|
|
|
public void fetchBookmarks(Account account) {
|
|
|
|
IqPacket iqPacket = new IqPacket(IqPacket.TYPE_GET);
|
|
|
|
IqPacket iqPacket = new IqPacket(IqPacket.TYPE_GET);
|
|
|
|
Element query = iqPacket.query("jabber:iq:private");
|
|
|
|
Element query = iqPacket.query("jabber:iq:private");
|
|
|
|
query.addChild("storage", "storage:bookmarks");
|
|
|
|
query.addChild("storage", "storage:bookmarks");
|
|
|
|
OnIqPacketReceived callback = new OnIqPacketReceived() {
|
|
|
|
OnIqPacketReceived callback = new OnIqPacketReceived() {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onIqPacketReceived(Account account, IqPacket packet) {
|
|
|
|
public void onIqPacketReceived(Account account, IqPacket packet) {
|
|
|
|
Element query = packet.query();
|
|
|
|
Element query = packet.query();
|
|
|
|
List<Bookmark> bookmarks = new CopyOnWriteArrayList<Bookmark>();
|
|
|
|
List<Bookmark> bookmarks = new CopyOnWriteArrayList<Bookmark>();
|
|
|
|
Element storage = query.findChild("storage", "storage:bookmarks");
|
|
|
|
Element storage = query.findChild("storage",
|
|
|
|
if (storage!=null) {
|
|
|
|
"storage:bookmarks");
|
|
|
|
for(Element item : storage.getChildren()) {
|
|
|
|
if (storage != null) {
|
|
|
|
|
|
|
|
for (Element item : storage.getChildren()) {
|
|
|
|
if (item.getName().equals("conference")) {
|
|
|
|
if (item.getName().equals("conference")) {
|
|
|
|
Bookmark bookmark = Bookmark.parse(item,account);
|
|
|
|
Bookmark bookmark = Bookmark.parse(item, account);
|
|
|
|
bookmarks.add(bookmark);
|
|
|
|
bookmarks.add(bookmark);
|
|
|
|
Conversation conversation = find(bookmark);
|
|
|
|
Conversation conversation = find(bookmark);
|
|
|
|
if (conversation!=null) {
|
|
|
|
if (conversation != null) {
|
|
|
|
conversation.setBookmark(bookmark);
|
|
|
|
conversation.setBookmark(bookmark);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
if (bookmark.autojoin()) {
|
|
|
|
if (bookmark.autojoin()) {
|
|
|
|
conversation = findOrCreateConversation(account, bookmark.getJid(), true);
|
|
|
|
conversation = findOrCreateConversation(
|
|
|
|
|
|
|
|
account, bookmark.getJid(), true);
|
|
|
|
conversation.setBookmark(bookmark);
|
|
|
|
conversation.setBookmark(bookmark);
|
|
|
|
joinMuc(conversation);
|
|
|
|
joinMuc(conversation);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -695,17 +730,17 @@ public class XmppConnectionService extends Service {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
sendIqPacket(account, iqPacket, callback);
|
|
|
|
sendIqPacket(account, iqPacket, callback);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void pushBookmarks(Account account) {
|
|
|
|
public void pushBookmarks(Account account) {
|
|
|
|
IqPacket iqPacket = new IqPacket(IqPacket.TYPE_SET);
|
|
|
|
IqPacket iqPacket = new IqPacket(IqPacket.TYPE_SET);
|
|
|
|
Element query = iqPacket.query("jabber:iq:private");
|
|
|
|
Element query = iqPacket.query("jabber:iq:private");
|
|
|
|
Element storage = query.addChild("storage", "storage:bookmarks");
|
|
|
|
Element storage = query.addChild("storage", "storage:bookmarks");
|
|
|
|
for(Bookmark bookmark : account.getBookmarks()) {
|
|
|
|
for (Bookmark bookmark : account.getBookmarks()) {
|
|
|
|
storage.addChild(bookmark.toElement());
|
|
|
|
storage.addChild(bookmark.toElement());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sendIqPacket(account, iqPacket,null);
|
|
|
|
sendIqPacket(account, iqPacket, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void mergePhoneContactsWithRoster() {
|
|
|
|
private void mergePhoneContactsWithRoster() {
|
|
|
@ -750,10 +785,10 @@ public class XmppConnectionService extends Service {
|
|
|
|
conv.setMessages(databaseBackend.getMessages(conv, 50));
|
|
|
|
conv.setMessages(databaseBackend.getMessages(conv, 50));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return this.conversations;
|
|
|
|
return this.conversations;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void populateWithOrderedConversations(List<Conversation> list) {
|
|
|
|
public void populateWithOrderedConversations(List<Conversation> list) {
|
|
|
|
list.clear();
|
|
|
|
list.clear();
|
|
|
|
list.addAll(getConversations());
|
|
|
|
list.addAll(getConversations());
|
|
|
@ -796,7 +831,8 @@ public class XmppConnectionService extends Service {
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Conversation find(List<Conversation> haystack, Account account, String jid) {
|
|
|
|
public Conversation find(List<Conversation> haystack, Account account,
|
|
|
|
|
|
|
|
String jid) {
|
|
|
|
for (Conversation conversation : haystack) {
|
|
|
|
for (Conversation conversation : haystack) {
|
|
|
|
if ((conversation.getAccount().equals(account))
|
|
|
|
if ((conversation.getAccount().equals(account))
|
|
|
|
&& (conversation.getContactJid().split("/")[0].equals(jid))) {
|
|
|
|
&& (conversation.getContactJid().split("/")[0].equals(jid))) {
|
|
|
@ -805,15 +841,14 @@ public class XmppConnectionService extends Service {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Conversation findOrCreateConversation(Account account, String jid,
|
|
|
|
public Conversation findOrCreateConversation(Account account, String jid,
|
|
|
|
boolean muc) {
|
|
|
|
boolean muc) {
|
|
|
|
Conversation conversation = find(account, jid);
|
|
|
|
Conversation conversation = find(account, jid);
|
|
|
|
if (conversation != null) {
|
|
|
|
if (conversation != null) {
|
|
|
|
return conversation;
|
|
|
|
return conversation;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
conversation = databaseBackend.findConversation(account,jid);
|
|
|
|
conversation = databaseBackend.findConversation(account, jid);
|
|
|
|
if (conversation != null) {
|
|
|
|
if (conversation != null) {
|
|
|
|
conversation.setStatus(Conversation.STATUS_AVAILABLE);
|
|
|
|
conversation.setStatus(Conversation.STATUS_AVAILABLE);
|
|
|
|
conversation.setAccount(account);
|
|
|
|
conversation.setAccount(account);
|
|
|
@ -850,7 +885,7 @@ public class XmppConnectionService extends Service {
|
|
|
|
public void archiveConversation(Conversation conversation) {
|
|
|
|
public void archiveConversation(Conversation conversation) {
|
|
|
|
if (conversation.getMode() == Conversation.MODE_MULTI) {
|
|
|
|
if (conversation.getMode() == Conversation.MODE_MULTI) {
|
|
|
|
Bookmark bookmark = conversation.getBookmark();
|
|
|
|
Bookmark bookmark = conversation.getBookmark();
|
|
|
|
if (bookmark!=null && bookmark.autojoin()) {
|
|
|
|
if (bookmark != null && bookmark.autojoin()) {
|
|
|
|
bookmark.setAutojoin(false);
|
|
|
|
bookmark.setAutojoin(false);
|
|
|
|
pushBookmarks(bookmark.getAccount());
|
|
|
|
pushBookmarks(bookmark.getAccount());
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -890,7 +925,7 @@ public class XmppConnectionService extends Service {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void deleteAccount(Account account) {
|
|
|
|
public void deleteAccount(Account account) {
|
|
|
|
for(Conversation conversation : conversations) {
|
|
|
|
for (Conversation conversation : conversations) {
|
|
|
|
if (conversation.getAccount() == account) {
|
|
|
|
if (conversation.getAccount() == account) {
|
|
|
|
if (conversation.getMode() == Conversation.MODE_MULTI) {
|
|
|
|
if (conversation.getMode() == Conversation.MODE_MULTI) {
|
|
|
|
leaveMuc(conversation);
|
|
|
|
leaveMuc(conversation);
|
|
|
@ -911,6 +946,9 @@ public class XmppConnectionService extends Service {
|
|
|
|
|
|
|
|
|
|
|
|
public void setOnConversationListChangedListener(
|
|
|
|
public void setOnConversationListChangedListener(
|
|
|
|
OnConversationUpdate listener) {
|
|
|
|
OnConversationUpdate listener) {
|
|
|
|
|
|
|
|
if (checkListeners()) {
|
|
|
|
|
|
|
|
switchToForeground();
|
|
|
|
|
|
|
|
}
|
|
|
|
this.mOnConversationUpdate = listener;
|
|
|
|
this.mOnConversationUpdate = listener;
|
|
|
|
this.convChangedListenerCount++;
|
|
|
|
this.convChangedListenerCount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -919,10 +957,16 @@ public class XmppConnectionService extends Service {
|
|
|
|
this.convChangedListenerCount--;
|
|
|
|
this.convChangedListenerCount--;
|
|
|
|
if (this.convChangedListenerCount == 0) {
|
|
|
|
if (this.convChangedListenerCount == 0) {
|
|
|
|
this.mOnConversationUpdate = null;
|
|
|
|
this.mOnConversationUpdate = null;
|
|
|
|
|
|
|
|
if (checkListeners()) {
|
|
|
|
|
|
|
|
switchToBackground();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void setOnAccountListChangedListener(OnAccountUpdate listener) {
|
|
|
|
public void setOnAccountListChangedListener(OnAccountUpdate listener) {
|
|
|
|
|
|
|
|
if (checkListeners()) {
|
|
|
|
|
|
|
|
switchToForeground();
|
|
|
|
|
|
|
|
}
|
|
|
|
this.mOnAccountUpdate = listener;
|
|
|
|
this.mOnAccountUpdate = listener;
|
|
|
|
this.accountChangedListenerCount++;
|
|
|
|
this.accountChangedListenerCount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -931,15 +975,53 @@ public class XmppConnectionService extends Service {
|
|
|
|
this.accountChangedListenerCount--;
|
|
|
|
this.accountChangedListenerCount--;
|
|
|
|
if (this.accountChangedListenerCount == 0) {
|
|
|
|
if (this.accountChangedListenerCount == 0) {
|
|
|
|
this.mOnAccountUpdate = null;
|
|
|
|
this.mOnAccountUpdate = null;
|
|
|
|
|
|
|
|
if (checkListeners()) {
|
|
|
|
|
|
|
|
switchToBackground();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void setOnRosterUpdateListener(OnRosterUpdate listener) {
|
|
|
|
public void setOnRosterUpdateListener(OnRosterUpdate listener) {
|
|
|
|
|
|
|
|
if (checkListeners()) {
|
|
|
|
|
|
|
|
switchToForeground();
|
|
|
|
|
|
|
|
}
|
|
|
|
this.mOnRosterUpdate = listener;
|
|
|
|
this.mOnRosterUpdate = listener;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void removeOnRosterUpdateListener() {
|
|
|
|
public void removeOnRosterUpdateListener() {
|
|
|
|
this.mOnRosterUpdate = null;
|
|
|
|
this.mOnRosterUpdate = null;
|
|
|
|
|
|
|
|
if (checkListeners()) {
|
|
|
|
|
|
|
|
switchToBackground();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean checkListeners() {
|
|
|
|
|
|
|
|
return (this.mOnAccountUpdate == null
|
|
|
|
|
|
|
|
&& this.mOnConversationUpdate == null && this.mOnRosterUpdate == null);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void switchToForeground() {
|
|
|
|
|
|
|
|
for (Account account : getAccounts()) {
|
|
|
|
|
|
|
|
if (account.getStatus() == Account.STATUS_ONLINE) {
|
|
|
|
|
|
|
|
XmppConnection connection = account.getXmppConnection();
|
|
|
|
|
|
|
|
if (connection != null && connection.getFeatures().csi()) {
|
|
|
|
|
|
|
|
connection.sendActive();
|
|
|
|
|
|
|
|
Log.d(LOGTAG, account.getJid() + " sending csi//active");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void switchToBackground() {
|
|
|
|
|
|
|
|
for (Account account : getAccounts()) {
|
|
|
|
|
|
|
|
if (account.getStatus() == Account.STATUS_ONLINE) {
|
|
|
|
|
|
|
|
XmppConnection connection = account.getXmppConnection();
|
|
|
|
|
|
|
|
if (connection != null && connection.getFeatures().csi()) {
|
|
|
|
|
|
|
|
connection.sendInactive();
|
|
|
|
|
|
|
|
Log.d(LOGTAG, account.getJid() + " sending csi//inactive");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void connectMultiModeConversations(Account account) {
|
|
|
|
public void connectMultiModeConversations(Account account) {
|
|
|
@ -958,12 +1040,13 @@ public class XmppConnectionService extends Service {
|
|
|
|
account.pendingConferenceJoins.remove(conversation);
|
|
|
|
account.pendingConferenceJoins.remove(conversation);
|
|
|
|
account.pendingConferenceLeaves.remove(conversation);
|
|
|
|
account.pendingConferenceLeaves.remove(conversation);
|
|
|
|
if (account.getStatus() == Account.STATUS_ONLINE) {
|
|
|
|
if (account.getStatus() == Account.STATUS_ONLINE) {
|
|
|
|
Log.d(LOGTAG,"joining conversation "+conversation.getContactJid());
|
|
|
|
Log.d(LOGTAG,
|
|
|
|
|
|
|
|
"joining conversation " + conversation.getContactJid());
|
|
|
|
String nick = conversation.getMucOptions().getProposedNick();
|
|
|
|
String nick = conversation.getMucOptions().getProposedNick();
|
|
|
|
conversation.getMucOptions().setJoinNick(nick);
|
|
|
|
conversation.getMucOptions().setJoinNick(nick);
|
|
|
|
PresencePacket packet = new PresencePacket();
|
|
|
|
PresencePacket packet = new PresencePacket();
|
|
|
|
String joinJid = conversation.getMucOptions().getJoinJid();
|
|
|
|
String joinJid = conversation.getMucOptions().getJoinJid();
|
|
|
|
packet.setAttribute("to",conversation.getMucOptions().getJoinJid());
|
|
|
|
packet.setAttribute("to", conversation.getMucOptions().getJoinJid());
|
|
|
|
Element x = new Element("x");
|
|
|
|
Element x = new Element("x");
|
|
|
|
x.setAttribute("xmlns", "http://jabber.org/protocol/muc");
|
|
|
|
x.setAttribute("xmlns", "http://jabber.org/protocol/muc");
|
|
|
|
String sig = account.getPgpSignature();
|
|
|
|
String sig = account.getPgpSignature();
|
|
|
@ -975,8 +1058,8 @@ public class XmppConnectionService extends Service {
|
|
|
|
final SimpleDateFormat mDateFormat = new SimpleDateFormat(
|
|
|
|
final SimpleDateFormat mDateFormat = new SimpleDateFormat(
|
|
|
|
"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US);
|
|
|
|
"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US);
|
|
|
|
mDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
|
|
|
|
mDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
|
|
|
|
Date date = new Date(
|
|
|
|
Date date = new Date(conversation.getLatestMessage()
|
|
|
|
conversation.getLatestMessage().getTimeSent() + 1000);
|
|
|
|
.getTimeSent() + 1000);
|
|
|
|
x.addChild("history").setAttribute("since",
|
|
|
|
x.addChild("history").setAttribute("since",
|
|
|
|
mDateFormat.format(date));
|
|
|
|
mDateFormat.format(date));
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1011,10 +1094,11 @@ public class XmppConnectionService extends Service {
|
|
|
|
renameListener.onRename(success);
|
|
|
|
renameListener.onRename(success);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (success) {
|
|
|
|
if (success) {
|
|
|
|
conversation.setContactJid(conversation.getMucOptions().getJoinJid());
|
|
|
|
conversation.setContactJid(conversation.getMucOptions()
|
|
|
|
|
|
|
|
.getJoinJid());
|
|
|
|
databaseBackend.updateConversation(conversation);
|
|
|
|
databaseBackend.updateConversation(conversation);
|
|
|
|
Bookmark bookmark = conversation.getBookmark();
|
|
|
|
Bookmark bookmark = conversation.getBookmark();
|
|
|
|
if (bookmark!=null) {
|
|
|
|
if (bookmark != null) {
|
|
|
|
bookmark.setNick(nick);
|
|
|
|
bookmark.setNick(nick);
|
|
|
|
pushBookmarks(bookmark.getAccount());
|
|
|
|
pushBookmarks(bookmark.getAccount());
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1023,7 +1107,7 @@ public class XmppConnectionService extends Service {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
options.flagAboutToRename();
|
|
|
|
options.flagAboutToRename();
|
|
|
|
PresencePacket packet = new PresencePacket();
|
|
|
|
PresencePacket packet = new PresencePacket();
|
|
|
|
packet.setAttribute("to",options.getJoinJid());
|
|
|
|
packet.setAttribute("to", options.getJoinJid());
|
|
|
|
packet.setAttribute("from", conversation.getAccount().getFullJid());
|
|
|
|
packet.setAttribute("from", conversation.getAccount().getFullJid());
|
|
|
|
|
|
|
|
|
|
|
|
String sig = account.getPgpSignature();
|
|
|
|
String sig = account.getPgpSignature();
|
|
|
@ -1031,13 +1115,13 @@ public class XmppConnectionService extends Service {
|
|
|
|
packet.addChild("status").setContent("online");
|
|
|
|
packet.addChild("status").setContent("online");
|
|
|
|
packet.addChild("x", "jabber:x:signed").setContent(sig);
|
|
|
|
packet.addChild("x", "jabber:x:signed").setContent(sig);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sendPresencePacket(account,packet);
|
|
|
|
sendPresencePacket(account, packet);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
conversation.setContactJid(options.getJoinJid());
|
|
|
|
conversation.setContactJid(options.getJoinJid());
|
|
|
|
databaseBackend.updateConversation(conversation);
|
|
|
|
databaseBackend.updateConversation(conversation);
|
|
|
|
if (conversation.getAccount().getStatus() == Account.STATUS_ONLINE) {
|
|
|
|
if (conversation.getAccount().getStatus() == Account.STATUS_ONLINE) {
|
|
|
|
Bookmark bookmark = conversation.getBookmark();
|
|
|
|
Bookmark bookmark = conversation.getBookmark();
|
|
|
|
if (bookmark!=null) {
|
|
|
|
if (bookmark != null) {
|
|
|
|
bookmark.setNick(nick);
|
|
|
|
bookmark.setNick(nick);
|
|
|
|
pushBookmarks(bookmark.getAccount());
|
|
|
|
pushBookmarks(bookmark.getAccount());
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1055,10 +1139,11 @@ public class XmppConnectionService extends Service {
|
|
|
|
packet.setAttribute("to", conversation.getMucOptions().getJoinJid());
|
|
|
|
packet.setAttribute("to", conversation.getMucOptions().getJoinJid());
|
|
|
|
packet.setAttribute("from", conversation.getAccount().getFullJid());
|
|
|
|
packet.setAttribute("from", conversation.getAccount().getFullJid());
|
|
|
|
packet.setAttribute("type", "unavailable");
|
|
|
|
packet.setAttribute("type", "unavailable");
|
|
|
|
sendPresencePacket(conversation.getAccount(),packet);
|
|
|
|
sendPresencePacket(conversation.getAccount(), packet);
|
|
|
|
conversation.getMucOptions().setOffline();
|
|
|
|
conversation.getMucOptions().setOffline();
|
|
|
|
conversation.deregisterWithBookmark();
|
|
|
|
conversation.deregisterWithBookmark();
|
|
|
|
Log.d(LOGTAG,conversation.getAccount().getJid()+" leaving muc "+conversation.getContactJid());
|
|
|
|
Log.d(LOGTAG, conversation.getAccount().getJid() + " leaving muc "
|
|
|
|
|
|
|
|
+ conversation.getContactJid());
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
account.pendingConferenceLeaves.add(conversation);
|
|
|
|
account.pendingConferenceLeaves.add(conversation);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1133,7 +1218,7 @@ public class XmppConnectionService extends Service {
|
|
|
|
if (outPacket != null) {
|
|
|
|
if (outPacket != null) {
|
|
|
|
msg.setStatus(Message.STATUS_SEND);
|
|
|
|
msg.setStatus(Message.STATUS_SEND);
|
|
|
|
databaseBackend.updateMessage(msg);
|
|
|
|
databaseBackend.updateMessage(msg);
|
|
|
|
sendMessagePacket(account,outPacket);
|
|
|
|
sendMessagePacket(account, outPacket);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (msg.getType() == Message.TYPE_IMAGE) {
|
|
|
|
} else if (msg.getType() == Message.TYPE_IMAGE) {
|
|
|
|
mJingleConnectionManager.createNewConnection(msg);
|
|
|
|
mJingleConnectionManager.createNewConnection(msg);
|
|
|
@ -1160,7 +1245,7 @@ public class XmppConnectionService extends Service {
|
|
|
|
packet.setBody(otrSession
|
|
|
|
packet.setBody(otrSession
|
|
|
|
.transformSending(CryptoHelper.FILETRANSFER
|
|
|
|
.transformSending(CryptoHelper.FILETRANSFER
|
|
|
|
+ CryptoHelper.bytesToHex(symmetricKey)));
|
|
|
|
+ CryptoHelper.bytesToHex(symmetricKey)));
|
|
|
|
sendMessagePacket(account,packet);
|
|
|
|
sendMessagePacket(account, packet);
|
|
|
|
conversation.setSymmetricKey(symmetricKey);
|
|
|
|
conversation.setSymmetricKey(symmetricKey);
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
} catch (OtrException e) {
|
|
|
|
} catch (OtrException e) {
|
|
|
@ -1176,26 +1261,30 @@ public class XmppConnectionService extends Service {
|
|
|
|
Account account = contact.getAccount();
|
|
|
|
Account account = contact.getAccount();
|
|
|
|
if (account.getStatus() == Account.STATUS_ONLINE) {
|
|
|
|
if (account.getStatus() == Account.STATUS_ONLINE) {
|
|
|
|
boolean ask = contact.getOption(Contact.Options.ASKING);
|
|
|
|
boolean ask = contact.getOption(Contact.Options.ASKING);
|
|
|
|
boolean sendUpdates = contact.getOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST)
|
|
|
|
boolean sendUpdates = contact
|
|
|
|
|
|
|
|
.getOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST)
|
|
|
|
&& contact.getOption(Contact.Options.PREEMPTIVE_GRANT);
|
|
|
|
&& contact.getOption(Contact.Options.PREEMPTIVE_GRANT);
|
|
|
|
IqPacket iq = new IqPacket(IqPacket.TYPE_SET);
|
|
|
|
IqPacket iq = new IqPacket(IqPacket.TYPE_SET);
|
|
|
|
iq.query("jabber:iq:roster").addChild(contact.asElement());
|
|
|
|
iq.query("jabber:iq:roster").addChild(contact.asElement());
|
|
|
|
account.getXmppConnection().sendIqPacket(iq, null);
|
|
|
|
account.getXmppConnection().sendIqPacket(iq, null);
|
|
|
|
if (sendUpdates) {
|
|
|
|
if (sendUpdates) {
|
|
|
|
sendPresencePacket(account, mPresenceGenerator.sendPresenceUpdatesTo(contact));
|
|
|
|
sendPresencePacket(account,
|
|
|
|
|
|
|
|
mPresenceGenerator.sendPresenceUpdatesTo(contact));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ask) {
|
|
|
|
if (ask) {
|
|
|
|
sendPresencePacket(account, mPresenceGenerator.requestPresenceUpdatesFrom(contact));
|
|
|
|
sendPresencePacket(account,
|
|
|
|
|
|
|
|
mPresenceGenerator.requestPresenceUpdatesFrom(contact));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void publishAvatar(Account account, Uri image,
|
|
|
|
public void publishAvatar(Account account, Uri image, final UiCallback<Avatar> callback) {
|
|
|
|
final UiCallback<Avatar> callback) {
|
|
|
|
final Bitmap.CompressFormat format = Defaults.AVATAR_FORMAT;
|
|
|
|
final Bitmap.CompressFormat format = Defaults.AVATAR_FORMAT;
|
|
|
|
final int size = Defaults.AVATAR_SIZE;
|
|
|
|
final int size = Defaults.AVATAR_SIZE;
|
|
|
|
final Avatar avatar = getFileBackend().getPepAvatar(image, size, format);
|
|
|
|
final Avatar avatar = getFileBackend()
|
|
|
|
if (avatar!=null) {
|
|
|
|
.getPepAvatar(image, size, format);
|
|
|
|
|
|
|
|
if (avatar != null) {
|
|
|
|
avatar.height = size;
|
|
|
|
avatar.height = size;
|
|
|
|
avatar.width = size;
|
|
|
|
avatar.width = size;
|
|
|
|
if (format.equals(Bitmap.CompressFormat.WEBP)) {
|
|
|
|
if (format.equals(Bitmap.CompressFormat.WEBP)) {
|
|
|
@ -1211,27 +1300,33 @@ public class XmppConnectionService extends Service {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
IqPacket packet = this.mIqGenerator.publishAvatar(avatar);
|
|
|
|
IqPacket packet = this.mIqGenerator.publishAvatar(avatar);
|
|
|
|
this.sendIqPacket(account, packet, new OnIqPacketReceived() {
|
|
|
|
this.sendIqPacket(account, packet, new OnIqPacketReceived() {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onIqPacketReceived(Account account, IqPacket result) {
|
|
|
|
public void onIqPacketReceived(Account account, IqPacket result) {
|
|
|
|
if (result.getType() == IqPacket.TYPE_RESULT) {
|
|
|
|
if (result.getType() == IqPacket.TYPE_RESULT) {
|
|
|
|
IqPacket packet = XmppConnectionService.this.mIqGenerator.publishAvatarMetadata(avatar);
|
|
|
|
IqPacket packet = XmppConnectionService.this.mIqGenerator
|
|
|
|
|
|
|
|
.publishAvatarMetadata(avatar);
|
|
|
|
sendIqPacket(account, packet, new OnIqPacketReceived() {
|
|
|
|
sendIqPacket(account, packet, new OnIqPacketReceived() {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onIqPacketReceived(Account account, IqPacket result) {
|
|
|
|
public void onIqPacketReceived(Account account,
|
|
|
|
|
|
|
|
IqPacket result) {
|
|
|
|
if (result.getType() == IqPacket.TYPE_RESULT) {
|
|
|
|
if (result.getType() == IqPacket.TYPE_RESULT) {
|
|
|
|
if (account.setAvatar(avatar.getFilename())) {
|
|
|
|
if (account.setAvatar(avatar.getFilename())) {
|
|
|
|
databaseBackend.updateAccount(account);
|
|
|
|
databaseBackend.updateAccount(account);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
callback.success(avatar);
|
|
|
|
callback.success(avatar);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
callback.error(R.string.error_publish_avatar_server_reject, avatar);
|
|
|
|
callback.error(
|
|
|
|
|
|
|
|
R.string.error_publish_avatar_server_reject,
|
|
|
|
|
|
|
|
avatar);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
callback.error(R.string.error_publish_avatar_server_reject, avatar);
|
|
|
|
callback.error(
|
|
|
|
|
|
|
|
R.string.error_publish_avatar_server_reject,
|
|
|
|
|
|
|
|
avatar);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -1239,55 +1334,60 @@ public class XmppConnectionService extends Service {
|
|
|
|
callback.error(R.string.error_publish_avatar_converting, null);
|
|
|
|
callback.error(R.string.error_publish_avatar_converting, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void fetchAvatar(Account account, Avatar avatar) {
|
|
|
|
public void fetchAvatar(Account account, Avatar avatar) {
|
|
|
|
fetchAvatar(account, avatar, null);
|
|
|
|
fetchAvatar(account, avatar, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void fetchAvatar(Account account, final Avatar avatar, final UiCallback<Avatar> callback) {
|
|
|
|
public void fetchAvatar(Account account, final Avatar avatar,
|
|
|
|
Log.d(LOGTAG,account.getJid()+": retrieving avatar for "+avatar.owner);
|
|
|
|
final UiCallback<Avatar> callback) {
|
|
|
|
|
|
|
|
Log.d(LOGTAG, account.getJid() + ": retrieving avatar for "
|
|
|
|
|
|
|
|
+ avatar.owner);
|
|
|
|
IqPacket packet = this.mIqGenerator.retrieveAvatar(avatar);
|
|
|
|
IqPacket packet = this.mIqGenerator.retrieveAvatar(avatar);
|
|
|
|
sendIqPacket(account, packet, new OnIqPacketReceived() {
|
|
|
|
sendIqPacket(account, packet, new OnIqPacketReceived() {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onIqPacketReceived(Account account, IqPacket result) {
|
|
|
|
public void onIqPacketReceived(Account account, IqPacket result) {
|
|
|
|
avatar.image = mIqParser.avatarData(result);
|
|
|
|
avatar.image = mIqParser.avatarData(result);
|
|
|
|
if (avatar.image!=null) {
|
|
|
|
if (avatar.image != null) {
|
|
|
|
if (getFileBackend().save(avatar)) {
|
|
|
|
if (getFileBackend().save(avatar)) {
|
|
|
|
if (account.getJid().equals(avatar.owner)) {
|
|
|
|
if (account.getJid().equals(avatar.owner)) {
|
|
|
|
if (account.setAvatar(avatar.getFilename())) {
|
|
|
|
if (account.setAvatar(avatar.getFilename())) {
|
|
|
|
databaseBackend.updateAccount(account);
|
|
|
|
databaseBackend.updateAccount(account);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
Contact contact = account.getRoster().getContact(avatar.owner);
|
|
|
|
Contact contact = account.getRoster().getContact(
|
|
|
|
|
|
|
|
avatar.owner);
|
|
|
|
contact.setAvatar(avatar.getFilename());
|
|
|
|
contact.setAvatar(avatar.getFilename());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (callback!=null) {
|
|
|
|
if (callback != null) {
|
|
|
|
callback.success(avatar);
|
|
|
|
callback.success(avatar);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (callback!=null) {
|
|
|
|
if (callback != null) {
|
|
|
|
callback.error(0, null);
|
|
|
|
callback.error(0, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void checkForAvatar(Account account, final UiCallback<Avatar> callback) {
|
|
|
|
public void checkForAvatar(Account account,
|
|
|
|
|
|
|
|
final UiCallback<Avatar> callback) {
|
|
|
|
IqPacket packet = this.mIqGenerator.retrieveAvatarMetaData(null);
|
|
|
|
IqPacket packet = this.mIqGenerator.retrieveAvatarMetaData(null);
|
|
|
|
this.sendIqPacket(account, packet, new OnIqPacketReceived() {
|
|
|
|
this.sendIqPacket(account, packet, new OnIqPacketReceived() {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onIqPacketReceived(Account account, IqPacket packet) {
|
|
|
|
public void onIqPacketReceived(Account account, IqPacket packet) {
|
|
|
|
if (packet.getType() == IqPacket.TYPE_RESULT) {
|
|
|
|
if (packet.getType() == IqPacket.TYPE_RESULT) {
|
|
|
|
Element pubsub = packet.findChild("pubsub", "http://jabber.org/protocol/pubsub");
|
|
|
|
Element pubsub = packet.findChild("pubsub",
|
|
|
|
if (pubsub!=null) {
|
|
|
|
"http://jabber.org/protocol/pubsub");
|
|
|
|
|
|
|
|
if (pubsub != null) {
|
|
|
|
Element items = pubsub.findChild("items");
|
|
|
|
Element items = pubsub.findChild("items");
|
|
|
|
if (items!=null) {
|
|
|
|
if (items != null) {
|
|
|
|
Avatar avatar = Avatar.parseMetadata(items);
|
|
|
|
Avatar avatar = Avatar.parseMetadata(items);
|
|
|
|
if (avatar!=null) {
|
|
|
|
if (avatar != null) {
|
|
|
|
avatar.owner = account.getJid();
|
|
|
|
avatar.owner = account.getJid();
|
|
|
|
if (fileBackend.isAvatarCached(avatar)) {
|
|
|
|
if (fileBackend.isAvatarCached(avatar)) {
|
|
|
|
if (account.setAvatar(avatar.getFilename())) {
|
|
|
|
if (account.setAvatar(avatar.getFilename())) {
|
|
|
@ -1295,7 +1395,7 @@ public class XmppConnectionService extends Service {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
callback.success(avatar);
|
|
|
|
callback.success(avatar);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
fetchAvatar(account, avatar,callback);
|
|
|
|
fetchAvatar(account, avatar, callback);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1306,7 +1406,7 @@ public class XmppConnectionService extends Service {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void deleteContactOnServer(Contact contact) {
|
|
|
|
public void deleteContactOnServer(Contact contact) {
|
|
|
|
contact.resetOption(Contact.Options.PREEMPTIVE_GRANT);
|
|
|
|
contact.resetOption(Contact.Options.PREEMPTIVE_GRANT);
|
|
|
|
contact.resetOption(Contact.Options.DIRTY_PUSH);
|
|
|
|
contact.resetOption(Contact.Options.DIRTY_PUSH);
|
|
|
@ -1347,7 +1447,19 @@ public class XmppConnectionService extends Service {
|
|
|
|
|
|
|
|
|
|
|
|
public void invite(Conversation conversation, String contact) {
|
|
|
|
public void invite(Conversation conversation, String contact) {
|
|
|
|
MessagePacket packet = mMessageGenerator.invite(conversation, contact);
|
|
|
|
MessagePacket packet = mMessageGenerator.invite(conversation, contact);
|
|
|
|
sendMessagePacket(conversation.getAccount(),packet);
|
|
|
|
sendMessagePacket(conversation.getAccount(), packet);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void resetSendingToWaiting(Account account) {
|
|
|
|
|
|
|
|
for (Conversation conversation : getConversations()) {
|
|
|
|
|
|
|
|
if (conversation.getAccount() == account) {
|
|
|
|
|
|
|
|
for (Message message : conversation.getMessages()) {
|
|
|
|
|
|
|
|
if (message.getStatus() == Message.STATUS_UNSEND) {
|
|
|
|
|
|
|
|
markMessage(message, Message.STATUS_WAITING);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public boolean markMessage(Account account, String recipient, String uuid,
|
|
|
|
public boolean markMessage(Account account, String recipient, String uuid,
|
|
|
@ -1395,19 +1507,19 @@ public class XmppConnectionService extends Service {
|
|
|
|
getConversations(), conversation, notify);
|
|
|
|
getConversations(), conversation, notify);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void updateConversationUi() {
|
|
|
|
public void updateConversationUi() {
|
|
|
|
if (mOnConversationUpdate != null) {
|
|
|
|
if (mOnConversationUpdate != null) {
|
|
|
|
mOnConversationUpdate.onConversationUpdate();
|
|
|
|
mOnConversationUpdate.onConversationUpdate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void updateAccountUi() {
|
|
|
|
public void updateAccountUi() {
|
|
|
|
if (mOnAccountUpdate != null) {
|
|
|
|
if (mOnAccountUpdate != null) {
|
|
|
|
mOnAccountUpdate.onAccountUpdate();
|
|
|
|
mOnAccountUpdate.onAccountUpdate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void updateRosterUi() {
|
|
|
|
public void updateRosterUi() {
|
|
|
|
if (mOnRosterUpdate != null) {
|
|
|
|
if (mOnRosterUpdate != null) {
|
|
|
|
mOnRosterUpdate.onRosterUpdate();
|
|
|
|
mOnRosterUpdate.onRosterUpdate();
|
|
|
@ -1422,7 +1534,7 @@ public class XmppConnectionService extends Service {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Conversation findConversationByUuid(String uuid) {
|
|
|
|
public Conversation findConversationByUuid(String uuid) {
|
|
|
|
for (Conversation conversation : getConversations()) {
|
|
|
|
for (Conversation conversation : getConversations()) {
|
|
|
|
if (conversation.getUuid().equals(uuid)) {
|
|
|
|
if (conversation.getUuid().equals(uuid)) {
|
|
|
@ -1438,10 +1550,11 @@ public class XmppConnectionService extends Service {
|
|
|
|
if (confirmMessages() && id != null) {
|
|
|
|
if (confirmMessages() && id != null) {
|
|
|
|
Account account = conversation.getAccount();
|
|
|
|
Account account = conversation.getAccount();
|
|
|
|
String to = conversation.getContactJid();
|
|
|
|
String to = conversation.getContactJid();
|
|
|
|
this.sendMessagePacket(conversation.getAccount(), mMessageGenerator.confirm(account, to, id));
|
|
|
|
this.sendMessagePacket(conversation.getAccount(),
|
|
|
|
|
|
|
|
mMessageGenerator.confirm(account, to, id));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void failWaitingOtrMessages(Conversation conversation) {
|
|
|
|
public void failWaitingOtrMessages(Conversation conversation) {
|
|
|
|
for (Message message : conversation.getMessages()) {
|
|
|
|
for (Message message : conversation.getMessages()) {
|
|
|
|
if (message.getEncryption() == Message.ENCRYPTION_OTR
|
|
|
|
if (message.getEncryption() == Message.ENCRYPTION_OTR
|
|
|
@ -1454,7 +1567,7 @@ public class XmppConnectionService extends Service {
|
|
|
|
public SecureRandom getRNG() {
|
|
|
|
public SecureRandom getRNG() {
|
|
|
|
return this.mRandom;
|
|
|
|
return this.mRandom;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public MemorizingTrustManager getMemorizingTrustManager() {
|
|
|
|
public MemorizingTrustManager getMemorizingTrustManager() {
|
|
|
|
return this.mMemorizingTrustManager;
|
|
|
|
return this.mMemorizingTrustManager;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1467,7 +1580,7 @@ public class XmppConnectionService extends Service {
|
|
|
|
if (account.getStatus() == Account.STATUS_ONLINE) {
|
|
|
|
if (account.getStatus() == Account.STATUS_ONLINE) {
|
|
|
|
MessagePacket error = this.mMessageGenerator
|
|
|
|
MessagePacket error = this.mMessageGenerator
|
|
|
|
.generateNotAcceptable(packet);
|
|
|
|
.generateNotAcceptable(packet);
|
|
|
|
sendMessagePacket(account,error);
|
|
|
|
sendMessagePacket(account, error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -1512,43 +1625,44 @@ public class XmppConnectionService extends Service {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return mucServers;
|
|
|
|
return mucServers;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void sendMessagePacket(Account account, MessagePacket packet) {
|
|
|
|
public void sendMessagePacket(Account account, MessagePacket packet) {
|
|
|
|
account.getXmppConnection().sendMessagePacket(packet);
|
|
|
|
account.getXmppConnection().sendMessagePacket(packet);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void sendPresencePacket(Account account, PresencePacket packet) {
|
|
|
|
public void sendPresencePacket(Account account, PresencePacket packet) {
|
|
|
|
account.getXmppConnection().sendPresencePacket(packet);
|
|
|
|
account.getXmppConnection().sendPresencePacket(packet);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void sendIqPacket(Account account, IqPacket packet, OnIqPacketReceived callback) {
|
|
|
|
public void sendIqPacket(Account account, IqPacket packet,
|
|
|
|
|
|
|
|
OnIqPacketReceived callback) {
|
|
|
|
account.getXmppConnection().sendIqPacket(packet, callback);
|
|
|
|
account.getXmppConnection().sendIqPacket(packet, callback);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public MessageGenerator getMessageGenerator() {
|
|
|
|
public MessageGenerator getMessageGenerator() {
|
|
|
|
return this.mMessageGenerator;
|
|
|
|
return this.mMessageGenerator;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public PresenceGenerator getPresenceGenerator() {
|
|
|
|
public PresenceGenerator getPresenceGenerator() {
|
|
|
|
return this.mPresenceGenerator;
|
|
|
|
return this.mPresenceGenerator;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public IqGenerator getIqGenerator() {
|
|
|
|
public IqGenerator getIqGenerator() {
|
|
|
|
return this.mIqGenerator ;
|
|
|
|
return this.mIqGenerator;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public JingleConnectionManager getJingleConnectionManager() {
|
|
|
|
public JingleConnectionManager getJingleConnectionManager() {
|
|
|
|
return this.mJingleConnectionManager;
|
|
|
|
return this.mJingleConnectionManager;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public interface OnConversationUpdate {
|
|
|
|
public interface OnConversationUpdate {
|
|
|
|
public void onConversationUpdate();
|
|
|
|
public void onConversationUpdate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public interface OnAccountUpdate {
|
|
|
|
public interface OnAccountUpdate {
|
|
|
|
public void onAccountUpdate();
|
|
|
|
public void onAccountUpdate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public interface OnRosterUpdate {
|
|
|
|
public interface OnRosterUpdate {
|
|
|
|
public void onRosterUpdate();
|
|
|
|
public void onRosterUpdate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|