This patch improves longform previews by including the image title and tags. In addition with minor UI touch ups. Testing: iPhone 15 Pro Max (17.3.1) Dark Mode: https://v.nostr.build/9zgvv.mp4 iPhone SE (3rd generation) (16.4) Light Mode: https://v.nostr.build/VwEKQ.mp4 Closes: https://github.com/damus-io/damus/issues/1742 Changelog-Added: Added title image and tags to longform events Signed-off-by: ericholguin <ericholguin@apache.org> Link: 20240415031636.68846-1-ericholguin@apache.org Signed-off-by: William Casarin <jb55@jb55.com>
42 lines
1.1 KiB
Swift
42 lines
1.1 KiB
Swift
//
|
|
// LongformEvent.swift
|
|
// damus
|
|
//
|
|
// Created by Daniel Nogueira on 2023-11-24.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
struct LongformEvent {
|
|
let event: NostrEvent
|
|
|
|
var title: String? = nil
|
|
var image: URL? = nil
|
|
var summary: String? = nil
|
|
var published_at: Date? = nil
|
|
var labels: [String]? = nil
|
|
|
|
static func parse(from ev: NostrEvent) -> LongformEvent {
|
|
var longform = LongformEvent(event: ev)
|
|
|
|
for tag in ev.tags {
|
|
guard tag.count >= 2 else { continue }
|
|
switch tag[0].string() {
|
|
case "title": longform.title = tag[1].string()
|
|
case "image": longform.image = URL(string: tag[1].string())
|
|
case "summary": longform.summary = tag[1].string()
|
|
case "published_at":
|
|
longform.published_at = Double(tag[1].string()).map { d in Date(timeIntervalSince1970: d) }
|
|
case "t":
|
|
if (longform.labels?.append(tag[1].string())) == nil {
|
|
longform.labels = [tag[1].string()]
|
|
}
|
|
default:
|
|
break
|
|
}
|
|
}
|
|
|
|
return longform
|
|
}
|
|
}
|