Skip to content

Commit

Permalink
fix spacing and shape based on order of DM content
Browse files Browse the repository at this point in the history
  • Loading branch information
suhailsaqan committed Aug 8, 2023
1 parent 2858d93 commit 4c8b58c
Showing 1 changed file with 41 additions and 12 deletions.
53 changes: 41 additions & 12 deletions damus/Views/DMView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ struct DMView: View {
}
}

func Image(urls: [MediaUrl]) -> some View {
func Image(urls: [MediaUrl], isLastInDM: Bool) -> some View {
return Group {
HStack {
if is_ours {
Expand All @@ -110,15 +110,15 @@ struct DMView: View {
let should_show_img = should_show_images(settings: damus_state.settings, contacts: damus_state.contacts, ev: event, our_pubkey: damus_state.pubkey)
if should_show_img {
ImageCarousel(state: damus_state, evid: event.id, urls: urls)
.clipShape(ChatBubbleShape(direction: isLastInGroup ? (is_ours ? ChatBubbleShape.Direction.right: ChatBubbleShape.Direction.left): ChatBubbleShape.Direction.none))
.clipShape(ChatBubbleShape(direction: (isLastInGroup && isLastInDM) ? (is_ours ? ChatBubbleShape.Direction.right: ChatBubbleShape.Direction.left): ChatBubbleShape.Direction.none))
.contextMenu{MenuItems(event: event, keypair: damus_state.keypair, target_pubkey: event.pubkey, bookmarks: damus_state.bookmarks, muted_threads: damus_state.muted_threads, settings: damus_state.settings)}
} else if !should_show_img {
ZStack {
ImageCarousel(state: damus_state, evid: event.id, urls: urls)
Blur()
.disabled(true)
}
.clipShape(ChatBubbleShape(direction: isLastInGroup ? (is_ours ? ChatBubbleShape.Direction.right: ChatBubbleShape.Direction.left): ChatBubbleShape.Direction.none))
.clipShape(ChatBubbleShape(direction: (isLastInGroup && isLastInDM) ? (is_ours ? ChatBubbleShape.Direction.right: ChatBubbleShape.Direction.left): ChatBubbleShape.Direction.none))
.contextMenu{MenuItems(event: event, keypair: damus_state.keypair, target_pubkey: event.pubkey, bookmarks: damus_state.bookmarks, muted_threads: damus_state.muted_threads, settings: damus_state.settings)}
}

Expand All @@ -129,15 +129,15 @@ struct DMView: View {
}
}

func Invoice(invoices: [Invoice]) -> some View {
func Invoice(invoices: [Invoice], isLastInDM: Bool) -> some View {
return Group {
HStack {
if is_ours {
Spacer(minLength: UIScreen.main.bounds.width * 0.1)
}

InvoicesView(our_pubkey: damus_state.keypair.pubkey, invoices: invoices, settings: damus_state.settings)
.clipShape(ChatBubbleShape(direction: isLastInGroup ? (is_ours ? ChatBubbleShape.Direction.right: ChatBubbleShape.Direction.left): ChatBubbleShape.Direction.none))
.clipShape(ChatBubbleShape(direction: (isLastInGroup && isLastInDM) ? (is_ours ? ChatBubbleShape.Direction.right: ChatBubbleShape.Direction.left): ChatBubbleShape.Direction.none))
.contextMenu{MenuItems(event: event, keypair: damus_state.keypair, target_pubkey: event.pubkey, bookmarks: damus_state.bookmarks, muted_threads: damus_state.muted_threads, settings: damus_state.settings)}

if !is_ours {
Expand Down Expand Up @@ -222,21 +222,43 @@ struct DMView: View {

return (show_text, txt)
}

func getLastInDM(text: CompatibleText?, mention: Mention?, url: [MediaUrl]?, invoices: [Invoice]?) -> DMContentType? {
var last: DMContentType?
if let text {
last = .text
}
if let mention {
last = .mention
}
if let url {
last = .url
}
if let invoices {
last = .invoice
}
return last
}

var body: some View {
VStack {
let (show_text, filtered_content): (Bool, CompatibleText?) = filter_content(blocks: event.blocks(damus_state.keypair.privkey), profiles: damus_state.profiles, privkey: damus_state.keypair.privkey)
let mention = first_eref_mention(ev: event, privkey: damus_state.keypair.privkey)
let url = separate_images(ev: event, privkey: damus_state.keypair.privkey)
let invoices = separate_invoices(ev: event, privkey: damus_state.keypair.privkey)
let lastInDM = getLastInDM(text: filtered_content, mention: mention, url: url, invoices: invoices)

if show_text, let filtered_content = filtered_content {
DM(content: filtered_content).padding(.bottom, isLastInGroup ? 0 : -6)
DM(content: filtered_content, isLastInDM: lastInDM == .text).padding(.bottom, (isLastInGroup && lastInDM == .text) ? 0 : -6)
}
if let mention = first_eref_mention(ev: event, privkey: damus_state.keypair.privkey) {
Mention(mention: mention).padding(.bottom, isLastInGroup ? 0 : -6)
if let mention {
Mention(mention: mention).padding(.bottom, (isLastInGroup && lastInDM == .mention) ? 0 : -6)
}
if let url = separate_images(ev: event, privkey: damus_state.keypair.privkey) {
Image(urls: url).padding(.bottom, isLastInGroup ? 0 : -6)
if let url {
Image(urls: url, isLastInDM: lastInDM == .url).padding(.bottom, (isLastInGroup && lastInDM == .url) ? 0 : -6)
}
if let invoices = separate_invoices(ev: event, privkey: damus_state.keypair.privkey) {
Invoice(invoices: invoices).padding(.bottom, isLastInGroup ? 0 : -6)
if let invoices {
Invoice(invoices: invoices, isLastInDM: lastInDM == .invoice).padding(.bottom, (isLastInGroup && lastInDM == .invoice) ? 0 : -6)
}
if (isLastInGroup) {
TimeStamp().padding(.top, -5)
Expand All @@ -245,6 +267,13 @@ struct DMView: View {
}
}

enum DMContentType {
case text
case mention
case url
case invoice
}

struct ChatBubbleShape: Shape {
enum Direction {
case left
Expand Down

0 comments on commit 4c8b58c

Please sign in to comment.