include mediaType and size in message content

This commit is contained in:
Daniel Gultsch 2023-04-19 08:11:39 +02:00
parent 506e4e1d0c
commit 69866e591c
No known key found for this signature in database
GPG key ID: F43D18AD2A0982C2
10 changed files with 93 additions and 24 deletions

View file

@ -74,7 +74,7 @@ dependencies {
annotationProcessor project(':annotation-processor')
// make Java 8 API available
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.2'
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.3'
// Jetpack / AndroidX libraries

View file

@ -2,7 +2,7 @@
"formatVersion": 1,
"database": {
"version": 1,
"identityHash": "8be54d59ea976565ba5a4f7a9faf9109",
"identityHash": "77c7c4ba9aae53855e38b8ce967e2668",
"entities": [
{
"tableName": "account",
@ -1947,7 +1947,7 @@
},
{
"tableName": "message_content",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `messageVersionId` INTEGER NOT NULL, `language` TEXT, `type` TEXT, `body` TEXT, `url` TEXT, FOREIGN KEY(`messageVersionId`) REFERENCES `message_version`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `messageVersionId` INTEGER NOT NULL, `language` TEXT, `partType` TEXT, `mediaType` TEXT, `size` INTEGER, `body` TEXT, `url` TEXT, `cached` INTEGER NOT NULL, FOREIGN KEY(`messageVersionId`) REFERENCES `message_version`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
"fields": [
{
"fieldPath": "id",
@ -1968,11 +1968,23 @@
"notNull": false
},
{
"fieldPath": "type",
"columnName": "type",
"fieldPath": "partType",
"columnName": "partType",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "mediaType",
"columnName": "mediaType",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "size",
"columnName": "size",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "body",
"columnName": "body",
@ -1984,6 +1996,12 @@
"columnName": "url",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "cached",
"columnName": "cached",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
@ -2694,7 +2712,7 @@
"views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '8be54d59ea976565ba5a4f7a9faf9109')"
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '77c7c4ba9aae53855e38b8ce967e2668')"
]
}
}

View file

@ -516,7 +516,8 @@ public class MessageTransformationTest extends BaseTransformationTest {
final var messages = database.messageDao().getMessagesForTesting(1L);
final var message = Iterables.getOnlyElement(messages);
Assert.assertEquals(Modification.RETRACTION, message.modification);
Assert.assertEquals(PartType.RETRACTION, Iterables.getOnlyElement(message.contents).type);
Assert.assertEquals(
PartType.RETRACTION, Iterables.getOnlyElement(message.contents).partType);
}
@Test

View file

@ -2,6 +2,7 @@ package im.conversations.android.database;
import androidx.room.TypeConverter;
import com.google.common.base.Strings;
import com.google.common.net.MediaType;
import de.measite.minidns.DNSName;
import java.io.IOException;
import java.net.InetAddress;
@ -176,4 +177,14 @@ public final class Converters {
return null;
}
}
@TypeConverter
public static String fromMediaType(final MediaType mediaType) {
return mediaType == null ? null : mediaType.toString();
}
@TypeConverter
public static MediaType toMediaType(final String mediaType) {
return mediaType == null ? null : MediaType.parse(mediaType);
}
}

View file

@ -5,6 +5,7 @@ import androidx.room.Entity;
import androidx.room.ForeignKey;
import androidx.room.Index;
import androidx.room.PrimaryKey;
import com.google.common.net.MediaType;
import im.conversations.android.database.model.MessageContent;
import im.conversations.android.database.model.PartType;
@ -26,20 +27,27 @@ public class MessageContentEntity {
public String language;
public PartType type;
public PartType partType;
public MediaType mediaType;
public Long size;
public String body;
public String url;
public boolean cached;
public static MessageContentEntity of(
final long messageVersionId, final MessageContent content) {
final var entity = new MessageContentEntity();
entity.messageVersionId = messageVersionId;
entity.language = content.language;
entity.type = content.type;
entity.partType = content.partType;
entity.mediaType = content.mediaType;
entity.size = content.size;
entity.body = content.body;
entity.url = content.url;
entity.cached = content.cached;
return entity;
}
}

View file

