aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2017-03-09 20:01:20 +0100
committerChristian Schneppe <christian@pix-art.de>2017-03-09 20:01:20 +0100
commit5b41c0da43d7c2f18fd96aa81cd70ffe8f5970f6 (patch)
tree1dc6659b8bfd15416b2b88958e1f588c51ffc4f4 /src/main/java/de/pixart/messenger
parentcc7c118cc5c43aa7a3ebf49198b540e519fee0d6 (diff)
closing the corresponding conversations after blocking a contact
Diffstat (limited to 'src/main/java/de/pixart/messenger')
-rw-r--r--src/main/java/de/pixart/messenger/parser/IqParser.java10
-rw-r--r--src/main/java/de/pixart/messenger/services/XmppConnectionService.java32
-rw-r--r--src/main/java/de/pixart/messenger/ui/BlockContactDialog.java27
-rw-r--r--src/main/java/de/pixart/messenger/ui/BlocklistActivity.java7
-rw-r--r--src/main/java/de/pixart/messenger/ui/ContactDetailsActivity.java4
-rw-r--r--src/main/java/de/pixart/messenger/ui/ConversationActivity.java72
-rw-r--r--src/main/java/de/pixart/messenger/ui/ConversationFragment.java2
-rw-r--r--src/main/java/de/pixart/messenger/ui/StartConversationActivity.java2
8 files changed, 109 insertions, 47 deletions
diff --git a/src/main/java/de/pixart/messenger/parser/IqParser.java b/src/main/java/de/pixart/messenger/parser/IqParser.java
index 073a36170..bfb2fa71e 100644
--- a/src/main/java/de/pixart/messenger/parser/IqParser.java
+++ b/src/main/java/de/pixart/messenger/parser/IqParser.java
@@ -26,7 +26,6 @@ import de.pixart.messenger.Config;
import de.pixart.messenger.crypto.axolotl.AxolotlService;
import de.pixart.messenger.entities.Account;
import de.pixart.messenger.entities.Contact;
-import de.pixart.messenger.entities.Conversation;
import de.pixart.messenger.services.XmppConnectionService;
import de.pixart.messenger.utils.Namespace;
import de.pixart.messenger.xml.Element;
@@ -321,11 +320,12 @@ public class IqParser extends AbstractParser implements OnIqPacketReceived {
}
account.getBlocklist().addAll(jids);
if (packet.getType() == IqPacket.TYPE.SET) {
+ boolean removed = false;
for(Jid jid : jids) {
- Conversation conversation = mXmppConnectionService.find(account,jid);
- if (conversation != null) {
- mXmppConnectionService.markRead(conversation);
- }
+ removed |= mXmppConnectionService.removeBlockedConversations(account, jid);
+ }
+ if (removed) {
+ mXmppConnectionService.updateConversationUi();
}
}
}
diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
index f2a6dc308..4c6dd9ccd 100644
--- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
+++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
@@ -3747,7 +3747,7 @@ public class XmppConnectionService extends Service {
mDatabaseExecutor.execute(runnable);
}
- public void sendBlockRequest(final Blockable blockable, boolean reportSpam) {
+ public boolean sendBlockRequest(final Blockable blockable, boolean reportSpam) {
if (blockable != null && blockable.getBlockedJid() != null) {
final Jid jid = blockable.getBlockedJid();
this.sendIqPacket(blockable.getAccount(), getIqGenerator().generateSetBlockRequest(jid, reportSpam), new OnIqPacketReceived() {
@@ -3760,7 +3760,37 @@ public class XmppConnectionService extends Service {
}
}
});
+ if (removeBlockedConversations(blockable.getAccount(), jid)) {
+ updateConversationUi();
+ return true;
+ } else {
+ return false;
+ }
+ } else {
+ return false;
+ }
+ }
+
+ public boolean removeBlockedConversations(final Account account, final Jid blockedJid) {
+ boolean removed = false;
+ synchronized (this.conversations) {
+ boolean domainJid = blockedJid.isDomainJid();
+ for (Conversation conversation : this.conversations) {
+ boolean jidMatches = (domainJid && blockedJid.getDomainpart().equals(conversation.getJid().getDomainpart()))
+ || blockedJid.equals(conversation.getJid().toBareJid());
+ if (conversation.getAccount() == account
+ && conversation.getMode() == Conversation.MODE_SINGLE
+ && jidMatches) {
+ this.conversations.remove(conversation);
+ markRead(conversation);
+ conversation.setStatus(Conversation.STATUS_ARCHIVED);
+ Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": archiving conversation " + conversation.getJid().toBareJid() + " because jid was blocked");
+ updateConversation(conversation);
+ removed = true;
+ }
+ }
}
+ return removed;
}
public void sendUnblockRequest(final Blockable blockable) {
diff --git a/src/main/java/de/pixart/messenger/ui/BlockContactDialog.java b/src/main/java/de/pixart/messenger/ui/BlockContactDialog.java
index 3be0d9344..bf33c35d9 100644
--- a/src/main/java/de/pixart/messenger/ui/BlockContactDialog.java
+++ b/src/main/java/de/pixart/messenger/ui/BlockContactDialog.java
@@ -11,19 +11,18 @@ import android.view.View;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.TextView;
+import android.widget.Toast;
import de.pixart.messenger.R;
import de.pixart.messenger.entities.Blockable;
-import de.pixart.messenger.services.XmppConnectionService;
public final class BlockContactDialog {
- public static void show(final Context context,
- final XmppConnectionService xmppConnectionService,
+ public static void show(final XmppActivity xmppActivity,
final Blockable blockable) {
- final AlertDialog.Builder builder = new AlertDialog.Builder(context);
+ final AlertDialog.Builder builder = new AlertDialog.Builder(xmppActivity);
final boolean isBlocked = blockable.isBlocked();
builder.setNegativeButton(R.string.cancel, null);
- LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+ LayoutInflater inflater = (LayoutInflater) xmppActivity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LinearLayout view = (LinearLayout) inflater.inflate(R.layout.dialog_block_contact, null);
TextView message = (TextView) view.findViewById(R.id.text);
final CheckBox report = (CheckBox) view.findViewById(R.id.report_spam);
@@ -36,11 +35,11 @@ public final class BlockContactDialog {
if (blockable.getJid().isDomainJid() || blockable.getAccount().isBlocked(blockable.getJid().toDomainJid())) {
builder.setTitle(isBlocked ? R.string.action_unblock_domain : R.string.action_block_domain);
value = blockable.getJid().toDomainJid().toString();
- spannable = new SpannableString(context.getString(isBlocked ? R.string.unblock_domain_text : R.string.block_domain_text, value));
+ spannable = new SpannableString(xmppActivity.getString(isBlocked ? R.string.unblock_domain_text : R.string.block_domain_text, value));
} else {
builder.setTitle(isBlocked ? R.string.action_unblock_contact : R.string.action_block_contact);
value = blockable.getJid().toBareJid().toString();
- spannable = new SpannableString(context.getString(isBlocked ? R.string.unblock_contact_text : R.string.block_contact_text, value));
+ spannable = new SpannableString(xmppActivity.getString(isBlocked ? R.string.unblock_contact_text : R.string.block_contact_text, value));
}
int start = spannable.toString().indexOf(value);
if (start >= 0) {
@@ -52,9 +51,19 @@ public final class BlockContactDialog {
@Override
public void onClick(final DialogInterface dialog, final int which) {
if (isBlocked) {
- xmppConnectionService.sendUnblockRequest(blockable);
+ xmppActivity.xmppConnectionService.sendUnblockRequest(blockable);
} else {
- xmppConnectionService.sendBlockRequest(blockable, report.isChecked());
+ boolean toastShown = false;
+ if (xmppActivity.xmppConnectionService.sendBlockRequest(blockable, report.isChecked())) {
+ Toast.makeText(xmppActivity, R.string.corresponding_conversations_closed, Toast.LENGTH_SHORT).show();
+ toastShown = true;
+ }
+ if (xmppActivity instanceof ContactDetailsActivity) {
+ if (!toastShown) {
+ Toast.makeText(xmppActivity, R.string.contact_blocked_past_tense, Toast.LENGTH_SHORT).show();
+ }
+ xmppActivity.finish();
+ }
}
}
});
diff --git a/src/main/java/de/pixart/messenger/ui/BlocklistActivity.java b/src/main/java/de/pixart/messenger/ui/BlocklistActivity.java
index 3f6a57381..3ee40aa7f 100644
--- a/src/main/java/de/pixart/messenger/ui/BlocklistActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/BlocklistActivity.java
@@ -6,6 +6,7 @@ import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
+import android.widget.Toast;
import java.util.ArrayList;
import java.util.Collections;
@@ -31,7 +32,7 @@ public class BlocklistActivity extends AbstractSearchableListItemActivity implem
final View view,
final int position,
final long id) {
- BlockContactDialog.show(parent.getContext(), xmppConnectionService, (Contact) getListItems().get(position));
+ BlockContactDialog.show(BlocklistActivity.this, (Contact) getListItems().get(position));
return true;
}
});
@@ -92,7 +93,9 @@ public class BlocklistActivity extends AbstractSearchableListItemActivity implem
@Override
public boolean onEnterJidDialogPositive(Jid accountJid, Jid contactJid) throws EnterJidDialog.JidError {
Contact contact = account.getRoster().getContact(contactJid);
- xmppConnectionService.sendBlockRequest(contact, false);
+ if (xmppConnectionService.sendBlockRequest(contact, false)) {
+ Toast.makeText(BlocklistActivity.this, R.string.corresponding_conversations_closed, Toast.LENGTH_SHORT).show();
+ }
return true;
}
});
diff --git a/src/main/java/de/pixart/messenger/ui/ContactDetailsActivity.java b/src/main/java/de/pixart/messenger/ui/ContactDetailsActivity.java
index de633ad17..1837e6df5 100644
--- a/src/main/java/de/pixart/messenger/ui/ContactDetailsActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/ContactDetailsActivity.java
@@ -366,10 +366,10 @@ public class ContactDetailsActivity extends OmemoActivity implements OnAccountUp
}
break;
case R.id.action_block:
- BlockContactDialog.show(this, xmppConnectionService, contact);
+ BlockContactDialog.show(this, contact);
break;
case R.id.action_unblock:
- BlockContactDialog.show(this, xmppConnectionService, contact);
+ BlockContactDialog.show(this, contact);
break;
}
return super.onOptionsItemSelected(menuItem);
diff --git a/src/main/java/de/pixart/messenger/ui/ConversationActivity.java b/src/main/java/de/pixart/messenger/ui/ConversationActivity.java
index e8d61d1df..d60fbcbe4 100644
--- a/src/main/java/de/pixart/messenger/ui/ConversationActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/ConversationActivity.java
@@ -837,10 +837,10 @@ public class ConversationActivity extends XmppActivity
clearHistoryDialog(getSelectedConversation());
break;
case R.id.action_block:
- BlockContactDialog.show(this, xmppConnectionService, getSelectedConversation());
+ BlockContactDialog.show(this, getSelectedConversation());
break;
case R.id.action_unblock:
- BlockContactDialog.show(this, xmppConnectionService, getSelectedConversation());
+ BlockContactDialog.show(this, getSelectedConversation());
break;
default:
break;
@@ -1281,6 +1281,18 @@ public class ConversationActivity extends XmppActivity
mPostponedActivityResult = null;
}
+ private void redirectToStartConversationActivity() {
+ Account pendingAccount = xmppConnectionService.getPendingAccount();
+ if (pendingAccount == null) {
+ Intent startConversationActivity = new Intent(this, StartConversationActivity.class);
+ startConversationActivity.putExtra("init", true);
+ startActivity(startConversationActivity);
+ } else {
+ switchToAccount(pendingAccount, true);
+ }
+ finish();
+ }
+
@Override
void onBackendConnected() {
this.xmppConnectionService.getNotificationService().setIsInForeground(true);
@@ -1338,15 +1350,7 @@ public class ConversationActivity extends XmppActivity
}
} else if (conversationList.size() <= 0) {
if (mRedirected.compareAndSet(false, true)) {
- Account pendingAccount = xmppConnectionService.getPendingAccount();
- if (pendingAccount == null) {
- Intent startConversationActivity = new Intent(this, StartConversationActivity.class);
- intent.putExtra("init", true);
- startActivity(startConversationActivity);
- } else {
- switchToAccount(pendingAccount, true);
- }
- finish();
+ redirectToStartConversationActivity();
}
} else if (selectConversationByUuid(mOpenConversation)) {
if (mPanelOpen) {
@@ -1367,10 +1371,7 @@ public class ConversationActivity extends XmppActivity
handleViewConversationIntent(intent);
intent.setAction(Intent.ACTION_MAIN);
} else if (getSelectedConversation() == null) {
- showConversationsOverview();
- clearPending();
- setSelectedConversation(conversationList.get(0));
- this.mConversationFragment.reInit(getSelectedConversation());
+ reInitLatestConversation();
} else {
this.mConversationFragment.messageListAdapter.updatePreferences();
this.mConversationFragment.messagesView.invalidateViews();
@@ -1388,12 +1389,7 @@ public class ConversationActivity extends XmppActivity
this.onActivityResult(mPostponedActivityResult.first, RESULT_OK, mPostponedActivityResult.second);
}
- final boolean stopping;
- if (Build.VERSION.SDK_INT >= 17) {
- stopping = isFinishing() || isDestroyed();
- } else {
- stopping = isFinishing();
- }
+ final boolean stopping = isStopping();
if (!forbidProcessingPendings) {
int ImageUrisCount = mPendingImageUris.size();
@@ -1436,6 +1432,21 @@ public class ConversationActivity extends XmppActivity
}
}
+ private boolean isStopping() {
+ if (Build.VERSION.SDK_INT >= 17) {
+ return isFinishing() || isDestroyed();
+ } else {
+ return isFinishing();
+ }
+ }
+
+ private void reInitLatestConversation() {
+ showConversationsOverview();
+ clearPending();
+ setSelectedConversation(conversationList.get(0));
+ this.mConversationFragment.reInit(getSelectedConversation());
+ }
+
private void handleViewConversationIntent(final Intent intent) {
final String uuid = intent.getStringExtra(CONVERSATION);
final String downloadUuid = intent.getStringExtra(EXTRA_DOWNLOAD_UUID);
@@ -1939,8 +1950,10 @@ public class ConversationActivity extends XmppActivity
}
public void updateConversationList() {
- xmppConnectionService
- .populateWithOrderedConversations(conversationList);
+ xmppConnectionService.populateWithOrderedConversations(conversationList);
+ if (!conversationList.contains(mSelectedConversation)) {
+ mSelectedConversation = null;
+ }
if (swipedConversation != null) {
if (swipedConversation.isRead()) {
conversationList.remove(swipedConversation);
@@ -2044,10 +2057,17 @@ public class ConversationActivity extends XmppActivity
if (!this.mConversationFragment.isAdded()) {
Log.d(Config.LOGTAG, "fragment NOT added to activity. detached=" + Boolean.toString(mConversationFragment.isDetached()));
}
- ConversationActivity.this.mConversationFragment.updateMessages();
- updateActionBarTitle();
- invalidateOptionsMenu();
+ if (getSelectedConversation() == null) {
+ reInitLatestConversation();
+ } else {
+ ConversationActivity.this.mConversationFragment.updateMessages();
+ updateActionBarTitle();
+ invalidateOptionsMenu();
+ }
} else {
+ if (!isStopping() && mRedirected.compareAndSet(false, true)) {
+ redirectToStartConversationActivity();
+ }
Log.d(Config.LOGTAG, "not updating conversations fragment because conversations list size was 0");
}
}
diff --git a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
index 8e8fb5e46..b985a2c35 100644
--- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
+++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
@@ -981,7 +981,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
}
});
if (conversation.isDomainBlocked()) {
- BlockContactDialog.show(activity, activity.xmppConnectionService, conversation);
+ BlockContactDialog.show(activity, conversation);
} else {
activity.unblockConversation(conversation);
}
diff --git a/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java b/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java
index a4a9db761..93663bda5 100644
--- a/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java
@@ -389,7 +389,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
protected void toggleContactBlock() {
final int position = contact_context_id;
- BlockContactDialog.show(this, xmppConnectionService, (Contact) contacts.get(position));
+ BlockContactDialog.show(this, (Contact) contacts.get(position));
}
protected void deleteContact() {