Browse Source

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>
profile-edit
William Casarin 2 years ago
parent
commit
97bca010f6
  1. 2
      damus/Models/HomeModel.swift
  2. 4
      damus/Models/ProfileModel.swift
  3. 2
      damus/Models/SearchHomeModel.swift
  4. 2
      damus/Models/SearchModel.swift
  5. 4
      damus/Models/ThreadModel.swift
  6. 12
      damus/Nostr/NostrEvent.swift

2
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) {

4
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
}

2
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
}

2
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)
}
}

4
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
}

12
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] {

Loading…
Cancel
Save