mv-experiment #1

Merged
fmodf merged 88 commits from mv-experiment into develop 2024-09-03 15:13:59 +00:00
4 changed files with 33 additions and 28 deletions
Showing only changes of commit 2890a6cd6d - Show all commits

View file

@ -72,9 +72,33 @@ extension Roster {
}
extension Roster {
static func fetchDeletedLocally() async throws -> [Roster] {
try await Database.shared.dbQueue.read { db in
try Roster.filter(Column("locallyDeleted") == true).fetchAll(db)
static var allDeletedLocally: [Roster] {
get async {
do {
let rosters = try await Database.shared.dbQueue.read { db in
try Roster
.filter(Column("locallyDeleted") == true)
.fetchAll(db)
}
return rosters
} catch {
return []
}
}
}
static var allActive: [Roster] {
get async {
do {
let rosters = try await Database.shared.dbQueue.read { db in
try Roster
.filter(Column("locallyDeleted") == false)
.fetchAll(db)
}
return rosters
} catch {
return []
}
}
}
}

View file

@ -100,7 +100,7 @@ extension ClientsStore {
func addRoster(_ credentials: Credentials, contactJID: String, name: String?, groups: [String]) async throws {
// check that roster exist in db as locally deleted and undelete it
let deletedLocally = try await Roster.fetchDeletedLocally()
let deletedLocally = await Roster.allDeletedLocally
if var roster = deletedLocally.first(where: { $0.contactBareJid == contactJID }) {
try await roster.setLocallyDeleted(false)
return

View file

@ -5,7 +5,7 @@ import GRDB
import Photos
@MainActor
final class ConversationStore: ObservableObject {
final class MessagesStore: ObservableObject {
@Published private(set) var messages: [Message] = []
@Published var replyText = ""
@ -21,7 +21,7 @@ final class ConversationStore: ObservableObject {
}
}
extension ConversationStore {
extension MessagesStore {
func sendMessage(_ message: String) {
Task {
var msg = Message.blank
@ -49,24 +49,7 @@ extension ConversationStore {
}
}
extension ConversationStore {
var contacts: [Roster] {
get async {
do {
let rosters = try await Database.shared.dbQueue.read { db in
try Roster
.filter(Column("locallyDeleted") == false)
.fetchAll(db)
}
return rosters
} catch {
return []
}
}
}
}
private extension ConversationStore {
private extension MessagesStore {
func subscribe() {
messagesCancellable = ValueObservation.tracking(Message
.filter(

View file

@ -42,15 +42,13 @@ struct ContactsPickerView: View {
.clipped()
.onTapGesture {
if let selectedContact = selectedContact {
Task {
await conversation.sendContact(selectedContact.contactBareJid)
}
conversation.sendContact(selectedContact.contactBareJid)
router.dismissEnvironment()
}
}
}
.task {
rosters = await conversation.contacts
rosters = await Roster.allActive
}
}
}