posting, global timeline

Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
William Casarin
2022-04-13 12:18:01 -07:00
parent 967c463976
commit 97fbee85c0
6 changed files with 91 additions and 23 deletions

View File

@@ -115,7 +115,10 @@ func decode_data<T: Decodable>(_ data: Data) -> T? {
}
func event_commitment(ev: NostrEvent, tags: String) -> String {
return "[0,\"\(ev.pubkey)\",\(ev.created_at),\(ev.kind),\(tags),\"\(ev.content)\"]"
let encoder = JSONEncoder()
let str_data = try! encoder.encode(ev.content)
let content = String(decoding: str_data, as: UTF8.self)
return "[0,\"\(ev.pubkey)\",\(ev.created_at),\(ev.kind),\(tags),\(content)]"
}
func calculate_event_id(ev: NostrEvent) -> String {

View File

@@ -27,11 +27,19 @@ struct NostrFilter: Codable {
}
public static var filter_text: NostrFilter {
NostrFilter(ids: nil, kinds: [1], referenced_ids: nil, pubkeys: nil, since: nil, until: nil, authors: nil)
return filter_kinds([1])
}
public static var filter_profiles: NostrFilter {
return NostrFilter(ids: nil, kinds: [0], referenced_ids: nil, pubkeys: nil, since: nil, until: nil, authors: nil)
return filter_kinds([0])
}
public static var filter_contacts: NostrFilter {
return filter_kinds([3])
}
public static func filter_kinds(_ kinds: [Int]) -> NostrFilter {
return NostrFilter(ids: nil, kinds: kinds, referenced_ids: nil, pubkeys: nil, since: nil, until: nil, authors: nil)
}
public static func filter_since(_ val: Int64) -> NostrFilter {

View File

@@ -0,0 +1,8 @@
//
// NostrTimeline.swift
// damus
//
// Created by William Casarin on 2022-04-12.
//
import Foundation

View File

@@ -84,7 +84,9 @@ func make_nostr_push_event(ev: NostrEvent) -> String? {
let encoder = JSONEncoder()
let event_data = try! encoder.encode(ev)
let event = String(decoding: event_data, as: UTF8.self)
return "[\"EVENT\",\(event)]"
let encoded = "[\"EVENT\",\(event)]"
print(encoded)
return encoded
}
func make_nostr_subscription_req(_ filters: [NostrFilter], sub_id: String) -> String? {