damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

commit 97bca010f6345de01decfc77d6dcf4fe95a3da12
parent 5c62a06618aa415297292eb8c6cb1a4087037880
Author: William Casarin <jb55@jb55.com>
Date:   Fri,  5 Aug 2022 12:20:48 -0700

Censor unclebobmartin from damus

Limits the size of posts viewable within damus to 32,000 bytes. It's
still probably too big, but let's have some sane limit so uncle's named
bob can't break your app just because they can.

Changelog-Fixed: Limit post sizes to max 32,000 as an upper bound sanity limit.
Signed-off-by: William Casarin <jb55@jb55.com>

Diffstat:
Mdamus/Models/HomeModel.swift | 2+-
Mdamus/Models/ProfileModel.swift | 4++++
Mdamus/Models/SearchHomeModel.swift | 2+-
Mdamus/Models/SearchModel.swift | 2+-
Mdamus/Models/ThreadModel.swift | 4++++
Mdamus/Nostr/NostrEvent.swift | 12++++++++++++
6 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/damus/Models/HomeModel.swift b/damus/Models/HomeModel.swift @@ -338,7 +338,7 @@ class HomeModel: ObservableObject { } func should_hide_event(_ ev: NostrEvent) -> Bool { - return false + return !ev.should_show_event } func handle_text_event(sub_id: String, _ ev: NostrEvent) { diff --git a/damus/Models/ProfileModel.swift b/damus/Models/ProfileModel.swift @@ -68,6 +68,10 @@ class ProfileModel: ObservableObject { } func add_event(_ ev: NostrEvent) { + guard ev.should_show_event else { + return + } + if seen_event.contains(ev.id) { return } diff --git a/damus/Models/SearchHomeModel.swift b/damus/Models/SearchHomeModel.swift @@ -62,7 +62,7 @@ class SearchHomeModel: ObservableObject { guard sub_id == self.base_subid || sub_id == self.profiles_subid else { return } - if ev.kind == NostrKind.text.rawValue { + if ev.is_textlike && ev.should_show_event { if seen_pubkey.contains(ev.pubkey) { return } diff --git a/damus/Models/SearchModel.swift b/damus/Models/SearchModel.swift @@ -52,7 +52,7 @@ class SearchModel: ObservableObject { func handle_event(relay_id: String, ev: NostrConnectionEvent) { let done = handle_subid_event(pool: pool, sub_id: sub_id, relay_id: relay_id, ev: ev) { ev in - if ev.known_kind == .text { + if ev.known_kind == .text && ev.should_show_event { self.add_event(ev) } } diff --git a/damus/Models/ThreadModel.swift b/damus/Models/ThreadModel.swift @@ -148,6 +148,10 @@ class ThreadModel: ObservableObject { } func add_event(_ ev: NostrEvent, privkey: String?) { + guard ev.should_show_event else { + return + } + if event_map[ev.id] != nil { return } diff --git a/damus/Nostr/NostrEvent.swift b/damus/Nostr/NostrEvent.swift @@ -55,6 +55,18 @@ class NostrEvent: Codable, Identifiable, CustomStringConvertible { let created_at: Int64 let kind: Int let content: String + + var is_textlike: Bool { + return kind == 1 || kind == 42 + } + + var too_big: Bool { + return self.content.count > 32000 + } + + var should_show_event: Bool { + return !too_big + } private var _blocks: [Block]? = nil func blocks(_ privkey: String?) -> [Block] {