@ -1,30 +1,45 @@
package im.conversations.android.database.model;
import com.google.common.base.Objects;
import com.google.common.net.MediaType;
public class MessageContent {
public final String language;
public final PartType type;
public final PartType partType;
public MediaType mediaType;
public Long size;
public final String body;
public final String url;
public MessageContent(String language, PartType type, String body, String url) {
public boolean cached;
public MessageContent(
String language,
PartType partType,
MediaType mediaType,
Long size,
String body,
String url,
boolean cached) {
this.language = language;
this.type = type;
this.partType = partType;
this.mediaType = mediaType;
this.size = size;
this.body = body;
this.url = url;
this.cached = cached;
}
public static MessageContent text(final String body, final String language) {
return new MessageContent(language, PartType.TEXT, body, null);
return new MessageContent(language, PartType.TEXT, null, null, body, null, false);
}
public static MessageContent file(final String url) {
return new MessageContent(null, PartType.FILE, null, url);
return new MessageContent(null, PartType.FILE, null, null, null, url, false);
}
@Override
@ -32,14 +47,17 @@ public class MessageContent {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
MessageContent that = (MessageContent) o;
return Objects.equal(language, that.language)
&& type == that.type
return cached == that.cached
&& Objects.equal(language, that.language)
&& partType == that.partType
&& Objects.equal(mediaType, that.mediaType)
&& Objects.equal(size, that.size)
&& Objects.equal(body, that.body)
&& Objects.equal(url, that.url);
}
@Override
public int hashCode() {
return Objects.hashCode(language, type, body, url);
return Objects.hashCode(language, partType, mediaType, size, body, url, cached);
}
}

View file

@ -105,7 +105,7 @@ public final class MessageWithContentReactions
}
public boolean hasPreview() {
return Iterables.tryFind(this.contents, c -> c.type == PartType.FILE).isPresent();
return Iterables.tryFind(this.contents, c -> c.partType == PartType.FILE).isPresent();
}
public boolean hasDownloadButton() {
@ -113,7 +113,7 @@ public final class MessageWithContentReactions
}
public boolean hasTextContent() {
return Iterables.tryFind(this.contents, c -> c.type == PartType.TEXT).isPresent();
return Iterables.tryFind(this.contents, c -> c.partType == PartType.TEXT).isPresent();
}
public boolean hasInReplyTo() {

View file

@ -22,13 +22,22 @@ public class MessageContentWrapper {
public static final MessageContentWrapper RETRACTION =
new MessageContentWrapper(
ImmutableList.of(new MessageContent(null, PartType.RETRACTION, null, null)),
ImmutableList.of(
new MessageContent(
null, PartType.RETRACTION, null, null, null, null, false)),
Encryption.CLEARTEXT,
null);
private static final List<MessageContent> NOT_ENCRYPTED_FOR_THIS_DEVICE =
ImmutableList.of(
new MessageContent(null, PartType.NOT_ENCRYPTED_FOR_THIS_DEVICE, null, null));
new MessageContent(
null,
PartType.NOT_ENCRYPTED_FOR_THIS_DEVICE,
null,
null,
null,
null,
false));
public final List<MessageContent> contents;
public final Encryption encryption;
@ -104,8 +113,11 @@ public class MessageContentWrapper {
new MessageContent(
null,
PartType.DECRYPTION_FAILURE,
null,
null,
exceptionToMessage(cause),
null)),
null,
false)),
Encryption.FAILURE,
null);
}

View file

@ -16,7 +16,8 @@ public final class TextContents {
final boolean removeFallback,
final int inReplyToFallbackStart,
final int inReplyToFallbackEnd) {
final var textContents = Collections2.filter(messageContents, c -> c.type == PartType.TEXT);
final var textContents =
Collections2.filter(messageContents, c -> c.partType == PartType.TEXT);
if (textContents.size() == 1 && removeFallback) {
final String body = Strings.nullToEmpty(Iterables.getOnlyElement(textContents).body);
if (inReplyToFallbackEnd > inReplyToFallbackStart

View file

@ -4,7 +4,7 @@ buildscript {
material = "1.8.0"
lifecycleVersion = "2.2.0"
navVersion = '2.5.3'
roomVersion = "2.5.0"
roomVersion = "2.5.1"
preferenceVersion = "1.2.0"
espressoVersion = "3.5.1"
pagingVersion = "3.1.1"