mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
do not load participant list without need
This commit is contained in:
@@ -501,7 +501,7 @@ public class GroupCreateActivity extends PassphraseRequiredActionBarActivity
|
||||
}
|
||||
|
||||
private void fillExistingGroup(Recipient recipient) {
|
||||
List<Recipient> participants = recipient.getParticipants();
|
||||
List<Recipient> participants = recipient.loadParticipants(this);
|
||||
Recipient[] participantsArray = new Recipient[participants.size()];
|
||||
participantsArray = participants.toArray(participantsArray);
|
||||
if (!isFinishing()) {
|
||||
|
||||
@@ -232,12 +232,7 @@ public class ApplicationDcContext extends DcContext {
|
||||
|
||||
@NonNull
|
||||
public Recipient getRecipient(DcChat chat) {
|
||||
int[] contactIds = getChatContacts(chat.getId());
|
||||
List<Recipient> participants = new ArrayList<>();
|
||||
for (int contactId : contactIds) {
|
||||
participants.add(getRecipient(RECIPIENT_TYPE_CONTACT, contactId));
|
||||
}
|
||||
Recipient recipient = new Recipient(Address.fromChat(chat.getId()), chat.getName(), participants);
|
||||
Recipient recipient = new Recipient(Address.fromChat(chat.getId()), chat.getName(), chat, null);
|
||||
if (!chat.isGroup()) {
|
||||
String identifier = Hash.sha256(chat.getName() + chat.getSubtitle());
|
||||
Uri systemContactPhoto = Prefs.getSystemContactPhoto(context, identifier);
|
||||
@@ -251,7 +246,7 @@ public class ApplicationDcContext extends DcContext {
|
||||
@NonNull
|
||||
|
||||
public Recipient getRecipient(DcContact contact) {
|
||||
Recipient recipient = new Recipient(Address.fromContact(contact.getId()), contact.getDisplayName(), null);
|
||||
Recipient recipient = new Recipient(Address.fromContact(contact.getId()), contact.getDisplayName(), null, contact);
|
||||
String identifier = Hash.sha256(contact.getName() + contact.getAddr());
|
||||
Uri systemContactPhoto = Prefs.getSystemContactPhoto(context, identifier);
|
||||
if (systemContactPhoto != null) {
|
||||
|
||||
@@ -52,10 +52,6 @@ public class Address implements Parcelable, Comparable<Address> {
|
||||
return GroupUtil.isEncodedGroup(address);
|
||||
}
|
||||
|
||||
public boolean isMmsGroup() {
|
||||
return GroupUtil.isMmsGroup(address);
|
||||
}
|
||||
|
||||
public boolean isEmail() {
|
||||
return NumberUtil.isValidEmail(address);
|
||||
}
|
||||
|
||||
@@ -25,6 +25,9 @@ import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.b44t.messenger.DcChat;
|
||||
import com.b44t.messenger.DcContact;
|
||||
|
||||
import org.thoughtcrime.securesms.connect.ApplicationDcContext;
|
||||
import org.thoughtcrime.securesms.connect.DcHelper;
|
||||
import org.thoughtcrime.securesms.contacts.avatars.ContactPhoto;
|
||||
@@ -38,6 +41,7 @@ import org.thoughtcrime.securesms.contacts.avatars.TransparentContactPhoto;
|
||||
import org.thoughtcrime.securesms.database.Address;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
@@ -50,11 +54,10 @@ public class Recipient implements RecipientModifiedListener {
|
||||
private final Set<RecipientModifiedListener> listeners = Collections.newSetFromMap(new WeakHashMap<RecipientModifiedListener, Boolean>());
|
||||
|
||||
private final @NonNull Address address;
|
||||
private final @NonNull List<Recipient> participants = new LinkedList<>();
|
||||
|
||||
private @Nullable String name;
|
||||
private @Nullable String customLabel;
|
||||
private boolean resolving;
|
||||
private final boolean resolving;
|
||||
|
||||
private @Nullable Uri systemContactPhoto;
|
||||
private Uri contactUri;
|
||||
@@ -64,6 +67,10 @@ public class Recipient implements RecipientModifiedListener {
|
||||
private @Nullable String profileName;
|
||||
private @Nullable String profileAvatar;
|
||||
|
||||
// either dcChat or dcContact are set
|
||||
private @Nullable DcChat dcChat;
|
||||
private @Nullable DcContact dcContact;
|
||||
|
||||
public static @NonNull Recipient fromChat(@NonNull Context context, int dcMsgId) {
|
||||
ApplicationDcContext dcContext = DcHelper.getContext(context);
|
||||
return fromChat(dcContext, dcMsgId);
|
||||
@@ -95,7 +102,9 @@ public class Recipient implements RecipientModifiedListener {
|
||||
return dcContext.getRecipient(dcContext.getContact(0));
|
||||
}
|
||||
|
||||
public Recipient(@NonNull Address address, @Nullable String name, @Nullable List<Recipient> participants) {
|
||||
public Recipient(@NonNull Address address, @Nullable String name, @Nullable DcChat dcChat, @Nullable DcContact dcContact) {
|
||||
this.dcChat = dcChat;
|
||||
this.dcContact = dcContact;
|
||||
this.address = address;
|
||||
this.contactUri = null;
|
||||
this.name = name;
|
||||
@@ -104,7 +113,6 @@ public class Recipient implements RecipientModifiedListener {
|
||||
this.blocked = false;
|
||||
this.profileName = null;
|
||||
this.profileAvatar = null;
|
||||
this.participants.addAll(participants==null? new LinkedList<>() : participants);
|
||||
this.resolving = false;
|
||||
}
|
||||
|
||||
@@ -113,16 +121,6 @@ public class Recipient implements RecipientModifiedListener {
|
||||
}
|
||||
|
||||
public synchronized @Nullable String getName() {
|
||||
if (this.name == null && isMmsGroupRecipient()) {
|
||||
List<String> names = new LinkedList<>();
|
||||
|
||||
for (Recipient recipient : participants) {
|
||||
names.add(recipient.toShortString());
|
||||
}
|
||||
|
||||
return Util.join(names, ", ");
|
||||
}
|
||||
|
||||
return this.name;
|
||||
}
|
||||
|
||||
@@ -156,30 +154,27 @@ public class Recipient implements RecipientModifiedListener {
|
||||
}
|
||||
|
||||
public boolean isGroupRecipient() {
|
||||
return participants.size() > 1;
|
||||
return dcChat!=null && dcChat.isGroup();
|
||||
}
|
||||
|
||||
public boolean isMmsGroupRecipient() {
|
||||
return address.isMmsGroup();
|
||||
}
|
||||
|
||||
public @NonNull synchronized List<Recipient> getParticipants() {
|
||||
return new LinkedList<>(participants);
|
||||
public @NonNull synchronized List<Recipient> loadParticipants(Context context) {
|
||||
List<Recipient> participants = new ArrayList<>();
|
||||
if (dcChat!=null) {
|
||||
ApplicationDcContext dcContext = DcHelper.getContext(context);
|
||||
int[] contactIds = dcContext.getChatContacts(dcChat.getId());
|
||||
for (int contactId : contactIds) {
|
||||
participants.add(dcContext.getRecipient(ApplicationDcContext.RECIPIENT_TYPE_CONTACT, contactId));
|
||||
}
|
||||
}
|
||||
return participants;
|
||||
}
|
||||
|
||||
public synchronized void addListener(RecipientModifiedListener listener) {
|
||||
if (listeners.isEmpty()) {
|
||||
for (Recipient recipient : participants) recipient.addListener(this);
|
||||
}
|
||||
listeners.add(listener);
|
||||
// TODO: better use DC_EVENT_*
|
||||
}
|
||||
|
||||
public synchronized void removeListener(RecipientModifiedListener listener) {
|
||||
listeners.remove(listener);
|
||||
|
||||
if (listeners.isEmpty()) {
|
||||
for (Recipient recipient : participants) recipient.removeListener(this);
|
||||
}
|
||||
// TODO: better use DC_EVENT_*
|
||||
}
|
||||
|
||||
public synchronized String toShortString() {
|
||||
@@ -188,11 +183,11 @@ public class Recipient implements RecipientModifiedListener {
|
||||
|
||||
public int getFallbackAvatarColor(Context context) {
|
||||
int rgb = 0x00808080;
|
||||
if(address.isDcContact()) {
|
||||
rgb = DcHelper.getContext(context).getContact(address.getDcContactId()).getColor();
|
||||
if(dcContact!=null) {
|
||||
rgb = dcContact.getColor();
|
||||
}
|
||||
else if(address.isDcChat()){
|
||||
rgb = DcHelper.getContext(context).getChat(address.getDcChatId()).getColor();
|
||||
else if(dcChat!=null){
|
||||
rgb = dcChat.getColor();
|
||||
}
|
||||
int argb = Color.argb(0xFF, Color.red(rgb), Color.green(rgb), Color.blue(rgb));
|
||||
return argb;
|
||||
@@ -301,7 +296,6 @@ public class Recipient implements RecipientModifiedListener {
|
||||
return "Recipient{" +
|
||||
"listeners=" + listeners +
|
||||
", address=" + address +
|
||||
", participants=" + participants +
|
||||
", name='" + name + '\'' +
|
||||
", customLabel='" + customLabel + '\'' +
|
||||
", resolving=" + resolving +
|
||||
|
||||
@@ -10,23 +10,8 @@ public class GroupUtil {
|
||||
private static final String ENCODED_MMS_GROUP_PREFIX = "__signal_mms_group__!";
|
||||
private static final String TAG = GroupUtil.class.getSimpleName();
|
||||
|
||||
public static String getEncodedId(byte[] groupId, boolean mms) {
|
||||
return (mms ? ENCODED_MMS_GROUP_PREFIX : ENCODED_SIGNAL_GROUP_PREFIX) + Hex.toStringCondensed(groupId);
|
||||
}
|
||||
|
||||
public static byte[] getDecodedId(String groupId) throws IOException {
|
||||
if (!isEncodedGroup(groupId)) {
|
||||
throw new IOException("Invalid encoding");
|
||||
}
|
||||
|
||||
return Hex.fromStringCondensed(groupId.split("!", 2)[1]);
|
||||
}
|
||||
|
||||
public static boolean isEncodedGroup(@NonNull String groupId) {
|
||||
return groupId.startsWith(ENCODED_SIGNAL_GROUP_PREFIX) || groupId.startsWith(ENCODED_MMS_GROUP_PREFIX);
|
||||
}
|
||||
|
||||
public static boolean isMmsGroup(@NonNull String groupId) {
|
||||
return groupId.startsWith(ENCODED_MMS_GROUP_PREFIX);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user