mirror of
https://github.com/oxen-io/session-android.git
synced 2025-12-25 05:56:20 +00:00
Switch MMS groups to use the group database infrastructure
Eliminate the concept of 'Recipients' (plural). There is now just a 'Recipient', which contains an Address that is either an individual or a group ID. MMS groups now exist as part of the group database, just like push groups. // FREEBIE
This commit is contained in:
@@ -62,11 +62,9 @@ import org.thoughtcrime.securesms.groups.GroupManager.GroupActionResult;
|
||||
import org.thoughtcrime.securesms.mms.RoundedCorners;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.recipients.RecipientFactory;
|
||||
import org.thoughtcrime.securesms.recipients.Recipients;
|
||||
import org.thoughtcrime.securesms.util.BitmapUtil;
|
||||
import org.thoughtcrime.securesms.util.DynamicLanguage;
|
||||
import org.thoughtcrime.securesms.util.DynamicTheme;
|
||||
import org.thoughtcrime.securesms.util.GroupUtil;
|
||||
import org.thoughtcrime.securesms.util.SelectedRecipientsAdapter;
|
||||
import org.thoughtcrime.securesms.util.SelectedRecipientsAdapter.OnRecipientDeletedListener;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
@@ -76,7 +74,6 @@ import org.whispersystems.libsignal.util.guava.Optional;
|
||||
import org.whispersystems.signalservice.api.util.InvalidNumberException;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
@@ -214,17 +211,8 @@ public class GroupCreateActivity extends PassphraseRequiredActionBarActivity
|
||||
private void initializeExistingGroup() {
|
||||
final Address groupAddress = getIntent().getParcelableExtra(GROUP_ADDRESS_EXTRA);
|
||||
|
||||
byte[] groupId;
|
||||
|
||||
try {
|
||||
if (groupAddress != null) groupId = GroupUtil.getDecodedId(groupAddress.toGroupString());
|
||||
else groupId = null;
|
||||
} catch (IOException ioe) {
|
||||
Log.w(TAG, "Couldn't decode the encoded groupId passed in via intent", ioe);
|
||||
groupId = null;
|
||||
}
|
||||
if (groupId != null) {
|
||||
new FillExistingGroupInfoAsyncTask(this).execute(groupId);
|
||||
if (groupAddress != null) {
|
||||
new FillExistingGroupInfoAsyncTask(this).execute(groupAddress.toGroupString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -261,8 +249,8 @@ public class GroupCreateActivity extends PassphraseRequiredActionBarActivity
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRecipientsPanelUpdate(Recipients recipients) {
|
||||
if (recipients != null) addSelectedContacts(recipients.getRecipientsList());
|
||||
public void onRecipientsPanelUpdate(List<Recipient> recipients) {
|
||||
if (recipients != null && !recipients.isEmpty()) addSelectedContacts(recipients);
|
||||
}
|
||||
|
||||
private void handleGroupCreate() {
|
||||
@@ -274,7 +262,7 @@ public class GroupCreateActivity extends PassphraseRequiredActionBarActivity
|
||||
if (isSignalGroup()) {
|
||||
new CreateSignalGroupTask(this, masterSecret, avatarBmp, getGroupName(), getAdapter().getRecipients()).execute();
|
||||
} else {
|
||||
new CreateMmsGroupTask(this, getAdapter().getRecipients()).execute();
|
||||
new CreateMmsGroupTask(this, masterSecret, getAdapter().getRecipients()).execute();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -283,11 +271,11 @@ public class GroupCreateActivity extends PassphraseRequiredActionBarActivity
|
||||
getGroupName(), getAdapter().getRecipients()).execute();
|
||||
}
|
||||
|
||||
private void handleOpenConversation(long threadId, Recipients recipients) {
|
||||
private void handleOpenConversation(long threadId, Recipient recipient) {
|
||||
Intent intent = new Intent(this, ConversationActivity.class);
|
||||
intent.putExtra(ConversationActivity.THREAD_ID_EXTRA, threadId);
|
||||
intent.putExtra(ConversationActivity.DISTRIBUTION_TYPE_EXTRA, ThreadDatabase.DistributionTypes.DEFAULT);
|
||||
intent.putExtra(ConversationActivity.ADDRESSES_EXTRA, recipients.getAddresses());
|
||||
intent.putExtra(ConversationActivity.ADDRESS_EXTRA, recipient.getAddress());
|
||||
startActivity(intent);
|
||||
finish();
|
||||
}
|
||||
@@ -347,31 +335,35 @@ public class GroupCreateActivity extends PassphraseRequiredActionBarActivity
|
||||
}
|
||||
}
|
||||
|
||||
private static class CreateMmsGroupTask extends AsyncTask<Void,Void,Long> {
|
||||
private GroupCreateActivity activity;
|
||||
private Set<Recipient> members;
|
||||
private static class CreateMmsGroupTask extends AsyncTask<Void,Void,GroupActionResult> {
|
||||
private final GroupCreateActivity activity;
|
||||
private final MasterSecret masterSecret;
|
||||
private final Set<Recipient> members;
|
||||
|
||||
public CreateMmsGroupTask(GroupCreateActivity activity, Set<Recipient> members) {
|
||||
this.activity = activity;
|
||||
this.members = members;
|
||||
public CreateMmsGroupTask(GroupCreateActivity activity, MasterSecret masterSecret, Set<Recipient> members) {
|
||||
this.activity = activity;
|
||||
this.masterSecret = masterSecret;
|
||||
this.members = members;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Long doInBackground(Void... avoid) {
|
||||
Recipients recipients = RecipientFactory.getRecipientsFor(activity, members, false);
|
||||
return DatabaseFactory.getThreadDatabase(activity)
|
||||
.getThreadIdFor(recipients, ThreadDatabase.DistributionTypes.CONVERSATION);
|
||||
}
|
||||
protected GroupActionResult doInBackground(Void... avoid) {
|
||||
List<Address> memberAddresses = new LinkedList<>();
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Long resultThread) {
|
||||
if (resultThread > -1) {
|
||||
activity.handleOpenConversation(resultThread,
|
||||
RecipientFactory.getRecipientsFor(activity, members, true));
|
||||
} else {
|
||||
Toast.makeText(activity, R.string.GroupCreateActivity_contacts_mms_exception, Toast.LENGTH_LONG).show();
|
||||
activity.finish();
|
||||
for (Recipient recipient : members) {
|
||||
memberAddresses.add(recipient.getAddress());
|
||||
}
|
||||
|
||||
String groupId = DatabaseFactory.getGroupDatabase(activity).getOrCreateGroupForMembers(memberAddresses, true);
|
||||
Recipient groupRecipient = RecipientFactory.getRecipientFor(activity, Address.fromSerialized(groupId), true);
|
||||
long threadId = DatabaseFactory.getThreadDatabase(activity).getThreadIdFor(groupRecipient, ThreadDatabase.DistributionTypes.DEFAULT);
|
||||
|
||||
return new GroupActionResult(groupRecipient, threadId);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(GroupActionResult result) {
|
||||
activity.handleOpenConversation(result.getThreadId(), result.getGroupRecipient());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -427,11 +419,7 @@ public class GroupCreateActivity extends PassphraseRequiredActionBarActivity
|
||||
|
||||
@Override
|
||||
protected Optional<GroupActionResult> doInBackground(Void... aVoid) {
|
||||
try {
|
||||
return Optional.of(GroupManager.createGroup(activity, masterSecret, members, avatar, name));
|
||||
} catch (InvalidNumberException e) {
|
||||
return Optional.absent();
|
||||
}
|
||||
return Optional.of(GroupManager.createGroup(activity, masterSecret, members, avatar, name, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -449,10 +437,10 @@ public class GroupCreateActivity extends PassphraseRequiredActionBarActivity
|
||||
}
|
||||
|
||||
private static class UpdateSignalGroupTask extends SignalGroupTask {
|
||||
private byte[] groupId;
|
||||
private String groupId;
|
||||
|
||||
public UpdateSignalGroupTask(GroupCreateActivity activity,
|
||||
MasterSecret masterSecret, byte[] groupId, Bitmap avatar, String name,
|
||||
MasterSecret masterSecret, String groupId, Bitmap avatar, String name,
|
||||
Set<Recipient> members)
|
||||
{
|
||||
super(activity, masterSecret, avatar, name, members);
|
||||
@@ -474,7 +462,7 @@ public class GroupCreateActivity extends PassphraseRequiredActionBarActivity
|
||||
if (!activity.isFinishing()) {
|
||||
Intent intent = activity.getIntent();
|
||||
intent.putExtra(GROUP_THREAD_EXTRA, result.get().getThreadId());
|
||||
intent.putExtra(GROUP_ADDRESS_EXTRA, result.get().getGroupRecipient().getPrimaryRecipient().getAddress());
|
||||
intent.putExtra(GROUP_ADDRESS_EXTRA, result.get().getGroupRecipient().getAddress());
|
||||
activity.setResult(RESULT_OK, intent);
|
||||
activity.finish();
|
||||
}
|
||||
@@ -541,7 +529,7 @@ public class GroupCreateActivity extends PassphraseRequiredActionBarActivity
|
||||
}
|
||||
}
|
||||
|
||||
private static class FillExistingGroupInfoAsyncTask extends ProgressDialogAsyncTask<byte[],Void,Optional<GroupData>> {
|
||||
private static class FillExistingGroupInfoAsyncTask extends ProgressDialogAsyncTask<String,Void,Optional<GroupData>> {
|
||||
private GroupCreateActivity activity;
|
||||
|
||||
public FillExistingGroupInfoAsyncTask(GroupCreateActivity activity) {
|
||||
@@ -552,12 +540,12 @@ public class GroupCreateActivity extends PassphraseRequiredActionBarActivity
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<GroupData> doInBackground(byte[]... groupIds) {
|
||||
protected Optional<GroupData> doInBackground(String... groupIds) {
|
||||
final GroupDatabase db = DatabaseFactory.getGroupDatabase(activity);
|
||||
final Recipients recipients = db.getGroupMembers(groupIds[0], false);
|
||||
final List<Recipient> recipients = db.getGroupMembers(groupIds[0], false);
|
||||
final GroupRecord group = db.getGroup(groupIds[0]);
|
||||
final Set<Recipient> existingContacts = new HashSet<>(recipients.getRecipientsList().size());
|
||||
existingContacts.addAll(recipients.getRecipientsList());
|
||||
final Set<Recipient> existingContacts = new HashSet<>(recipients.size());
|
||||
existingContacts.addAll(recipients);
|
||||
|
||||
if (group != null) {
|
||||
return Optional.of(new GroupData(groupIds[0],
|
||||
@@ -600,13 +588,13 @@ public class GroupCreateActivity extends PassphraseRequiredActionBarActivity
|
||||
}
|
||||
|
||||
private static class GroupData {
|
||||
byte[] id;
|
||||
String id;
|
||||
Set<Recipient> recipients;
|
||||
Bitmap avatarBmp;
|
||||
byte[] avatarBytes;
|
||||
String name;
|
||||
|
||||
public GroupData(byte[] id, Set<Recipient> recipients, Bitmap avatarBmp, byte[] avatarBytes, String name) {
|
||||
public GroupData(String id, Set<Recipient> recipients, Bitmap avatarBmp, byte[] avatarBytes, String name) {
|
||||
this.id = id;
|
||||
this.recipients = recipients;
|
||||
this.avatarBmp = avatarBmp;
|
||||
|
||||
Reference in New Issue
Block a user