mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-19 03:29:28 +01:00
remove dao methods to delete data when user is removed
...will be done by foreign keys cascading. Therefore, also added foreign key to ChatBlockEntity Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
parent
e951b3d53a
commit
da04f536f7
@ -2,7 +2,7 @@
|
|||||||
"formatVersion": 1,
|
"formatVersion": 1,
|
||||||
"database": {
|
"database": {
|
||||||
"version": 10,
|
"version": 10,
|
||||||
"identityHash": "1b97b7e937102e4087f8534f1204fe94",
|
"identityHash": "c07a2543aa583e08e7b3208f44fcc7ac",
|
||||||
"entities": [
|
"entities": [
|
||||||
{
|
{
|
||||||
"tableName": "User",
|
"tableName": "User",
|
||||||
@ -138,7 +138,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"tableName": "Conversations",
|
"tableName": "Conversations",
|
||||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`internalId` TEXT NOT NULL, `accountId` INTEGER, `token` TEXT, `name` TEXT, `displayName` TEXT, `description` TEXT, `type` TEXT, `lastPing` INTEGER NOT NULL, `participantType` TEXT, `hasPassword` INTEGER NOT NULL, `sessionId` TEXT, `actorId` TEXT, `actorType` TEXT, `isFavorite` INTEGER NOT NULL, `lastActivity` INTEGER NOT NULL, `unreadMessages` INTEGER NOT NULL, `unreadMention` INTEGER NOT NULL, `lastMessageJson` TEXT, `objectType` TEXT, `notificationLevel` TEXT, `readOnly` TEXT, `lobbyState` TEXT, `lobbyTimer` INTEGER, `lastReadMessage` INTEGER NOT NULL, `lastCommonReadMessage` INTEGER NOT NULL, `hasCall` INTEGER NOT NULL, `callFlag` INTEGER NOT NULL, `canStartCall` INTEGER NOT NULL, `canLeaveConversation` INTEGER, `canDeleteConversation` INTEGER, `unreadMentionDirect` INTEGER, `notificationCalls` INTEGER, `permissions` INTEGER NOT NULL, `messageExpiration` INTEGER NOT NULL, `status` TEXT, `statusIcon` TEXT, `statusMessage` TEXT, `statusClearAt` INTEGER, `callRecording` INTEGER NOT NULL, `avatarVersion` TEXT, `isCustomAvatar` INTEGER, `callStartTime` INTEGER, `recordingConsent` INTEGER NOT NULL, `remoteServer` TEXT, `remoteToken` TEXT, PRIMARY KEY(`internalId`), FOREIGN KEY(`accountId`) REFERENCES `User`(`id`) ON UPDATE CASCADE ON DELETE CASCADE )",
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`internalId` TEXT NOT NULL, `accountId` INTEGER NOT NULL, `token` TEXT, `name` TEXT, `displayName` TEXT, `description` TEXT, `type` TEXT, `lastPing` INTEGER NOT NULL, `participantType` TEXT, `hasPassword` INTEGER NOT NULL, `sessionId` TEXT, `actorId` TEXT, `actorType` TEXT, `isFavorite` INTEGER NOT NULL, `lastActivity` INTEGER NOT NULL, `unreadMessages` INTEGER NOT NULL, `unreadMention` INTEGER NOT NULL, `lastMessageJson` TEXT, `objectType` TEXT, `notificationLevel` TEXT, `readOnly` TEXT, `lobbyState` TEXT, `lobbyTimer` INTEGER, `lastReadMessage` INTEGER NOT NULL, `lastCommonReadMessage` INTEGER NOT NULL, `hasCall` INTEGER NOT NULL, `callFlag` INTEGER NOT NULL, `canStartCall` INTEGER NOT NULL, `canLeaveConversation` INTEGER, `canDeleteConversation` INTEGER, `unreadMentionDirect` INTEGER, `notificationCalls` INTEGER, `permissions` INTEGER NOT NULL, `messageExpiration` INTEGER NOT NULL, `status` TEXT, `statusIcon` TEXT, `statusMessage` TEXT, `statusClearAt` INTEGER, `callRecording` INTEGER NOT NULL, `avatarVersion` TEXT, `isCustomAvatar` INTEGER, `callStartTime` INTEGER, `recordingConsent` INTEGER NOT NULL, `remoteServer` TEXT, `remoteToken` TEXT, PRIMARY KEY(`internalId`), FOREIGN KEY(`accountId`) REFERENCES `User`(`id`) ON UPDATE CASCADE ON DELETE CASCADE )",
|
||||||
"fields": [
|
"fields": [
|
||||||
{
|
{
|
||||||
"fieldPath": "internalId",
|
"fieldPath": "internalId",
|
||||||
@ -150,7 +150,7 @@
|
|||||||
"fieldPath": "accountId",
|
"fieldPath": "accountId",
|
||||||
"columnName": "accountId",
|
"columnName": "accountId",
|
||||||
"affinity": "INTEGER",
|
"affinity": "INTEGER",
|
||||||
"notNull": false
|
"notNull": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldPath": "token",
|
"fieldPath": "token",
|
||||||
@ -633,7 +633,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"tableName": "ChatBlocks",
|
"tableName": "ChatBlocks",
|
||||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `internalConversationId` TEXT NOT NULL, `oldestMessageId` INTEGER NOT NULL, `newestMessageId` INTEGER NOT NULL, `hasHistory` INTEGER NOT NULL)",
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `internalConversationId` TEXT NOT NULL, `accountId` INTEGER, `token` TEXT, `oldestMessageId` INTEGER NOT NULL, `newestMessageId` INTEGER NOT NULL, `hasHistory` INTEGER NOT NULL, FOREIGN KEY(`internalConversationId`) REFERENCES `Conversations`(`internalId`) ON UPDATE CASCADE ON DELETE CASCADE )",
|
||||||
"fields": [
|
"fields": [
|
||||||
{
|
{
|
||||||
"fieldPath": "id",
|
"fieldPath": "id",
|
||||||
@ -647,6 +647,18 @@
|
|||||||
"affinity": "TEXT",
|
"affinity": "TEXT",
|
||||||
"notNull": true
|
"notNull": true
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "accountId",
|
||||||
|
"columnName": "accountId",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "token",
|
||||||
|
"columnName": "token",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": false
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"fieldPath": "oldestMessageId",
|
"fieldPath": "oldestMessageId",
|
||||||
"columnName": "oldestMessageId",
|
"columnName": "oldestMessageId",
|
||||||
@ -673,13 +685,25 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"indices": [],
|
"indices": [],
|
||||||
"foreignKeys": []
|
"foreignKeys": [
|
||||||
|
{
|
||||||
|
"table": "Conversations",
|
||||||
|
"onDelete": "CASCADE",
|
||||||
|
"onUpdate": "CASCADE",
|
||||||
|
"columns": [
|
||||||
|
"internalConversationId"
|
||||||
|
],
|
||||||
|
"referencedColumns": [
|
||||||
|
"internalId"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"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, '1b97b7e937102e4087f8534f1204fe94')"
|
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'c07a2543aa583e08e7b3208f44fcc7ac')"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -421,6 +421,8 @@ class OfflineFirstChatRepository @Inject constructor(
|
|||||||
|
|
||||||
val newChatBlock = ChatBlockEntity(
|
val newChatBlock = ChatBlockEntity(
|
||||||
internalConversationId = internalConversationId,
|
internalConversationId = internalConversationId,
|
||||||
|
accountId = conversationModel.accountId,
|
||||||
|
token = conversationModel.token,
|
||||||
oldestMessageId = oldestMessageIdForNewChatBlock,
|
oldestMessageId = oldestMessageIdForNewChatBlock,
|
||||||
newestMessageId = newestMessageIdForNewChatBlock,
|
newestMessageId = newestMessageIdForNewChatBlock,
|
||||||
hasHistory = hasHistory
|
hasHistory = hasHistory
|
||||||
@ -531,6 +533,8 @@ class OfflineFirstChatRepository @Inject constructor(
|
|||||||
|
|
||||||
val newChatBlock = ChatBlockEntity(
|
val newChatBlock = ChatBlockEntity(
|
||||||
internalConversationId = internalConversationId,
|
internalConversationId = internalConversationId,
|
||||||
|
accountId = conversationModel.accountId,
|
||||||
|
token = conversationModel.token,
|
||||||
oldestMessageId = oldestIdFromDbChatBlocks,
|
oldestMessageId = oldestIdFromDbChatBlocks,
|
||||||
newestMessageId = newestIdFromDbChatBlocks,
|
newestMessageId = newestIdFromDbChatBlocks,
|
||||||
hasHistory = hasHistory
|
hasHistory = hasHistory
|
||||||
|
@ -16,6 +16,7 @@ import com.nextcloud.talk.models.json.conversations.Conversation
|
|||||||
fun ConversationModel.asEntity() =
|
fun ConversationModel.asEntity() =
|
||||||
ConversationEntity(
|
ConversationEntity(
|
||||||
internalId = internalId,
|
internalId = internalId,
|
||||||
|
accountId = accountId,
|
||||||
token = token,
|
token = token,
|
||||||
name = name,
|
name = name,
|
||||||
displayName = displayName,
|
displayName = displayName,
|
||||||
@ -64,6 +65,7 @@ fun ConversationModel.asEntity() =
|
|||||||
fun ConversationEntity.asModel() =
|
fun ConversationEntity.asModel() =
|
||||||
ConversationModel(
|
ConversationModel(
|
||||||
internalId = internalId,
|
internalId = internalId,
|
||||||
|
accountId = accountId,
|
||||||
token = token,
|
token = token,
|
||||||
name = name,
|
name = name,
|
||||||
displayName = displayName,
|
displayName = displayName,
|
||||||
|
@ -12,18 +12,24 @@ import androidx.room.Entity
|
|||||||
import androidx.room.PrimaryKey
|
import androidx.room.PrimaryKey
|
||||||
|
|
||||||
@Entity(
|
@Entity(
|
||||||
tableName = "ChatBlocks"
|
tableName = "ChatBlocks",
|
||||||
// indices = [
|
foreignKeys = [
|
||||||
// androidx.room.Index(value = ["accountId"])
|
androidx.room.ForeignKey(
|
||||||
// ]
|
entity = ConversationEntity::class,
|
||||||
|
parentColumns = arrayOf("internalId"),
|
||||||
|
childColumns = arrayOf("internalConversationId"),
|
||||||
|
onDelete = androidx.room.ForeignKey.CASCADE,
|
||||||
|
onUpdate = androidx.room.ForeignKey.CASCADE
|
||||||
|
)
|
||||||
|
],
|
||||||
)
|
)
|
||||||
data class ChatBlockEntity(
|
data class ChatBlockEntity(
|
||||||
@PrimaryKey(autoGenerate = true)
|
@PrimaryKey(autoGenerate = true)
|
||||||
@ColumnInfo(name = "id") var id: Int = 0,
|
@ColumnInfo(name = "id") var id: Long = 0,
|
||||||
// accountId@token
|
// accountId@token
|
||||||
@ColumnInfo(name = "internalConversationId") var internalConversationId: String,
|
@ColumnInfo(name = "internalConversationId") var internalConversationId: String,
|
||||||
// @ColumnInfo(name = "accountId") var accountId: Long? = null,
|
@ColumnInfo(name = "accountId") var accountId: Long? = null,
|
||||||
// @ColumnInfo(name = "token") var token: String?,
|
@ColumnInfo(name = "token") var token: String?,
|
||||||
@ColumnInfo(name = "oldestMessageId") var oldestMessageId: Long,
|
@ColumnInfo(name = "oldestMessageId") var oldestMessageId: Long,
|
||||||
@ColumnInfo(name = "newestMessageId") var newestMessageId: Long,
|
@ColumnInfo(name = "newestMessageId") var newestMessageId: Long,
|
||||||
@ColumnInfo(name = "hasHistory") var hasHistory: Boolean
|
@ColumnInfo(name = "hasHistory") var hasHistory: Boolean
|
||||||
|
@ -36,7 +36,7 @@ data class ConversationEntity(
|
|||||||
var internalId: String,
|
var internalId: String,
|
||||||
|
|
||||||
// Defines to which talk app account this conversation belongs to
|
// Defines to which talk app account this conversation belongs to
|
||||||
@ColumnInfo(name = "accountId") var accountId: Long? = null,
|
@ColumnInfo(name = "accountId") var accountId: Long,
|
||||||
|
|
||||||
// We don't use token as primary key as we have to manage multiple talk app accounts on
|
// We don't use token as primary key as we have to manage multiple talk app accounts on
|
||||||
// the phone, thus multiple accounts can have the same conversation in their list. That's why the servers
|
// the phone, thus multiple accounts can have the same conversation in their list. That's why the servers
|
||||||
|
@ -182,7 +182,6 @@ public class AccountRemovalWorker extends Worker {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
arbitraryStorageManager.deleteAllEntriesForAccountIdentifier(user.getId());
|
arbitraryStorageManager.deleteAllEntriesForAccountIdentifier(user.getId());
|
||||||
deleteAllUserInfo(user);
|
|
||||||
deleteUser(user);
|
deleteUser(user);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
Log.e(TAG, "error while trying to delete All Entries For Account Identifier", e);
|
Log.e(TAG, "error while trying to delete All Entries For Account Identifier", e);
|
||||||
@ -190,14 +189,6 @@ public class AccountRemovalWorker extends Worker {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void deleteAllUserInfo(User user) {
|
|
||||||
String accountId = Objects.requireNonNull(user.getId()).toString();
|
|
||||||
String pattern = accountId + "@%"; // ... LIKE "<accountId>@%"
|
|
||||||
chatMessagesDao.clearAllMessagesForUser(pattern);
|
|
||||||
conversationsDao.clearAllConversationsForUser(user.getId());
|
|
||||||
chatBlocksDao.clearChatBlocksForUser(pattern);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void deleteUser(User user) {
|
private void deleteUser(User user) {
|
||||||
if (user.getId() != null) {
|
if (user.getId() != null) {
|
||||||
String username = user.getUsername();
|
String username = user.getUsername();
|
||||||
|
@ -15,6 +15,7 @@ import com.nextcloud.talk.models.json.participants.Participant
|
|||||||
|
|
||||||
class ConversationModel(
|
class ConversationModel(
|
||||||
var internalId: String,
|
var internalId: String,
|
||||||
|
var accountId: Long,
|
||||||
var roomId: String? = null,
|
var roomId: String? = null,
|
||||||
var token: String? = null,
|
var token: String? = null,
|
||||||
var name: String? = null,
|
var name: String? = null,
|
||||||
@ -32,7 +33,6 @@ class ConversationModel(
|
|||||||
var lastActivity: Long = 0,
|
var lastActivity: Long = 0,
|
||||||
var unreadMessages: Int = 0,
|
var unreadMessages: Int = 0,
|
||||||
var unreadMention: Boolean = false,
|
var unreadMention: Boolean = false,
|
||||||
// var lastMessageViaConversationList: LastMessageJson? = null,
|
|
||||||
var lastMessageViaConversationList: ChatMessageJson? = null,
|
var lastMessageViaConversationList: ChatMessageJson? = null,
|
||||||
var objectType: ConversationEnums.ObjectType? = null,
|
var objectType: ConversationEnums.ObjectType? = null,
|
||||||
var notificationLevel: ConversationEnums.NotificationLevel? = null,
|
var notificationLevel: ConversationEnums.NotificationLevel? = null,
|
||||||
@ -67,6 +67,7 @@ class ConversationModel(
|
|||||||
fun mapToConversationModel(conversation: Conversation, user: User): ConversationModel {
|
fun mapToConversationModel(conversation: Conversation, user: User): ConversationModel {
|
||||||
return ConversationModel(
|
return ConversationModel(
|
||||||
internalId = user.id!!.toString() + "@" + conversation.token,
|
internalId = user.id!!.toString() + "@" + conversation.token,
|
||||||
|
accountId = user.id!!,
|
||||||
roomId = conversation.roomId,
|
roomId = conversation.roomId,
|
||||||
token = conversation.token,
|
token = conversation.token,
|
||||||
name = conversation.name,
|
name = conversation.name,
|
||||||
|
Loading…
Reference in New Issue
Block a user