Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.astralquarks.notes.repository

import com.astralquarks.notes.auth.AuthManager
import com.astralquarks.notes.db.NoteDao
import com.astralquarks.notes.util.WebShareManager
import com.astralquarks.notes.model.Note
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
Expand Down Expand Up @@ -83,6 +84,7 @@ class NoteRepository(
if (authManager.isSignedIn) {
repositoryScope.launch {
authManager.deleteNoteFromFirestore(noteId)
WebShareManager.revokeSharesForNote(noteId)
}
}
}
Expand All @@ -94,6 +96,7 @@ class NoteRepository(
repositoryScope.launch {
trashNotes.forEach { note ->
authManager.deleteNoteFromFirestore(note.id)
WebShareManager.revokeSharesForNote(note.id)
}
}
}
Expand Down
20 changes: 20 additions & 0 deletions app/src/main/java/com/astralquarks/notes/util/WebShareManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,24 @@ object WebShareManager {
false
}
}

suspend fun revokeSharesForNote(noteId: String) = withContext(Dispatchers.IO) {
val auth = FirebaseAuth.getInstance()
val uid = auth.currentUser?.uid ?: return@withContext

try {
val firestore = FirebaseFirestore.getInstance()
val snapshot = firestore.collection("shares")
.whereEqualTo("ownerUid", uid)
.whereEqualTo("noteId", noteId)
.get()
.await()

for (doc in snapshot.documents) {
doc.reference.delete().await()
}
} catch (e: Exception) {
// Ignore failure
}
}
}