wip
This commit is contained in:
parent
b910b2ac4b
commit
08f3b548a6
|
@ -58,6 +58,23 @@ extension Database {
|
|||
table.column("date", .datetime).notNull()
|
||||
table.column("pending", .boolean).notNull()
|
||||
table.column("sentError", .boolean).notNull()
|
||||
table.column("attachment", .text).references("attachments", onDelete: .cascade)
|
||||
}
|
||||
|
||||
// attachments
|
||||
try db.create(table: "attachments", options: [.ifNotExists]) { table in
|
||||
table.column("id", .text).notNull().primaryKey().unique(onConflict: .replace)
|
||||
}
|
||||
|
||||
// attachment items
|
||||
try db.create(table: "attachment_items", options: [.ifNotExists]) { table in
|
||||
table.column("id", .text).notNull().primaryKey().unique(onConflict: .replace)
|
||||
table.belongsTo("attachments", onDelete: .cascade).notNull()
|
||||
table.column("type", .integer).notNull()
|
||||
table.column("localPath", .text)
|
||||
table.column("remotePath", .text)
|
||||
table.column("localThumbnailPath", .text)
|
||||
table.column("string", .text)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,22 +3,34 @@ import GRDB
|
|||
import Martin
|
||||
import SwiftUI
|
||||
|
||||
enum AttachmentType: Stateable {
|
||||
case movie
|
||||
case image
|
||||
case audio
|
||||
case file
|
||||
case location
|
||||
case contact
|
||||
enum AttachmentType: Int, Stateable, DatabaseValueConvertible {
|
||||
case movie = 0
|
||||
case image = 1
|
||||
case audio = 2
|
||||
case file = 3
|
||||
case location = 4
|
||||
case contact = 5
|
||||
}
|
||||
|
||||
struct AttachmentItem: Stateable {
|
||||
let type: AttachmentType
|
||||
let data: Data
|
||||
let string: String
|
||||
}
|
||||
struct AttachmentItem: DBStorable {
|
||||
static let databaseTableName = "attachment_items"
|
||||
|
||||
struct Attachment: Stateable {
|
||||
let id: String
|
||||
let items: [AttachmentItem]
|
||||
static let attachment = belongsTo(Attachment.self)
|
||||
let type: AttachmentType
|
||||
let localPath: URL?
|
||||
let remotePath: URL?
|
||||
let localThumbnailPath: URL?
|
||||
let string: String?
|
||||
}
|
||||
|
||||
struct Attachment: DBStorable {
|
||||
static let databaseTableName = "attachments"
|
||||
|
||||
let id: String
|
||||
static let items = hasMany(AttachmentItem.self)
|
||||
static let message = hasOne(Message.self)
|
||||
}
|
||||
|
||||
extension AttachmentItem: Equatable {}
|
||||
extension Attachment: Equatable {}
|
||||
|
|
|
@ -32,6 +32,8 @@ struct Message: DBStorable, Equatable {
|
|||
let date: Date
|
||||
let pending: Bool
|
||||
let sentError: Bool
|
||||
|
||||
static let attachment = hasOne(Attachment.self)
|
||||
}
|
||||
|
||||
extension Message {
|
||||
|
|
|
@ -39,8 +39,13 @@ struct AttachmentContactsPickerView: View {
|
|||
}
|
||||
.clipped()
|
||||
.onTapGesture {
|
||||
// TODO: Send selected media
|
||||
print("Send location")
|
||||
if let selectedContact = selectedContact {
|
||||
let attachment = Attachment(id: UUID().uuidString, items: [
|
||||
AttachmentItem(type: .contact, data: Data(), string: selectedContact.contactBareJid)
|
||||
])
|
||||
store.dispatch(.conversationAction(.sendAttachment(attachment)))
|
||||
store.dispatch(.conversationAction(.showAttachmentPicker(false)))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,8 +62,15 @@ struct AttachmentLocationPickerView: View {
|
|||
}
|
||||
.clipped()
|
||||
.onTapGesture {
|
||||
// TODO: Send selected media
|
||||
print("Send location")
|
||||
let attachment = Attachment(id: UUID().uuidString, items: [
|
||||
AttachmentItem(
|
||||
type: .location,
|
||||
data: Data(),
|
||||
string: "\(region.center.latitude),\(region.center.longitude)"
|
||||
)
|
||||
])
|
||||
store.dispatch(.conversationAction(.sendAttachment(attachment)))
|
||||
store.dispatch(.conversationAction(.showAttachmentPicker(false)))
|
||||
}
|
||||
}
|
||||
.onAppear {
|
||||
|
|
Loading…
Reference in a new issue