wip
This commit is contained in:
parent
07993baddc
commit
a28d60e128
|
@ -301,6 +301,12 @@ private extension DatabaseMiddleware {
|
||||||
.publisher(in: database._db, scheduling: .immediate)
|
.publisher(in: database._db, scheduling: .immediate)
|
||||||
.sink { _ in
|
.sink { _ in
|
||||||
} receiveValue: { messages in
|
} receiveValue: { messages in
|
||||||
|
// messages
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
store.dispatch(.conversationAction(.messagesUpdated(messages: messages)))
|
||||||
|
}
|
||||||
|
|
||||||
|
// attachments
|
||||||
var attachments: [Attachment] = []
|
var attachments: [Attachment] = []
|
||||||
for message in messages {
|
for message in messages {
|
||||||
do {
|
do {
|
||||||
|
@ -314,7 +320,6 @@ private extension DatabaseMiddleware {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
store.dispatch(.conversationAction(.messagesUpdated(messages: messages)))
|
|
||||||
store.dispatch(.conversationAction(.attachmentsUpdated(attachments: attachments)))
|
store.dispatch(.conversationAction(.attachmentsUpdated(attachments: attachments)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,9 @@ extension ConversationState {
|
||||||
state.replyText = text.makeReply
|
state.replyText = text.makeReply
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case .attachmentsUpdated(let attachments):
|
||||||
|
state.currentAttachments = attachments
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ struct ConversationState: Stateable {
|
||||||
var currentChat: Chat?
|
var currentChat: Chat?
|
||||||
var currentRoster: Roster?
|
var currentRoster: Roster?
|
||||||
var currentMessages: [Message]
|
var currentMessages: [Message]
|
||||||
|
var currentAttachments: [Attachment]
|
||||||
|
|
||||||
var replyText: String
|
var replyText: String
|
||||||
}
|
}
|
||||||
|
@ -10,6 +11,7 @@ struct ConversationState: Stateable {
|
||||||
extension ConversationState {
|
extension ConversationState {
|
||||||
init() {
|
init() {
|
||||||
currentMessages = []
|
currentMessages = []
|
||||||
|
currentAttachments = []
|
||||||
replyText = ""
|
replyText = ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,5 +39,8 @@ enum Const {
|
||||||
static let galleryGridSize = UIScreen.main.bounds.width / 3
|
static let galleryGridSize = UIScreen.main.bounds.width / 3
|
||||||
|
|
||||||
// Size for map preview for location messages
|
// 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)
|
.frame(width: Const.mapPreviewSize, height: Const.mapPreviewSize)
|
||||||
.cornerRadius(10)
|
|
||||||
.onTapGesture {
|
.onTapGesture {
|
||||||
let mapItem = MKMapItem(placemark: MKPlacemark(coordinate: location))
|
let mapItem = MKMapItem(placemark: MKPlacemark(coordinate: location))
|
||||||
mapItem.name = "Location"
|
mapItem.name = "Location"
|
||||||
|
@ -67,9 +66,58 @@ private struct EmbededMapView: View {
|
||||||
}
|
}
|
||||||
|
|
||||||
private struct AttachmentView: View {
|
private struct AttachmentView: View {
|
||||||
|
@EnvironmentObject var store: AppStore
|
||||||
|
|
||||||
let attachmentId: String
|
let attachmentId: String
|
||||||
|
|
||||||
var body: some View {
|
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