diff options
author | d34d <clark@cyngn.com> | 2016-08-10 16:44:55 -0700 |
---|---|---|
committer | Clark Scheff <clark@cyngn.com> | 2016-08-15 12:59:09 -0700 |
commit | cdee7eb90ebe68a45a8d87ed513643f4ea21838a (patch) | |
tree | 248b95da7b32c2eb1b960d41b3b0e618ae79cf64 | |
parent | 450fbf230739cb0750421d07111a4c00ce3d1cae (diff) | |
download | android_packages_apps_Messaging-cdee7eb90ebe68a45a8d87ed513643f4ea21838a.tar.gz android_packages_apps_Messaging-cdee7eb90ebe68a45a8d87ed513643f4ea21838a.tar.bz2 android_packages_apps_Messaging-cdee7eb90ebe68a45a8d87ed513643f4ea21838a.zip |
Unachive conversations from unblocked participants
When a contact is blocked, the conversation with that participant is
archived. This patch unarchives the conversation when the participant
is no longer being blocked.
Change-Id: Ief7146ad76fc786621f080c3909e922ace1f4a75
TICKET: CYNGNOS-3226
(cherry picked from commit 6086e51e7e16f1c1f7d17fd0546cafa3957b0b8b)
-rw-r--r-- | src/com/android/messaging/util/BlacklistSync.java | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/com/android/messaging/util/BlacklistSync.java b/src/com/android/messaging/util/BlacklistSync.java index 50ec8f9..c3ed7b8 100644 --- a/src/com/android/messaging/util/BlacklistSync.java +++ b/src/com/android/messaging/util/BlacklistSync.java @@ -16,6 +16,7 @@ package com.android.messaging.util; +import android.content.ContentValues; import android.content.Context; import android.content.SharedPreferences; import android.database.Cursor; @@ -27,11 +28,14 @@ import android.text.format.Time; import android.util.Log; import com.android.messaging.datamodel.BugleDatabaseOperations; import com.android.messaging.datamodel.DataModel; +import com.android.messaging.datamodel.DatabaseHelper; import com.android.messaging.datamodel.DatabaseWrapper; import com.android.messaging.datamodel.MessagingContentProvider; import com.android.messaging.datamodel.data.ParticipantData; import com.android.messaging.util.LogUtil; +import java.util.ArrayList; + public class BlacklistSync extends AsyncTask<Void, Void, Void> { private Context mContext; @@ -49,6 +53,8 @@ public class BlacklistSync extends AsyncTask<Void, Void, Void> { Cursor cursor; DatabaseWrapper db = DataModel.get().getDatabase(); + ArrayList<String> blockedParticipants = getBlockedParticipants(db); + BugleDatabaseOperations.resetBlockedParticpants(db); // need to update local blacklist database - we are simply overwriting the @@ -97,7 +103,42 @@ public class BlacklistSync extends AsyncTask<Void, Void, Void> { cursor.close(); } + // unarchive conversations from participants that are no longer blocked + boolean conversationsUpdated = false; + ArrayList<String> updateBlockedParticipants = getBlockedParticipants(db); + for (String participant : blockedParticipants) { + if (!updateBlockedParticipants.contains(participant)) { + String selection = + DatabaseHelper.ConversationColumns.OTHER_PARTICIPANT_NORMALIZED_DESTINATION + + "=?"; + String[] selectionArgs = {participant}; + ContentValues values = new ContentValues(); + values.put(DatabaseHelper.ConversationColumns.ARCHIVE_STATUS, 0); + db.update(DatabaseHelper.CONVERSATIONS_TABLE, values, selection, selectionArgs); + conversationsUpdated = true; + } + } + MessagingContentProvider.notifyAllParticipantsChanged(); + if (conversationsUpdated) MessagingContentProvider.notifyConversationListChanged(); return null; } + + private ArrayList getBlockedParticipants(DatabaseWrapper db) { + final String[] projection = {DatabaseHelper.ParticipantColumns.NORMALIZED_DESTINATION}; + final String selection = DatabaseHelper.ParticipantColumns.BLOCKED + "=?"; + final String[] selectionArgs = { "1" }; + final ArrayList<String> blockedParticipants = new ArrayList<>(); + try (Cursor cursor = db.query(DatabaseHelper.PARTICIPANTS_TABLE, projection, selection, + selectionArgs, null, null, null)) { + if (cursor != null && cursor.getCount() > 0) { + while (cursor.moveToNext()) { + String normalizedDestination = cursor.getString(0); + blockedParticipants.add(normalizedDestination); + } + } + } + + return blockedParticipants; + } } |