left join trust into MessageWithContentReactions
This commit is contained in:
parent
3c207c28b4
commit
5e79dd8b68
|
@ -2,7 +2,7 @@
|
||||||
"formatVersion": 1,
|
"formatVersion": 1,
|
||||||
"database": {
|
"database": {
|
||||||
"version": 1,
|
"version": 1,
|
||||||
"identityHash": "8f66e4197a1676d0164aa77eea8f2a20",
|
"identityHash": "9d2672ebdefc9df52add6eebf635031f",
|
||||||
"entities": [
|
"entities": [
|
||||||
{
|
{
|
||||||
"tableName": "account",
|
"tableName": "account",
|
||||||
|
@ -432,7 +432,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"tableName": "axolotl_identity",
|
"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": [
|
"fields": [
|
||||||
{
|
{
|
||||||
"fieldPath": "id",
|
"fieldPath": "id",
|
||||||
|
@ -452,12 +452,6 @@
|
||||||
"affinity": "TEXT",
|
"affinity": "TEXT",
|
||||||
"notNull": true
|
"notNull": true
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"fieldPath": "deviceId",
|
|
||||||
"columnName": "deviceId",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"fieldPath": "identityKey",
|
"fieldPath": "identityKey",
|
||||||
"columnName": "identityKey",
|
"columnName": "identityKey",
|
||||||
|
@ -479,15 +473,25 @@
|
||||||
},
|
},
|
||||||
"indices": [
|
"indices": [
|
||||||
{
|
{
|
||||||
"name": "index_axolotl_identity_accountId_address_deviceId",
|
"name": "index_axolotl_identity_accountId_address_identityKey",
|
||||||
"unique": true,
|
"unique": true,
|
||||||
"columnNames": [
|
"columnNames": [
|
||||||
"accountId",
|
"accountId",
|
||||||
"address",
|
"address",
|
||||||
"deviceId"
|
"identityKey"
|
||||||
],
|
],
|
||||||
"orders": [],
|
"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": [
|
"foreignKeys": [
|
||||||
|
@ -2376,7 +2380,7 @@
|
||||||
"views": [],
|
"views": [],
|
||||||
"setupQueries": [
|
"setupQueries": [
|
||||||
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
|
"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')"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -427,6 +427,8 @@ public class MessageTransformationTest {
|
||||||
Assert.assertEquals(1L, embeddedMessage.contents.size());
|
Assert.assertEquals(1L, embeddedMessage.contents.size());
|
||||||
Assert.assertEquals(
|
Assert.assertEquals(
|
||||||
"Hi. How are you?", Iterables.getOnlyElement(embeddedMessage.contents).body);
|
"Hi. How are you?", Iterables.getOnlyElement(embeddedMessage.contents).body);
|
||||||
|
Assert.assertNull(response.identityKey);
|
||||||
|
Assert.assertNull(response.trust);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -50,13 +50,7 @@ public class AxolotlDatabaseStore extends AbstractAccountService implements Sign
|
||||||
} else {
|
} else {
|
||||||
trust = Trust.TRUSTED;
|
trust = Trust.TRUSTED;
|
||||||
}
|
}
|
||||||
return axolotlDao()
|
return axolotlDao().setIdentity(account, address.getJid(), identityKey, trust);
|
||||||
.setIdentity(
|
|
||||||
account,
|
|
||||||
address.getJid(),
|
|
||||||
address.getDeviceId(),
|
|
||||||
identityKey,
|
|
||||||
trust);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -127,12 +127,11 @@ public abstract class AxolotlDao {
|
||||||
public boolean setIdentity(
|
public boolean setIdentity(
|
||||||
final Account account,
|
final Account account,
|
||||||
final BareJid address,
|
final BareJid address,
|
||||||
final int deviceId,
|
|
||||||
final IdentityKey identityKey,
|
final IdentityKey identityKey,
|
||||||
final Trust trust) {
|
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)) {
|
if (existing == null || !existing.equals(identityKey)) {
|
||||||
insert(AxolotlIdentityEntity.of(account, address, deviceId, identityKey, trust));
|
insert(AxolotlIdentityEntity.of(account, address, identityKey, trust));
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
@ -155,8 +154,9 @@ public abstract class AxolotlDao {
|
||||||
|
|
||||||
@Query(
|
@Query(
|
||||||
"SELECT identityKey FROM AXOLOTL_IDENTITY WHERE accountId=:account AND"
|
"SELECT identityKey FROM AXOLOTL_IDENTITY WHERE accountId=:account AND"
|
||||||
+ " address=:address AND deviceId=:deviceId")
|
+ " address=:address AND identityKey=:identityKey")
|
||||||
protected abstract IdentityKey getIdentityKey(long account, BareJid address, int deviceId);
|
protected abstract IdentityKey getIdentityKey(
|
||||||
|
long account, BareJid address, IdentityKey identityKey);
|
||||||
|
|
||||||
@Query(
|
@Query(
|
||||||
"SELECT preKeyRecord FROM axolotl_pre_key WHERE accountId=:account AND"
|
"SELECT preKeyRecord FROM axolotl_pre_key WHERE accountId=:account AND"
|
||||||
|
|
|
@ -422,10 +422,12 @@ public abstract class MessageDao {
|
||||||
@Query(
|
@Query(
|
||||||
"SELECT message.id as"
|
"SELECT message.id as"
|
||||||
+ " id,sentAt,outgoing,toBare,toResource,fromBare,fromResource,modification,latestVersion"
|
+ " id,sentAt,outgoing,toBare,toResource,fromBare,fromResource,modification,latestVersion"
|
||||||
+ " as version,inReplyToMessageEntityId,encryption,identityKey FROM message JOIN"
|
+ " as version,inReplyToMessageEntityId,encryption,message_version.identityKey,trust"
|
||||||
+ " message_version ON message.latestVersion=message_version.id WHERE"
|
+ " FROM chat JOIN message on message.chatId=chat.id JOIN message_version ON"
|
||||||
+ " message.chatId=:chatId AND latestVersion IS NOT NULL ORDER BY"
|
+ " message.latestVersion=message_version.id LEFT JOIN axolotl_identity ON"
|
||||||
+ " message.receivedAt")
|
+ " 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 abstract List<MessageWithContentReactions> getMessages(long chatId);
|
||||||
|
|
||||||
public void setInReplyTo(
|
public void setInReplyTo(
|
||||||
|
|
|
@ -20,8 +20,11 @@ import org.whispersystems.libsignal.IdentityKey;
|
||||||
onDelete = ForeignKey.CASCADE),
|
onDelete = ForeignKey.CASCADE),
|
||||||
indices = {
|
indices = {
|
||||||
@Index(
|
@Index(
|
||||||
value = {"accountId", "address", "deviceId"},
|
value = {"accountId", "address", "identityKey"},
|
||||||
unique = true)
|
unique = true),
|
||||||
|
@Index(
|
||||||
|
value = {"accountId", "identityKey"},
|
||||||
|
unique = false)
|
||||||
})
|
})
|
||||||
public class AxolotlIdentityEntity {
|
public class AxolotlIdentityEntity {
|
||||||
|
|
||||||
|
@ -32,18 +35,18 @@ public class AxolotlIdentityEntity {
|
||||||
|
|
||||||
@NonNull public BareJid address;
|
@NonNull public BareJid address;
|
||||||
|
|
||||||
@NonNull public Integer deviceId;
|
|
||||||
|
|
||||||
@NonNull public IdentityKey identityKey;
|
@NonNull public IdentityKey identityKey;
|
||||||
|
|
||||||
@NonNull public Trust trust;
|
@NonNull public Trust trust;
|
||||||
|
|
||||||
public static AxolotlIdentityEntity of(
|
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();
|
final var entity = new AxolotlIdentityEntity();
|
||||||
entity.accountId = account.id;
|
entity.accountId = account.id;
|
||||||
entity.address = address;
|
entity.address = address;
|
||||||
entity.deviceId = deviceId;
|
|
||||||
entity.identityKey = identityKey;
|
entity.identityKey = identityKey;
|
||||||
entity.trust = trust;
|
entity.trust = trust;
|
||||||
return entity;
|
return entity;
|
||||||
|
|
|
@ -34,6 +34,7 @@ public class MessageWithContentReactions {
|
||||||
public Long inReplyToMessageEntityId;
|
public Long inReplyToMessageEntityId;
|
||||||
public Encryption encryption;
|
public Encryption encryption;
|
||||||
public IdentityKey identityKey;
|
public IdentityKey identityKey;
|
||||||
|
public Trust trust;
|
||||||
|
|
||||||
@Relation(
|
@Relation(
|
||||||
entity = MessageEntity.class,
|
entity = MessageEntity.class,
|
||||||
|
|
Loading…
Reference in a new issue