wip
This commit is contained in:
parent
07993baddc
commit
a28d60e128
|
@ -301,6 +301,12 @@ private extension DatabaseMiddleware {
|
|||
.publisher(in: database._db, scheduling: .immediate)
|
||||
.sink { _ in
|
||||
} receiveValue: { messages in
|
||||
// messages
|
||||
DispatchQueue.main.async {
|
||||
store.dispatch(.conversationAction(.messagesUpdated(messages: messages)))
|
||||
}
|
||||
|
||||
// attachments
|
||||
var attachments: [Attachment] = []
|
||||
for message in messages {
|
||||
do {
|
||||
|
@ -314,7 +320,6 @@ private extension DatabaseMiddleware {
|
|||
}
|
||||
}
|
||||
DispatchQueue.main.async {
|
||||
store.dispatch(.conversationAction(.messagesUpdated(messages: messages)))
|
||||
store.dispatch(.conversationAction(.attachmentsUpdated(attachments: attachments)))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,9 @@ extension ConversationState {
|
|||
state.replyText = text.makeReply
|
||||
}
|
||||
|
||||
case .attachmentsUpdated(let attachments):
|
||||
state.currentAttachments = attachments
|
||||
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ struct ConversationState: Stateable {
|
|||
var currentChat: Chat?
|
||||
var currentRoster: Roster?
|
||||
var currentMessages: [Message]
|
||||
var currentAttachments: [Attachment]
|
||||
|
||||
var replyText: String
|
||||
}
|
||||
|
@ -10,6 +11,7 @@ struct ConversationState: Stateable {
|
|||
extension ConversationState {
|
||||
init() {
|
||||
currentMessages = []
|
||||
currentAttachments = []
|
||||
replyText = ""
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,5 +39,8 @@ enum Const {
|
|||
static let galleryGridSize = UIScreen.main.bounds.width / 3
|
||||
|
||||
// Size for map preview for location messages
|
||||
static let mapPreviewSize = UIScreen.main.bounds.width * 0.75
|
||||
static let mapPreviewSize = UIScreen.main.bounds.width * 0.5
|
||||
|
||||
// Size for attachment preview
|
||||
static let attachmentPreviewSize = UIScreen.main.bounds.width * 0.5
|
||||
}
|
||||
|
|
|
@ -57,7 +57,6 @@ private struct EmbededMapView: View {
|
|||
}
|
||||
)
|
||||
.frame(width: Const.mapPreviewSize, height: Const.mapPreviewSize)
|
||||
.cornerRadius(10)
|
||||
.onTapGesture {
|
||||
let mapItem = MKMapItem(placemark: MKPlacemark(coordinate: location))
|
||||
mapItem.name = "Location"
|
||||
|
@ -67,9 +66,58 @@ private struct EmbededMapView: View {
|
|||
}
|
||||
|
||||
private struct AttachmentView: View {
|
||||
@EnvironmentObject var store: AppStore
|
||||
|
||||
let attachmentId: String
|
||||
|
||||
var body: some View {
|
||||
Text("Attachment \(attachmentId)")
|
||||
if let attachment = store.state.conversationsState.currentAttachments.first(where: { $0.id == attachmentId }) {
|
||||
if let localPath = attachment.localPath {
|
||||
Image(systemName: "questionmark.square")
|
||||
.resizable()
|
||||
.aspectRatio(contentMode: .fill)
|
||||
.frame(width: Const.attachmentPreviewSize, height: Const.attachmentPreviewSize)
|
||||
.cornerRadius(10)
|
||||
} else {
|
||||
AttachmentPlaceholderView(placeholderImageName: progressImageName(attachment.type))
|
||||
}
|
||||
} else {
|
||||
AttachmentPlaceholderView(placeholderImageName: nil)
|
||||
}
|
||||
}
|
||||
|
||||
private func progressImageName(_ type: AttachmentType) -> String {
|
||||
switch type {
|
||||
case .image:
|
||||
return "photo"
|
||||
case .audio:
|
||||
return "music.note"
|
||||
case .movie:
|
||||
return "film"
|
||||
case .file:
|
||||
return "doc"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private struct AttachmentPlaceholderView: View {
|
||||
let placeholderImageName: String?
|
||||
|
||||
var body: some View {
|
||||
Rectangle()
|
||||
.foregroundColor(.Material.Background.dark)
|
||||
.frame(width: Const.attachmentPreviewSize, height: Const.attachmentPreviewSize)
|
||||
.overlay {
|
||||
ZStack {
|
||||
ProgressView()
|
||||
.scaleEffect(1.5)
|
||||
.progressViewStyle(CircularProgressViewStyle(tint: .Material.Elements.active))
|
||||
if let imageName = placeholderImageName {
|
||||
Image(systemName: imageName)
|
||||
.font(.body1)
|
||||
.foregroundColor(.Material.Elements.active)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue