mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-21 09:20:19 +01:00
Remove SmsMessageRecord.
This commit is contained in:
@@ -61,7 +61,6 @@ import org.thoughtcrime.securesms.database.model.MessageRecord;
|
||||
import org.thoughtcrime.securesms.database.model.NotificationMmsMessageRecord;
|
||||
import org.thoughtcrime.securesms.database.model.ParentStoryId;
|
||||
import org.thoughtcrime.securesms.database.model.Quote;
|
||||
import org.thoughtcrime.securesms.database.model.SmsMessageRecord;
|
||||
import org.thoughtcrime.securesms.database.model.StoryResult;
|
||||
import org.thoughtcrime.securesms.database.model.StoryType;
|
||||
import org.thoughtcrime.securesms.database.model.StoryViewState;
|
||||
@@ -349,18 +348,6 @@ public class MessageTable extends DatabaseTable implements MmsSmsColumns, Recipi
|
||||
return rawQuery(where, null);
|
||||
}
|
||||
|
||||
public SmsMessageRecord getSmsMessage(long messageId) throws NoSuchMessageException {
|
||||
SQLiteDatabase db = databaseHelper.getSignalReadableDatabase();
|
||||
Cursor cursor = db.query(TABLE_NAME, SMS_PROJECTION, ID_WHERE, new String[]{messageId + ""}, null, null, null);
|
||||
SmsReader reader = new SmsReader(cursor);
|
||||
SmsMessageRecord record = reader.getNext();
|
||||
|
||||
reader.close();
|
||||
|
||||
if (record == null) throw new NoSuchMessageException("No message for ID: " + messageId);
|
||||
else return record;
|
||||
}
|
||||
|
||||
public Cursor getMessageCursor(long messageId) {
|
||||
return internalGetMessage(messageId);
|
||||
}
|
||||
@@ -713,7 +700,7 @@ public class MessageTable extends DatabaseTable implements MmsSmsColumns, Recipi
|
||||
String[] args = SqlUtil.buildArgs(Types.GROUP_CALL_TYPE, threadId);
|
||||
boolean sameEraId = false;
|
||||
|
||||
try (SmsReader reader = new SmsReader(db.query(TABLE_NAME, SMS_PROJECTION, where, args, null, null, DATE_RECEIVED + " DESC", "1"))) {
|
||||
try (MmsReader reader = new MmsReader(db.query(TABLE_NAME, SMS_PROJECTION, where, args, null, null, DATE_RECEIVED + " DESC", "1"))) {
|
||||
MessageRecord record = reader.getNext();
|
||||
if (record != null) {
|
||||
GroupCallUpdateDetails groupCallUpdateDetails = GroupCallUpdateDetailsUtil.parse(record.getBody());
|
||||
@@ -776,7 +763,7 @@ public class MessageTable extends DatabaseTable implements MmsSmsColumns, Recipi
|
||||
String[] args = SqlUtil.buildArgs(Types.GROUP_CALL_TYPE, threadId);
|
||||
boolean sameEraId = false;
|
||||
|
||||
try (SmsReader reader = new SmsReader(db.query(TABLE_NAME, SMS_PROJECTION, where, args, null, null, DATE_RECEIVED + " DESC", "1"))) {
|
||||
try (MmsReader reader = new MmsReader(db.query(TABLE_NAME, SMS_PROJECTION, where, args, null, null, DATE_RECEIVED + " DESC", "1"))) {
|
||||
MessageRecord record = reader.getNext();
|
||||
if (record == null) {
|
||||
return false;
|
||||
@@ -3090,7 +3077,7 @@ public class MessageTable extends DatabaseTable implements MmsSmsColumns, Recipi
|
||||
String where = THREAD_ID + " = ? AND " + DATE_RECEIVED + " >= ? AND " + TYPE + " = ?";
|
||||
String[] args = SqlUtil.buildArgs(threadId, afterTimestamp, Types.PROFILE_CHANGE_TYPE);
|
||||
|
||||
try (SmsReader reader = smsReaderFor(queryMessages(where, args, true, -1))) {
|
||||
try (MmsReader reader = mmsReaderFor(queryMessages(where, args, true, -1))) {
|
||||
List<MessageRecord> results = new ArrayList<>(reader.getCount());
|
||||
while (reader.getNext() != null) {
|
||||
results.add(reader.getCurrent());
|
||||
@@ -3330,10 +3317,6 @@ public class MessageTable extends DatabaseTable implements MmsSmsColumns, Recipi
|
||||
return new MmsReader(cursor);
|
||||
}
|
||||
|
||||
public static SmsReader smsReaderFor(Cursor cursor) {
|
||||
return new SmsReader(cursor);
|
||||
}
|
||||
|
||||
public static OutgoingMmsReader readerFor(OutgoingMessage message, long threadId) {
|
||||
return new OutgoingMmsReader(message, threadId);
|
||||
}
|
||||
@@ -4145,121 +4128,6 @@ public class MessageTable extends DatabaseTable implements MmsSmsColumns, Recipi
|
||||
ALL
|
||||
}
|
||||
|
||||
public static class SmsReader implements MessageTable.Reader {
|
||||
|
||||
private final Cursor cursor;
|
||||
private final Context context;
|
||||
|
||||
public SmsReader(Cursor cursor) {
|
||||
this.cursor = cursor;
|
||||
this.context = ApplicationDependencies.getApplication();
|
||||
}
|
||||
|
||||
public SmsMessageRecord getNext() {
|
||||
if (cursor == null || !cursor.moveToNext())
|
||||
return null;
|
||||
|
||||
return getCurrent();
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
if (cursor == null) return 0;
|
||||
else return cursor.getCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull MessageExportState getMessageExportStateForCurrentRecord() {
|
||||
byte[] messageExportState = CursorUtil.requireBlob(cursor, MmsSmsColumns.EXPORT_STATE);
|
||||
if (messageExportState == null) {
|
||||
return MessageExportState.getDefaultInstance();
|
||||
}
|
||||
|
||||
try {
|
||||
return MessageExportState.parseFrom(messageExportState);
|
||||
} catch (InvalidProtocolBufferException e) {
|
||||
return MessageExportState.getDefaultInstance();
|
||||
}
|
||||
}
|
||||
|
||||
public SmsMessageRecord getCurrent() {
|
||||
long messageId = cursor.getLong(cursor.getColumnIndexOrThrow(MmsSmsColumns.ID));
|
||||
long recipientId = cursor.getLong(cursor.getColumnIndexOrThrow(MmsSmsColumns.RECIPIENT_ID));
|
||||
int addressDeviceId = cursor.getInt(cursor.getColumnIndexOrThrow(MmsSmsColumns.RECIPIENT_DEVICE_ID));
|
||||
long type = cursor.getLong(cursor.getColumnIndexOrThrow(MmsSmsColumns.TYPE));
|
||||
long dateReceived = cursor.getLong(cursor.getColumnIndexOrThrow(MmsSmsColumns.DATE_RECEIVED));
|
||||
long dateSent = cursor.getLong(cursor.getColumnIndexOrThrow(MmsSmsColumns.DATE_SENT));
|
||||
long dateServer = cursor.getLong(cursor.getColumnIndexOrThrow(MmsSmsColumns.DATE_SERVER));
|
||||
long threadId = cursor.getLong(cursor.getColumnIndexOrThrow(MmsSmsColumns.THREAD_ID));
|
||||
int status = cursor.getInt(cursor.getColumnIndexOrThrow(MessageTable.MMS_STATUS));
|
||||
int deliveryReceiptCount = cursor.getInt(cursor.getColumnIndexOrThrow(MmsSmsColumns.DELIVERY_RECEIPT_COUNT));
|
||||
int readReceiptCount = cursor.getInt(cursor.getColumnIndexOrThrow(MmsSmsColumns.READ_RECEIPT_COUNT));
|
||||
String mismatchDocument = cursor.getString(cursor.getColumnIndexOrThrow(MmsSmsColumns.MISMATCHED_IDENTITIES));
|
||||
int subscriptionId = cursor.getInt(cursor.getColumnIndexOrThrow(MmsSmsColumns.SMS_SUBSCRIPTION_ID));
|
||||
long expiresIn = cursor.getLong(cursor.getColumnIndexOrThrow(MmsSmsColumns.EXPIRES_IN));
|
||||
long expireStarted = cursor.getLong(cursor.getColumnIndexOrThrow(MmsSmsColumns.EXPIRE_STARTED));
|
||||
String body = cursor.getString(cursor.getColumnIndexOrThrow(MmsSmsColumns.BODY));
|
||||
boolean unidentified = cursor.getInt(cursor.getColumnIndexOrThrow(MmsSmsColumns.UNIDENTIFIED)) == 1;
|
||||
boolean remoteDelete = cursor.getInt(cursor.getColumnIndexOrThrow(MmsSmsColumns.REMOTE_DELETED)) == 1;
|
||||
long notifiedTimestamp = CursorUtil.requireLong(cursor, NOTIFIED_TIMESTAMP);
|
||||
long receiptTimestamp = CursorUtil.requireLong(cursor, RECEIPT_TIMESTAMP);
|
||||
|
||||
if (!TextSecurePreferences.isReadReceiptsEnabled(context)) {
|
||||
readReceiptCount = 0;
|
||||
}
|
||||
|
||||
Set<IdentityKeyMismatch> mismatches = getMismatches(mismatchDocument);
|
||||
Recipient recipient = Recipient.live(RecipientId.from(recipientId)).get();
|
||||
|
||||
return new SmsMessageRecord(messageId, body, recipient,
|
||||
recipient,
|
||||
addressDeviceId,
|
||||
dateSent, dateReceived, dateServer, deliveryReceiptCount, type,
|
||||
threadId, status, mismatches, subscriptionId,
|
||||
expiresIn, expireStarted,
|
||||
readReceiptCount, unidentified, Collections.emptyList(), remoteDelete,
|
||||
notifiedTimestamp, receiptTimestamp);
|
||||
}
|
||||
|
||||
private Set<IdentityKeyMismatch> getMismatches(String document) {
|
||||
try {
|
||||
if (!TextUtils.isEmpty(document)) {
|
||||
return JsonUtils.fromJson(document, IdentityKeyMismatchSet.class).getItems();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Log.w(TAG, e);
|
||||
}
|
||||
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
cursor.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Iterator<MessageRecord> iterator() {
|
||||
return new ReaderIterator();
|
||||
}
|
||||
|
||||
private class ReaderIterator implements Iterator<MessageRecord> {
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return cursor != null && cursor.getCount() != 0 && !cursor.isLast();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MessageRecord next() {
|
||||
MessageRecord record = getNext();
|
||||
if (record == null) {
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
|
||||
return record;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class MmsStatus {
|
||||
public static final int DOWNLOAD_INITIALIZED = 1;
|
||||
public static final int DOWNLOAD_NO_CONNECTIVITY = 2;
|
||||
|
||||
@@ -1,117 +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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.thoughtcrime.securesms.database.model;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.SpannableString;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.WorkerThread;
|
||||
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.database.MmsSmsColumns;
|
||||
import org.thoughtcrime.securesms.database.documents.IdentityKeyMismatch;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* The message record model which represents standard SMS messages.
|
||||
*
|
||||
* @author Moxie Marlinspike
|
||||
*
|
||||
*/
|
||||
|
||||
public class SmsMessageRecord extends MessageRecord {
|
||||
|
||||
public SmsMessageRecord(long id,
|
||||
String body, Recipient recipient,
|
||||
Recipient individualRecipient,
|
||||
int recipientDeviceId,
|
||||
long dateSent, long dateReceived, long dateServer,
|
||||
int deliveryReceiptCount,
|
||||
long type, long threadId,
|
||||
int status, Set<IdentityKeyMismatch> mismatches,
|
||||
int subscriptionId, long expiresIn, long expireStarted,
|
||||
int readReceiptCount, boolean unidentified,
|
||||
@NonNull List<ReactionRecord> reactions, boolean remoteDelete,
|
||||
long notifiedTimestamp, long receiptTimestamp)
|
||||
{
|
||||
super(id, body, recipient, individualRecipient, recipientDeviceId,
|
||||
dateSent, dateReceived, dateServer, threadId, status, deliveryReceiptCount, type,
|
||||
mismatches, new HashSet<>(), subscriptionId,
|
||||
expiresIn, expireStarted, readReceiptCount, unidentified, reactions, remoteDelete, notifiedTimestamp, 0, receiptTimestamp);
|
||||
}
|
||||
|
||||
public long getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
@WorkerThread
|
||||
public SpannableString getDisplayBody(@NonNull Context context) {
|
||||
if (MmsSmsColumns.Types.isChatSessionRefresh(type)) {
|
||||
return emphasisAdded(context.getString(R.string.MessageRecord_chat_session_refreshed));
|
||||
} else if (isCorruptedKeyExchange()) {
|
||||
return emphasisAdded(context.getString(R.string.SmsMessageRecord_received_corrupted_key_exchange_message));
|
||||
} else if (isInvalidVersionKeyExchange()) {
|
||||
return emphasisAdded(context.getString(R.string.SmsMessageRecord_received_key_exchange_message_for_invalid_protocol_version));
|
||||
} else if (MmsSmsColumns.Types.isLegacyType(type)) {
|
||||
return emphasisAdded(context.getString(R.string.MessageRecord_message_encrypted_with_a_legacy_protocol_version_that_is_no_longer_supported));
|
||||
} else if (isBundleKeyExchange()) {
|
||||
return emphasisAdded(context.getString(R.string.SmsMessageRecord_received_message_with_new_safety_number_tap_to_process));
|
||||
} else if (isKeyExchange() && isOutgoing()) {
|
||||
return new SpannableString("");
|
||||
} else if (isKeyExchange() && !isOutgoing()) {
|
||||
return emphasisAdded(context.getString(R.string.ConversationItem_received_key_exchange_message_tap_to_process));
|
||||
} else if (MmsSmsColumns.Types.isDuplicateMessageType(type)) {
|
||||
return emphasisAdded(context.getString(R.string.SmsMessageRecord_duplicate_message));
|
||||
} else if (MmsSmsColumns.Types.isNoRemoteSessionType(type)) {
|
||||
return emphasisAdded(context.getString(R.string.MessageDisplayHelper_message_encrypted_for_non_existing_session));
|
||||
} else if (isEndSession() && isOutgoing()) {
|
||||
return emphasisAdded(context.getString(R.string.SmsMessageRecord_secure_session_reset));
|
||||
} else if (isEndSession()) {
|
||||
return emphasisAdded(context.getString(R.string.SmsMessageRecord_secure_session_reset_s, getIndividualRecipient().getDisplayName(context)));
|
||||
} else if (MmsSmsColumns.Types.isUnsupportedMessageType(type)) {
|
||||
return emphasisAdded(context.getString(R.string.SmsMessageRecord_this_message_could_not_be_processed_because_it_was_sent_from_a_newer_version));
|
||||
} else if (MmsSmsColumns.Types.isInvalidMessageType(type)) {
|
||||
return emphasisAdded(context.getString(R.string.SmsMessageRecord_error_handling_incoming_message));
|
||||
} else {
|
||||
return super.getDisplayBody(context);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMms() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMmsNotification() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public @NonNull SmsMessageRecord withReactions(@NonNull List<ReactionRecord> reactions) {
|
||||
return new SmsMessageRecord(getId(), getBody(), getRecipient(), getIndividualRecipient(), getRecipientDeviceId(), getDateSent(), getDateReceived(),
|
||||
getServerTimestamp(), getDeliveryReceiptCount(), getType(), getThreadId(), getDeliveryStatus(), getIdentityKeyMismatches(),
|
||||
getSubscriptionId(), getExpiresIn(), getExpireStarted(), getReadReceiptCount(), isUnidentified(), reactions, isRemoteDelete(),
|
||||
getNotifiedTimestamp(), getReceiptTimestamp());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user