diff options
Diffstat (limited to 'src/main/java')
5 files changed, 91 insertions, 48 deletions
diff --git a/src/main/java/eu/siacs/conversations/services/MessageArchiveService.java b/src/main/java/eu/siacs/conversations/services/MessageArchiveService.java index 9dfe179c..fe1871ea 100644 --- a/src/main/java/eu/siacs/conversations/services/MessageArchiveService.java +++ b/src/main/java/eu/siacs/conversations/services/MessageArchiveService.java @@ -3,7 +3,9 @@ package eu.siacs.conversations.services; import android.util.Log; import java.math.BigInteger; +import java.util.ArrayList; import java.util.HashSet; +import java.util.Iterator; import java.util.List; import eu.siacs.conversations.Config; @@ -22,6 +24,7 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded { private final XmppConnectionService mXmppConnectionService; private final HashSet<Query> queries = new HashSet<Query>(); + private ArrayList<Query> pendingQueries = new ArrayList<Query>(); public enum PagingOrder { NORMAL, @@ -83,18 +86,41 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded { } } + public void executePendingQueries(final Account account) { + List<Query> pending = new ArrayList<>(); + synchronized(this.pendingQueries) { + for(Iterator<Query> iterator = this.pendingQueries.iterator(); iterator.hasNext();) { + Query query = iterator.next(); + if (query.getAccount() == account) { + pending.add(query); + iterator.remove(); + } + } + } + for(Query query : pending) { + this.execute(query); + } + } + private void execute(final Query query) { - Log.d(Config.LOGTAG,query.getAccount().getJid().toBareJid().toString()+": running mam query "+query.toString()); - IqPacket packet = this.mXmppConnectionService.getIqGenerator().queryMessageArchiveManagement(query); - this.mXmppConnectionService.sendIqPacket(query.getAccount(), packet, new OnIqPacketReceived() { + final Account account= query.getAccount(); + if (account.getStatus() == Account.State.ONLINE) { + Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": running mam query " + query.toString()); + IqPacket packet = this.mXmppConnectionService.getIqGenerator().queryMessageArchiveManagement(query); + this.mXmppConnectionService.sendIqPacket(account, packet, new OnIqPacketReceived() { @Override public void onIqPacketReceived(Account account, IqPacket packet) { if (packet.getType() == IqPacket.TYPE_ERROR) { - Log.d(Config.LOGTAG,account.getJid().toBareJid().toString()+": error executing mam: "+packet.toString()); + Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": error executing mam: " + packet.toString()); finalizeQuery(query); } } }); + } else { + synchronized (this.pendingQueries) { + this.pendingQueries.add(query); + } + } } private void finalizeQuery(Query query) { diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 9b1ecdea..ef93dcc7 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -160,6 +160,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa for (Conversation conversation : account.pendingConferenceJoins) { joinMuc(conversation); } + mMessageArchiveService.executePendingQueries(account); mJingleConnectionManager.cancelInTransmission(); List<Conversation> conversations = getConversations(); for (Conversation conversation : conversations) { @@ -2085,6 +2086,16 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa } } + public void clearConversationHistory(final Conversation conversation) { + conversation.clearMessages(); + new Thread(new Runnable() { + @Override + public void run() { + databaseBackend.deleteMessagesInConversation(conversation); + } + }).start(); + } + public interface OnConversationUpdate { public void onConversationUpdate(); } diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java index a5efe12e..6656de2b 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java @@ -491,7 +491,7 @@ public class ConversationActivity extends XmppActivity implements @Override public void onClick(DialogInterface dialog, int which) { - conversation.clearMessages(); + ConversationActivity.this.xmppConnectionService.clearConversationHistory(conversation); if (endConversationCheckBox.isChecked()) { endConversation(conversation); } else { diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java index 32062699..478586b9 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java @@ -268,7 +268,7 @@ public class MessageAdapter extends ArrayAdapter<Message> { @Override public void onClick(View v) { - startDonwloadable(message); + startDownloadable(message); } }); viewHolder.download_button.setOnLongClickListener(openContextMenu); @@ -284,7 +284,7 @@ public class MessageAdapter extends ArrayAdapter<Message> { @Override public void onClick(View v) { - openDonwloadable(file); + openDownloadable(file); } }); viewHolder.download_button.setOnLongClickListener(openContextMenu); @@ -438,6 +438,8 @@ public class MessageAdapter extends ArrayAdapter<Message> { } view.setLayoutParams(view.getLayoutParams()); return view; + } else if (viewHolder.messageBody == null || viewHolder.image == null) { + return view; //avoiding weird platform bugs } else if (type == RECEIVED) { Contact contact = message.getContact(); if (contact != null) { @@ -446,38 +448,36 @@ public class MessageAdapter extends ArrayAdapter<Message> { viewHolder.contact_picture.setImageBitmap(activity.avatarService().get(getDisplayedMucCounterpart(message.getCounterpart()), activity.getPixel(48))); } - } else if (type == SENT && viewHolder.contact_picture != null) { + } else if (type == SENT) { viewHolder.contact_picture.setImageBitmap(activity.avatarService().get(account, activity.getPixel(48))); } - if (viewHolder != null && viewHolder.contact_picture != null) { - viewHolder.contact_picture - .setOnClickListener(new OnClickListener() { - - @Override - public void onClick(View v) { - if (MessageAdapter.this.mOnContactPictureClickedListener != null) { - MessageAdapter.this.mOnContactPictureClickedListener - .onContactPictureClicked(message); - } + viewHolder.contact_picture + .setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + if (MessageAdapter.this.mOnContactPictureClickedListener != null) { + MessageAdapter.this.mOnContactPictureClickedListener + .onContactPictureClicked(message); } - }); - viewHolder.contact_picture - .setOnLongClickListener(new OnLongClickListener() { - - @Override - public boolean onLongClick(View v) { - if (MessageAdapter.this.mOnContactPictureLongClickedListener != null) { - MessageAdapter.this.mOnContactPictureLongClickedListener - .onContactPictureLongClicked(message); - return true; - } else { - return false; - } + + } + }); + viewHolder.contact_picture + .setOnLongClickListener(new OnLongClickListener() { + + @Override + public boolean onLongClick(View v) { + if (MessageAdapter.this.mOnContactPictureLongClickedListener != null) { + MessageAdapter.this.mOnContactPictureLongClickedListener + .onContactPictureLongClicked(message); + return true; + } else { + return false; } - }); - } + } + }); if (message.getDownloadable() != null && message.getDownloadable().getStatus() != Downloadable.STATUS_UPLOADING) { Downloadable d = message.getDownloadable(); @@ -546,7 +546,7 @@ public class MessageAdapter extends ArrayAdapter<Message> { return view; } - public void startDonwloadable(Message message) { + public void startDownloadable(Message message) { Downloadable downloadable = message.getDownloadable(); if (downloadable != null) { if (!downloadable.start()) { @@ -556,7 +556,7 @@ public class MessageAdapter extends ArrayAdapter<Message> { } } - public void openDonwloadable(DownloadableFile file) { + public void openDownloadable(DownloadableFile file) { if (!file.exists()) { Toast.makeText(activity,R.string.file_deleted,Toast.LENGTH_SHORT).show(); return; diff --git a/src/main/java/eu/siacs/conversations/utils/DNSHelper.java b/src/main/java/eu/siacs/conversations/utils/DNSHelper.java index 2aa6f573..a09b4d0f 100644 --- a/src/main/java/eu/siacs/conversations/utils/DNSHelper.java +++ b/src/main/java/eu/siacs/conversations/utils/DNSHelper.java @@ -140,23 +140,17 @@ public class DNSHelper { } ArrayList<Bundle> values = new ArrayList<>(); for (SRV srv : result) { - Bundle namePort = new Bundle(); - namePort.putString("name", srv.getName()); - namePort.putInt("port", srv.getPort()); + boolean added = false; if (ips6.containsKey(srv.getName())) { - ArrayList<String> ip = ips6.get(srv.getName()); - Collections.shuffle(ip, rnd); - namePort.putString("ip", ip.get(0)); - values.add(namePort); + values.add(createNamePortBundle(srv.getName(),srv.getPort(),ips6)); + added = true; } if (ips4.containsKey(srv.getName())) { - ArrayList<String> ip = ips4.get(srv.getName()); - Collections.shuffle(ip, rnd); - namePort.putString("ip", ip.get(0)); - values.add(namePort); + values.add(createNamePortBundle(srv.getName(),srv.getPort(),ips4)); + added = true; } - if (!ips6.containsKey(srv.getName()) && !ips4.containsKey(srv.getName())) { - values.add(namePort); + if (!added) { + values.add(createNamePortBundle(srv.getName(),srv.getPort(),null)); } } bundle.putParcelableArrayList("values", values); @@ -168,6 +162,18 @@ public class DNSHelper { return bundle; } + private static Bundle createNamePortBundle(String name, int port, TreeMap<String, ArrayList<String>> ips) { + Bundle namePort = new Bundle(); + namePort.putString("name", name); + namePort.putInt("port", port); + if (ips!=null) { + ArrayList<String> ip = ips.get(name); + Collections.shuffle(ip, new Random()); + namePort.putString("ip", ip.get(0)); + } + return namePort; + } + final protected static char[] hexArray = "0123456789ABCDEF".toCharArray(); public static String bytesToHex(byte[] bytes) { |