This is a non-behavioral change in preparation for the actual switchover from Strings to Ids. The purpose of this kit is to reduce the size of the switchover commit which is going to be very large.
33 lines
631 B
Swift
33 lines
631 B
Swift
//
|
|
// ReplyMap.swift
|
|
// damus
|
|
//
|
|
// Created by William Casarin on 2022-04-19.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
class ReplyMap {
|
|
var replies: [NoteId: Set<NoteId>] = [:]
|
|
|
|
func lookup(_ id: NoteId) -> Set<NoteId>? {
|
|
return replies[id]
|
|
}
|
|
|
|
private func ensure_set(id: NoteId) {
|
|
if replies[id] == nil {
|
|
replies[id] = Set()
|
|
}
|
|
}
|
|
|
|
@discardableResult
|
|
func add(id: NoteId, reply_id: NoteId) -> Bool {
|
|
ensure_set(id: id)
|
|
if (replies[id]!).contains(reply_id) {
|
|
return false
|
|
}
|
|
replies[id]!.insert(reply_id)
|
|
return true
|
|
}
|
|
}
|