Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ai summary fixes #1928

Merged
merged 2 commits into from
Jan 9, 2025
Merged
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
22 changes: 14 additions & 8 deletions NextcloudTalk/ChatViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1407,7 +1407,7 @@ import SwiftyAttributes

// MARK: - ChatMessageTableViewCellDelegate delegate

override public func cellDidSelectedReaction(_ reaction: NCChatReaction!, for message: NCChatMessage!) {
override public func cellDidSelectedReaction(_ reaction: NCChatReaction!, for message: NCChatMessage) {
self.addOrRemoveReaction(reaction: reaction, in: message)
}

Expand All @@ -1432,19 +1432,25 @@ import SwiftyAttributes
return
}

if status == .noMessagesFound {
NotificationPresenter.shared().present(text: NSLocalizedString("No messages found to summarize", comment: ""), dismissAfterDelay: 7.0, includedStyle: .error)
return
}

guard let taskId, status != .failed else {
NotificationPresenter.shared().present(text: NSLocalizedString("Generating summary of unread messages failed", comment: ""), dismissAfterDelay: 7.0, includedStyle: .error)
return
}

AiSummaryController.shared.addSummaryTaskId(forRoomInternalId: self.room.internalId, withTaskId: taskId)
let hasRunningAiSummaryTasks = !AiSummaryController.shared.getSummaryTaskIds(forRoomInternalId: self.room.internalId).isEmpty

print("Scheduled summary task with taskId \(taskId) and nextOffset \(String(describing: nextOffset))")
// No messages to summarize found, no previous tasks running and no more messages -> Nothing we can do, stop here
if status == .noMessagesFound, !hasRunningAiSummaryTasks, nextOffset == nil {
NotificationPresenter.shared().present(text: NSLocalizedString("No messages found to summarize", comment: ""), dismissAfterDelay: 7.0, includedStyle: .error)
return
}

// We might end up here with a status of "noMessagesFound". That can happen if we have previous running tasks, or got a nextOffset.
// Therefore we explictly check for "success" to only track tasks that were successfully submitted with messages
if status == .success {
AiSummaryController.shared.addSummaryTaskId(forRoomInternalId: self.room.internalId, withTaskId: taskId)
print("Scheduled summary task with taskId \(taskId) and nextOffset \(String(describing: nextOffset))")
}

// Add a safe-guard to make sure there's really a nextOffset. Otherwise we might end up requesting the same task over and over again
if let nextOffset, nextOffset > messageId {
Expand Down
1 change: 1 addition & 0 deletions NextcloudTalk/NCAPIControllerExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ import Foundation

if ocsError?.responseStatusCode == 500, let error = ocsError?.dataDict?["error"] as? String, error == "ai-no-provider" {
completionBlock(.noAiProvider, nil, nil)
return
}

guard let dict = ocsResponse?.dataDict as? [String: Int] else {
Expand Down
Loading