-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathChatTabInfo+Storage.swift
More file actions
48 lines (39 loc) · 1.58 KB
/
ChatTabInfo+Storage.swift
File metadata and controls
48 lines (39 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import Foundation
import ChatTab
import Persist
import Logger
extension ChatTabInfo {
func toConversationItem() -> ConversationItem {
// Currently, no additional data to store.
let data = "{}"
return ConversationItem(id: self.id, title: self.title, isSelected: self.isSelected, CLSConversationID: self.CLSConversationID, data: data, createdAt: self.createdAt, updatedAt: self.updatedAt)
}
static func from(_ conversationItem: ConversationItem, with metadata: StorageMetadata) -> ChatTabInfo? {
var chatTabInfo: ChatTabInfo? = nil
chatTabInfo = .init(
id: conversationItem.id,
title: conversationItem.title,
isSelected: conversationItem.isSelected,
CLSConversationID: conversationItem.CLSConversationID,
createdAt: conversationItem.createdAt,
updatedAt: conversationItem.updatedAt,
workspacePath: metadata.workspacePath,
username: metadata.username)
return chatTabInfo
}
}
extension Array where Element == ChatTabInfo {
func toConversationItems() -> [ConversationItem] {
return self.map { $0.toConversationItem() }
}
}
extension ChatTabPreviewInfo {
static func from(_ conversationPreviewItem: ConversationPreviewItem) -> ChatTabPreviewInfo {
return .init(
id: conversationPreviewItem.id,
title: conversationPreviewItem.title,
isSelected: conversationPreviewItem.isSelected,
updatedAt: conversationPreviewItem.updatedAt
)
}
}