Skip to content

Commit

Permalink
Deletes all user information after account is removed
Browse files Browse the repository at this point in the history
Signed-off-by: rapterjet2004 <juliuslinus1@gmail.com>
  • Loading branch information
rapterjet2004 committed Jul 24, 2024
1 parent a613434 commit ffb471f
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,12 @@ interface ChatBlocksDao {

@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun upsertChatBlock(chatBlock: ChatBlockEntity)

@Query(
"""
DELETE FROM ChatBlocks
WHERE internalConversationId LIKE :pattern
"""
)
fun clearChatBlocksForUser(pattern: String)
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,12 @@ interface ChatMessagesDao {
"""
)
fun getCountBetweenMessageIds(internalConversationId: String, oldestMessageId: Long, newestMessageId: Long): Int

@Query(
"""
DELETE FROM chatmessages
WHERE internalId LIKE :pattern
"""
)
fun clearAllMessagesForUser(pattern: String)
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,12 @@ interface ConversationsDao {

@Update
fun updateConversation(conversationEntity: ConversationEntity)

@Query(
"""
DELETE FROM conversations
WHERE internalId LIKE :pattern
"""
)
fun clearAllConversationsForUser(pattern: String)
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
import com.nextcloud.talk.api.NcApi;
import com.nextcloud.talk.application.NextcloudTalkApplication;
import com.nextcloud.talk.arbitrarystorage.ArbitraryStorageManager;
import com.nextcloud.talk.data.database.dao.ChatBlocksDao;
import com.nextcloud.talk.data.database.dao.ChatMessagesDao;
import com.nextcloud.talk.data.database.dao.ConversationsDao;
import com.nextcloud.talk.data.user.model.User;
import com.nextcloud.talk.models.json.generic.GenericMeta;
import com.nextcloud.talk.models.json.generic.GenericOverall;
Expand Down Expand Up @@ -46,17 +49,19 @@
public class AccountRemovalWorker extends Worker {
public static final String TAG = "AccountRemovalWorker";

@Inject
UserManager userManager;
@Inject UserManager userManager;

@Inject
ArbitraryStorageManager arbitraryStorageManager;
@Inject ArbitraryStorageManager arbitraryStorageManager;

@Inject
Retrofit retrofit;
@Inject Retrofit retrofit;

@Inject
OkHttpClient okHttpClient;
@Inject OkHttpClient okHttpClient;

@Inject ChatMessagesDao chatMessagesDao;

@Inject ConversationsDao conversationsDao;

@Inject ChatBlocksDao chatBlocksDao;

NcApi ncApi;

Expand Down Expand Up @@ -177,13 +182,22 @@ private void initiateUserDeletion(User user) {

try {
arbitraryStorageManager.deleteAllEntriesForAccountIdentifier(user.getId());
deleteAllUserInfo(user);
deleteUser(user);
} catch (Throwable e) {
Log.e(TAG, "error while trying to delete All Entries For Account Identifier", e);
}
}
}

private void deleteAllUserInfo(User user) {
String accountId = Objects.requireNonNull(user.getId()).toString();
String pattern = accountId + "@%"; // ... LIKE "<accountId>@%"
chatMessagesDao.clearAllMessagesForUser(pattern);
conversationsDao.clearAllConversationsForUser(pattern);
chatBlocksDao.clearChatBlocksForUser(pattern);
}

private void deleteUser(User user) {
if (user.getId() != null) {
String username = user.getUsername();
Expand Down

0 comments on commit ffb471f

Please sign in to comment.