Fix crash on displaying unknown contact header

Fixes #6924

// FREEBIE
This commit is contained in:
Moxie Marlinspike 2017-09-06 15:49:10 -07:00
parent bdb67725c5
commit e172b84603
5 changed files with 20 additions and 11 deletions

View File

@ -317,9 +317,9 @@ public class ConversationAdapter <V extends View & BindableConversationItem>
if (lastSeen <= 0) return -1;
if (!isActiveCursor()) return -1;
int count = getItemCount() - (hasHeaderView() ? 1 : 0) - (hasFooterView() ? 1 : 0);
int count = getItemCount() - (hasFooterView() ? 1 : 0);
for (int i=0;i<count;i++) {
for (int i=(hasHeaderView() ? 1 : 0);i<count;i++) {
MessageRecord messageRecord = getRecordForPositionOrThrow(i);
if (messageRecord.isOutgoing() || messageRecord.getDateReceived() <= lastSeen) {

View File

@ -431,7 +431,7 @@ public class ConversationFragment extends Fragment
setLastSeen(loader.getLastSeen());
}
if (!loader.hasSent() && !recipient.isSystemContact() && !recipient.isGroupRecipient() && recipient.getRegistered() != RecipientDatabase.RegisteredState.REGISTERED) {
if (!loader.hasSent() && !recipient.isSystemContact() && !recipient.isGroupRecipient() && recipient.getRegistered() == RecipientDatabase.RegisteredState.REGISTERED) {
getListAdapter().setHeaderView(unknownSenderView);
} else {
getListAdapter().setHeaderView(null);

View File

@ -69,6 +69,7 @@ public class DatabaseUpgradeActivity extends BaseActivity {
public static final int MEDIA_DOWNLOAD_CONTROLS_VERSION = 151;
public static final int REDPHONE_SUPPORT_VERSION = 157;
public static final int NO_MORE_CANONICAL_DB_VERSION = 276;
public static final int PROFILES = 289;
private static final SortedSet<Integer> UPGRADE_VERSIONS = new TreeSet<Integer>() {{
add(NO_MORE_KEY_EXCHANGE_PREFIX_VERSION);
@ -233,6 +234,12 @@ public class DatabaseUpgradeActivity extends BaseActivity {
.add(new DirectoryRefreshJob(getApplicationContext()));
}
if (params[0] < PROFILES) {
ApplicationContext.getInstance(getApplicationContext())
.getJobManager()
.add(new DirectoryRefreshJob(getApplicationContext()));
}
return null;
}

View File

@ -9,6 +9,7 @@ import android.support.annotation.NonNull;
import android.support.v7.app.AlertDialog;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import org.thoughtcrime.securesms.R;
@ -27,6 +28,7 @@ public class UnknownSenderView extends FrameLayout {
this.threadId = threadId;
inflate(context, R.layout.unknown_sender_view, this);
setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
View block = ViewUtil.findById(this, R.id.block);
View add = ViewUtil.findById(this, R.id.add_to_contacts);

View File

@ -67,7 +67,7 @@ class RecipientProvider {
private static final Map<String, RecipientDetails> STATIC_DETAILS = new HashMap<String, RecipientDetails>() {{
put("262966", new RecipientDetails("Amazon", null, null,
ContactPhotoFactory.getResourceContactPhoto(R.drawable.ic_amazon),
null, null));
false, null, null));
}};
@NonNull Recipient getRecipient(Context context, Address address, Optional<RecipientSettings> settings, Optional<GroupRecord> groupRecord, boolean asynchronous) {
@ -100,7 +100,7 @@ class RecipientProvider {
if (address.isGroup() && settings.isPresent() && groupRecord.isPresent()) {
return Optional.of(getGroupRecipientDetails(context, address, groupRecord, settings, true));
} else if (!address.isGroup() && settings.isPresent()) {
return Optional.of(new RecipientDetails(null, null, null, ContactPhotoFactory.getLoadingPhoto(), settings.get(), null));
return Optional.of(new RecipientDetails(null, null, null, ContactPhotoFactory.getLoadingPhoto(), !TextUtils.isEmpty(settings.get().getSystemDisplayName()), settings.get(), null));
}
return Optional.absent();
@ -145,7 +145,7 @@ class RecipientProvider {
address,
name);
return new RecipientDetails(cursor.getString(0), cursor.getString(4), contactUri, contactPhoto, settings.orNull(), null);
return new RecipientDetails(cursor.getString(0), cursor.getString(4), contactUri, contactPhoto, true, settings.orNull(), null);
} else {
Log.w(TAG, "resultNumber is null");
}
@ -157,7 +157,7 @@ class RecipientProvider {
}
if (STATIC_DETAILS.containsKey(address.serialize())) return STATIC_DETAILS.get(address.serialize());
else return new RecipientDetails(null, null, null, ContactPhotoFactory.getSignalAvatarContactPhoto(context, address, null, context.getResources().getDimensionPixelSize(R.dimen.contact_photo_target_size)), settings.orNull(), null);
else return new RecipientDetails(null, null, null, ContactPhotoFactory.getSignalAvatarContactPhoto(context, address, null, context.getResources().getDimensionPixelSize(R.dimen.contact_photo_target_size)), false, settings.orNull(), null);
}
private @NonNull RecipientDetails getGroupRecipientDetails(Context context, Address groupId, Optional<GroupRecord> groupRecord, Optional<RecipientSettings> settings, boolean asynchronous) {
@ -183,10 +183,10 @@ class RecipientProvider {
title = context.getString(R.string.RecipientProvider_unnamed_group);;
}
return new RecipientDetails(title, null, null, contactPhoto, settings.orNull(), members);
return new RecipientDetails(title, null, null, contactPhoto, false, settings.orNull(), members);
}
return new RecipientDetails(context.getString(R.string.RecipientProvider_unnamed_group), null, null, ContactPhotoFactory.getDefaultGroupPhoto(), settings.orNull(), null);
return new RecipientDetails(context.getString(R.string.RecipientProvider_unnamed_group), null, null, ContactPhotoFactory.getDefaultGroupPhoto(), false, settings.orNull(), null);
}
static class RecipientDetails {
@ -212,7 +212,7 @@ class RecipientProvider {
public RecipientDetails(@Nullable String name, @Nullable String customLabel,
@Nullable Uri contactUri, @NonNull ContactPhoto avatar,
@Nullable RecipientSettings settings,
boolean systemContact, @Nullable RecipientSettings settings,
@Nullable List<Recipient> participants)
{
this.customLabel = customLabel;
@ -232,7 +232,7 @@ class RecipientProvider {
this.profileKey = settings != null ? settings.getProfileKey() : null;
this.profileAvatar = settings != null ? settings.getProfileAvatar() : null;
this.profileSharing = settings != null && settings.isProfileSharing();
this.systemContact = settings != null && !TextUtils.isEmpty(settings.getSystemDisplayName());
this.systemContact = systemContact;
if (name == null && settings != null) this.name = settings.getSystemDisplayName();
else this.name = name;