Skip to content

Commit

Permalink
Merge pull request #1928 from nextcloud/ai-summary-fixes
Browse files Browse the repository at this point in the history
Ai summary fixes
  • Loading branch information
Ivansss authored Jan 9, 2025
2 parents 7936167 + fdb1cf3 commit c324484
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
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

0 comments on commit c324484

Please sign in to comment.