adds the ability to rename chats
This commit is contained in:
@@ -851,6 +851,40 @@ final class SybilViewModel {
|
||||
}
|
||||
}
|
||||
|
||||
func renameChat(chatID: String, title: String) async {
|
||||
guard isAuthenticated else {
|
||||
return
|
||||
}
|
||||
|
||||
let trimmedTitle = title.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
guard !trimmedTitle.isEmpty else {
|
||||
errorMessage = "Enter a chat title."
|
||||
return
|
||||
}
|
||||
|
||||
SybilLog.info(SybilLog.ui, "Renaming chat \(chatID)")
|
||||
errorMessage = nil
|
||||
|
||||
do {
|
||||
let updated = try await client().updateChatTitle(chatID: chatID, title: trimmedTitle)
|
||||
chats.removeAll(where: { $0.id == updated.id })
|
||||
chats.insert(updated, at: 0)
|
||||
upsertWorkspaceChat(updated)
|
||||
|
||||
if selectedChat?.id == updated.id {
|
||||
selectedChat?.title = updated.title
|
||||
selectedChat?.updatedAt = updated.updatedAt
|
||||
selectedChat?.initiatedProvider = updated.initiatedProvider
|
||||
selectedChat?.initiatedModel = updated.initiatedModel
|
||||
selectedChat?.lastUsedProvider = updated.lastUsedProvider
|
||||
selectedChat?.lastUsedModel = updated.lastUsedModel
|
||||
}
|
||||
} catch {
|
||||
errorMessage = normalizeAPIError(error)
|
||||
SybilLog.error(SybilLog.ui, "Rename failed", error: error)
|
||||
}
|
||||
}
|
||||
|
||||
func refreshAfterSettingsChange() async {
|
||||
SybilLog.info(SybilLog.ui, "Settings changed, reconnecting")
|
||||
settings.persist()
|
||||
|
||||
Reference in New Issue
Block a user