Add support for replying to gift badges.

This commit is contained in:
Alex Hart
2022-05-10 10:10:35 -03:00
parent 0c1edd6a56
commit 8ca0f4baf4
22 changed files with 247 additions and 54 deletions

View File

@@ -130,6 +130,7 @@ public class MmsDatabase extends MessageDatabase {
static final String QUOTE_ATTACHMENT = "quote_attachment";
static final String QUOTE_MISSING = "quote_missing";
static final String QUOTE_MENTIONS = "quote_mentions";
static final String QUOTE_TYPE = "quote_type";
static final String SHARED_CONTACTS = "shared_contacts";
static final String LINK_PREVIEWS = "previews";
@@ -171,6 +172,7 @@ public class MmsDatabase extends MessageDatabase {
QUOTE_ATTACHMENT + " INTEGER DEFAULT -1, " +
QUOTE_MISSING + " INTEGER DEFAULT 0, " +
QUOTE_MENTIONS + " BLOB DEFAULT NULL," +
QUOTE_TYPE + " INTEGER DEFAULT 0," +
SHARED_CONTACTS + " TEXT, " +
UNIDENTIFIED + " INTEGER DEFAULT 0, " +
LINK_PREVIEWS + " TEXT, " +
@@ -209,7 +211,7 @@ public class MmsDatabase extends MessageDatabase {
MESSAGE_SIZE, STATUS, TRANSACTION_ID,
BODY, PART_COUNT, RECIPIENT_ID, ADDRESS_DEVICE_ID,
DELIVERY_RECEIPT_COUNT, READ_RECEIPT_COUNT, MISMATCHED_IDENTITIES, NETWORK_FAILURE, SUBSCRIPTION_ID,
EXPIRES_IN, EXPIRE_STARTED, NOTIFIED, QUOTE_ID, QUOTE_AUTHOR, QUOTE_BODY, QUOTE_ATTACHMENT, QUOTE_MISSING, QUOTE_MENTIONS,
EXPIRES_IN, EXPIRE_STARTED, NOTIFIED, QUOTE_ID, QUOTE_AUTHOR, QUOTE_BODY, QUOTE_ATTACHMENT, QUOTE_TYPE, QUOTE_MISSING, QUOTE_MENTIONS,
SHARED_CONTACTS, LINK_PREVIEWS, UNIDENTIFIED, VIEW_ONCE, REACTIONS_UNREAD, REACTIONS_LAST_SEEN,
REMOTE_DELETED, MENTIONS_SELF, NOTIFIED_TIMESTAMP, VIEWED_RECEIPT_COUNT, RECEIPT_TIMESTAMP, MESSAGE_RANGES,
STORY_TYPE, PARENT_STORY_ID,
@@ -1216,6 +1218,7 @@ public class MmsDatabase extends MessageDatabase {
values.putNull(QUOTE_BODY);
values.putNull(QUOTE_AUTHOR);
values.putNull(QUOTE_ATTACHMENT);
values.putNull(QUOTE_TYPE);
values.putNull(QUOTE_ID);
values.putNull(LINK_PREVIEWS);
values.putNull(SHARED_CONTACTS);
@@ -1536,6 +1539,7 @@ public class MmsDatabase extends MessageDatabase {
long quoteId = cursor.getLong(cursor.getColumnIndexOrThrow(QUOTE_ID));
long quoteAuthor = cursor.getLong(cursor.getColumnIndexOrThrow(QUOTE_AUTHOR));
String quoteText = cursor.getString(cursor.getColumnIndexOrThrow(QUOTE_BODY));
int quoteType = cursor.getInt(cursor.getColumnIndexOrThrow(QUOTE_TYPE));
boolean quoteMissing = cursor.getInt(cursor.getColumnIndexOrThrow(QUOTE_MISSING)) == 1;
List<Attachment> quoteAttachments = Stream.of(associatedAttachments).filter(Attachment::isQuote).map(a -> (Attachment)a).toList();
List<Mention> quoteMentions = parseQuoteMentions(context, cursor);
@@ -1555,7 +1559,7 @@ public class MmsDatabase extends MessageDatabase {
QuoteModel quote = null;
if (quoteId > 0 && quoteAuthor > 0 && (!TextUtils.isEmpty(quoteText) || !quoteAttachments.isEmpty())) {
quote = new QuoteModel(quoteId, RecipientId.from(quoteAuthor), quoteText, quoteMissing, quoteAttachments, quoteMentions);
quote = new QuoteModel(quoteId, RecipientId.from(quoteAuthor), quoteText, quoteMissing, quoteAttachments, quoteMentions, QuoteModel.Type.fromCode(quoteType));
}
if (!TextUtils.isEmpty(mismatchDocument)) {
@@ -1739,6 +1743,7 @@ public class MmsDatabase extends MessageDatabase {
contentValues.put(QUOTE_ID, retrieved.getQuote().getId());
contentValues.put(QUOTE_BODY, retrieved.getQuote().getText().toString());
contentValues.put(QUOTE_AUTHOR, retrieved.getQuote().getAuthor().serialize());
contentValues.put(QUOTE_TYPE, retrieved.getQuote().getType().getCode());
contentValues.put(QUOTE_MISSING, retrieved.getQuote().isOriginalMissing() ? 1 : 0);
BodyRangeList mentionsList = MentionUtil.mentionsToBodyRangeList(retrieved.getQuote().getMentions());
@@ -2011,6 +2016,7 @@ public class MmsDatabase extends MessageDatabase {
contentValues.put(QUOTE_ID, message.getOutgoingQuote().getId());
contentValues.put(QUOTE_AUTHOR, message.getOutgoingQuote().getAuthor().serialize());
contentValues.put(QUOTE_BODY, updated.getBodyAsString());
contentValues.put(QUOTE_TYPE, message.getOutgoingQuote().getType().getCode());
contentValues.put(QUOTE_MISSING, message.getOutgoingQuote().isOriginalMissing() ? 1 : 0);
BodyRangeList mentionsList = MentionUtil.mentionsToBodyRangeList(updated.getMentions());
@@ -2485,7 +2491,8 @@ public class MmsDatabase extends MessageDatabase {
quoteText,
message.getOutgoingQuote().isOriginalMissing(),
new SlideDeck(context, message.getOutgoingQuote().getAttachments()),
quoteMentions) :
quoteMentions,
message.getOutgoingQuote().getType()) :
null,
message.getSharedContacts(),
message.getLinkPreviews(),
@@ -2699,6 +2706,7 @@ public class MmsDatabase extends MessageDatabase {
long quoteId = cursor.getLong(cursor.getColumnIndexOrThrow(MmsDatabase.QUOTE_ID));
long quoteAuthor = cursor.getLong(cursor.getColumnIndexOrThrow(MmsDatabase.QUOTE_AUTHOR));
CharSequence quoteText = cursor.getString(cursor.getColumnIndexOrThrow(MmsDatabase.QUOTE_BODY));
int quoteType = cursor.getInt(cursor.getColumnIndexOrThrow(MmsDatabase.QUOTE_TYPE));
boolean quoteMissing = cursor.getInt(cursor.getColumnIndexOrThrow(MmsDatabase.QUOTE_MISSING)) == 1;
List<Mention> quoteMentions = parseQuoteMentions(context, cursor);
List<DatabaseAttachment> attachments = SignalDatabase.attachments().getAttachments(cursor);
@@ -2713,7 +2721,7 @@ public class MmsDatabase extends MessageDatabase {
quoteMentions = updated.getMentions();
}
return new Quote(quoteId, RecipientId.from(quoteAuthor), quoteText, quoteMissing, quoteDeck, quoteMentions);
return new Quote(quoteId, RecipientId.from(quoteAuthor), quoteText, quoteMissing, quoteDeck, quoteMentions, QuoteModel.Type.fromCode(quoteType));
} else {
return null;
}

View File

@@ -99,6 +99,7 @@ public class MmsSmsDatabase extends Database {
MmsDatabase.QUOTE_BODY,
MmsDatabase.QUOTE_MISSING,
MmsDatabase.QUOTE_ATTACHMENT,
MmsDatabase.QUOTE_TYPE,
MmsDatabase.QUOTE_MENTIONS,
MmsDatabase.SHARED_CONTACTS,
MmsDatabase.LINK_PREVIEWS,
@@ -777,6 +778,7 @@ public class MmsSmsDatabase extends Database {
MmsDatabase.QUOTE_BODY,
MmsDatabase.QUOTE_MISSING,
MmsDatabase.QUOTE_ATTACHMENT,
MmsDatabase.QUOTE_TYPE,
MmsDatabase.QUOTE_MENTIONS,
MmsDatabase.SHARED_CONTACTS,
MmsDatabase.LINK_PREVIEWS,
@@ -813,6 +815,7 @@ public class MmsSmsDatabase extends Database {
MmsDatabase.QUOTE_BODY,
MmsDatabase.QUOTE_MISSING,
MmsDatabase.QUOTE_ATTACHMENT,
MmsDatabase.QUOTE_TYPE,
MmsDatabase.QUOTE_MENTIONS,
MmsDatabase.SHARED_CONTACTS,
MmsDatabase.LINK_PREVIEWS,
@@ -878,6 +881,7 @@ public class MmsSmsDatabase extends Database {
mmsColumnsPresent.add(MmsDatabase.QUOTE_BODY);
mmsColumnsPresent.add(MmsDatabase.QUOTE_MISSING);
mmsColumnsPresent.add(MmsDatabase.QUOTE_ATTACHMENT);
mmsColumnsPresent.add(MmsDatabase.QUOTE_TYPE);
mmsColumnsPresent.add(MmsDatabase.QUOTE_MENTIONS);
mmsColumnsPresent.add(MmsDatabase.SHARED_CONTACTS);
mmsColumnsPresent.add(MmsDatabase.LINK_PREVIEWS);

View File

@@ -195,8 +195,9 @@ object SignalDatabaseMigrations {
private const val REMOVE_KNOWN_UNKNOWNS = 139
private const val CDS_V2 = 140
private const val GROUP_SERVICE_ID = 141
private const val QUOTE_TYPE = 142
const val DATABASE_VERSION = 141
const val DATABASE_VERSION = 142
@JvmStatic
fun migrate(context: Application, db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
@@ -2528,6 +2529,10 @@ object SignalDatabaseMigrations {
if (oldVersion < GROUP_SERVICE_ID) {
db.execSQL("ALTER TABLE groups ADD COLUMN auth_service_id TEXT DEFAULT NULL")
}
if (oldVersion < QUOTE_TYPE) {
db.execSQL("ALTER TABLE mms ADD COLUMN quote_type INTEGER DEFAULT 0")
}
}
@JvmStatic

View File

@@ -6,6 +6,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.thoughtcrime.securesms.components.mention.MentionAnnotation;
import org.thoughtcrime.securesms.mms.QuoteModel;
import org.thoughtcrime.securesms.mms.SlideDeck;
import org.thoughtcrime.securesms.recipients.RecipientId;
@@ -13,25 +14,28 @@ import java.util.List;
public class Quote {
private final long id;
private final RecipientId author;
private final CharSequence text;
private final boolean missing;
private final SlideDeck attachment;
private final List<Mention> mentions;
private final long id;
private final RecipientId author;
private final CharSequence text;
private final boolean missing;
private final SlideDeck attachment;
private final List<Mention> mentions;
private final QuoteModel.Type quoteType;
public Quote(long id,
@NonNull RecipientId author,
@Nullable CharSequence text,
boolean missing,
@NonNull SlideDeck attachment,
@NonNull List<Mention> mentions)
@NonNull List<Mention> mentions,
@NonNull QuoteModel.Type quoteType)
{
this.id = id;
this.author = author;
this.missing = missing;
this.attachment = attachment;
this.mentions = mentions;
this.id = id;
this.author = author;
this.missing = missing;
this.attachment = attachment;
this.mentions = mentions;
this.quoteType = quoteType;
SpannableString spannable = new SpannableString(text);
MentionAnnotation.setMentionAnnotations(spannable, mentions);
@@ -40,7 +44,7 @@ public class Quote {
}
public @NonNull Quote withAttachment(@NonNull SlideDeck updatedAttachment) {
return new Quote(id, author, text, missing, updatedAttachment, mentions);
return new Quote(id, author, text, missing, updatedAttachment, mentions, quoteType);
}
@@ -63,4 +67,8 @@ public class Quote {
public @NonNull SlideDeck getAttachment() {
return attachment;
}
public @NonNull QuoteModel.Type getQuoteType() {
return quoteType;
}
}