@@ -42,6 +42,8 @@ final class Jobs {
4242 private func refresh ( ) { app . refresh ( ) }
4343
4444 var pending : [ Recording ] = [ ]
45+ /// Recordings saved as meetings without checking who's who, whose voices can still be named.
46+ var unchecked : [ Recording ] = [ ]
4547 var progress : [ String : JobProgress ] = [ : ]
4648 /// Meetings whose summary is being written now, and why the last attempt failed, by path.
4749 var summarising = Set < String > ( )
@@ -50,6 +52,11 @@ final class Jobs {
5052 var regenerating : [ String : SummaryPart ] = [ : ]
5153 /// Where each meeting being summarised lives now: it can be renamed or moved while the model writes.
5254 private var summaryJobs : [ UUID : String ] = [ : ]
55+ /// Summaries being written of a transcript that has since had its voices named (a meeting saved
56+ /// without checking who's who): what the model is writing has the old names, so it's asked again.
57+ private var staleSummaries = Set < UUID > ( )
58+ /// Jobs regenerating a meeting's to-dos that are followed by its summary: a voice was left out meanwhile.
59+ private var summaryAgain = Set < UUID > ( )
5360 var reviewDrafts : [ String : ReviewDraft ] = [ : ]
5461 /// Meetings whose to-dos couldn't be read from the model's reply, and why, by path.
5562 var todoProblems : [ String : String ] = [ : ]
@@ -128,6 +135,71 @@ final class Jobs {
128135 return
129136 }
130137 if let outcome { apply ( id , outcome ) }
138+ // Settings › General › After a call: saved now, rather than waiting under Needs review.
139+ if outcome ? . done == true , config . afterCall != . review { autoSave ( id ) }
140+ }
141+ }
142+
143+ /// Saves a processed recording as a meeting without stopping at who's who: a voice Oatcake
144+ /// recognised under that person's name, the rest as "Voice 1"… They can be named later from the
145+ /// meeting. If it can't be saved, it waits under Needs review as usual.
146+ private func autoSave ( _ id : String ) {
147+ guard let rec = Recordings . get ( id ) , rec . state == . processed , let analysis = try? loadAnalysis ( rec ) else { return }
148+ let folder = rec . folder ?? " "
149+ let withSummary = config . afterCall == . saveWithSummary
150+ do {
151+ let path = try saveMeeting ( config , rec , decisions : suggestedDecisions ( analysis ) , folder : folder , title : rec . title , unchecked : true )
152+ reviewDrafts . removeValue ( forKey : id )
153+ if withSummary { writeSummary ( path ) }
154+ tidySavedRecordings ( )
155+ toast ( " “ \( rec . title ) ” saved to \( folderPath ( folder ) ) " )
156+ refresh ( )
157+ // Watching it being processed: on to the meeting.
158+ if app . selection ( ) == . job ( id ) { app . select ( . meeting ( path , jump : Jump ( tab : withSummary ? . summary : . transcript ) ) ) }
159+ } catch {
160+ toast ( " Couldn’t save “ \( rec . title ) ” by itself: \( error . localizedDescription ) It’s waiting under Needs review. " , isError : true )
161+ }
162+ }
163+
164+ /// Names the voices of a meeting saved without checking: its transcript and meeting.json are
165+ /// written again in place, and the new names are put into its summary and to-dos. Returns its path.
166+ func updateMeeting ( _ rec : Recording , decisions : [ String : Decision ] ) throws -> String {
167+ guard let path = Recordings . meetingPath ( rec , meetingsRoot : config . meetingsRoot ) else {
168+ throw OatcakeError ( " The meeting saved from this recording couldn’t be found. It may have been deleted. " )
169+ }
170+ // Asked before saving: after it, what the voices were saved as is no longer on record.
171+ let leftOut = leavesOutSavedVoice ( rec , decisions )
172+ let saved = try saveMeeting ( config , rec , decisions : decisions , folder : " " , into : path )
173+ // A summary of it that's still being written was asked for with the old names.
174+ let writing = summaryJobs . filter { $0 . value == saved } . map ( \. key )
175+ staleSummaries . formUnion ( writing )
176+ // A voice left out of a meeting that has its summary already: putting new names in can't take
177+ // out what the summary says of that voice, so the summary is written again from the transcript
178+ // as it is now. One being written is read again anyway; a job that's only regenerating the
179+ // to-dos is followed by the summary.
180+ if leftOut , ( try? Meetings ( root : config . meetingsRoot ) . read ( saved ) . summary . trimmed . isEmpty ) == false {
181+ if writing . isEmpty {
182+ writeSummary ( saved , only : . summary )
183+ } else if regenerating [ saved ] == . todos {
184+ summaryAgain . formUnion ( writing )
185+ }
186+ }
187+ reviewDrafts . removeValue ( forKey : rec . id )
188+ tidySavedRecordings ( )
189+ return saved
190+ }
191+
192+ /// Keep as is: the meeting stays with the names it was saved with, and the recording's working
193+ /// folder (its analysis, voice fingerprints and clips) is cleared away.
194+ func keepAsIs ( _ id : String ) {
195+ guard let rec = unchecked . first ( where : { $0 . id == id } ) else { return }
196+ do {
197+ try Recordings . markChecked ( rec )
198+ reviewDrafts . removeValue ( forKey : id )
199+ tidySavedRecordings ( )
200+ refresh ( )
201+ } catch {
202+ toast ( error . localizedDescription , isError : true )
131203 }
132204 }
133205
@@ -211,15 +283,25 @@ final class Jobs {
211283 summaryJobs [ job ] = path
212284 let config = config
213285 Task {
286+ defer { staleSummaries . remove ( job ) }
214287 do {
215288 // What's there now: if it's changed by the time the model is done, it isn't replaced.
216- let previous = try part . map { part in
217- let files = try Meetings ( root : config . meetingsRoot ) . read ( path )
218- return part == . summary ? files . summary : files . todo
289+ @MainActor func partNow ( ) throws -> String ? {
290+ try part . map { part in
291+ let files = try Meetings ( root : config . meetingsRoot ) . read ( summaryJobs [ job ] ?? path )
292+ return part == . summary ? files . summary : files . todo
293+ }
219294 }
295+ var previous = try partNow ( )
220296 try await downloads . ensureModel ( )
221- // Where the meeting is now: it may have been renamed or moved while the model downloaded.
222- let draft = try await OatcakeCore . draftSummary ( config , meeting : summaryJobs [ job ] ?? path , only : part )
297+ var draft : SummaryDraft
298+ repeat {
299+ // The meeting's voices were named meanwhile: the transcript is read again with its new
300+ // names, and what's there now is what they were just put into.
301+ if staleSummaries . remove ( job ) != nil { previous = try partNow ( ) }
302+ // Where the meeting is now: it may have been renamed or moved while the model downloaded.
303+ draft = try await OatcakeCore . draftSummary ( config , meeting : summaryJobs [ job ] ?? path , only : part )
304+ } while staleSummaries . contains ( job )
223305 if let part , let previous {
224306 try OatcakeCore . writeRegenerated ( part , draft , config : config , meeting : summaryJobs [ job ] ?? path , previous : previous )
225307 regenerating . removeValue ( forKey : summaryJobs [ job ] ?? path )
@@ -231,8 +313,10 @@ final class Jobs {
231313 } catch {
232314 summaryErrors [ summaryJobs [ job ] ?? path ] = error . localizedDescription
233315 }
234- summarising . remove ( summaryJobs [ job ] ?? path )
316+ let meeting = summaryJobs [ job ] ?? path
317+ summarising . remove ( meeting )
235318 summaryJobs . removeValue ( forKey : job )
319+ if summaryAgain . remove ( job ) != nil { writeSummary ( meeting , only : . summary ) }
236320 refresh ( )
237321 }
238322 }
0 commit comments