mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
simplify Recipient handling
This commit is contained in:
@@ -30,7 +30,6 @@ import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.database.Address;
|
||||
import org.thoughtcrime.securesms.database.model.ThreadRecord;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.recipients.RecipientProvider;
|
||||
import org.thoughtcrime.securesms.util.Hash;
|
||||
import org.thoughtcrime.securesms.util.Prefs;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
@@ -195,8 +194,7 @@ public class ApplicationDcContext extends DcContext {
|
||||
for (int contactId : contactIds) {
|
||||
participants.add(getRecipient(RECIPIENT_TYPE_CONTACT, contactId));
|
||||
}
|
||||
RecipientProvider.RecipientDetails recipientDetails = new RecipientProvider.RecipientDetails(chat.getName(), null, false, null, participants);
|
||||
Recipient recipient = new Recipient(Address.fromChat(chat.getId()), recipientDetails);
|
||||
Recipient recipient = new Recipient(Address.fromChat(chat.getId()), chat.getName(), participants);
|
||||
if (!chat.isGroup()) {
|
||||
String identifier = Hash.sha256(chat.getName() + chat.getSubtitle());
|
||||
Uri systemContactPhoto = Prefs.getSystemContactPhoto(context, identifier);
|
||||
@@ -210,8 +208,7 @@ public class ApplicationDcContext extends DcContext {
|
||||
@NonNull
|
||||
|
||||
public Recipient getRecipient(DcContact contact) {
|
||||
RecipientProvider.RecipientDetails recipientDetails = new RecipientProvider.RecipientDetails(contact.getDisplayName(), null, false, null, null);
|
||||
Recipient recipient = new Recipient(Address.fromContact(contact.getId()), recipientDetails);
|
||||
Recipient recipient = new Recipient(Address.fromContact(contact.getId()), contact.getDisplayName(), null);
|
||||
String identifier = Hash.sha256(contact.getName() + contact.getAddr());
|
||||
Uri systemContactPhoto = Prefs.getSystemContactPhoto(context, identifier);
|
||||
if (systemContactPhoto != null) {
|
||||
|
||||
@@ -1,133 +0,0 @@
|
||||
package org.thoughtcrime.securesms.database;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import org.thoughtcrime.securesms.util.guava.Optional;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class RecipientDatabase extends Database {
|
||||
|
||||
private static final String TAG = RecipientDatabase.class.getSimpleName();
|
||||
|
||||
public enum RegisteredState {
|
||||
UNKNOWN(0), REGISTERED(1), NOT_REGISTERED(2);
|
||||
|
||||
private final int id;
|
||||
|
||||
RegisteredState(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
public RecipientDatabase(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public Cursor getBlocked() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<Address> getRegistered() {
|
||||
List<Address> results = new LinkedList<>();
|
||||
return results;
|
||||
}
|
||||
|
||||
public static class RecipientSettings {
|
||||
private final boolean blocked;
|
||||
private final boolean seenInviteReminder;
|
||||
private final int defaultSubscriptionId;
|
||||
private final int expireMessages;
|
||||
private final RegisteredState registered;
|
||||
private final byte[] profileKey;
|
||||
private final String systemDisplayName;
|
||||
private final String systemContactPhoto;
|
||||
private final String systemPhoneLabel;
|
||||
private final String systemContactUri;
|
||||
private final String signalProfileName;
|
||||
private final String signalProfileAvatar;
|
||||
|
||||
RecipientSettings(boolean blocked, long muteUntil,
|
||||
boolean seenInviteReminder,
|
||||
int defaultSubscriptionId,
|
||||
int expireMessages,
|
||||
@NonNull RegisteredState registered,
|
||||
@Nullable byte[] profileKey,
|
||||
@Nullable String systemDisplayName,
|
||||
@Nullable String systemContactPhoto,
|
||||
@Nullable String systemPhoneLabel,
|
||||
@Nullable String systemContactUri,
|
||||
@Nullable String signalProfileName,
|
||||
@Nullable String signalProfileAvatar)
|
||||
{
|
||||
this.blocked = blocked;
|
||||
this.seenInviteReminder = seenInviteReminder;
|
||||
this.defaultSubscriptionId = defaultSubscriptionId;
|
||||
this.expireMessages = expireMessages;
|
||||
this.registered = registered;
|
||||
this.profileKey = profileKey;
|
||||
this.systemDisplayName = systemDisplayName;
|
||||
this.systemContactPhoto = systemContactPhoto;
|
||||
this.systemPhoneLabel = systemPhoneLabel;
|
||||
this.systemContactUri = systemContactUri;
|
||||
this.signalProfileName = signalProfileName;
|
||||
this.signalProfileAvatar = signalProfileAvatar;
|
||||
}
|
||||
|
||||
public boolean isBlocked() {
|
||||
return blocked;
|
||||
}
|
||||
|
||||
public boolean hasSeenInviteReminder() {
|
||||
return seenInviteReminder;
|
||||
}
|
||||
|
||||
public Optional<Integer> getDefaultSubscriptionId() {
|
||||
return defaultSubscriptionId != -1 ? Optional.of(defaultSubscriptionId) : Optional.absent();
|
||||
}
|
||||
|
||||
public int getExpireMessages() {
|
||||
return expireMessages;
|
||||
}
|
||||
|
||||
public RegisteredState getRegistered() {
|
||||
return registered;
|
||||
}
|
||||
|
||||
public byte[] getProfileKey() {
|
||||
return profileKey;
|
||||
}
|
||||
|
||||
public @Nullable String getSystemDisplayName() {
|
||||
return systemDisplayName;
|
||||
}
|
||||
|
||||
public @Nullable String getSystemContactPhotoUri() {
|
||||
return systemContactPhoto;
|
||||
}
|
||||
|
||||
public @Nullable String getSystemPhoneLabel() {
|
||||
return systemPhoneLabel;
|
||||
}
|
||||
|
||||
public @Nullable String getSystemContactUri() {
|
||||
return systemContactUri;
|
||||
}
|
||||
|
||||
public @Nullable String getProfileName() {
|
||||
return signalProfileName;
|
||||
}
|
||||
|
||||
public @Nullable String getProfileAvatar() {
|
||||
return signalProfileAvatar;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -36,12 +36,8 @@ import org.thoughtcrime.securesms.contacts.avatars.ProfileContactPhoto;
|
||||
import org.thoughtcrime.securesms.contacts.avatars.SystemContactPhoto;
|
||||
import org.thoughtcrime.securesms.contacts.avatars.TransparentContactPhoto;
|
||||
import org.thoughtcrime.securesms.database.Address;
|
||||
import org.thoughtcrime.securesms.database.RecipientDatabase.RegisteredState;
|
||||
import org.thoughtcrime.securesms.recipients.RecipientProvider.RecipientDetails;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.thoughtcrime.securesms.util.guava.Optional;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
@@ -51,8 +47,6 @@ import java.util.WeakHashMap;
|
||||
|
||||
public class Recipient implements RecipientModifiedListener {
|
||||
|
||||
private static final String TAG = Recipient.class.getSimpleName();
|
||||
|
||||
private final Set<RecipientModifiedListener> listeners = Collections.newSetFromMap(new WeakHashMap<RecipientModifiedListener, Boolean>());
|
||||
|
||||
private final @NonNull Address address;
|
||||
@@ -66,12 +60,7 @@ public class Recipient implements RecipientModifiedListener {
|
||||
private Uri contactUri;
|
||||
private @Nullable Uri messageRingtone = null;
|
||||
private boolean blocked = false;
|
||||
private int expireMessages = 0;
|
||||
private Optional<Integer> defaultSubscriptionId = Optional.absent();
|
||||
private @NonNull RegisteredState registered = RegisteredState.UNKNOWN;
|
||||
|
||||
private boolean seenInviteReminder;
|
||||
private @Nullable byte[] profileKey;
|
||||
private @Nullable String profileName;
|
||||
private @Nullable String profileAvatar;
|
||||
|
||||
@@ -106,21 +95,16 @@ public class Recipient implements RecipientModifiedListener {
|
||||
return dcContext.getRecipient(dcContext.getContact(0));
|
||||
}
|
||||
|
||||
public Recipient(@NonNull Address address, @NonNull RecipientDetails details) {
|
||||
public Recipient(@NonNull Address address, @Nullable String name, @Nullable List<Recipient> participants) {
|
||||
this.address = address;
|
||||
this.contactUri = details.contactUri;
|
||||
this.name = details.name;
|
||||
this.systemContactPhoto = details.systemContactPhoto;
|
||||
this.customLabel = details.customLabel;
|
||||
this.blocked = details.blocked;
|
||||
this.expireMessages = details.expireMessages;
|
||||
this.seenInviteReminder = details.seenInviteReminder;
|
||||
this.defaultSubscriptionId = details.defaultSubscriptionId;
|
||||
this.registered = details.registered;
|
||||
this.profileKey = details.profileKey;
|
||||
this.profileName = details.profileName;
|
||||
this.profileAvatar = details.profileAvatar;
|
||||
this.participants.addAll(details.participants);
|
||||
this.contactUri = null;
|
||||
this.name = name;
|
||||
this.systemContactPhoto = null;
|
||||
this.customLabel = null;
|
||||
this.blocked = false;
|
||||
this.profileName = null;
|
||||
this.profileAvatar = null;
|
||||
this.participants.addAll(participants==null? new LinkedList<>() : participants);
|
||||
this.resolving = false;
|
||||
}
|
||||
|
||||
@@ -179,10 +163,6 @@ public class Recipient implements RecipientModifiedListener {
|
||||
return address.isMmsGroup();
|
||||
}
|
||||
|
||||
public boolean isPushGroupRecipient() {
|
||||
return address.isGroup() && !address.isMmsGroup();
|
||||
}
|
||||
|
||||
public @NonNull synchronized List<Recipient> getParticipants() {
|
||||
return new LinkedList<>(participants);
|
||||
}
|
||||
@@ -284,26 +264,6 @@ public class Recipient implements RecipientModifiedListener {
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
public synchronized RegisteredState getRegistered() {
|
||||
if (isPushGroupRecipient()) return RegisteredState.REGISTERED;
|
||||
else if (isMmsGroupRecipient()) return RegisteredState.NOT_REGISTERED;
|
||||
|
||||
return registered;
|
||||
}
|
||||
|
||||
public void setRegistered(@NonNull RegisteredState value) {
|
||||
boolean notify = false;
|
||||
|
||||
synchronized (this) {
|
||||
if (this.registered != value) {
|
||||
this.registered = value;
|
||||
notify = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (notify) notifyListeners();
|
||||
}
|
||||
|
||||
public synchronized Recipient resolve() {
|
||||
while (resolving) Util.wait(this, 0);
|
||||
return this;
|
||||
@@ -348,11 +308,6 @@ public class Recipient implements RecipientModifiedListener {
|
||||
", systemContactPhoto=" + systemContactPhoto +
|
||||
", contactUri=" + contactUri +
|
||||
", blocked=" + blocked +
|
||||
", expireMessages=" + expireMessages +
|
||||
", defaultSubscriptionId=" + defaultSubscriptionId +
|
||||
", registered=" + registered +
|
||||
", seenInviteReminder=" + seenInviteReminder +
|
||||
", profileKey=" + Arrays.toString(profileKey) +
|
||||
", profileName='" + profileName + '\'' +
|
||||
", profileAvatar='" + profileAvatar + '\'' +
|
||||
'}';
|
||||
|
||||
@@ -1,76 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011 Whisper Systems
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.thoughtcrime.securesms.recipients;
|
||||
|
||||
import android.net.Uri;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import org.thoughtcrime.securesms.database.RecipientDatabase.RecipientSettings;
|
||||
import org.thoughtcrime.securesms.database.RecipientDatabase.RegisteredState;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.thoughtcrime.securesms.util.guava.Optional;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class RecipientProvider {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static final String TAG = RecipientProvider.class.getSimpleName();
|
||||
|
||||
public static class RecipientDetails {
|
||||
@Nullable final String name;
|
||||
@Nullable final String customLabel;
|
||||
@Nullable final Uri systemContactPhoto;
|
||||
@Nullable final Uri contactUri;
|
||||
@Nullable final Long groupAvatarId;
|
||||
final boolean blocked;
|
||||
final int expireMessages;
|
||||
@NonNull final List<Recipient> participants;
|
||||
@Nullable final String profileName;
|
||||
final boolean seenInviteReminder;
|
||||
final Optional<Integer> defaultSubscriptionId;
|
||||
@NonNull final RegisteredState registered;
|
||||
@Nullable final byte[] profileKey;
|
||||
@Nullable final String profileAvatar;
|
||||
final boolean systemContact;
|
||||
|
||||
public RecipientDetails(@Nullable String name, @Nullable Long groupAvatarId,
|
||||
boolean systemContact, @Nullable RecipientSettings settings,
|
||||
@Nullable List<Recipient> participants)
|
||||
{
|
||||
this.groupAvatarId = groupAvatarId;
|
||||
this.systemContactPhoto = settings != null ? Util.uri(settings.getSystemContactPhotoUri()) : null;
|
||||
this.customLabel = settings != null ? settings.getSystemPhoneLabel() : null;
|
||||
this.contactUri = settings != null ? Util.uri(settings.getSystemContactUri()) : null;
|
||||
this.blocked = settings != null && settings.isBlocked();
|
||||
this.expireMessages = settings != null ? settings.getExpireMessages() : 0;
|
||||
this.participants = participants == null ? new LinkedList<>() : participants;
|
||||
this.profileName = settings != null ? settings.getProfileName() : null;
|
||||
this.seenInviteReminder = settings != null && settings.hasSeenInviteReminder();
|
||||
this.defaultSubscriptionId = settings != null ? settings.getDefaultSubscriptionId() : Optional.absent();
|
||||
this.registered = settings != null ? settings.getRegistered() : RegisteredState.UNKNOWN;
|
||||
this.profileKey = settings != null ? settings.getProfileKey() : null;
|
||||
this.profileAvatar = settings != null ? settings.getProfileAvatar() : null;
|
||||
this.systemContact = systemContact;
|
||||
|
||||
if (name == null && settings != null) this.name = settings.getSystemDisplayName();
|
||||
else this.name = name;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user