wip
This commit is contained in:
parent
b97c8991bf
commit
2890a6cd6d
|
@ -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 []
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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(
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue