From fbefdcf1272410634ec4901f57d1b18186889e9e Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Fri, 14 Dec 2018 23:38:54 +0100 Subject: [PATCH] simplify ThreadRecord --- .../securesms/ConversationListFragment.java | 2 +- .../securesms/ConversationListItem.java | 6 -- .../connect/ApplicationDcContext.java | 12 +-- .../securesms/database/MmsSmsColumns.java | 65 ------------ .../database/model/DisplayRecord.java | 98 ------------------- .../database/model/ThreadRecord.java | 61 +++++++----- 6 files changed, 38 insertions(+), 206 deletions(-) delete mode 100644 src/org/thoughtcrime/securesms/database/MmsSmsColumns.java delete mode 100644 src/org/thoughtcrime/securesms/database/model/DisplayRecord.java diff --git a/src/org/thoughtcrime/securesms/ConversationListFragment.java b/src/org/thoughtcrime/securesms/ConversationListFragment.java index a8a63e129..b2c8cb8e0 100644 --- a/src/org/thoughtcrime/securesms/ConversationListFragment.java +++ b/src/org/thoughtcrime/securesms/ConversationListFragment.java @@ -379,7 +379,7 @@ public class ConversationListFragment extends Fragment return; } - handleCreateConversation(threadId, item.getLastSeen()); + handleCreateConversation(threadId, 0); } else { ConversationListAdapter adapter = (ConversationListAdapter)list.getAdapter(); adapter.toggleThreadInBatchSet(item.getThreadId()); diff --git a/src/org/thoughtcrime/securesms/ConversationListItem.java b/src/org/thoughtcrime/securesms/ConversationListItem.java index 69a7f4b48..e65676304 100644 --- a/src/org/thoughtcrime/securesms/ConversationListItem.java +++ b/src/org/thoughtcrime/securesms/ConversationListItem.java @@ -81,7 +81,6 @@ public class ConversationListItem extends RelativeLayout private DeliveryStatusView deliveryStatusIndicator; private ImageView unreadIndicator; private ImageView groupIndicator; - private long lastSeen; private int unreadCount; private AvatarImageView contactPhotoImage; @@ -138,7 +137,6 @@ public class ConversationListItem extends RelativeLayout this.msgId = msgId; this.glideRequests = glideRequests; this.unreadCount = thread.getUnreadCount(); - this.lastSeen = thread.getLastSeen(); if (highlightSubstring != null) { this.fromView.setText(getHighlightedSpan(locale, recipient.getName(), highlightSubstring)); @@ -245,10 +243,6 @@ public class ConversationListItem extends RelativeLayout return dcContext.getMsg(msgId).getFromId(); } - public long getLastSeen() { - return lastSeen; - } - private void setStatusIcons(ThreadRecord thread) { if (thread.isArchived()) { diff --git a/src/org/thoughtcrime/securesms/connect/ApplicationDcContext.java b/src/org/thoughtcrime/securesms/connect/ApplicationDcContext.java index 908b2341c..1e904e47c 100644 --- a/src/org/thoughtcrime/securesms/connect/ApplicationDcContext.java +++ b/src/org/thoughtcrime/securesms/connect/ApplicationDcContext.java @@ -232,7 +232,6 @@ public class ApplicationDcContext extends DcContext { @NonNull public ThreadRecord getThreadRecord(DcLot summary, DcChat chat) { // adapted from ThreadDatabase.getCurrent() int chatId = chat.getId(); - int distributionType = chatId == DcChat.DC_CHAT_ID_ARCHIVED_LINK ? ThreadRecord.DistributionTypes.ARCHIVE : ThreadRecord.DistributionTypes.CONVERSATION; String body = summary.getText1(); if (!body.isEmpty()) { @@ -242,18 +241,13 @@ public class ApplicationDcContext extends DcContext { Recipient recipient = getRecipient(chat); long date = summary.getTimestamp(); - long count = 1; int unreadCount = getFreshMsgCount(chatId); - long type = 0;//cursor.getLong(cursor.getColumnIndexOrThrow(ThreadDatabase.SNIPPET_TYPE)); boolean archived = chat.getArchived() != 0; - int status = 0; - long expiresIn = 0; - long lastSeen = 0; boolean verified = chat.isVerified(); - return new ThreadRecord(context, body, null, recipient, date, count, - unreadCount, chatId, 0, status, type, - distributionType, archived, expiresIn, lastSeen, 0, verified, summary); + return new ThreadRecord(context, body, recipient, date, + unreadCount, chatId, + archived, verified, summary); } diff --git a/src/org/thoughtcrime/securesms/database/MmsSmsColumns.java b/src/org/thoughtcrime/securesms/database/MmsSmsColumns.java deleted file mode 100644 index 7c71010d2..000000000 --- a/src/org/thoughtcrime/securesms/database/MmsSmsColumns.java +++ /dev/null @@ -1,65 +0,0 @@ -package org.thoughtcrime.securesms.database; - -@SuppressWarnings("UnnecessaryInterfaceModifier") -public interface MmsSmsColumns { - - public static final String ID = "_id"; - public static final String READ = "read"; - public static final String BODY = "body"; - - public static class Types { - // Base Types - protected static final long BASE_TYPE_MASK = 0x1F; - - protected static final long OUTGOING_CALL_TYPE = 2; - - protected static final long BASE_OUTBOX_TYPE = 21; - protected static final long BASE_SENDING_TYPE = 22; - protected static final long BASE_SENT_TYPE = 23; - protected static final long BASE_SENT_FAILED_TYPE = 24; - protected static final long BASE_PENDING_SECURE_SMS_FALLBACK = 25; - protected static final long BASE_PENDING_INSECURE_SMS_FALLBACK = 26; - - protected static final long[] OUTGOING_MESSAGE_TYPES = {BASE_OUTBOX_TYPE, BASE_SENT_TYPE, - BASE_SENDING_TYPE, BASE_SENT_FAILED_TYPE, - BASE_PENDING_SECURE_SMS_FALLBACK, - BASE_PENDING_INSECURE_SMS_FALLBACK, - OUTGOING_CALL_TYPE}; - - // Key Exchange Information - protected static final long KEY_EXCHANGE_IDENTITY_VERIFIED_BIT = 0x4000; - protected static final long KEY_EXCHANGE_IDENTITY_DEFAULT_BIT = 0x2000; - - public static boolean isFailedMessageType(long type) { - return (type & BASE_TYPE_MASK) == BASE_SENT_FAILED_TYPE; - } - - public static boolean isOutgoingMessageType(long type) { - for (long outgoingType : OUTGOING_MESSAGE_TYPES) { - if ((type & BASE_TYPE_MASK) == outgoingType) - return true; - } - - return false; - } - - public static boolean isPendingMessageType(long type) { - return - (type & BASE_TYPE_MASK) == BASE_OUTBOX_TYPE || - (type & BASE_TYPE_MASK) == BASE_SENDING_TYPE; - } - - public static boolean isPendingSecureSmsFallbackType(long type) { - return (type & BASE_TYPE_MASK) == BASE_PENDING_SECURE_SMS_FALLBACK; - } - - public static boolean isIdentityVerified(long type) { - return (type & KEY_EXCHANGE_IDENTITY_VERIFIED_BIT) != 0; - } - - public static boolean isIdentityDefault(long type) { - return (type & KEY_EXCHANGE_IDENTITY_DEFAULT_BIT) != 0; - } - - } -} diff --git a/src/org/thoughtcrime/securesms/database/model/DisplayRecord.java b/src/org/thoughtcrime/securesms/database/model/DisplayRecord.java deleted file mode 100644 index b250268ae..000000000 --- a/src/org/thoughtcrime/securesms/database/model/DisplayRecord.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright (C) 2012 Moxie Marlinspike - * - * 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 . - */ -package org.thoughtcrime.securesms.database.model; - -import android.content.Context; -import android.support.annotation.NonNull; -import android.text.SpannableString; - -import org.thoughtcrime.securesms.database.MmsSmsColumns; -import org.thoughtcrime.securesms.recipients.Recipient; - -/** - * The base class for all message record models. Encapsulates basic data - * shared between ThreadRecord and MessageRecord. - * - * @author Moxie Marlinspike - * - */ - -public abstract class DisplayRecord { - - protected final Context context; - protected final long type; - - private final Recipient recipient; - private final long dateReceived; - private final long threadId; - private final String body; - - DisplayRecord(Context context, String body, Recipient recipient, long dateSent, - long dateReceived, long threadId, int deliveryStatus, int deliveryReceiptCount, - long type) - { - this.context = context.getApplicationContext(); - this.threadId = threadId; - this.recipient = recipient; - this.dateReceived = dateReceived; - this.type = type; - this.body = body; - } - - public @NonNull String getBody() { - return body == null ? "" : body; - } - - public boolean isFailed() { - return - MmsSmsColumns.Types.isFailedMessageType(type) || - MmsSmsColumns.Types.isPendingSecureSmsFallbackType(type) || - false; -// deliveryStatus >= SmsDatabase.Status.STATUS_FAILED; - } - - - public boolean isPending() { - return MmsSmsColumns.Types.isPendingMessageType(type) && - !MmsSmsColumns.Types.isIdentityVerified(type) && - !MmsSmsColumns.Types.isIdentityDefault(type); - } - - public boolean isOutgoing() { - return MmsSmsColumns.Types.isOutgoingMessageType(type); - } - - public abstract SpannableString getDisplayBody(); - - public Recipient getRecipient() { - return recipient; - } - - public long getDateReceived() { - return dateReceived; - } - - public long getThreadId() { - return threadId; - } - - public boolean isDelivered() { - return false; -// return (deliveryStatus >= SmsDatabase.Status.STATUS_COMPLETE && -// deliveryStatus < SmsDatabase.Status.STATUS_PENDING) || deliveryReceiptCount > 0; - } -} diff --git a/src/org/thoughtcrime/securesms/database/model/ThreadRecord.java b/src/org/thoughtcrime/securesms/database/model/ThreadRecord.java index 9ed0b10d8..cd735e2b3 100644 --- a/src/org/thoughtcrime/securesms/database/model/ThreadRecord.java +++ b/src/org/thoughtcrime/securesms/database/model/ThreadRecord.java @@ -35,31 +35,53 @@ import org.thoughtcrime.securesms.recipients.Recipient; * @author Moxie Marlinspike * */ -public class ThreadRecord extends DisplayRecord { +public class ThreadRecord { + + protected final Context context; + + private final Recipient recipient; + private final long dateReceived; + private final long threadId; + private final String body; - private final long count; private final int unreadCount; private final boolean archived; - private final long lastSeen; private final boolean verified; private @Nullable final DcLot dcSummary; - public ThreadRecord(@NonNull Context context, @NonNull String body, @Nullable Uri snippetUri, - @NonNull Recipient recipient, long date, long count, int unreadCount, - long threadId, int deliveryReceiptCount, int status, long snippetType, - int distributionType, boolean archived, long expiresIn, long lastSeen, - int readReceiptCount, boolean verified, @Nullable DcLot dcSummary) + public ThreadRecord(@NonNull Context context, @NonNull String body, + @NonNull Recipient recipient, long dateReceived, int unreadCount, + long threadId, + boolean archived, + boolean verified, @Nullable DcLot dcSummary) { - super(context, body, recipient, date, date, threadId, status, deliveryReceiptCount, snippetType); - this.count = count; + this.context = context.getApplicationContext(); + this.threadId = threadId; + this.recipient = recipient; + this.dateReceived = dateReceived; + this.body = body; this.unreadCount = unreadCount; this.archived = archived; - this.lastSeen = lastSeen; this.verified = verified; this.dcSummary = dcSummary; } - @Override + public @NonNull String getBody() { + return body == null ? "" : body; + } + + public Recipient getRecipient() { + return recipient; + } + + public long getDateReceived() { + return dateReceived; + } + + public long getThreadId() { + return threadId; + } + public SpannableString getDisplayBody() { if(dcSummary!=null && dcSummary.getText1Meaning()==DcLot.DC_TEXT1_DRAFT) { String draftText = dcSummary.getText1() + ":"; @@ -76,10 +98,6 @@ public class ThreadRecord extends DisplayRecord { return spannable; } - public long getCount() { - return count; - } - public int getUnreadCount() { return unreadCount; } @@ -92,18 +110,7 @@ public class ThreadRecord extends DisplayRecord { return archived; } - public long getLastSeen() { - return lastSeen; - } - public boolean isVerified() { return verified; } - - public static class DistributionTypes { - public static final int DEFAULT = 2; - public static final int CONVERSATION = 2; - public static final int ARCHIVE = 3; - public static final int INBOX_ZERO = 4; - } }