ndb: sync up a few remaining NdbNote tag differences
This commit is contained in:
@@ -104,7 +104,7 @@ class NdbNote: Equatable, Hashable {
|
||||
|
||||
static let max_note_size: Int = 2 << 18
|
||||
|
||||
init?(content: String, keypair: Keypair, kind: Int = 1, tags: [[String]] = [], createdAt: UInt32 = UInt32(Date().timeIntervalSince1970)) {
|
||||
init?(content: String, keypair: Keypair, kind: UInt32 = 1, tags: [[String]] = [], createdAt: UInt32 = UInt32(Date().timeIntervalSince1970)) {
|
||||
|
||||
var builder = ndb_builder()
|
||||
let buflen = MAX_NOTE_SIZE
|
||||
|
||||
@@ -83,6 +83,19 @@ struct NdbTagElem: Sequence, Hashable {
|
||||
return str.str[0] == c.cchar && str.str[1] == 0
|
||||
}
|
||||
|
||||
func matches_str(_ s: String) -> Bool {
|
||||
if str.flag == NDB_PACKED_ID,
|
||||
s.utf8.count == 64,
|
||||
var decoded = hex_decode(s), decoded.count == 32
|
||||
{
|
||||
return memcmp(&decoded, str.id, 32) == 0
|
||||
}
|
||||
|
||||
let len = strlen(str.str)
|
||||
guard len == s.utf8.count else { return false }
|
||||
return s.withCString { cstr in memcmp(str.str, cstr, len) == 0 }
|
||||
}
|
||||
|
||||
var ndbstr: ndb_str {
|
||||
return ndb_tag_str(note.note, tag, index)
|
||||
}
|
||||
|
||||
@@ -15,8 +15,12 @@ struct TagSequence: Sequence {
|
||||
tag.pointee.count
|
||||
}
|
||||
|
||||
subscript(index: Int) -> NdbTagElem? {
|
||||
guard index < count else { return nil }
|
||||
func strings() -> [String] {
|
||||
return self.map { $0.string() }
|
||||
}
|
||||
|
||||
subscript(index: Int) -> NdbTagElem {
|
||||
precondition(index < count, "Index out of bounds")
|
||||
|
||||
return NdbTagElem(note: note, tag: tag, index: Int32(index))
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ final class NdbTests: XCTestCase {
|
||||
}
|
||||
|
||||
if tags == 7 {
|
||||
XCTAssertEqual(tag[2]?.string(), "wss://nostr-pub.wellorder.net")
|
||||
XCTAssertEqual(tag[2].string(), "wss://nostr-pub.wellorder.net")
|
||||
}
|
||||
|
||||
for elem in tag {
|
||||
|
||||
Reference in New Issue
Block a user