Pass recipient ids, not recipient objects

Fixes #2233
// FREEBIE
This commit is contained in:
Jake McGinty 2014-12-17 18:14:19 -08:00
parent 60a343120d
commit e8b947dfde
16 changed files with 58 additions and 113 deletions

View File

@ -246,7 +246,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
addAttachmentContactInfo(data.getData()); addAttachmentContactInfo(data.getData());
break; break;
case GROUP_EDIT: case GROUP_EDIT:
this.recipients = data.getParcelableExtra(GroupCreateActivity.GROUP_RECIPIENT_EXTRA); this.recipients = RecipientFactory.getRecipientsForIds(this, data.getLongArrayExtra(GroupCreateActivity.GROUP_RECIPIENT_EXTRA), true);
initializeTitleBar(); initializeTitleBar();
break; break;
} }
@ -349,7 +349,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
private void handleVerifyIdentity() { private void handleVerifyIdentity() {
Intent verifyIdentityIntent = new Intent(this, VerifyIdentityActivity.class); Intent verifyIdentityIntent = new Intent(this, VerifyIdentityActivity.class);
verifyIdentityIntent.putExtra("recipient", getRecipients().getPrimaryRecipient()); verifyIdentityIntent.putExtra("recipient", getRecipients().getPrimaryRecipient().getRecipientId());
verifyIdentityIntent.putExtra("master_secret", masterSecret); verifyIdentityIntent.putExtra("master_secret", masterSecret);
startActivity(verifyIdentityIntent); startActivity(verifyIdentityIntent);
} }
@ -458,7 +458,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
private void handleEditPushGroup() { private void handleEditPushGroup() {
Intent intent = new Intent(ConversationActivity.this, GroupCreateActivity.class); Intent intent = new Intent(ConversationActivity.this, GroupCreateActivity.class);
intent.putExtra(GroupCreateActivity.MASTER_SECRET_EXTRA, masterSecret); intent.putExtra(GroupCreateActivity.MASTER_SECRET_EXTRA, masterSecret);
intent.putExtra(GroupCreateActivity.GROUP_RECIPIENT_EXTRA, recipients); intent.putExtra(GroupCreateActivity.GROUP_RECIPIENT_EXTRA, recipients.getIds());
startActivityForResult(intent, GROUP_EDIT); startActivityForResult(intent, GROUP_EDIT);
} }
@ -719,7 +719,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
} }
private void initializeResources() { private void initializeResources() {
recipients = RecipientFactory.getRecipientsForIds(this, getIntent().getStringExtra(RECIPIENTS_EXTRA), true); recipients = RecipientFactory.getRecipientsForIds(this, getIntent().getLongArrayExtra(RECIPIENTS_EXTRA), true);
threadId = getIntent().getLongExtra(THREAD_ID_EXTRA, -1); threadId = getIntent().getLongExtra(THREAD_ID_EXTRA, -1);
distributionType = getIntent().getIntExtra(DISTRIBUTION_TYPE_EXTRA, distributionType = getIntent().getIntExtra(DISTRIBUTION_TYPE_EXTRA,
ThreadDatabase.DistributionTypes.DEFAULT); ThreadDatabase.DistributionTypes.DEFAULT);
@ -779,7 +779,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
Log.w("ConversationActivity", "Group update received..."); Log.w("ConversationActivity", "Group update received...");
if (recipients != null) { if (recipients != null) {
String ids = recipients.toIdString(); long[] ids = recipients.getIds();
Log.w("ConversationActivity", "Looking up new recipients..."); Log.w("ConversationActivity", "Looking up new recipients...");
recipients = RecipientFactory.getRecipientsForIds(context, ids, false); recipients = RecipientFactory.getRecipientsForIds(context, ids, false);
initializeTitleBar(); initializeTitleBar();

View File

@ -79,10 +79,8 @@ public class ConversationFragment extends ListFragment
} }
private void initializeResources() { private void initializeResources() {
String recipientIds = this.getActivity().getIntent().getStringExtra("recipients");
this.masterSecret = this.getActivity().getIntent().getParcelableExtra("master_secret"); this.masterSecret = this.getActivity().getIntent().getParcelableExtra("master_secret");
this.recipients = RecipientFactory.getRecipientsForIds(getActivity(), recipientIds, true); this.recipients = RecipientFactory.getRecipientsForIds(getActivity(), getActivity().getIntent().getLongArrayExtra("recipients"), true);
this.threadId = this.getActivity().getIntent().getLongExtra("thread_id", -1); this.threadId = this.getActivity().getIntent().getLongExtra("thread_id", -1);
} }

View File

@ -400,7 +400,7 @@ public class ConversationItem extends LinearLayout {
intent.setClass(context, AutoInitiateActivity.class); intent.setClass(context, AutoInitiateActivity.class);
intent.putExtra("threadId", threadId); intent.putExtra("threadId", threadId);
intent.putExtra("masterSecret", masterSecret); intent.putExtra("masterSecret", masterSecret);
intent.putExtra("recipient", recipient); intent.putExtra("recipient", recipient.getRecipientId());
context.startActivity(intent); context.startActivity(intent);
} }
@ -440,7 +440,7 @@ public class ConversationItem extends LinearLayout {
private void handleKeyExchangeClicked() { private void handleKeyExchangeClicked() {
Intent intent = new Intent(context, ReceiveKeyActivity.class); Intent intent = new Intent(context, ReceiveKeyActivity.class);
intent.putExtra("recipient", messageRecord.getIndividualRecipient()); intent.putExtra("recipient", messageRecord.getIndividualRecipient().getRecipientId());
intent.putExtra("recipient_device_id", messageRecord.getRecipientDeviceId()); intent.putExtra("recipient_device_id", messageRecord.getRecipientDeviceId());
intent.putExtra("body", messageRecord.getBody().getBody()); intent.putExtra("body", messageRecord.getBody().getBody());
intent.putExtra("thread_id", messageRecord.getThreadId()); intent.putExtra("thread_id", messageRecord.getThreadId());
@ -479,7 +479,7 @@ public class ConversationItem extends LinearLayout {
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.setDataAndType(slide.getUri(), slide.getContentType()); intent.setDataAndType(slide.getUri(), slide.getContentType());
intent.putExtra(MediaPreviewActivity.MASTER_SECRET_EXTRA, masterSecret); intent.putExtra(MediaPreviewActivity.MASTER_SECRET_EXTRA, masterSecret);
if (!messageRecord.isOutgoing()) intent.putExtra(MediaPreviewActivity.RECIPIENT_EXTRA, messageRecord.getIndividualRecipient()); if (!messageRecord.isOutgoing()) intent.putExtra(MediaPreviewActivity.RECIPIENT_EXTRA, messageRecord.getIndividualRecipient().getRecipientId());
intent.putExtra(MediaPreviewActivity.DATE_EXTRA, messageRecord.getDateReceived()); intent.putExtra(MediaPreviewActivity.DATE_EXTRA, messageRecord.getDateReceived());
context.startActivity(intent); context.startActivity(intent);
} else { } else {

View File

@ -22,21 +22,11 @@ import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.provider.ContactsContract; import android.provider.ContactsContract;
import android.util.Log; import android.util.Log;
import android.provider.Telephony;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.view.GravityCompat;
import android.support.v4.view.MenuItemCompat; import android.support.v4.view.MenuItemCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.widget.SearchView; import android.support.v7.widget.SearchView;
import android.util.Log;
import android.view.Menu; import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import org.thoughtcrime.securesms.crypto.MasterSecret; import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.database.DatabaseFactory; import org.thoughtcrime.securesms.database.DatabaseFactory;
@ -197,7 +187,7 @@ public class ConversationListActivity extends PassphraseRequiredActionBarActivit
private void createConversation(long threadId, Recipients recipients, int distributionType) { private void createConversation(long threadId, Recipients recipients, int distributionType) {
Intent intent = new Intent(this, ConversationActivity.class); Intent intent = new Intent(this, ConversationActivity.class);
intent.putExtra(ConversationActivity.RECIPIENTS_EXTRA, recipients.toIdString()); intent.putExtra(ConversationActivity.RECIPIENTS_EXTRA, recipients.getIds());
intent.putExtra(ConversationActivity.THREAD_ID_EXTRA, threadId); intent.putExtra(ConversationActivity.THREAD_ID_EXTRA, threadId);
intent.putExtra(ConversationActivity.MASTER_SECRET_EXTRA, masterSecret); intent.putExtra(ConversationActivity.MASTER_SECRET_EXTRA, masterSecret);
intent.putExtra(ConversationActivity.DISTRIBUTION_TYPE_EXTRA, distributionType); intent.putExtra(ConversationActivity.DISTRIBUTION_TYPE_EXTRA, distributionType);

View File

@ -18,7 +18,6 @@
package org.thoughtcrime.securesms; package org.thoughtcrime.securesms;
import android.app.Activity; import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.graphics.Bitmap; import android.graphics.Bitmap;
@ -70,7 +69,6 @@ import org.whispersystems.textsecure.api.util.InvalidNumberException;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
@ -110,7 +108,7 @@ public class GroupCreateActivity extends PassphraseRequiredActionBarActivity {
private ImageView avatar; private ImageView avatar;
private TextView creatingText; private TextView creatingText;
private Recipients groupRecipient = null; private Recipient groupRecipient = null;
private long groupThread = -1; private long groupThread = -1;
private byte[] groupId = null; private byte[] groupId = null;
private Set<Recipient> existingContacts = null; private Set<Recipient> existingContacts = null;
@ -217,10 +215,10 @@ public class GroupCreateActivity extends PassphraseRequiredActionBarActivity {
} }
private void initializeResources() { private void initializeResources() {
groupRecipient = getIntent().getParcelableExtra(GROUP_RECIPIENT_EXTRA); groupRecipient = RecipientFactory.getRecipientForId(this, getIntent().getLongExtra(GROUP_RECIPIENT_EXTRA, -1), true);
groupThread = getIntent().getLongExtra(GROUP_THREAD_EXTRA, -1); groupThread = getIntent().getLongExtra(GROUP_THREAD_EXTRA, -1);
if (groupRecipient != null) { if (groupRecipient != null) {
final String encodedGroupId = groupRecipient.getPrimaryRecipient().getNumber(); final String encodedGroupId = groupRecipient.getNumber();
if (encodedGroupId != null) { if (encodedGroupId != null) {
try { try {
groupId = GroupUtil.getDecodedId(encodedGroupId); groupId = GroupUtil.getDecodedId(encodedGroupId);
@ -543,7 +541,7 @@ public class GroupCreateActivity extends PassphraseRequiredActionBarActivity {
intent.putExtra(ConversationActivity.DISTRIBUTION_TYPE_EXTRA, ThreadDatabase.DistributionTypes.DEFAULT); intent.putExtra(ConversationActivity.DISTRIBUTION_TYPE_EXTRA, ThreadDatabase.DistributionTypes.DEFAULT);
ArrayList<Recipient> selectedContactsList = setToArrayList(selectedContacts); ArrayList<Recipient> selectedContactsList = setToArrayList(selectedContacts);
intent.putExtra(ConversationActivity.RECIPIENTS_EXTRA, new Recipients(selectedContactsList).toIdString()); intent.putExtra(ConversationActivity.RECIPIENTS_EXTRA, new Recipients(selectedContactsList).getIds());
startActivity(intent); startActivity(intent);
finish(); finish();
} else { } else {
@ -594,7 +592,7 @@ public class GroupCreateActivity extends PassphraseRequiredActionBarActivity {
if (threadId > -1) { if (threadId > -1) {
Intent intent = getIntent(); Intent intent = getIntent();
intent.putExtra(GROUP_THREAD_EXTRA, threadId); intent.putExtra(GROUP_THREAD_EXTRA, threadId);
intent.putExtra(GROUP_RECIPIENT_EXTRA, recipients); intent.putExtra(GROUP_RECIPIENT_EXTRA, recipients.getIds());
setResult(RESULT_OK, intent); setResult(RESULT_OK, intent);
finish(); finish();
} else if (threadId == RES_BAD_NUMBER) { } else if (threadId == RES_BAD_NUMBER) {
@ -642,7 +640,7 @@ public class GroupCreateActivity extends PassphraseRequiredActionBarActivity {
intent.putExtra(ConversationActivity.MASTER_SECRET_EXTRA, masterSecret); intent.putExtra(ConversationActivity.MASTER_SECRET_EXTRA, masterSecret);
intent.putExtra(ConversationActivity.THREAD_ID_EXTRA, threadId); intent.putExtra(ConversationActivity.THREAD_ID_EXTRA, threadId);
intent.putExtra(ConversationActivity.DISTRIBUTION_TYPE_EXTRA, ThreadDatabase.DistributionTypes.DEFAULT); intent.putExtra(ConversationActivity.DISTRIBUTION_TYPE_EXTRA, ThreadDatabase.DistributionTypes.DEFAULT);
intent.putExtra(ConversationActivity.RECIPIENTS_EXTRA, recipients.toIdString()); intent.putExtra(ConversationActivity.RECIPIENTS_EXTRA, recipients.getIds());
startActivity(intent); startActivity(intent);
finish(); finish();
} else if (threadId == RES_BAD_NUMBER) { } else if (threadId == RES_BAD_NUMBER) {

View File

@ -152,7 +152,7 @@ public class NewConversationActivity extends PassphraseRequiredActionBarActivity
private void openNewConversation(Recipients recipients) { private void openNewConversation(Recipients recipients) {
if (recipients != null) { if (recipients != null) {
Intent intent = new Intent(this, ConversationActivity.class); Intent intent = new Intent(this, ConversationActivity.class);
intent.putExtra(ConversationActivity.RECIPIENTS_EXTRA, recipients.toIdString()); intent.putExtra(ConversationActivity.RECIPIENTS_EXTRA, recipients.getIds());
intent.putExtra(ConversationActivity.MASTER_SECRET_EXTRA, masterSecret); intent.putExtra(ConversationActivity.MASTER_SECRET_EXTRA, masterSecret);
intent.putExtra(ConversationActivity.DRAFT_TEXT_EXTRA, getIntent().getStringExtra(ConversationActivity.DRAFT_TEXT_EXTRA)); intent.putExtra(ConversationActivity.DRAFT_TEXT_EXTRA, getIntent().getStringExtra(ConversationActivity.DRAFT_TEXT_EXTRA));
intent.putExtra(ConversationActivity.DRAFT_AUDIO_EXTRA, getIntent().getParcelableExtra(ConversationActivity.DRAFT_AUDIO_EXTRA)); intent.putExtra(ConversationActivity.DRAFT_AUDIO_EXTRA, getIntent().getParcelableExtra(ConversationActivity.DRAFT_AUDIO_EXTRA));

View File

@ -41,6 +41,7 @@ import org.thoughtcrime.securesms.database.PushDatabase;
import org.thoughtcrime.securesms.jobs.PushDecryptJob; import org.thoughtcrime.securesms.jobs.PushDecryptJob;
import org.thoughtcrime.securesms.jobs.SmsDecryptJob; import org.thoughtcrime.securesms.jobs.SmsDecryptJob;
import org.thoughtcrime.securesms.recipients.Recipient; import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.recipients.RecipientFactory;
import org.thoughtcrime.securesms.sms.IncomingIdentityUpdateMessage; import org.thoughtcrime.securesms.sms.IncomingIdentityUpdateMessage;
import org.thoughtcrime.securesms.sms.IncomingKeyExchangeMessage; import org.thoughtcrime.securesms.sms.IncomingKeyExchangeMessage;
import org.thoughtcrime.securesms.sms.IncomingPreKeyBundleMessage; import org.thoughtcrime.securesms.sms.IncomingPreKeyBundleMessage;
@ -123,7 +124,7 @@ public class ReceiveKeyActivity extends Activity {
@Override @Override
public void onClick(View widget) { public void onClick(View widget) {
Intent intent = new Intent(ReceiveKeyActivity.this, VerifyIdentityActivity.class); Intent intent = new Intent(ReceiveKeyActivity.this, VerifyIdentityActivity.class);
intent.putExtra("recipient", recipient); intent.putExtra("recipient", recipient.getRecipientId());
intent.putExtra("master_secret", masterSecret); intent.putExtra("master_secret", masterSecret);
intent.putExtra("remote_identity", new IdentityKeyParcelable(identityKey)); intent.putExtra("remote_identity", new IdentityKeyParcelable(identityKey));
startActivity(intent); startActivity(intent);
@ -167,7 +168,7 @@ public class ReceiveKeyActivity extends Activity {
this.descriptionText = (TextView) findViewById(R.id.description_text); this.descriptionText = (TextView) findViewById(R.id.description_text);
this.confirmButton = (Button) findViewById(R.id.ok_button); this.confirmButton = (Button) findViewById(R.id.ok_button);
this.cancelButton = (Button) findViewById(R.id.cancel_button); this.cancelButton = (Button) findViewById(R.id.cancel_button);
this.recipient = getIntent().getParcelableExtra("recipient"); this.recipient = RecipientFactory.getRecipientForId(this, getIntent().getLongExtra("recipient", -1), true);
this.recipientDeviceId = getIntent().getIntExtra("recipient_device_id", -1); this.recipientDeviceId = getIntent().getIntExtra("recipient_device_id", -1);
this.messageId = getIntent().getLongExtra("message_id", -1); this.messageId = getIntent().getLongExtra("message_id", -1);
this.masterSecret = getIntent().getParcelableExtra("master_secret"); this.masterSecret = getIntent().getParcelableExtra("master_secret");

View File

@ -129,7 +129,7 @@ public class RoutingActivity extends PassphraseRequiredActionBarActivity {
private Intent getConversationIntent(ConversationParameters parameters) { private Intent getConversationIntent(ConversationParameters parameters) {
Intent intent = new Intent(this, ConversationActivity.class); Intent intent = new Intent(this, ConversationActivity.class);
intent.putExtra(ConversationActivity.RECIPIENTS_EXTRA, parameters.recipients != null ? parameters.recipients.toIdString() : ""); intent.putExtra(ConversationActivity.RECIPIENTS_EXTRA, parameters.recipients != null ? parameters.recipients.getIds() : new long[]{});
intent.putExtra(ConversationActivity.THREAD_ID_EXTRA, parameters.thread); intent.putExtra(ConversationActivity.THREAD_ID_EXTRA, parameters.thread);
intent.putExtra(ConversationActivity.MASTER_SECRET_EXTRA, masterSecret); intent.putExtra(ConversationActivity.MASTER_SECRET_EXTRA, masterSecret);
intent.putExtra(ConversationActivity.DRAFT_TEXT_EXTRA, parameters.draftText); intent.putExtra(ConversationActivity.DRAFT_TEXT_EXTRA, parameters.draftText);
@ -247,7 +247,8 @@ public class RoutingActivity extends PassphraseRequiredActionBarActivity {
private ConversationParameters getConversationParametersForInternalAction() { private ConversationParameters getConversationParametersForInternalAction() {
long threadId = getIntent().getLongExtra("thread_id", -1); long threadId = getIntent().getLongExtra("thread_id", -1);
Recipients recipients = getIntent().getParcelableExtra("recipients"); long[] recipientIds = getIntent().getLongArrayExtra("recipients");
Recipients recipients = recipientIds == null ? null : RecipientFactory.getRecipientsForIds(this, recipientIds, true);
return new ConversationParameters(threadId, recipients, null, null, null, null); return new ConversationParameters(threadId, recipients, null, null, null, null);
} }

View File

@ -120,7 +120,7 @@ public class ShareActivity extends PassphraseRequiredActionBarActivity
private void createConversation(long threadId, Recipients recipients, int distributionType) { private void createConversation(long threadId, Recipients recipients, int distributionType) {
final Intent intent = getBaseShareIntent(ConversationActivity.class); final Intent intent = getBaseShareIntent(ConversationActivity.class);
intent.putExtra(ConversationActivity.RECIPIENTS_EXTRA, recipients.toIdString()); intent.putExtra(ConversationActivity.RECIPIENTS_EXTRA, recipients.getIds());
intent.putExtra(ConversationActivity.THREAD_ID_EXTRA, threadId); intent.putExtra(ConversationActivity.THREAD_ID_EXTRA, threadId);
intent.putExtra(ConversationActivity.DISTRIBUTION_TYPE_EXTRA, distributionType); intent.putExtra(ConversationActivity.DISTRIBUTION_TYPE_EXTRA, distributionType);

View File

@ -144,7 +144,7 @@ public class IdentityDatabase extends Database {
public Identity getCurrent() { public Identity getCurrent() {
long recipientId = cursor.getLong(cursor.getColumnIndexOrThrow(RECIPIENT)); long recipientId = cursor.getLong(cursor.getColumnIndexOrThrow(RECIPIENT));
Recipients recipients = RecipientFactory.getRecipientsForIds(context, recipientId + "", true); Recipients recipients = RecipientFactory.getRecipientsForIds(context, new long[]{recipientId}, true);
try { try {
String identityKeyString = cursor.getString(cursor.getColumnIndexOrThrow(IDENTITY_KEY)); String identityKeyString = cursor.getString(cursor.getColumnIndexOrThrow(IDENTITY_KEY));

View File

@ -86,7 +86,7 @@ public class MessageNotifier {
} else { } else {
Intent intent = new Intent(context, RoutingActivity.class); Intent intent = new Intent(context, RoutingActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.putExtra("recipients", recipients); intent.putExtra("recipients", recipients.getIds());
intent.putExtra("thread_id", threadId); intent.putExtra("thread_id", threadId);
intent.setData((Uri.parse("custom://"+System.currentTimeMillis()))); intent.setData((Uri.parse("custom://"+System.currentTimeMillis())));

View File

@ -74,8 +74,8 @@ public class NotificationItem {
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
if (recipients != null || threadRecipients != null) { if (recipients != null || threadRecipients != null) {
if (threadRecipients != null) intent.putExtra("recipients", threadRecipients); if (threadRecipients != null) intent.putExtra("recipients", threadRecipients.getIds());
else intent.putExtra("recipients", recipients); else intent.putExtra("recipients", recipients.getIds());
intent.putExtra("thread_id", threadId); intent.putExtra("thread_id", threadId);
} }

View File

@ -20,10 +20,9 @@ public class SecurityEventListener implements TextSecureMessageSender.EventListe
@Override @Override
public void onSecurityEvent(long recipientId) { public void onSecurityEvent(long recipientId) {
Recipients recipients = RecipientFactory.getRecipientsForIds(context, String.valueOf(recipientId), false); Recipients recipients = RecipientFactory.getRecipientsForIds(context, new long[]{recipientId}, false);
long threadId = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(recipients); long threadId = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(recipients);
SecurityEvent.broadcastSecurityUpdateEvent(context, threadId); SecurityEvent.broadcastSecurityUpdateEvent(context, threadId);
} }
} }

View File

@ -19,8 +19,6 @@ package org.thoughtcrime.securesms.recipients;
import android.content.Context; import android.content.Context;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.net.Uri; import android.net.Uri;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.Log; import android.util.Log;
import org.thoughtcrime.securesms.contacts.ContactPhotoFactory; import org.thoughtcrime.securesms.contacts.ContactPhotoFactory;
@ -31,20 +29,10 @@ import org.thoughtcrime.securesms.util.ListenableFutureTask;
import java.util.HashSet; import java.util.HashSet;
public class Recipient implements Parcelable { public class Recipient {
private final static String TAG = Recipient.class.getSimpleName(); private final static String TAG = Recipient.class.getSimpleName();
public static final Parcelable.Creator<Recipient> CREATOR = new Parcelable.Creator<Recipient>() {
public Recipient createFromParcel(Parcel in) {
return new Recipient(in);
}
public Recipient[] newArray(int size) {
return new Recipient[size];
}
};
private final HashSet<RecipientModifiedListener> listeners = new HashSet<RecipientModifiedListener>(); private final HashSet<RecipientModifiedListener> listeners = new HashSet<RecipientModifiedListener>();
private final long recipientId; private final long recipientId;
@ -107,14 +95,6 @@ public class Recipient implements Parcelable {
this.circleCroppedContactPhoto = circleCroppedContactPhoto; this.circleCroppedContactPhoto = circleCroppedContactPhoto;
} }
public Recipient(Parcel in) {
this.number = in.readString();
this.name = in.readString();
this.recipientId = in.readLong();
this.contactUri = in.readParcelable(null);
this.contactPhoto = in.readParcelable(null);
}
public synchronized Uri getContactUri() { public synchronized Uri getContactUri() {
return this.contactUri; return this.contactUri;
} }
@ -137,10 +117,6 @@ public class Recipient implements Parcelable {
return number; return number;
} }
public int describeContents() {
return 0;
}
public long getRecipientId() { public long getRecipientId() {
return recipientId; return recipientId;
} }
@ -169,14 +145,6 @@ public class Recipient implements Parcelable {
} }
} }
public synchronized void writeToParcel(Parcel dest, int flags) {
dest.writeString(number);
dest.writeString(name);
dest.writeLong(recipientId);
dest.writeParcelable(contactUri, 0);
dest.writeParcelable(contactPhoto, 0);
}
public synchronized String toShortString() { public synchronized String toShortString() {
return (name == null ? number : name); return (name == null ? number : name);
} }

View File

@ -23,6 +23,7 @@ import android.util.Log;
import org.thoughtcrime.securesms.contacts.ContactPhotoFactory; import org.thoughtcrime.securesms.contacts.ContactPhotoFactory;
import org.thoughtcrime.securesms.database.CanonicalAddressDatabase; import org.thoughtcrime.securesms.database.CanonicalAddressDatabase;
import java.util.Collections;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.StringTokenizer; import java.util.StringTokenizer;
@ -35,12 +36,12 @@ public class RecipientFactory {
if (TextUtils.isEmpty(recipientIds)) if (TextUtils.isEmpty(recipientIds))
return new Recipients(new LinkedList<Recipient>()); return new Recipients(new LinkedList<Recipient>());
List<Recipient> results = new LinkedList<Recipient>(); List<Recipient> results = new LinkedList<>();
StringTokenizer tokenizer = new StringTokenizer(recipientIds.trim(), " "); StringTokenizer tokenizer = new StringTokenizer(recipientIds.trim(), " ");
while (tokenizer.hasMoreTokens()) { while (tokenizer.hasMoreTokens()) {
String recipientId = tokenizer.nextToken(); String recipientId = tokenizer.nextToken();
Recipient recipient = getRecipientFromProviderId(context, recipientId, asynchronous); Recipient recipient = getRecipientFromProviderId(context, Long.parseLong(recipientId), asynchronous);
results.add(recipient); results.add(recipient);
} }
@ -48,6 +49,19 @@ public class RecipientFactory {
return new Recipients(results); return new Recipients(results);
} }
public static Recipient getRecipientForId(Context context, long recipientId, boolean asynchronous) {
return getRecipientFromProviderId(context, recipientId, asynchronous);
}
public static Recipients getRecipientsForIds(Context context, long[] recipientIds, boolean asynchronous) {
List<Recipient> results = new LinkedList<>();
if (recipientIds == null) return new Recipients(results);
for (long recipientId : recipientIds) {
results.add(getRecipientFromProviderId(context, recipientId, asynchronous));
}
return new Recipients(results);
}
private static Recipient getRecipientForNumber(Context context, String number, boolean asynchronous) { private static Recipient getRecipientForNumber(Context context, String number, boolean asynchronous) {
long recipientId = CanonicalAddressDatabase.getInstance(context).getCanonicalAddressId(number); long recipientId = CanonicalAddressDatabase.getInstance(context).getCanonicalAddressId(number);
return provider.getRecipient(context, recipientId, asynchronous); return provider.getRecipient(context, recipientId, asynchronous);
@ -72,9 +86,9 @@ public class RecipientFactory {
return new Recipients(results); return new Recipients(results);
} }
private static Recipient getRecipientFromProviderId(Context context, String recipientId, boolean asynchronous) { private static Recipient getRecipientFromProviderId(Context context, long recipientId, boolean asynchronous) {
try { try {
return provider.getRecipient(context, Long.parseLong(recipientId), asynchronous); return provider.getRecipient(context, recipientId, asynchronous);
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
Log.w("RecipientFactory", e); Log.w("RecipientFactory", e);
return Recipient.getUnknownRecipient(context); return Recipient.getUnknownRecipient(context);

View File

@ -16,8 +16,6 @@
*/ */
package org.thoughtcrime.securesms.recipients; package org.thoughtcrime.securesms.recipients;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.Patterns; import android.util.Patterns;
import org.thoughtcrime.securesms.recipients.Recipient.RecipientModifiedListener; import org.thoughtcrime.securesms.recipients.Recipient.RecipientModifiedListener;
@ -30,18 +28,7 @@ import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
public class Recipients implements Parcelable { public class Recipients {
public static final Parcelable.Creator<Recipients> CREATOR = new Parcelable.Creator<Recipients>() {
public Recipients createFromParcel(Parcel in) {
return new Recipients(in);
}
public Recipients[] newArray(int size) {
return new Recipients[size];
}
};
private List<Recipient> recipients; private List<Recipient> recipients;
@ -55,11 +42,6 @@ public class Recipients implements Parcelable {
}}; }};
} }
public Recipients(Parcel in) {
this.recipients = new ArrayList<Recipient>();
in.readTypedList(recipients, Recipient.CREATOR);
}
public void append(Recipients recipients) { public void append(Recipients recipients) {
this.recipients.addAll(recipients.getRecipientsList()); this.recipients.addAll(recipients.getRecipientsList());
} }
@ -138,14 +120,12 @@ public class Recipients implements Parcelable {
return this.recipients; return this.recipients;
} }
public String toIdString() { public long[] getIds() {
List<String> ids = new LinkedList<String>(); long[] ids = new long[recipients.size()];
for (int i=0; i<recipients.size(); i++) {
for (Recipient recipient : recipients) { ids[i] = recipients.get(i).getRecipientId();
ids.add(String.valueOf(recipient.getRecipientId()));
} }
return ids;
return Util.join(ids, " ");
} }
public String[] toNumberStringArray(boolean scrub) { public String[] toNumberStringArray(boolean scrub) {
@ -185,8 +165,4 @@ public class Recipients implements Parcelable {
public int describeContents() { public int describeContents() {
return 0; return 0;
} }
public void writeToParcel(Parcel dest, int flags) {
dest.writeTypedList(recipients);
}
} }