left join trust into MessageWithContentReactions

This commit is contained in:
Daniel Gultsch 2023-03-01 07:55:28 +01:00
parent 3c207c28b4
commit 5e79dd8b68
No known key found for this signature in database
GPG key ID: F43D18AD2A0982C2
7 changed files with 40 additions and 34 deletions

View file

@ -2,7 +2,7 @@
"formatVersion": 1,
"database": {
"version": 1,
"identityHash": "8f66e4197a1676d0164aa77eea8f2a20",
"identityHash": "9d2672ebdefc9df52add6eebf635031f",
"entities": [
{
"tableName": "account",
@ -432,7 +432,7 @@
},
{
"tableName": "axolotl_identity",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `accountId` INTEGER NOT NULL, `address` TEXT NOT NULL, `deviceId` INTEGER NOT NULL, `identityKey` BLOB NOT NULL, `trust` TEXT NOT NULL, FOREIGN KEY(`accountId`) REFERENCES `account`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `accountId` INTEGER NOT NULL, `address` TEXT NOT NULL, `identityKey` BLOB NOT NULL, `trust` TEXT NOT NULL, FOREIGN KEY(`accountId`) REFERENCES `account`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
"fields": [
{
"fieldPath": "id",
@ -452,12 +452,6 @@
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "deviceId",
"columnName": "deviceId",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "identityKey",
"columnName": "identityKey",
@ -479,15 +473,25 @@
},
"indices": [
{
"name": "index_axolotl_identity_accountId_address_deviceId",
"name": "index_axolotl_identity_accountId_address_identityKey",
"unique": true,
"columnNames": [
"accountId",
"address",
"deviceId"
"identityKey"
],
"orders": [],
"createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `index_axolotl_identity_accountId_address_deviceId` ON `${TABLE_NAME}` (`accountId`, `address`, `deviceId`)"
"createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `index_axolotl_identity_accountId_address_identityKey` ON `${TABLE_NAME}` (`accountId`, `address`, `identityKey`)"
},
{
"name": "index_axolotl_identity_accountId_identityKey",
"unique": false,
"columnNames": [
"accountId",
"identityKey"
],
"orders": [],
"createSql": "CREATE INDEX IF NOT EXISTS `index_axolotl_identity_accountId_identityKey` ON `${TABLE_NAME}` (`accountId`, `identityKey`)"
}
],
"foreignKeys": [
@ -2376,7 +2380,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, '8f66e4197a1676d0164aa77eea8f2a20')"
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '9d2672ebdefc9df52add6eebf635031f')"
]
}
}

View file

@ -427,6 +427,8 @@ public class MessageTransformationTest {
Assert.assertEquals(1L, embeddedMessage.contents.size());
Assert.assertEquals(
"Hi. How are you?", Iterables.getOnlyElement(embeddedMessage.contents).body);
Assert.assertNull(response.identityKey);
Assert.assertNull(response.trust);
}
@Test

View file

@ -50,13 +50,7 @@ public class AxolotlDatabaseStore extends AbstractAccountService implements Sign
} else {
trust = Trust.TRUSTED;
}
return axolotlDao()
.setIdentity(
account,
address.getJid(),
address.getDeviceId(),
identityKey,
trust);
return axolotlDao().setIdentity(account, address.getJid(), identityKey, trust);
});
}

View file

@ -127,12 +127,11 @@ public abstract class AxolotlDao {
public boolean setIdentity(
final Account account,
final BareJid address,
final int deviceId,
final IdentityKey identityKey,
final Trust trust) {
final var existing = getIdentityKey(account.id, address, deviceId);
final var existing = getIdentityKey(account.id, address, identityKey);
if (existing == null || !existing.equals(identityKey)) {
insert(AxolotlIdentityEntity.of(account, address, deviceId, identityKey, trust));
insert(AxolotlIdentityEntity.of(account, address, identityKey, trust));
return true;
} else {
return false;
@ -155,8 +154,9 @@ public abstract class AxolotlDao {
@Query(
"SELECT identityKey FROM AXOLOTL_IDENTITY WHERE accountId=:account AND"
+ " address=:address AND deviceId=:deviceId")
protected abstract IdentityKey getIdentityKey(long account, BareJid address, int deviceId);
+ " address=:address AND identityKey=:identityKey")
protected abstract IdentityKey getIdentityKey(
long account, BareJid address, IdentityKey identityKey);
@Query(
"SELECT preKeyRecord FROM axolotl_pre_key WHERE accountId=:account AND"

View file

@ -422,10 +422,12 @@ public abstract class MessageDao {
@Query(
"SELECT message.id as"
+ " id,sentAt,outgoing,toBare,toResource,fromBare,fromResource,modification,latestVersion"
+ " as version,inReplyToMessageEntityId,encryption,identityKey FROM message JOIN"
+ " message_version ON message.latestVersion=message_version.id WHERE"
+ " message.chatId=:chatId AND latestVersion IS NOT NULL ORDER BY"
+ " message.receivedAt")
+ " as version,inReplyToMessageEntityId,encryption,message_version.identityKey,trust"
+ " FROM chat JOIN message on message.chatId=chat.id JOIN message_version ON"
+ " message.latestVersion=message_version.id LEFT JOIN axolotl_identity ON"
+ " chat.accountId=axolotl_identity.accountId AND"
+ " message_version.identityKey=axolotl_identity.identityKey WHERE chat.id=:chatId"
+ " AND latestVersion IS NOT NULL ORDER BY message.receivedAt")
public abstract List<MessageWithContentReactions> getMessages(long chatId);
public void setInReplyTo(

View file

@ -20,8 +20,11 @@ import org.whispersystems.libsignal.IdentityKey;
onDelete = ForeignKey.CASCADE),
indices = {
@Index(
value = {"accountId", "address", "deviceId"},
unique = true)
value = {"accountId", "address", "identityKey"},
unique = true),
@Index(
value = {"accountId", "identityKey"},
unique = false)
})
public class AxolotlIdentityEntity {
@ -32,18 +35,18 @@ public class AxolotlIdentityEntity {
@NonNull public BareJid address;
@NonNull public Integer deviceId;
@NonNull public IdentityKey identityKey;
@NonNull public Trust trust;
public static AxolotlIdentityEntity of(
Account account, BareJid address, int deviceId, IdentityKey identityKey, Trust trust) {
final Account account,
final BareJid address,
final IdentityKey identityKey,
final Trust trust) {
final var entity = new AxolotlIdentityEntity();
entity.accountId = account.id;
entity.address = address;
entity.deviceId = deviceId;
entity.identityKey = identityKey;
entity.trust = trust;
return entity;

View file

@ -34,6 +34,7 @@ public class MessageWithContentReactions {
public Long inReplyToMessageEntityId;
public Encryption encryption;
public IdentityKey identityKey;
public Trust trust;
@Relation(
entity = MessageEntity.class,