autosyncing, appearance tweaks
This commit is contained in:
@@ -14,17 +14,27 @@ struct ConversationListView: View
|
||||
|
||||
var body: some View {
|
||||
List($model.conversations, selection: $model.selectedConversations) { conv in
|
||||
VStack(alignment: .leading) {
|
||||
Text(conv.wrappedValue.displayName)
|
||||
.bold()
|
||||
let isUnread = conv.wrappedValue.unreadCount > 0
|
||||
|
||||
HStack(spacing: 0.0) {
|
||||
Image(systemName: isUnread ? "circlebadge.fill" : "")
|
||||
.foregroundStyle(.tint)
|
||||
.frame(width: 10.0)
|
||||
|
||||
Text(conv.wrappedValue.messagePreview)
|
||||
VStack(alignment: .leading) {
|
||||
Text(conv.wrappedValue.displayName)
|
||||
.bold()
|
||||
|
||||
Text(conv.wrappedValue.messagePreview)
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
.padding(8.0)
|
||||
}
|
||||
.id(conv.id)
|
||||
.padding(8.0)
|
||||
}
|
||||
.listStyle(.sidebar)
|
||||
.task { await watchForConversationListChanges() }
|
||||
.task { await model.triggerSync() }
|
||||
}
|
||||
|
||||
private func watchForConversationListChanges() async {
|
||||
@@ -33,9 +43,9 @@ struct ConversationListView: View
|
||||
case .conversationsUpdated:
|
||||
model.setNeedsReload()
|
||||
case .messagesUpdated(_):
|
||||
model.setNeedsReload()
|
||||
await model.triggerSync()
|
||||
case .updateStreamReconnected:
|
||||
model.setNeedsReload()
|
||||
await model.triggerSync()
|
||||
default:
|
||||
break
|
||||
}
|
||||
@@ -51,6 +61,7 @@ struct ConversationListView: View
|
||||
var selectedConversations: Set<Display.Conversation.ID>
|
||||
|
||||
private var needsReload: Bool = true
|
||||
private let client = XPCClient()
|
||||
|
||||
public init(conversations: [Display.Conversation] = []) {
|
||||
self.conversations = conversations
|
||||
@@ -58,6 +69,14 @@ struct ConversationListView: View
|
||||
setNeedsReload()
|
||||
}
|
||||
|
||||
func triggerSync() async {
|
||||
do {
|
||||
try await client.syncConversationList()
|
||||
} catch {
|
||||
print("Conversation List Sync Error: \(error)")
|
||||
}
|
||||
}
|
||||
|
||||
func setNeedsReload() {
|
||||
needsReload = true
|
||||
Task { @MainActor [weak self] in
|
||||
@@ -71,7 +90,7 @@ struct ConversationListView: View
|
||||
needsReload = false
|
||||
|
||||
do {
|
||||
let client = XPCClient()
|
||||
|
||||
let clientConversations = try await client.getConversations()
|
||||
.map { Display.Conversation(from: $0) }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user