| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "strings" |
| 5 | |
| 6 | "reasonix/desktop/internal/legacycleanup" |
| 7 | "reasonix/desktop/internal/workspacestate" |
| 8 | ) |
| 9 | |
| 10 | func legacyCleanupArchivedSessions(state legacycleanup.State) map[string]legacycleanup.Candidate { |
| 11 | items := map[string]legacycleanup.Candidate{} |
| 12 | for _, item := range state.Items { |
| 13 | if (item.Kind == "session" || item.Kind == "legacy") && item.Phase == "archived" && !item.Restored && item.SessionID != "" { |
| 14 | items[item.SessionID] = item |
| 15 | } |
| 16 | } |
| 17 | return items |
| 18 | } |
| 19 | |
| 20 | func decorateLegacyCleanupTrashEntry(row *TrashEntry, batchID string, item legacycleanup.Candidate) { |
| 21 | if row == nil || item.ID == "" { |
| 22 | return |
| 23 | } |
| 24 | row.CleanupBatchID, row.CleanupKind = batchID, item.Kind |
| 25 | } |
| 26 | |
| 27 | func legacyCleanupTopicTrashEntries(cleanup legacycleanup.State, workspaces workspacestate.State, query string) []TrashEntry { |
| 28 | rows := []TrashEntry{} |
| 29 | query = strings.ToLower(query) |
| 30 | for _, item := range cleanup.Items { |
| 31 | if item.Kind != "topic" || item.Phase != "archived" || item.Restored { |
| 32 | continue |
| 33 | } |
| 34 | workspace := workspaces.Workspaces[item.WorkspaceID] |
| 35 | row := TrashEntry{ |
| 36 | ID: item.ID, RecoveryEntryID: "legacy-cleanup:" + item.ID, |
| 37 | Title: item.Title, WorkspaceID: item.WorkspaceID, WorkspaceTitle: workspace.Title, |
| 38 | ArchivedAt: item.ArchivedAt, Health: "ready", CanRestore: true, CanPurge: true, |
| 39 | CleanupBatchID: cleanup.BatchID, CleanupKind: "topic_placeholder", |
| 40 | } |
| 41 | if strings.Contains(strings.ToLower(row.Title+"\n"+row.WorkspaceTitle), query) { |
| 42 | rows = append(rows, row) |
| 43 | } |
| 44 | } |
| 45 | return rows |
| 46 | } |
| 47 |