diff --git a/Configs/Release.xcconfig b/Configs/Release.xcconfig index f018b882..4084b5a0 100644 --- a/Configs/Release.xcconfig +++ b/Configs/Release.xcconfig @@ -1,4 +1,4 @@ -MARKETING_VERSION = 1.7.1 +MARKETING_VERSION = 1.8.0 CURRENT_PROJECT_VERSION = 1 IPHONEOS_DEPLOYMENT_TARGET = 16.0 diff --git a/Package.resolved b/Package.resolved index d7f00213..e2fe84fe 100644 --- a/Package.resolved +++ b/Package.resolved @@ -5,8 +5,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/21-DOT-DEV/swift-secp256k1", "state" : { - "revision" : "8c62aba8a3011c9bcea232e5ee007fb0b34a15e2", - "version" : "0.21.1" + "revision" : "bcd6dd8e615ce243eab7097f213c8c4b39305a2e", + "version" : "0.24.0" } } ], diff --git a/Package.swift b/Package.swift index 2bb83521..f5e5146f 100644 --- a/Package.swift +++ b/Package.swift @@ -19,7 +19,7 @@ let package = Package( .package(path: "localPackages/Arti"), .package(path: "localPackages/BitFoundation"), .package(path: "localPackages/BitLogger"), - .package(url: "https://github.com/21-DOT-DEV/swift-secp256k1", exact: "0.21.1") + .package(url: "https://github.com/21-DOT-DEV/swift-secp256k1", exact: "0.24.0") ], targets: [ .executableTarget( @@ -38,7 +38,10 @@ let package = Package( "bitchat.entitlements", "bitchat-macOS.entitlements", "LaunchScreen.storyboard", - "ViewModels/Extensions/README.md" + "ViewModels/Extensions/README.md", + // Globe picker geometry, bundled by the Xcode app targets and read + // from Bundle.main; the SwiftPM build only runs tests. + "Resources/Globe" ], resources: [ .process("Localizable.xcstrings") diff --git a/bitchat.xcodeproj/project.pbxproj b/bitchat.xcodeproj/project.pbxproj index d9239d66..bcf11381 100644 --- a/bitchat.xcodeproj/project.pbxproj +++ b/bitchat.xcodeproj/project.pbxproj @@ -935,7 +935,7 @@ repositoryURL = "https://github.com/21-DOT-DEV/swift-secp256k1"; requirement = { kind = exactVersion; - version = 0.21.1; + version = 0.24.0; }; }; /* End XCRemoteSwiftPackageReference section */ diff --git a/bitchat/App/ConversationUIModel.swift b/bitchat/App/ConversationUIModel.swift index 131177b1..e4db4e9c 100644 --- a/bitchat/App/ConversationUIModel.swift +++ b/bitchat/App/ConversationUIModel.swift @@ -11,7 +11,6 @@ final class ConversationUIModel: ObservableObject { @Published private(set) var autocompleteSuggestions: [String] = [] @Published private(set) var selectedAutocompleteIndex = 0 @Published private(set) var currentNickname: String - @Published private(set) var isBatchingPublic = false @Published private(set) var canSendMediaInCurrentContext = true @Published private(set) var legacyPrivateMediaConsentRequest: LegacyPrivateMediaConsentRequest? /// Who is talking live in the public mesh channel right now (floor @@ -23,6 +22,15 @@ final class ConversationUIModel: ObservableObject { private let conversations: ConversationStore private var activeChannel: ChannelID private var cancellables = Set() + /// My geochat sender ID for the location channel on screen, kept with the + /// public key it was built from. `publicKeyHex` hex-encodes on every + /// access, too slow to repeat per row render; keying on the key itself + /// means a geohash switch or a panic wipe (which reseeds every identity) + /// can never leave a stale ID behind. A switch to #mesh, where no row + /// reads it, drops it: a panic wipe always lands there, and the retired + /// key must not stay in memory until a geochat row next renders. + /// (Read access is internal so tests can check that.) + private(set) var ownGeoChatSender: (publicKey: Data, peerID: PeerID)? init( chatViewModel: ChatViewModel, @@ -34,7 +42,6 @@ final class ConversationUIModel: ObservableObject { self.conversations = conversations self.activeChannel = conversations.activeChannel self.currentNickname = chatViewModel.nickname - self.isBatchingPublic = chatViewModel.isBatchingPublic self.showAutocomplete = chatViewModel.showAutocomplete self.autocompleteSuggestions = chatViewModel.autocompleteSuggestions self.selectedAutocompleteIndex = chatViewModel.selectedAutocompleteIndex @@ -144,19 +151,50 @@ final class ConversationUIModel: ObservableObject { } func mediaAttachment(for message: BitchatMessage) -> BitchatMessage.Media? { - message.mediaAttachment(for: currentNickname) + // The model loads from outgoing/ exactly when the row's sender equals + // the name it is given. Ask with the row's own sender first: text rows, + // most of the timeline, stop here without an identity check per render. + guard let outgoing = message.mediaAttachment(for: message.sender) else { return nil } + if isSentByCurrentUser(message) { return outgoing } + // Not mine by identity: a name the sender can never equal (one + // character longer) loads it from incoming/, so a namesake's file + // resolves there while my send from before a rename stays outgoing. + return message.mediaAttachment(for: message.sender + "\u{0}") } func isSelfSender(peerID: PeerID?, displayName: String?) -> Bool { chatViewModel.isSelfSender(peerID: peerID, displayName: displayName) } + /// Whether this device wrote the row, by the sender ID it carries (see + /// `BitchatMessage.isOwn`), never by its display name: a namesake, an + /// `anon#xxxx` stranger next to a reader named "anon", and my own rows + /// from before a rename are all told apart correctly. func isSentByCurrentUser(_ message: BitchatMessage) -> Bool { - message.sender == currentNickname || message.sender.hasPrefix(currentNickname + "#") + message.isOwn( + myPeerID: chatViewModel.meshService.myPeerID, + myGeoChatPeerID: ownGeoChatPeerID() + ) } func isMediaMessageFromCurrentUser(_ message: BitchatMessage) -> Bool { - message.sender == currentNickname || message.senderPeerID == chatViewModel.meshService.myPeerID + isSentByCurrentUser(message) + } + + /// My geochat sender ID in the location channel on screen (nil on #mesh), + /// memoized in `ownGeoChatSender`. + private func ownGeoChatPeerID() -> PeerID? { + // The store's channel, not the mirrored `activeChannel`, which trails + // a switch by a runloop turn. + guard case .location(let channel) = conversations.activeChannel, + let identity = chatViewModel.geohashIdentity(for: channel.geohash) + else { return nil } + if let cached = ownGeoChatSender, cached.publicKey == identity.publicKey { + return cached.peerID + } + let peerID = PeerID(nostr: identity.publicKeyHex) + ownGeoChatSender = (identity.publicKey, peerID) + return peerID } /// Whether a private-message row should show the filled verification seal @@ -224,31 +262,35 @@ final class ConversationUIModel: ObservableObject { } private func bind() { + // Every message row observes this model, so each republish re-renders + // all of them: forward only real changes, never a re-sent equal value. chatViewModel.$nickname + .removeDuplicates() .receive(on: DispatchQueue.main) .assign(to: &$currentNickname) chatViewModel.$showAutocomplete + .removeDuplicates() .receive(on: DispatchQueue.main) .assign(to: &$showAutocomplete) chatViewModel.$autocompleteSuggestions + .removeDuplicates() .receive(on: DispatchQueue.main) .assign(to: &$autocompleteSuggestions) chatViewModel.$selectedAutocompleteIndex + .removeDuplicates() .receive(on: DispatchQueue.main) .assign(to: &$selectedAutocompleteIndex) - chatViewModel.$isBatchingPublic - .receive(on: DispatchQueue.main) - .assign(to: &$isBatchingPublic) - chatViewModel.$activePublicVoiceTalker + .removeDuplicates() .receive(on: DispatchQueue.main) .assign(to: &$activeLiveVoiceTalker) chatViewModel.$legacyPrivateMediaConsentRequest + .removeDuplicates() .receive(on: DispatchQueue.main) .assign(to: &$legacyPrivateMediaConsentRequest) @@ -256,6 +298,9 @@ final class ConversationUIModel: ObservableObject { .receive(on: DispatchQueue.main) .sink { [weak self] channel in self?.activeChannel = channel + if channel == .mesh { + self?.ownGeoChatSender = nil + } self?.refreshComputedState() } .store(in: &cancellables) @@ -278,18 +323,24 @@ final class ConversationUIModel: ObservableObject { } private func refreshComputedState() { + let canSendMedia: Bool if let selectedPeerID = privateConversationModel.selectedPeerID { // Media transfer is not wired for groups in v1; keep it off so the // composer can't strand a media placeholder that never sends. - canSendMediaInCurrentContext = !(selectedPeerID.isGeoDM || selectedPeerID.isGeoChat || selectedPeerID.isGroup) - return + canSendMedia = !(selectedPeerID.isGeoDM || selectedPeerID.isGeoChat || selectedPeerID.isGroup) + } else { + switch activeChannel { + case .mesh: + canSendMedia = true + case .location: + canSendMedia = false + } } - - switch activeChannel { - case .mesh: - canSendMediaInCurrentContext = true - case .location: - canSendMediaInCurrentContext = false + // Every write republishes to every message row, and most triggers + // (each peer, favorite or status refresh of the selection) leave the + // value as it was. + if canSendMediaInCurrentContext != canSendMedia { + canSendMediaInCurrentContext = canSendMedia } } } diff --git a/bitchat/App/LocationPresenceStore.swift b/bitchat/App/LocationPresenceStore.swift index b67731ba..26ec4131 100644 --- a/bitchat/App/LocationPresenceStore.swift +++ b/bitchat/App/LocationPresenceStore.swift @@ -30,17 +30,22 @@ final class LocationPresenceStore: ObservableObject { currentGeohash = normalized } - func setNickname(_ nickname: String, for pubkeyHex: String) { + /// Returns whether the stored nickname changed. Chat events repeat the + /// sender's nickname every time; rewriting an unchanged value would + /// republish the whole table. + @discardableResult + func setNickname(_ nickname: String, for pubkeyHex: String) -> Bool { guard geoNicknameCapacity > 0 else { clearGeoNicknames() - return + return false } let nickname = nickname.normalizedNickname let key = pubkeyHex.lowercased() - if geoNicknames[key] != nil { + if let existing = geoNicknames[key] { + guard existing != nickname else { return false } geoNicknames[key] = nickname - return + return true } while geoNicknameOrder.count >= geoNicknameCapacity, let oldest = geoNicknameOrder.first { @@ -50,6 +55,7 @@ final class LocationPresenceStore: ObservableObject { geoNicknames[key] = nickname geoNicknameOrder.append(key) + return true } func replaceGeoNicknames(_ nicknames: [String: String]) { @@ -83,12 +89,6 @@ final class LocationPresenceStore: ObservableObject { geoNicknameOrder.removeAll() } - func retainGeoNicknames(keeping pubkeys: Set) { - let allowed = Set(pubkeys.map { $0.lowercased() }) - geoNicknameOrder = geoNicknameOrder.filter { allowed.contains($0) } - geoNicknames = geoNicknames.filter { allowed.contains($0.key) } - } - func markTeleported(_ pubkeyHex: String) { guard teleportedGeoCapacity > 0 else { clearTeleportedGeo() @@ -109,6 +109,7 @@ final class LocationPresenceStore: ObservableObject { func clearTeleported(_ pubkeyHex: String) { let key = pubkeyHex.lowercased() + guard teleportedGeo.contains(key) else { return } teleportedGeo.remove(key) teleportedGeoOrder.removeAll { $0 == key } } @@ -132,8 +133,11 @@ final class LocationPresenceStore: ObservableObject { teleportedGeo = Set(ordered) } + /// Prunes only when someone actually left: every assignment republishes + /// `teleportedGeo`, and its subscribers rebuild the people list. func retainTeleportedGeo(keeping pubkeys: Set) { let allowed = Set(pubkeys.map { $0.lowercased() }) + guard !teleportedGeo.isSubset(of: allowed) else { return } teleportedGeoOrder = teleportedGeoOrder.filter { allowed.contains($0) } teleportedGeo = teleportedGeo.intersection(allowed) } diff --git a/bitchat/App/PeerListModel.swift b/bitchat/App/PeerListModel.swift index f641d9d8..9e613eb4 100644 --- a/bitchat/App/PeerListModel.swift +++ b/bitchat/App/PeerListModel.swift @@ -58,7 +58,6 @@ struct RecentChatRow: Identifiable, Equatable { @MainActor final class PeerListModel: ObservableObject { - @Published private(set) var allPeers: [BitchatPeer] = [] @Published private(set) var meshRows: [MeshPeerRow] = [] @Published private(set) var geohashPeople: [GeohashPersonRow] = [] @Published private(set) var groupRows: [GroupChatRow] = [] @@ -66,14 +65,17 @@ final class PeerListModel: ObservableObject { @Published private(set) var reachableMeshPeerCount = 0 @Published private(set) var connectedMeshPeerCount = 0 @Published private(set) var visibleGeohashPeerCount = 0 - @Published private(set) var renderID = "" private let chatViewModel: ChatViewModel private let conversations: ConversationStore private let locationChannelsModel: LocationChannelsModel private let peerIdentityStore: PeerIdentityStore private let locationPresenceStore: LocationPresenceStore + /// The mesh roster `refresh()` builds rows from. Not published: no view + /// reads it, and publishing it would re-render on every mesh snapshot. + private var allPeers: [BitchatPeer] = [] private var cancellables = Set() + private var refreshScheduled = false init( chatViewModel: ChatViewModel, @@ -132,32 +134,37 @@ final class PeerListModel: ObservableObject { } private func bind() { + // No equality guard: `BitchatPeer.==` compares only peer IDs, so a + // rename or a connection, favorite or petname change looks unchanged, + // and blocking someone republishes identical peers. The refresh is + // coalesced, and rows are compared in full before they're written. chatViewModel.$allPeers .receive(on: DispatchQueue.main) .sink { [weak self] peers in - self?.allPeers = peers - self?.refresh() + guard let self else { return } + self.allPeers = peers + self.setNeedsRefresh() } .store(in: &cancellables) chatViewModel.$nickname .receive(on: DispatchQueue.main) .sink { [weak self] _ in - self?.refresh() + self?.setNeedsRefresh() } .store(in: &cancellables) locationPresenceStore.$teleportedGeo .receive(on: DispatchQueue.main) .sink { [weak self] _ in - self?.refresh() + self?.setNeedsRefresh() } .store(in: &cancellables) conversations.$unreadConversations .receive(on: DispatchQueue.main) .sink { [weak self] _ in - self?.refresh() + self?.setNeedsRefresh() } .store(in: &cancellables) @@ -168,67 +175,89 @@ final class PeerListModel: ObservableObject { .receive(on: DispatchQueue.main) .sink { [weak self] change in guard case .direct = Self.changedConversationID(change) else { return } - self?.refresh() + self?.setNeedsRefresh() } .store(in: &cancellables) chatViewModel.groupStore.$groups .receive(on: DispatchQueue.main) .sink { [weak self] _ in - self?.refresh() + self?.setNeedsRefresh() } .store(in: &cancellables) peerIdentityStore.$encryptionStatuses .receive(on: DispatchQueue.main) .sink { [weak self] _ in - self?.refresh() + self?.setNeedsRefresh() } .store(in: &cancellables) peerIdentityStore.$verifiedFingerprints .receive(on: DispatchQueue.main) .sink { [weak self] _ in - self?.refresh() + self?.setNeedsRefresh() } .store(in: &cancellables) NotificationCenter.default.publisher(for: Notification.Name("peerStatusUpdated")) .receive(on: DispatchQueue.main) .sink { [weak self] _ in - self?.refresh() + self?.setNeedsRefresh() } .store(in: &cancellables) chatViewModel.participantTracker.$visiblePeople .receive(on: DispatchQueue.main) .sink { [weak self] _ in - self?.refresh() + self?.setNeedsRefresh() } .store(in: &cancellables) locationChannelsModel.$selectedChannel .receive(on: DispatchQueue.main) .sink { [weak self] _ in - self?.refresh() + self?.setNeedsRefresh() } .store(in: &cancellables) locationChannelsModel.$teleported .receive(on: DispatchQueue.main) .sink { [weak self] _ in - self?.refresh() + self?.setNeedsRefresh() } .store(in: &cancellables) locationChannelsModel.$availableChannels .receive(on: DispatchQueue.main) .sink { [weak self] _ in - self?.refresh() + self?.setNeedsRefresh() } .store(in: &cancellables) } + /// Rebuilds the rows now. The geohash roster republishes only when + /// membership or names change, so its recency order goes stale while the + /// same people stay active; the people sheet calls this as it opens. + func refreshNow() { + refresh() + } + + /// Coalesces bursts of triggers into one rebuild per main-queue turn: a + /// participant event republishes the roster and the teleport set, and a + /// mesh snapshot touches peers, unread and encryption state at once. + private func setNeedsRefresh() { + guard !refreshScheduled else { return } + refreshScheduled = true + DispatchQueue.main.async { [weak self] in + MainActor.assumeIsolated { + guard let self else { return } + self.refreshScheduled = false + self.refresh() + } + } + } + private func refresh() { let myPeerID = chatViewModel.meshService.myPeerID let meshRows = allPeers.map { peer in @@ -281,27 +310,15 @@ final class PeerListModel: ObservableObject { let groupRows = buildGroupRows() let recentChatRows = buildRecentChatRows(meshRows: meshRows, geohashPeople: geohashPeople) - self.meshRows = meshRows - reachableMeshPeerCount = meshCounts.reachable - connectedMeshPeerCount = meshCounts.connected - self.geohashPeople = geohashPeople - visibleGeohashPeerCount = geohashPeople.count - self.groupRows = groupRows - self.recentChatRows = recentChatRows - renderID = ( - meshRows.map { - "\($0.id)-\($0.displayName)-\($0.isConnected)-\($0.isReachable)-\($0.hasUnread)-\($0.isFavorite)-\($0.isBlocked)" - } + - geohashPeople.map { - "geo:\($0.id)-\($0.isTeleported)-\($0.isBlocked)-\($0.displayName)" - } + - groupRows.map { - "group:\($0.id)-\($0.name)-\($0.memberCount)-\($0.hasUnread)" - } + - recentChatRows.map { - "chat:\($0.id)-\($0.displayName)-\($0.hasUnread)" - } - ).joined(separator: "|") + // Assign only what changed: every @Published write re-renders every + // view observing this model (root, header, the open sheet). + if self.meshRows != meshRows { self.meshRows = meshRows } + if reachableMeshPeerCount != meshCounts.reachable { reachableMeshPeerCount = meshCounts.reachable } + if connectedMeshPeerCount != meshCounts.connected { connectedMeshPeerCount = meshCounts.connected } + if self.geohashPeople != geohashPeople { self.geohashPeople = geohashPeople } + if visibleGeohashPeerCount != geohashPeople.count { visibleGeohashPeerCount = geohashPeople.count } + if self.groupRows != groupRows { self.groupRows = groupRows } + if self.recentChatRows != recentChatRows { self.recentChatRows = recentChatRows } } /// Direct conversations with people absent from the rosters above: diff --git a/bitchat/Localizable.xcstrings b/bitchat/Localizable.xcstrings index 07526ee6..e808553d 100644 --- a/bitchat/Localizable.xcstrings +++ b/bitchat/Localizable.xcstrings @@ -19195,1131 +19195,6 @@ } } }, - "notification.mute.direct.mute" : { - "comment" : "Accessibility label to silence notifications for this direct conversation", - "localizations" : { - "ar" : { - "stringUnit" : { - "state" : "translated", - "value" : "كتم الإشعارات" - } - }, - "bn" : { - "stringUnit" : { - "state" : "translated", - "value" : "বিজ্ঞপ্তি নিঃশব্দ করো" - } - }, - "de" : { - "stringUnit" : { - "state" : "translated", - "value" : "benachrichtigungen stummschalten" - } - }, - "en" : { - "stringUnit" : { - "state" : "translated", - "value" : "mute notifications" - } - }, - "es" : { - "stringUnit" : { - "state" : "translated", - "value" : "silenciar notificaciones" - } - }, - "fa" : { - "stringUnit" : { - "state" : "translated", - "value" : "بی‌صدا کردن اعلان‌ها" - } - }, - "fil" : { - "stringUnit" : { - "state" : "translated", - "value" : "i-mute ang mga notification" - } - }, - "fr" : { - "stringUnit" : { - "state" : "translated", - "value" : "couper les notifications" - } - }, - "he" : { - "stringUnit" : { - "state" : "translated", - "value" : "השתק התראות" - } - }, - "hi" : { - "stringUnit" : { - "state" : "translated", - "value" : "सूचनाएँ म्यूट करो" - } - }, - "id" : { - "stringUnit" : { - "state" : "translated", - "value" : "bisukan notifikasi" - } - }, - "it" : { - "stringUnit" : { - "state" : "translated", - "value" : "silenzia le notifiche" - } - }, - "ja" : { - "stringUnit" : { - "state" : "translated", - "value" : "通知をミュート" - } - }, - "ko" : { - "stringUnit" : { - "state" : "translated", - "value" : "알림 뮤트" - } - }, - "ms" : { - "stringUnit" : { - "state" : "translated", - "value" : "senyapkan pemberitahuan" - } - }, - "ne" : { - "stringUnit" : { - "state" : "translated", - "value" : "सूचना म्युट गर" - } - }, - "nl" : { - "stringUnit" : { - "state" : "translated", - "value" : "meldingen dempen" - } - }, - "pl" : { - "stringUnit" : { - "state" : "translated", - "value" : "wycisz powiadomienia" - } - }, - "pt" : { - "stringUnit" : { - "state" : "translated", - "value" : "silenciar notificações" - } - }, - "pt-BR" : { - "stringUnit" : { - "state" : "translated", - "value" : "silenciar notificações" - } - }, - "ru" : { - "stringUnit" : { - "state" : "translated", - "value" : "выключить уведомления" - } - }, - "sv" : { - "stringUnit" : { - "state" : "translated", - "value" : "tysta aviseringar" - } - }, - "ta" : { - "stringUnit" : { - "state" : "translated", - "value" : "அறிவிப்புகளை முடக்கு" - } - }, - "th" : { - "stringUnit" : { - "state" : "translated", - "value" : "ปิดการแจ้งเตือน" - } - }, - "tr" : { - "stringUnit" : { - "state" : "translated", - "value" : "bildirimleri sessize al" - } - }, - "uk" : { - "stringUnit" : { - "state" : "translated", - "value" : "вимкнути сповіщення" - } - }, - "ur" : { - "stringUnit" : { - "state" : "translated", - "value" : "اطلاعات خاموش کریں" - } - }, - "vi" : { - "stringUnit" : { - "state" : "translated", - "value" : "tắt thông báo" - } - }, - "zh-Hans" : { - "stringUnit" : { - "state" : "translated", - "value" : "静音通知" - } - }, - "zh-Hant" : { - "stringUnit" : { - "state" : "translated", - "value" : "靜音通知" - } - } - } - }, - "notification.mute.direct.unmute" : { - "comment" : "Accessibility label to resume notifications for this direct conversation", - "localizations" : { - "ar" : { - "stringUnit" : { - "state" : "translated", - "value" : "إلغاء كتم الإشعارات" - } - }, - "bn" : { - "stringUnit" : { - "state" : "translated", - "value" : "বিজ্ঞপ্তি আনমিউট করো" - } - }, - "de" : { - "stringUnit" : { - "state" : "translated", - "value" : "benachrichtigungen wieder an" - } - }, - "en" : { - "stringUnit" : { - "state" : "translated", - "value" : "unmute notifications" - } - }, - "es" : { - "stringUnit" : { - "state" : "translated", - "value" : "activar notificaciones" - } - }, - "fa" : { - "stringUnit" : { - "state" : "translated", - "value" : "وصل کردن اعلان‌ها" - } - }, - "fil" : { - "stringUnit" : { - "state" : "translated", - "value" : "i-unmute ang mga notification" - } - }, - "fr" : { - "stringUnit" : { - "state" : "translated", - "value" : "réactiver les notifications" - } - }, - "he" : { - "stringUnit" : { - "state" : "translated", - "value" : "בטל השתקת התראות" - } - }, - "hi" : { - "stringUnit" : { - "state" : "translated", - "value" : "सूचनाएँ अनम्यूट करो" - } - }, - "id" : { - "stringUnit" : { - "state" : "translated", - "value" : "nyalakan notifikasi" - } - }, - "it" : { - "stringUnit" : { - "state" : "translated", - "value" : "riattiva le notifiche" - } - }, - "ja" : { - "stringUnit" : { - "state" : "translated", - "value" : "通知のミュートを解除" - } - }, - "ko" : { - "stringUnit" : { - "state" : "translated", - "value" : "알림 뮤트 해제" - } - }, - "ms" : { - "stringUnit" : { - "state" : "translated", - "value" : "nyahsenyap pemberitahuan" - } - }, - "ne" : { - "stringUnit" : { - "state" : "translated", - "value" : "सूचना अनम्युट गर" - } - }, - "nl" : { - "stringUnit" : { - "state" : "translated", - "value" : "meldingen aanzetten" - } - }, - "pl" : { - "stringUnit" : { - "state" : "translated", - "value" : "włącz powiadomienia" - } - }, - "pt" : { - "stringUnit" : { - "state" : "translated", - "value" : "reativar notificações" - } - }, - "pt-BR" : { - "stringUnit" : { - "state" : "translated", - "value" : "reativar notificações" - } - }, - "ru" : { - "stringUnit" : { - "state" : "translated", - "value" : "включить уведомления" - } - }, - "sv" : { - "stringUnit" : { - "state" : "translated", - "value" : "slå på aviseringar" - } - }, - "ta" : { - "stringUnit" : { - "state" : "translated", - "value" : "அறிவிப்பு முடக்கம் நீக்கு" - } - }, - "th" : { - "stringUnit" : { - "state" : "translated", - "value" : "เปิดการแจ้งเตือน" - } - }, - "tr" : { - "stringUnit" : { - "state" : "translated", - "value" : "bildirimleri aç" - } - }, - "uk" : { - "stringUnit" : { - "state" : "translated", - "value" : "увімкнути сповіщення" - } - }, - "ur" : { - "stringUnit" : { - "state" : "translated", - "value" : "اطلاعات آن کریں" - } - }, - "vi" : { - "stringUnit" : { - "state" : "translated", - "value" : "bật thông báo" - } - }, - "zh-Hans" : { - "stringUnit" : { - "state" : "translated", - "value" : "取消静音通知" - } - }, - "zh-Hant" : { - "stringUnit" : { - "state" : "translated", - "value" : "取消靜音通知" - } - } - } - }, - "notification.mute.geohash.mute" : { - "comment" : "Accessibility label to silence notifications for this location channel", - "localizations" : { - "ar" : { - "stringUnit" : { - "state" : "translated", - "value" : "كتم إشعارات القناة" - } - }, - "bn" : { - "stringUnit" : { - "state" : "translated", - "value" : "চ্যানেল বিজ্ঞপ্তি নিঃশব্দ করো" - } - }, - "de" : { - "stringUnit" : { - "state" : "translated", - "value" : "kanal-benachrichtigungen stummschalten" - } - }, - "en" : { - "stringUnit" : { - "state" : "translated", - "value" : "mute channel notifications" - } - }, - "es" : { - "stringUnit" : { - "state" : "translated", - "value" : "silenciar notificaciones del canal" - } - }, - "fa" : { - "stringUnit" : { - "state" : "translated", - "value" : "بی‌صدا کردن اعلان‌های کانال" - } - }, - "fil" : { - "stringUnit" : { - "state" : "translated", - "value" : "i-mute ang notification ng channel" - } - }, - "fr" : { - "stringUnit" : { - "state" : "translated", - "value" : "couper les notifications du canal" - } - }, - "he" : { - "stringUnit" : { - "state" : "translated", - "value" : "השתק התראות ערוץ" - } - }, - "hi" : { - "stringUnit" : { - "state" : "translated", - "value" : "चैनल सूचनाएँ म्यूट करो" - } - }, - "id" : { - "stringUnit" : { - "state" : "translated", - "value" : "bisukan notifikasi kanal" - } - }, - "it" : { - "stringUnit" : { - "state" : "translated", - "value" : "silenzia le notifiche del canale" - } - }, - "ja" : { - "stringUnit" : { - "state" : "translated", - "value" : "チャンネル通知をミュート" - } - }, - "ko" : { - "stringUnit" : { - "state" : "translated", - "value" : "채널 알림 뮤트" - } - }, - "ms" : { - "stringUnit" : { - "state" : "translated", - "value" : "senyapkan pemberitahuan saluran" - } - }, - "ne" : { - "stringUnit" : { - "state" : "translated", - "value" : "च्यानल सूचना म्युट गर" - } - }, - "nl" : { - "stringUnit" : { - "state" : "translated", - "value" : "kanaalmeldingen dempen" - } - }, - "pl" : { - "stringUnit" : { - "state" : "translated", - "value" : "wycisz powiadomienia kanału" - } - }, - "pt" : { - "stringUnit" : { - "state" : "translated", - "value" : "silenciar notificações do canal" - } - }, - "pt-BR" : { - "stringUnit" : { - "state" : "translated", - "value" : "silenciar notificações do canal" - } - }, - "ru" : { - "stringUnit" : { - "state" : "translated", - "value" : "выключить уведомления канала" - } - }, - "sv" : { - "stringUnit" : { - "state" : "translated", - "value" : "tysta kanalaviseringar" - } - }, - "ta" : { - "stringUnit" : { - "state" : "translated", - "value" : "சேனல் அறிவிப்புகளை முடக்கு" - } - }, - "th" : { - "stringUnit" : { - "state" : "translated", - "value" : "ปิดการแจ้งเตือนช่อง" - } - }, - "tr" : { - "stringUnit" : { - "state" : "translated", - "value" : "kanal bildirimlerini sessize al" - } - }, - "uk" : { - "stringUnit" : { - "state" : "translated", - "value" : "вимкнути сповіщення каналу" - } - }, - "ur" : { - "stringUnit" : { - "state" : "translated", - "value" : "چینل اطلاعات خاموش کریں" - } - }, - "vi" : { - "stringUnit" : { - "state" : "translated", - "value" : "tắt thông báo kênh" - } - }, - "zh-Hans" : { - "stringUnit" : { - "state" : "translated", - "value" : "静音频道通知" - } - }, - "zh-Hant" : { - "stringUnit" : { - "state" : "translated", - "value" : "靜音頻道通知" - } - } - } - }, - "notification.mute.geohash.unmute" : { - "comment" : "Accessibility label to resume notifications for this location channel", - "localizations" : { - "ar" : { - "stringUnit" : { - "state" : "translated", - "value" : "إلغاء كتم إشعارات القناة" - } - }, - "bn" : { - "stringUnit" : { - "state" : "translated", - "value" : "চ্যানেল বিজ্ঞপ্তি আনমিউট করো" - } - }, - "de" : { - "stringUnit" : { - "state" : "translated", - "value" : "kanal-benachrichtigungen wieder an" - } - }, - "en" : { - "stringUnit" : { - "state" : "translated", - "value" : "unmute channel notifications" - } - }, - "es" : { - "stringUnit" : { - "state" : "translated", - "value" : "activar notificaciones del canal" - } - }, - "fa" : { - "stringUnit" : { - "state" : "translated", - "value" : "وصل کردن اعلان‌های کانال" - } - }, - "fil" : { - "stringUnit" : { - "state" : "translated", - "value" : "i-unmute ang notification ng channel" - } - }, - "fr" : { - "stringUnit" : { - "state" : "translated", - "value" : "réactiver les notifications du canal" - } - }, - "he" : { - "stringUnit" : { - "state" : "translated", - "value" : "בטל השתקת התראות ערוץ" - } - }, - "hi" : { - "stringUnit" : { - "state" : "translated", - "value" : "चैनل सूचनाएँ अनम्यूट करो" - } - }, - "id" : { - "stringUnit" : { - "state" : "translated", - "value" : "nyalakan notifikasi kanal" - } - }, - "it" : { - "stringUnit" : { - "state" : "translated", - "value" : "riattiva le notifiche del canale" - } - }, - "ja" : { - "stringUnit" : { - "state" : "translated", - "value" : "チャンネル通知のミュートを解除" - } - }, - "ko" : { - "stringUnit" : { - "state" : "translated", - "value" : "채널 알림 뮤트 해제" - } - }, - "ms" : { - "stringUnit" : { - "state" : "translated", - "value" : "nyahsenyap pemberitahuan saluran" - } - }, - "ne" : { - "stringUnit" : { - "state" : "translated", - "value" : "च्यानल सूचना अनम्युट गर" - } - }, - "nl" : { - "stringUnit" : { - "state" : "translated", - "value" : "kanaalmeldingen aanzetten" - } - }, - "pl" : { - "stringUnit" : { - "state" : "translated", - "value" : "włącz powiadomienia kanału" - } - }, - "pt" : { - "stringUnit" : { - "state" : "translated", - "value" : "reativar notificações do canal" - } - }, - "pt-BR" : { - "stringUnit" : { - "state" : "translated", - "value" : "reativar notificações do canal" - } - }, - "ru" : { - "stringUnit" : { - "state" : "translated", - "value" : "включить уведомления канала" - } - }, - "sv" : { - "stringUnit" : { - "state" : "translated", - "value" : "slå på kanalaviseringar" - } - }, - "ta" : { - "stringUnit" : { - "state" : "translated", - "value" : "சேனல் அறிவிப்பு முடக்கம் நீக்கு" - } - }, - "th" : { - "stringUnit" : { - "state" : "translated", - "value" : "เปิดการแจ้งเตือนช่อง" - } - }, - "tr" : { - "stringUnit" : { - "state" : "translated", - "value" : "kanal bildirimlerini aç" - } - }, - "uk" : { - "stringUnit" : { - "state" : "translated", - "value" : "увімкнути сповіщення каналу" - } - }, - "ur" : { - "stringUnit" : { - "state" : "translated", - "value" : "چینل اطلاعات آن کریں" - } - }, - "vi" : { - "stringUnit" : { - "state" : "translated", - "value" : "bật thông báo kênh" - } - }, - "zh-Hans" : { - "stringUnit" : { - "state" : "translated", - "value" : "取消静音频道通知" - } - }, - "zh-Hant" : { - "stringUnit" : { - "state" : "translated", - "value" : "取消靜音頻道通知" - } - } - } - }, - "notification.mute.state.muted" : { - "comment" : "Badge on a peer row indicating that conversation's notifications are muted", - "localizations" : { - "ar" : { - "stringUnit" : { - "state" : "translated", - "value" : "مكتوم" - } - }, - "bn" : { - "stringUnit" : { - "state" : "translated", - "value" : "নিঃশব্দ" - } - }, - "de" : { - "stringUnit" : { - "state" : "translated", - "value" : "stumm" - } - }, - "en" : { - "stringUnit" : { - "state" : "translated", - "value" : "notifications muted" - } - }, - "es" : { - "stringUnit" : { - "state" : "translated", - "value" : "silenciado" - } - }, - "fa" : { - "stringUnit" : { - "state" : "translated", - "value" : "بی‌صدا" - } - }, - "fil" : { - "stringUnit" : { - "state" : "translated", - "value" : "naka-mute" - } - }, - "fr" : { - "stringUnit" : { - "state" : "translated", - "value" : "en sourdine" - } - }, - "he" : { - "stringUnit" : { - "state" : "translated", - "value" : "מושתק" - } - }, - "hi" : { - "stringUnit" : { - "state" : "translated", - "value" : "म्यूट" - } - }, - "id" : { - "stringUnit" : { - "state" : "translated", - "value" : "dibisukan" - } - }, - "it" : { - "stringUnit" : { - "state" : "translated", - "value" : "silenziato" - } - }, - "ja" : { - "stringUnit" : { - "state" : "translated", - "value" : "ミュート中" - } - }, - "ko" : { - "stringUnit" : { - "state" : "translated", - "value" : "뮤트됨" - } - }, - "ms" : { - "stringUnit" : { - "state" : "translated", - "value" : "disenyapkan" - } - }, - "ne" : { - "stringUnit" : { - "state" : "translated", - "value" : "म्युट" - } - }, - "nl" : { - "stringUnit" : { - "state" : "translated", - "value" : "gedempt" - } - }, - "pl" : { - "stringUnit" : { - "state" : "translated", - "value" : "wyciszone" - } - }, - "pt" : { - "stringUnit" : { - "state" : "translated", - "value" : "silenciado" - } - }, - "pt-BR" : { - "stringUnit" : { - "state" : "translated", - "value" : "silenciado" - } - }, - "ru" : { - "stringUnit" : { - "state" : "translated", - "value" : "без звука" - } - }, - "sv" : { - "stringUnit" : { - "state" : "translated", - "value" : "tystad" - } - }, - "ta" : { - "stringUnit" : { - "state" : "translated", - "value" : "முடக்கப்பட்டது" - } - }, - "th" : { - "stringUnit" : { - "state" : "translated", - "value" : "ปิดเสียงแล้ว" - } - }, - "tr" : { - "stringUnit" : { - "state" : "translated", - "value" : "sessiz" - } - }, - "uk" : { - "stringUnit" : { - "state" : "translated", - "value" : "без звуку" - } - }, - "ur" : { - "stringUnit" : { - "state" : "translated", - "value" : "خاموش" - } - }, - "vi" : { - "stringUnit" : { - "state" : "translated", - "value" : "đã tắt" - } - }, - "zh-Hans" : { - "stringUnit" : { - "state" : "translated", - "value" : "已静音" - } - }, - "zh-Hant" : { - "stringUnit" : { - "state" : "translated", - "value" : "已靜音" - } - } - } - }, - "#%@" : { - "comment" : "Non-localizable channel hashtag format used in code", - "extractionState" : "manual", - "shouldTranslate" : false, - "localizations" : { - "fa" : { - "stringUnit" : { - "state" : "translated", - "value" : "#%@" - } - } - } - }, - "%@" : { - "comment" : "Non-localizable symbol used in code", - "extractionState" : "manual", - "localizations" : { - "ar" : { - "stringUnit" : { - "state" : "translated", - "value" : "%@" - } - }, - "bn" : { - "stringUnit" : { - "state" : "translated", - "value" : "%@" - } - }, - "de" : { - "stringUnit" : { - "state" : "translated", - "value" : "%@" - } - }, - "en" : { - "stringUnit" : { - "state" : "translated", - "value" : "%@" - } - }, - "es" : { - "stringUnit" : { - "state" : "translated", - "value" : "%@" - } - }, - "fa" : { - "stringUnit" : { - "state" : "translated", - "value" : "%@" - } - }, - "fil" : { - "stringUnit" : { - "state" : "translated", - "value" : "%@" - } - }, - "fr" : { - "stringUnit" : { - "state" : "translated", - "value" : "%@" - } - }, - "he" : { - "stringUnit" : { - "state" : "translated", - "value" : "%@" - } - }, - "hi" : { - "stringUnit" : { - "state" : "translated", - "value" : "%@" - } - }, - "id" : { - "stringUnit" : { - "state" : "translated", - "value" : "%@" - } - }, - "it" : { - "stringUnit" : { - "state" : "translated", - "value" : "%@" - } - }, - "ja" : { - "stringUnit" : { - "state" : "translated", - "value" : "%@" - } - }, - "ko" : { - "stringUnit" : { - "state" : "translated", - "value" : "%@" - } - }, - "ms" : { - "stringUnit" : { - "state" : "translated", - "value" : "%@" - } - }, - "ne" : { - "stringUnit" : { - "state" : "translated", - "value" : "%@" - } - }, - "nl" : { - "stringUnit" : { - "state" : "translated", - "value" : "%@" - } - }, - "pl" : { - "stringUnit" : { - "state" : "translated", - "value" : "%@" - } - }, - "pt" : { - "stringUnit" : { - "state" : "translated", - "value" : "%@" - } - }, - "pt-BR" : { - "stringUnit" : { - "state" : "translated", - "value" : "%@" - } - }, - "ru" : { - "stringUnit" : { - "state" : "translated", - "value" : "%@" - } - }, - "sv" : { - "stringUnit" : { - "state" : "translated", - "value" : "%@" - } - }, - "ta" : { - "stringUnit" : { - "state" : "translated", - "value" : "%@" - } - }, - "th" : { - "stringUnit" : { - "state" : "translated", - "value" : "%@" - } - }, - "tr" : { - "stringUnit" : { - "state" : "translated", - "value" : "%@" - } - }, - "uk" : { - "stringUnit" : { - "state" : "translated", - "value" : "%@" - } - }, - "ur" : { - "stringUnit" : { - "state" : "translated", - "value" : "%@" - } - }, - "vi" : { - "stringUnit" : { - "state" : "translated", - "value" : "%@" - } - }, - "zh-Hans" : { - "stringUnit" : { - "state" : "translated", - "value" : "%@" - } - }, - "zh-Hant" : { - "stringUnit" : { - "state" : "translated", - "value" : "%@" - } - } - }, - "shouldTranslate" : false - }, "%@ active" : { "comment" : "A label at the bottom of the people list sheet showing the number of active users.", "extractionState" : "stale", @@ -67914,6 +66789,1122 @@ } } }, + "geohash_picker.accessibility.decrease_precision" : { + "comment" : "Accessibility label for the globe picker button that zooms out to a larger geohash cell", + "extractionState" : "manual", + "localizations" : { + "ar" : { + "stringUnit" : { + "state" : "translated", + "value" : "خفض الدقة" + } + }, + "bn" : { + "stringUnit" : { + "state" : "translated", + "value" : "নির্ভুলতা কমান" + } + }, + "de" : { + "stringUnit" : { + "state" : "translated", + "value" : "genauigkeit verringern" + } + }, + "en" : { + "stringUnit" : { + "state" : "translated", + "value" : "decrease precision" + } + }, + "es" : { + "stringUnit" : { + "state" : "translated", + "value" : "disminuir precisión" + } + }, + "fa" : { + "stringUnit" : { + "state" : "translated", + "value" : "کاهش دقت" + } + }, + "fil" : { + "stringUnit" : { + "state" : "translated", + "value" : "bawasan ang precision" + } + }, + "fr" : { + "stringUnit" : { + "state" : "translated", + "value" : "diminuer la précision" + } + }, + "he" : { + "stringUnit" : { + "state" : "translated", + "value" : "הפחת דיוק" + } + }, + "hi" : { + "stringUnit" : { + "state" : "translated", + "value" : "सटीकता घटाएँ" + } + }, + "id" : { + "stringUnit" : { + "state" : "translated", + "value" : "kurangi presisi" + } + }, + "it" : { + "stringUnit" : { + "state" : "translated", + "value" : "diminuisci precisione" + } + }, + "ja" : { + "stringUnit" : { + "state" : "translated", + "value" : "精度を下げる" + } + }, + "ko" : { + "stringUnit" : { + "state" : "translated", + "value" : "정밀도 낮추기" + } + }, + "ms" : { + "stringUnit" : { + "state" : "translated", + "value" : "kurangkan ketepatan" + } + }, + "ne" : { + "stringUnit" : { + "state" : "translated", + "value" : "शुद्धता घटाउनुहोस्" + } + }, + "nl" : { + "stringUnit" : { + "state" : "translated", + "value" : "precisie verlagen" + } + }, + "pl" : { + "stringUnit" : { + "state" : "translated", + "value" : "zmniejsz precyzję" + } + }, + "pt" : { + "stringUnit" : { + "state" : "translated", + "value" : "diminuir precisão" + } + }, + "pt-BR" : { + "stringUnit" : { + "state" : "translated", + "value" : "diminuir precisão" + } + }, + "ru" : { + "stringUnit" : { + "state" : "translated", + "value" : "уменьшить точность" + } + }, + "sv" : { + "stringUnit" : { + "state" : "translated", + "value" : "minska precision" + } + }, + "ta" : { + "stringUnit" : { + "state" : "translated", + "value" : "துல்லியத்தைக் குறை" + } + }, + "th" : { + "stringUnit" : { + "state" : "translated", + "value" : "ลดความแม่นยำ" + } + }, + "tr" : { + "stringUnit" : { + "state" : "translated", + "value" : "hassasiyeti azalt" + } + }, + "uk" : { + "stringUnit" : { + "state" : "translated", + "value" : "зменшити точність" + } + }, + "ur" : { + "stringUnit" : { + "state" : "translated", + "value" : "درستگی کم کریں" + } + }, + "vi" : { + "stringUnit" : { + "state" : "translated", + "value" : "giảm độ chính xác" + } + }, + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "降低精度" + } + }, + "zh-Hant" : { + "stringUnit" : { + "state" : "translated", + "value" : "降低精確度" + } + } + } + }, + "geohash_picker.accessibility.increase_precision" : { + "comment" : "Accessibility label for the globe picker button that zooms in to a smaller geohash cell", + "extractionState" : "manual", + "localizations" : { + "ar" : { + "stringUnit" : { + "state" : "translated", + "value" : "رفع الدقة" + } + }, + "bn" : { + "stringUnit" : { + "state" : "translated", + "value" : "নির্ভুলতা বাড়ান" + } + }, + "de" : { + "stringUnit" : { + "state" : "translated", + "value" : "genauigkeit erhöhen" + } + }, + "en" : { + "stringUnit" : { + "state" : "translated", + "value" : "increase precision" + } + }, + "es" : { + "stringUnit" : { + "state" : "translated", + "value" : "aumentar precisión" + } + }, + "fa" : { + "stringUnit" : { + "state" : "translated", + "value" : "افزایش دقت" + } + }, + "fil" : { + "stringUnit" : { + "state" : "translated", + "value" : "dagdagan ang precision" + } + }, + "fr" : { + "stringUnit" : { + "state" : "translated", + "value" : "augmenter la précision" + } + }, + "he" : { + "stringUnit" : { + "state" : "translated", + "value" : "הגבר דיוק" + } + }, + "hi" : { + "stringUnit" : { + "state" : "translated", + "value" : "सटीकता बढ़ाएँ" + } + }, + "id" : { + "stringUnit" : { + "state" : "translated", + "value" : "tingkatkan presisi" + } + }, + "it" : { + "stringUnit" : { + "state" : "translated", + "value" : "aumenta precisione" + } + }, + "ja" : { + "stringUnit" : { + "state" : "translated", + "value" : "精度を上げる" + } + }, + "ko" : { + "stringUnit" : { + "state" : "translated", + "value" : "정밀도 높이기" + } + }, + "ms" : { + "stringUnit" : { + "state" : "translated", + "value" : "tingkatkan ketepatan" + } + }, + "ne" : { + "stringUnit" : { + "state" : "translated", + "value" : "शुद्धता बढाउनुहोस्" + } + }, + "nl" : { + "stringUnit" : { + "state" : "translated", + "value" : "precisie verhogen" + } + }, + "pl" : { + "stringUnit" : { + "state" : "translated", + "value" : "zwiększ precyzję" + } + }, + "pt" : { + "stringUnit" : { + "state" : "translated", + "value" : "aumentar precisão" + } + }, + "pt-BR" : { + "stringUnit" : { + "state" : "translated", + "value" : "aumentar precisão" + } + }, + "ru" : { + "stringUnit" : { + "state" : "translated", + "value" : "увеличить точность" + } + }, + "sv" : { + "stringUnit" : { + "state" : "translated", + "value" : "öka precision" + } + }, + "ta" : { + "stringUnit" : { + "state" : "translated", + "value" : "துல்லியத்தை அதிகரி" + } + }, + "th" : { + "stringUnit" : { + "state" : "translated", + "value" : "เพิ่มความแม่นยำ" + } + }, + "tr" : { + "stringUnit" : { + "state" : "translated", + "value" : "hassasiyeti artır" + } + }, + "uk" : { + "stringUnit" : { + "state" : "translated", + "value" : "збільшити точність" + } + }, + "ur" : { + "stringUnit" : { + "state" : "translated", + "value" : "درستگی بڑھائیں" + } + }, + "vi" : { + "stringUnit" : { + "state" : "translated", + "value" : "tăng độ chính xác" + } + }, + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "提高精度" + } + }, + "zh-Hant" : { + "stringUnit" : { + "state" : "translated", + "value" : "提高精確度" + } + } + } + }, + "geohash_picker.accessibility.select" : { + "comment" : "Accessibility label for the globe picker's select button", + "extractionState" : "manual", + "localizations" : { + "ar" : { + "stringUnit" : { + "state" : "translated", + "value" : "اختر geohash" + } + }, + "bn" : { + "stringUnit" : { + "state" : "translated", + "value" : "জিওহ্যাশ নির্বাচন করুন" + } + }, + "de" : { + "stringUnit" : { + "state" : "translated", + "value" : "geohash auswählen" + } + }, + "en" : { + "stringUnit" : { + "state" : "translated", + "value" : "select geohash" + } + }, + "es" : { + "stringUnit" : { + "state" : "translated", + "value" : "seleccionar geohash" + } + }, + "fa" : { + "stringUnit" : { + "state" : "translated", + "value" : "انتخاب geohash" + } + }, + "fil" : { + "stringUnit" : { + "state" : "translated", + "value" : "piliin ang geohash" + } + }, + "fr" : { + "stringUnit" : { + "state" : "translated", + "value" : "sélectionner le geohash" + } + }, + "he" : { + "stringUnit" : { + "state" : "translated", + "value" : "בחר geohash" + } + }, + "hi" : { + "stringUnit" : { + "state" : "translated", + "value" : "geohash चुनें" + } + }, + "id" : { + "stringUnit" : { + "state" : "translated", + "value" : "pilih geohash" + } + }, + "it" : { + "stringUnit" : { + "state" : "translated", + "value" : "seleziona geohash" + } + }, + "ja" : { + "stringUnit" : { + "state" : "translated", + "value" : "geohash を選択" + } + }, + "ko" : { + "stringUnit" : { + "state" : "translated", + "value" : "geohash 선택" + } + }, + "ms" : { + "stringUnit" : { + "state" : "translated", + "value" : "pilih geohash" + } + }, + "ne" : { + "stringUnit" : { + "state" : "translated", + "value" : "geohash छान्नुहोस्" + } + }, + "nl" : { + "stringUnit" : { + "state" : "translated", + "value" : "geohash selecteren" + } + }, + "pl" : { + "stringUnit" : { + "state" : "translated", + "value" : "wybierz geohash" + } + }, + "pt" : { + "stringUnit" : { + "state" : "translated", + "value" : "selecionar geohash" + } + }, + "pt-BR" : { + "stringUnit" : { + "state" : "translated", + "value" : "selecionar geohash" + } + }, + "ru" : { + "stringUnit" : { + "state" : "translated", + "value" : "выбрать geohash" + } + }, + "sv" : { + "stringUnit" : { + "state" : "translated", + "value" : "välj geohash" + } + }, + "ta" : { + "stringUnit" : { + "state" : "translated", + "value" : "ஜியோஹாஷைத் தேர்ந்தெடு" + } + }, + "th" : { + "stringUnit" : { + "state" : "translated", + "value" : "เลือก geohash" + } + }, + "tr" : { + "stringUnit" : { + "state" : "translated", + "value" : "geohash seç" + } + }, + "uk" : { + "stringUnit" : { + "state" : "translated", + "value" : "вибрати геохеш" + } + }, + "ur" : { + "stringUnit" : { + "state" : "translated", + "value" : "geohash منتخب کریں" + } + }, + "vi" : { + "stringUnit" : { + "state" : "translated", + "value" : "chọn geohash" + } + }, + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "选择 geohash" + } + }, + "zh-Hant" : { + "stringUnit" : { + "state" : "translated", + "value" : "選擇地理雜湊" + } + } + } + }, + "geohash_picker.instruction" : { + "comment" : "Hint at the top of the globe geohash picker explaining its gestures", + "extractionState" : "manual", + "localizations" : { + "ar" : { + "stringUnit" : { + "state" : "translated", + "value" : "اسحب للتدوير · قرّب بإصبعين للتكبير · انقر للتركيز" + } + }, + "bn" : { + "stringUnit" : { + "state" : "translated", + "value" : "ঘোরাতে টানুন · জুম করতে পিঞ্চ করুন · ফোকাস করতে ট্যাপ করুন" + } + }, + "de" : { + "stringUnit" : { + "state" : "translated", + "value" : "ziehen zum drehen · zwei finger zum zoomen · tippen zum fokussieren" + } + }, + "en" : { + "stringUnit" : { + "state" : "translated", + "value" : "drag to spin · pinch to zoom · tap to focus" + } + }, + "es" : { + "stringUnit" : { + "state" : "translated", + "value" : "arrastra para girar · pellizca para hacer zoom · toca para enfocar" + } + }, + "fa" : { + "stringUnit" : { + "state" : "translated", + "value" : "برای چرخاندن بکشید · برای بزرگ‌نمایی دو انگشت را باز کنید · برای تمرکز ضربه بزنید" + } + }, + "fil" : { + "stringUnit" : { + "state" : "translated", + "value" : "i-drag para paikutin · i-pinch para mag-zoom · i-tap para mag-focus" + } + }, + "fr" : { + "stringUnit" : { + "state" : "translated", + "value" : "glisser pour tourner · pincer pour zoomer · toucher pour centrer" + } + }, + "he" : { + "stringUnit" : { + "state" : "translated", + "value" : "גרור לסיבוב · צבוט לזום · הקש למיקוד" + } + }, + "hi" : { + "stringUnit" : { + "state" : "translated", + "value" : "घुमाने के लिए खींचें · ज़ूम के लिए पिंच करें · फ़ोकस के लिए टैप करें" + } + }, + "id" : { + "stringUnit" : { + "state" : "translated", + "value" : "seret untuk memutar · cubit untuk zoom · ketuk untuk fokus" + } + }, + "it" : { + "stringUnit" : { + "state" : "translated", + "value" : "trascina per ruotare · pizzica per lo zoom · tocca per centrare" + } + }, + "ja" : { + "stringUnit" : { + "state" : "translated", + "value" : "ドラッグで回転 · ピンチでズーム · タップでフォーカス" + } + }, + "ko" : { + "stringUnit" : { + "state" : "translated", + "value" : "드래그하여 회전 · 핀치하여 확대/축소 · 탭하여 초점 맞추기" + } + }, + "ms" : { + "stringUnit" : { + "state" : "translated", + "value" : "seret untuk memutar · cubit untuk zum · ketik untuk fokus" + } + }, + "ne" : { + "stringUnit" : { + "state" : "translated", + "value" : "घुमाउन तान्नुहोस् · जुम गर्न पिन्च गर्नुहोस् · फोकस गर्न ट्याप गर्नुहोस्" + } + }, + "nl" : { + "stringUnit" : { + "state" : "translated", + "value" : "sleep om te draaien · knijp om te zoomen · tik om te focussen" + } + }, + "pl" : { + "stringUnit" : { + "state" : "translated", + "value" : "przeciągnij, aby obrócić · uszczypnij, aby powiększyć · stuknij, aby wyśrodkować" + } + }, + "pt" : { + "stringUnit" : { + "state" : "translated", + "value" : "arraste para rodar · aperte para ampliar · toque para focar" + } + }, + "pt-BR" : { + "stringUnit" : { + "state" : "translated", + "value" : "arraste para girar · faça pinça para ampliar · toque para focar" + } + }, + "ru" : { + "stringUnit" : { + "state" : "translated", + "value" : "потяните, чтобы вращать · сведите пальцы для масштаба · коснитесь для фокуса" + } + }, + "sv" : { + "stringUnit" : { + "state" : "translated", + "value" : "dra för att snurra · nyp för att zooma · tryck för att fokusera" + } + }, + "ta" : { + "stringUnit" : { + "state" : "translated", + "value" : "சுழற்ற இழுக்கவும் · பெரிதாக்க பிஞ்ச் செய்யவும் · கவனம் செலுத்த தட்டவும்" + } + }, + "th" : { + "stringUnit" : { + "state" : "translated", + "value" : "ลากเพื่อหมุน · จีบนิ้วเพื่อซูม · แตะเพื่อโฟกัส" + } + }, + "tr" : { + "stringUnit" : { + "state" : "translated", + "value" : "döndürmek için sürükle · yakınlaştırmak için kıstır · odaklamak için dokun" + } + }, + "uk" : { + "stringUnit" : { + "state" : "translated", + "value" : "потягніть, щоб обертати · зведіть пальці для масштабу · торкніться для фокусу" + } + }, + "ur" : { + "stringUnit" : { + "state" : "translated", + "value" : "گھمانے کے لیے گھسیٹیں · زوم کے لیے چٹکی لیں · فوکس کے لیے تھپتھپائیں" + } + }, + "vi" : { + "stringUnit" : { + "state" : "translated", + "value" : "kéo để xoay · chụm để thu phóng · chạm để lấy nét" + } + }, + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "拖动旋转 · 双指缩放 · 轻点聚焦" + } + }, + "zh-Hant" : { + "stringUnit" : { + "state" : "translated", + "value" : "拖曳旋轉 · 雙指縮放 · 輕點聚焦" + } + } + } + }, + "geohash_picker.no_selection" : { + "comment" : "Shown in the globe geohash picker before a geohash is under the crosshair", + "extractionState" : "manual", + "localizations" : { + "ar" : { + "stringUnit" : { + "state" : "translated", + "value" : "اختر موقعًا" + } + }, + "bn" : { + "stringUnit" : { + "state" : "translated", + "value" : "অবস্থান নির্বাচন করুন" + } + }, + "de" : { + "stringUnit" : { + "state" : "translated", + "value" : "ort auswählen" + } + }, + "en" : { + "stringUnit" : { + "state" : "translated", + "value" : "select location" + } + }, + "es" : { + "stringUnit" : { + "state" : "translated", + "value" : "selecciona una ubicación" + } + }, + "fa" : { + "stringUnit" : { + "state" : "translated", + "value" : "انتخاب مکان" + } + }, + "fil" : { + "stringUnit" : { + "state" : "translated", + "value" : "pumili ng lokasyon" + } + }, + "fr" : { + "stringUnit" : { + "state" : "translated", + "value" : "choisir un lieu" + } + }, + "he" : { + "stringUnit" : { + "state" : "translated", + "value" : "בחר מיקום" + } + }, + "hi" : { + "stringUnit" : { + "state" : "translated", + "value" : "स्थान चुनें" + } + }, + "id" : { + "stringUnit" : { + "state" : "translated", + "value" : "pilih lokasi" + } + }, + "it" : { + "stringUnit" : { + "state" : "translated", + "value" : "seleziona una posizione" + } + }, + "ja" : { + "stringUnit" : { + "state" : "translated", + "value" : "場所を選択" + } + }, + "ko" : { + "stringUnit" : { + "state" : "translated", + "value" : "위치 선택" + } + }, + "ms" : { + "stringUnit" : { + "state" : "translated", + "value" : "pilih lokasi" + } + }, + "ne" : { + "stringUnit" : { + "state" : "translated", + "value" : "स्थान छान्नुहोस्" + } + }, + "nl" : { + "stringUnit" : { + "state" : "translated", + "value" : "kies een locatie" + } + }, + "pl" : { + "stringUnit" : { + "state" : "translated", + "value" : "wybierz lokalizację" + } + }, + "pt" : { + "stringUnit" : { + "state" : "translated", + "value" : "selecionar local" + } + }, + "pt-BR" : { + "stringUnit" : { + "state" : "translated", + "value" : "selecionar local" + } + }, + "ru" : { + "stringUnit" : { + "state" : "translated", + "value" : "выберите место" + } + }, + "sv" : { + "stringUnit" : { + "state" : "translated", + "value" : "välj plats" + } + }, + "ta" : { + "stringUnit" : { + "state" : "translated", + "value" : "இடத்தைத் தேர்ந்தெடு" + } + }, + "th" : { + "stringUnit" : { + "state" : "translated", + "value" : "เลือกตำแหน่ง" + } + }, + "tr" : { + "stringUnit" : { + "state" : "translated", + "value" : "konum seç" + } + }, + "uk" : { + "stringUnit" : { + "state" : "translated", + "value" : "виберіть місце" + } + }, + "ur" : { + "stringUnit" : { + "state" : "translated", + "value" : "مقام منتخب کریں" + } + }, + "vi" : { + "stringUnit" : { + "state" : "translated", + "value" : "chọn vị trí" + } + }, + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "选择位置" + } + }, + "zh-Hant" : { + "stringUnit" : { + "state" : "translated", + "value" : "選擇位置" + } + } + } + }, + "geohash_picker.select" : { + "comment" : "Button in the globe geohash picker that teleports to the geohash under the crosshair", + "extractionState" : "manual", + "localizations" : { + "ar" : { + "stringUnit" : { + "state" : "translated", + "value" : "اختيار" + } + }, + "bn" : { + "stringUnit" : { + "state" : "translated", + "value" : "নির্বাচন করুন" + } + }, + "de" : { + "stringUnit" : { + "state" : "translated", + "value" : "auswählen" + } + }, + "en" : { + "stringUnit" : { + "state" : "translated", + "value" : "select" + } + }, + "es" : { + "stringUnit" : { + "state" : "translated", + "value" : "seleccionar" + } + }, + "fa" : { + "stringUnit" : { + "state" : "translated", + "value" : "انتخاب" + } + }, + "fil" : { + "stringUnit" : { + "state" : "translated", + "value" : "piliin" + } + }, + "fr" : { + "stringUnit" : { + "state" : "translated", + "value" : "sélectionner" + } + }, + "he" : { + "stringUnit" : { + "state" : "translated", + "value" : "בחר" + } + }, + "hi" : { + "stringUnit" : { + "state" : "translated", + "value" : "चयन करें" + } + }, + "id" : { + "stringUnit" : { + "state" : "translated", + "value" : "pilih" + } + }, + "it" : { + "stringUnit" : { + "state" : "translated", + "value" : "seleziona" + } + }, + "ja" : { + "stringUnit" : { + "state" : "translated", + "value" : "選択" + } + }, + "ko" : { + "stringUnit" : { + "state" : "translated", + "value" : "선택" + } + }, + "ms" : { + "stringUnit" : { + "state" : "translated", + "value" : "pilih" + } + }, + "ne" : { + "stringUnit" : { + "state" : "translated", + "value" : "छान्नुहोस्" + } + }, + "nl" : { + "stringUnit" : { + "state" : "translated", + "value" : "selecteren" + } + }, + "pl" : { + "stringUnit" : { + "state" : "translated", + "value" : "wybierz" + } + }, + "pt" : { + "stringUnit" : { + "state" : "translated", + "value" : "selecionar" + } + }, + "pt-BR" : { + "stringUnit" : { + "state" : "translated", + "value" : "selecionar" + } + }, + "ru" : { + "stringUnit" : { + "state" : "translated", + "value" : "выбрать" + } + }, + "sv" : { + "stringUnit" : { + "state" : "translated", + "value" : "välj" + } + }, + "ta" : { + "stringUnit" : { + "state" : "translated", + "value" : "தேர்ந்தெடு" + } + }, + "th" : { + "stringUnit" : { + "state" : "translated", + "value" : "เลือก" + } + }, + "tr" : { + "stringUnit" : { + "state" : "translated", + "value" : "seç" + } + }, + "uk" : { + "stringUnit" : { + "state" : "translated", + "value" : "вибрати" + } + }, + "ur" : { + "stringUnit" : { + "state" : "translated", + "value" : "منتخب کریں" + } + }, + "vi" : { + "stringUnit" : { + "state" : "translated", + "value" : "chọn" + } + }, + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "选择" + } + }, + "zh-Hant" : { + "stringUnit" : { + "state" : "translated", + "value" : "選擇" + } + } + } + }, "groups.accessibility.open_group_hint" : { "extractionState" : "manual", "localizations" : { @@ -69396,6 +69387,192 @@ } } }, + "location_channels.accessibility.open_map" : { + "comment" : "Accessibility label for the button that opens the globe geohash picker", + "extractionState" : "manual", + "localizations" : { + "ar" : { + "stringUnit" : { + "state" : "translated", + "value" : "فتح الخريطة" + } + }, + "bn" : { + "stringUnit" : { + "state" : "translated", + "value" : "মানচিত্র খুলুন" + } + }, + "de" : { + "stringUnit" : { + "state" : "translated", + "value" : "karte öffnen" + } + }, + "en" : { + "stringUnit" : { + "state" : "translated", + "value" : "open map" + } + }, + "es" : { + "stringUnit" : { + "state" : "translated", + "value" : "abrir mapa" + } + }, + "fa" : { + "stringUnit" : { + "state" : "translated", + "value" : "باز کردن نقشه" + } + }, + "fil" : { + "stringUnit" : { + "state" : "translated", + "value" : "buksan ang mapa" + } + }, + "fr" : { + "stringUnit" : { + "state" : "translated", + "value" : "ouvrir la carte" + } + }, + "he" : { + "stringUnit" : { + "state" : "translated", + "value" : "פתח מפה" + } + }, + "hi" : { + "stringUnit" : { + "state" : "translated", + "value" : "मानचित्र खोलें" + } + }, + "id" : { + "stringUnit" : { + "state" : "translated", + "value" : "buka peta" + } + }, + "it" : { + "stringUnit" : { + "state" : "translated", + "value" : "apri mappa" + } + }, + "ja" : { + "stringUnit" : { + "state" : "translated", + "value" : "地図を開く" + } + }, + "ko" : { + "stringUnit" : { + "state" : "translated", + "value" : "지도 열기" + } + }, + "ms" : { + "stringUnit" : { + "state" : "translated", + "value" : "buka peta" + } + }, + "ne" : { + "stringUnit" : { + "state" : "translated", + "value" : "नक्सा खोल्नुहोस्" + } + }, + "nl" : { + "stringUnit" : { + "state" : "translated", + "value" : "kaart openen" + } + }, + "pl" : { + "stringUnit" : { + "state" : "translated", + "value" : "otwórz mapę" + } + }, + "pt" : { + "stringUnit" : { + "state" : "translated", + "value" : "abrir mapa" + } + }, + "pt-BR" : { + "stringUnit" : { + "state" : "translated", + "value" : "abrir mapa" + } + }, + "ru" : { + "stringUnit" : { + "state" : "translated", + "value" : "открыть карту" + } + }, + "sv" : { + "stringUnit" : { + "state" : "translated", + "value" : "öppna karta" + } + }, + "ta" : { + "stringUnit" : { + "state" : "translated", + "value" : "வரைபடத்தைத் திற" + } + }, + "th" : { + "stringUnit" : { + "state" : "translated", + "value" : "เปิดแผนที่" + } + }, + "tr" : { + "stringUnit" : { + "state" : "translated", + "value" : "haritayı aç" + } + }, + "uk" : { + "stringUnit" : { + "state" : "translated", + "value" : "відкрити карту" + } + }, + "ur" : { + "stringUnit" : { + "state" : "translated", + "value" : "نقشہ کھولیں" + } + }, + "vi" : { + "stringUnit" : { + "state" : "translated", + "value" : "mở bản đồ" + } + }, + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "打开地图" + } + }, + "zh-Hant" : { + "stringUnit" : { + "state" : "translated", + "value" : "開啟地圖" + } + } + } + }, "location_channels.accessibility.remove_bookmark" : { "comment" : "Accessibility action name for removing a channel bookmark", "extractionState" : "manual", @@ -83906,6 +84083,931 @@ } } }, + "notification.mute.direct.mute" : { + "comment" : "Accessibility label to silence notifications for this direct conversation", + "localizations" : { + "ar" : { + "stringUnit" : { + "state" : "translated", + "value" : "كتم الإشعارات" + } + }, + "bn" : { + "stringUnit" : { + "state" : "translated", + "value" : "বিজ্ঞপ্তি নিঃশব্দ করো" + } + }, + "de" : { + "stringUnit" : { + "state" : "translated", + "value" : "benachrichtigungen stummschalten" + } + }, + "en" : { + "stringUnit" : { + "state" : "translated", + "value" : "mute notifications" + } + }, + "es" : { + "stringUnit" : { + "state" : "translated", + "value" : "silenciar notificaciones" + } + }, + "fa" : { + "stringUnit" : { + "state" : "translated", + "value" : "بی‌صدا کردن اعلان‌ها" + } + }, + "fil" : { + "stringUnit" : { + "state" : "translated", + "value" : "i-mute ang mga notification" + } + }, + "fr" : { + "stringUnit" : { + "state" : "translated", + "value" : "couper les notifications" + } + }, + "he" : { + "stringUnit" : { + "state" : "translated", + "value" : "השתק התראות" + } + }, + "hi" : { + "stringUnit" : { + "state" : "translated", + "value" : "सूचनाएँ म्यूट करो" + } + }, + "id" : { + "stringUnit" : { + "state" : "translated", + "value" : "bisukan notifikasi" + } + }, + "it" : { + "stringUnit" : { + "state" : "translated", + "value" : "silenzia le notifiche" + } + }, + "ja" : { + "stringUnit" : { + "state" : "translated", + "value" : "通知をミュート" + } + }, + "ko" : { + "stringUnit" : { + "state" : "translated", + "value" : "알림 뮤트" + } + }, + "ms" : { + "stringUnit" : { + "state" : "translated", + "value" : "senyapkan pemberitahuan" + } + }, + "ne" : { + "stringUnit" : { + "state" : "translated", + "value" : "सूचना म्युट गर" + } + }, + "nl" : { + "stringUnit" : { + "state" : "translated", + "value" : "meldingen dempen" + } + }, + "pl" : { + "stringUnit" : { + "state" : "translated", + "value" : "wycisz powiadomienia" + } + }, + "pt" : { + "stringUnit" : { + "state" : "translated", + "value" : "silenciar notificações" + } + }, + "pt-BR" : { + "stringUnit" : { + "state" : "translated", + "value" : "silenciar notificações" + } + }, + "ru" : { + "stringUnit" : { + "state" : "translated", + "value" : "выключить уведомления" + } + }, + "sv" : { + "stringUnit" : { + "state" : "translated", + "value" : "tysta aviseringar" + } + }, + "ta" : { + "stringUnit" : { + "state" : "translated", + "value" : "அறிவிப்புகளை முடக்கு" + } + }, + "th" : { + "stringUnit" : { + "state" : "translated", + "value" : "ปิดการแจ้งเตือน" + } + }, + "tr" : { + "stringUnit" : { + "state" : "translated", + "value" : "bildirimleri sessize al" + } + }, + "uk" : { + "stringUnit" : { + "state" : "translated", + "value" : "вимкнути сповіщення" + } + }, + "ur" : { + "stringUnit" : { + "state" : "translated", + "value" : "اطلاعات خاموش کریں" + } + }, + "vi" : { + "stringUnit" : { + "state" : "translated", + "value" : "tắt thông báo" + } + }, + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "静音通知" + } + }, + "zh-Hant" : { + "stringUnit" : { + "state" : "translated", + "value" : "靜音通知" + } + } + } + }, + "notification.mute.direct.unmute" : { + "comment" : "Accessibility label to resume notifications for this direct conversation", + "localizations" : { + "ar" : { + "stringUnit" : { + "state" : "translated", + "value" : "إلغاء كتم الإشعارات" + } + }, + "bn" : { + "stringUnit" : { + "state" : "translated", + "value" : "বিজ্ঞপ্তি আনমিউট করো" + } + }, + "de" : { + "stringUnit" : { + "state" : "translated", + "value" : "benachrichtigungen wieder an" + } + }, + "en" : { + "stringUnit" : { + "state" : "translated", + "value" : "unmute notifications" + } + }, + "es" : { + "stringUnit" : { + "state" : "translated", + "value" : "activar notificaciones" + } + }, + "fa" : { + "stringUnit" : { + "state" : "translated", + "value" : "وصل کردن اعلان‌ها" + } + }, + "fil" : { + "stringUnit" : { + "state" : "translated", + "value" : "i-unmute ang mga notification" + } + }, + "fr" : { + "stringUnit" : { + "state" : "translated", + "value" : "réactiver les notifications" + } + }, + "he" : { + "stringUnit" : { + "state" : "translated", + "value" : "בטל השתקת התראות" + } + }, + "hi" : { + "stringUnit" : { + "state" : "translated", + "value" : "सूचनाएँ अनम्यूट करो" + } + }, + "id" : { + "stringUnit" : { + "state" : "translated", + "value" : "nyalakan notifikasi" + } + }, + "it" : { + "stringUnit" : { + "state" : "translated", + "value" : "riattiva le notifiche" + } + }, + "ja" : { + "stringUnit" : { + "state" : "translated", + "value" : "通知のミュートを解除" + } + }, + "ko" : { + "stringUnit" : { + "state" : "translated", + "value" : "알림 뮤트 해제" + } + }, + "ms" : { + "stringUnit" : { + "state" : "translated", + "value" : "nyahsenyap pemberitahuan" + } + }, + "ne" : { + "stringUnit" : { + "state" : "translated", + "value" : "सूचना अनम्युट गर" + } + }, + "nl" : { + "stringUnit" : { + "state" : "translated", + "value" : "meldingen aanzetten" + } + }, + "pl" : { + "stringUnit" : { + "state" : "translated", + "value" : "włącz powiadomienia" + } + }, + "pt" : { + "stringUnit" : { + "state" : "translated", + "value" : "reativar notificações" + } + }, + "pt-BR" : { + "stringUnit" : { + "state" : "translated", + "value" : "reativar notificações" + } + }, + "ru" : { + "stringUnit" : { + "state" : "translated", + "value" : "включить уведомления" + } + }, + "sv" : { + "stringUnit" : { + "state" : "translated", + "value" : "slå på aviseringar" + } + }, + "ta" : { + "stringUnit" : { + "state" : "translated", + "value" : "அறிவிப்பு முடக்கம் நீக்கு" + } + }, + "th" : { + "stringUnit" : { + "state" : "translated", + "value" : "เปิดการแจ้งเตือน" + } + }, + "tr" : { + "stringUnit" : { + "state" : "translated", + "value" : "bildirimleri aç" + } + }, + "uk" : { + "stringUnit" : { + "state" : "translated", + "value" : "увімкнути сповіщення" + } + }, + "ur" : { + "stringUnit" : { + "state" : "translated", + "value" : "اطلاعات آن کریں" + } + }, + "vi" : { + "stringUnit" : { + "state" : "translated", + "value" : "bật thông báo" + } + }, + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "取消静音通知" + } + }, + "zh-Hant" : { + "stringUnit" : { + "state" : "translated", + "value" : "取消靜音通知" + } + } + } + }, + "notification.mute.geohash.mute" : { + "comment" : "Accessibility label to silence notifications for this location channel", + "localizations" : { + "ar" : { + "stringUnit" : { + "state" : "translated", + "value" : "كتم إشعارات القناة" + } + }, + "bn" : { + "stringUnit" : { + "state" : "translated", + "value" : "চ্যানেল বিজ্ঞপ্তি নিঃশব্দ করো" + } + }, + "de" : { + "stringUnit" : { + "state" : "translated", + "value" : "kanal-benachrichtigungen stummschalten" + } + }, + "en" : { + "stringUnit" : { + "state" : "translated", + "value" : "mute channel notifications" + } + }, + "es" : { + "stringUnit" : { + "state" : "translated", + "value" : "silenciar notificaciones del canal" + } + }, + "fa" : { + "stringUnit" : { + "state" : "translated", + "value" : "بی‌صدا کردن اعلان‌های کانال" + } + }, + "fil" : { + "stringUnit" : { + "state" : "translated", + "value" : "i-mute ang notification ng channel" + } + }, + "fr" : { + "stringUnit" : { + "state" : "translated", + "value" : "couper les notifications du canal" + } + }, + "he" : { + "stringUnit" : { + "state" : "translated", + "value" : "השתק התראות ערוץ" + } + }, + "hi" : { + "stringUnit" : { + "state" : "translated", + "value" : "चैनल सूचनाएँ म्यूट करो" + } + }, + "id" : { + "stringUnit" : { + "state" : "translated", + "value" : "bisukan notifikasi kanal" + } + }, + "it" : { + "stringUnit" : { + "state" : "translated", + "value" : "silenzia le notifiche del canale" + } + }, + "ja" : { + "stringUnit" : { + "state" : "translated", + "value" : "チャンネル通知をミュート" + } + }, + "ko" : { + "stringUnit" : { + "state" : "translated", + "value" : "채널 알림 뮤트" + } + }, + "ms" : { + "stringUnit" : { + "state" : "translated", + "value" : "senyapkan pemberitahuan saluran" + } + }, + "ne" : { + "stringUnit" : { + "state" : "translated", + "value" : "च्यानल सूचना म्युट गर" + } + }, + "nl" : { + "stringUnit" : { + "state" : "translated", + "value" : "kanaalmeldingen dempen" + } + }, + "pl" : { + "stringUnit" : { + "state" : "translated", + "value" : "wycisz powiadomienia kanału" + } + }, + "pt" : { + "stringUnit" : { + "state" : "translated", + "value" : "silenciar notificações do canal" + } + }, + "pt-BR" : { + "stringUnit" : { + "state" : "translated", + "value" : "silenciar notificações do canal" + } + }, + "ru" : { + "stringUnit" : { + "state" : "translated", + "value" : "выключить уведомления канала" + } + }, + "sv" : { + "stringUnit" : { + "state" : "translated", + "value" : "tysta kanalaviseringar" + } + }, + "ta" : { + "stringUnit" : { + "state" : "translated", + "value" : "சேனல் அறிவிப்புகளை முடக்கு" + } + }, + "th" : { + "stringUnit" : { + "state" : "translated", + "value" : "ปิดการแจ้งเตือนช่อง" + } + }, + "tr" : { + "stringUnit" : { + "state" : "translated", + "value" : "kanal bildirimlerini sessize al" + } + }, + "uk" : { + "stringUnit" : { + "state" : "translated", + "value" : "вимкнути сповіщення каналу" + } + }, + "ur" : { + "stringUnit" : { + "state" : "translated", + "value" : "چینل اطلاعات خاموش کریں" + } + }, + "vi" : { + "stringUnit" : { + "state" : "translated", + "value" : "tắt thông báo kênh" + } + }, + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "静音频道通知" + } + }, + "zh-Hant" : { + "stringUnit" : { + "state" : "translated", + "value" : "靜音頻道通知" + } + } + } + }, + "notification.mute.geohash.unmute" : { + "comment" : "Accessibility label to resume notifications for this location channel", + "localizations" : { + "ar" : { + "stringUnit" : { + "state" : "translated", + "value" : "إلغاء كتم إشعارات القناة" + } + }, + "bn" : { + "stringUnit" : { + "state" : "translated", + "value" : "চ্যানেল বিজ্ঞপ্তি আনমিউট করো" + } + }, + "de" : { + "stringUnit" : { + "state" : "translated", + "value" : "kanal-benachrichtigungen wieder an" + } + }, + "en" : { + "stringUnit" : { + "state" : "translated", + "value" : "unmute channel notifications" + } + }, + "es" : { + "stringUnit" : { + "state" : "translated", + "value" : "activar notificaciones del canal" + } + }, + "fa" : { + "stringUnit" : { + "state" : "translated", + "value" : "وصل کردن اعلان‌های کانال" + } + }, + "fil" : { + "stringUnit" : { + "state" : "translated", + "value" : "i-unmute ang notification ng channel" + } + }, + "fr" : { + "stringUnit" : { + "state" : "translated", + "value" : "réactiver les notifications du canal" + } + }, + "he" : { + "stringUnit" : { + "state" : "translated", + "value" : "בטל השתקת התראות ערוץ" + } + }, + "hi" : { + "stringUnit" : { + "state" : "translated", + "value" : "चैनل सूचनाएँ अनम्यूट करो" + } + }, + "id" : { + "stringUnit" : { + "state" : "translated", + "value" : "nyalakan notifikasi kanal" + } + }, + "it" : { + "stringUnit" : { + "state" : "translated", + "value" : "riattiva le notifiche del canale" + } + }, + "ja" : { + "stringUnit" : { + "state" : "translated", + "value" : "チャンネル通知のミュートを解除" + } + }, + "ko" : { + "stringUnit" : { + "state" : "translated", + "value" : "채널 알림 뮤트 해제" + } + }, + "ms" : { + "stringUnit" : { + "state" : "translated", + "value" : "nyahsenyap pemberitahuan saluran" + } + }, + "ne" : { + "stringUnit" : { + "state" : "translated", + "value" : "च्यानल सूचना अनम्युट गर" + } + }, + "nl" : { + "stringUnit" : { + "state" : "translated", + "value" : "kanaalmeldingen aanzetten" + } + }, + "pl" : { + "stringUnit" : { + "state" : "translated", + "value" : "włącz powiadomienia kanału" + } + }, + "pt" : { + "stringUnit" : { + "state" : "translated", + "value" : "reativar notificações do canal" + } + }, + "pt-BR" : { + "stringUnit" : { + "state" : "translated", + "value" : "reativar notificações do canal" + } + }, + "ru" : { + "stringUnit" : { + "state" : "translated", + "value" : "включить уведомления канала" + } + }, + "sv" : { + "stringUnit" : { + "state" : "translated", + "value" : "slå på kanalaviseringar" + } + }, + "ta" : { + "stringUnit" : { + "state" : "translated", + "value" : "சேனல் அறிவிப்பு முடக்கம் நீக்கு" + } + }, + "th" : { + "stringUnit" : { + "state" : "translated", + "value" : "เปิดการแจ้งเตือนช่อง" + } + }, + "tr" : { + "stringUnit" : { + "state" : "translated", + "value" : "kanal bildirimlerini aç" + } + }, + "uk" : { + "stringUnit" : { + "state" : "translated", + "value" : "увімкнути сповіщення каналу" + } + }, + "ur" : { + "stringUnit" : { + "state" : "translated", + "value" : "چینل اطلاعات آن کریں" + } + }, + "vi" : { + "stringUnit" : { + "state" : "translated", + "value" : "bật thông báo kênh" + } + }, + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "取消静音频道通知" + } + }, + "zh-Hant" : { + "stringUnit" : { + "state" : "translated", + "value" : "取消靜音頻道通知" + } + } + } + }, + "notification.mute.state.muted" : { + "comment" : "Badge on a peer row indicating that conversation's notifications are muted", + "localizations" : { + "ar" : { + "stringUnit" : { + "state" : "translated", + "value" : "مكتوم" + } + }, + "bn" : { + "stringUnit" : { + "state" : "translated", + "value" : "নিঃশব্দ" + } + }, + "de" : { + "stringUnit" : { + "state" : "translated", + "value" : "stumm" + } + }, + "en" : { + "stringUnit" : { + "state" : "translated", + "value" : "notifications muted" + } + }, + "es" : { + "stringUnit" : { + "state" : "translated", + "value" : "silenciado" + } + }, + "fa" : { + "stringUnit" : { + "state" : "translated", + "value" : "بی‌صدا" + } + }, + "fil" : { + "stringUnit" : { + "state" : "translated", + "value" : "naka-mute" + } + }, + "fr" : { + "stringUnit" : { + "state" : "translated", + "value" : "en sourdine" + } + }, + "he" : { + "stringUnit" : { + "state" : "translated", + "value" : "מושתק" + } + }, + "hi" : { + "stringUnit" : { + "state" : "translated", + "value" : "म्यूट" + } + }, + "id" : { + "stringUnit" : { + "state" : "translated", + "value" : "dibisukan" + } + }, + "it" : { + "stringUnit" : { + "state" : "translated", + "value" : "silenziato" + } + }, + "ja" : { + "stringUnit" : { + "state" : "translated", + "value" : "ミュート中" + } + }, + "ko" : { + "stringUnit" : { + "state" : "translated", + "value" : "뮤트됨" + } + }, + "ms" : { + "stringUnit" : { + "state" : "translated", + "value" : "disenyapkan" + } + }, + "ne" : { + "stringUnit" : { + "state" : "translated", + "value" : "म्युट" + } + }, + "nl" : { + "stringUnit" : { + "state" : "translated", + "value" : "gedempt" + } + }, + "pl" : { + "stringUnit" : { + "state" : "translated", + "value" : "wyciszone" + } + }, + "pt" : { + "stringUnit" : { + "state" : "translated", + "value" : "silenciado" + } + }, + "pt-BR" : { + "stringUnit" : { + "state" : "translated", + "value" : "silenciado" + } + }, + "ru" : { + "stringUnit" : { + "state" : "translated", + "value" : "без звука" + } + }, + "sv" : { + "stringUnit" : { + "state" : "translated", + "value" : "tystad" + } + }, + "ta" : { + "stringUnit" : { + "state" : "translated", + "value" : "முடக்கப்பட்டது" + } + }, + "th" : { + "stringUnit" : { + "state" : "translated", + "value" : "ปิดเสียงแล้ว" + } + }, + "tr" : { + "stringUnit" : { + "state" : "translated", + "value" : "sessiz" + } + }, + "uk" : { + "stringUnit" : { + "state" : "translated", + "value" : "без звуку" + } + }, + "ur" : { + "stringUnit" : { + "state" : "translated", + "value" : "خاموش" + } + }, + "vi" : { + "stringUnit" : { + "state" : "translated", + "value" : "đã tắt" + } + }, + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "已静音" + } + }, + "zh-Hant" : { + "stringUnit" : { + "state" : "translated", + "value" : "已靜音" + } + } + } + }, "notification.redacted.body" : { "comment" : "Lock-screen notification body shown in place of the message text when message previews are hidden", "extractionState" : "manual", diff --git a/bitchat/Models/BitchatMessage+Authorship.swift b/bitchat/Models/BitchatMessage+Authorship.swift new file mode 100644 index 00000000..817b3309 --- /dev/null +++ b/bitchat/Models/BitchatMessage+Authorship.swift @@ -0,0 +1,38 @@ +// +// BitchatMessage+Authorship.swift +// bitchat +// +// This is free and unencumbered software released into the public domain. +// For more information, see +// + +import BitFoundation + +extension BitchatMessage { + /// Whether this device wrote the row, judged by the sender ID it carries + /// and never by its display name. Names collide: geochat shows everyone + /// as `nick#`, so a namesake reads `#xxxx` and a + /// stranger without a nickname tag reads `anon#xxxx`, while mesh peers, + /// group members and bridged senders can carry my exact name. + /// + /// - A `system` row is never mine, although local DM system lines carry + /// my mesh peer ID. + /// - A row without a sender ID (public system lines) is not mine. + /// - A geochat row (`nostr:` + 8 hex) is mine when it carries the ID of my + /// identity for the location channel on screen, `myGeoChatPeerID`. + /// - Every other row I write carries my mesh peer ID, `myPeerID`: mesh + /// public text and its echoes, mesh and geo DMs, group messages, media. + /// + /// Each ID is evaluated only for the kind of row that needs it. + func isOwn( + myPeerID: @autoclosure () -> PeerID, + myGeoChatPeerID: @autoclosure () -> PeerID? + ) -> Bool { + guard sender != "system", let senderPeerID else { return false } + if senderPeerID.isGeoChat { + return senderPeerID == myGeoChatPeerID() + } + let myPeerID = myPeerID() + return !myPeerID.isEmpty && senderPeerID == myPeerID + } +} diff --git a/bitchat/Models/BitchatMessage+Media.swift b/bitchat/Models/BitchatMessage+Media.swift index 16e35a79..6d1e9380 100644 --- a/bitchat/Models/BitchatMessage+Media.swift +++ b/bitchat/Models/BitchatMessage+Media.swift @@ -33,11 +33,19 @@ extension BitchatMessage { } func mediaAttachment(for nickname: String) -> Media? { + // Files only travel over the mesh radio; geochats, geo DMs and + // bridged messages (internet-relayed from a rendezvous) carry text + // alone. A "[image] " line from such a sender names no file it sent + // us, so it stays a text row. + if let senderPeerID, senderPeerID.isGeoChat || senderPeerID.isGeoDM || senderPeerID.isBridge { + return nil + } guard let baseDirectory = Cache.shared.filesDir else { return nil } func url(for category: MimeType.Category) -> URL? { guard content.hasPrefix(category.messagePrefix), - let filename = String(content.dropFirst(category.messagePrefix.count)).trimmedOrNilIfEmpty + let filename = String(content.dropFirst(category.messagePrefix.count)).trimmedOrNilIfEmpty, + Self.isSafeMediaFilename(filename) else { return nil } @@ -59,4 +67,19 @@ extension BitchatMessage { } return nil } + + /// Whether a media filename taken from message text is one plain path + /// component. Anything else ("../outgoing/x.jpg", "a/b", "..") would + /// resolve outside the media directory, so it is rejected, not repaired: + /// sanitizing would still point the row at some other local file. + static func isSafeMediaFilename(_ filename: String) -> Bool { + guard !filename.isEmpty, + filename != ".", + filename != "..", + !filename.unicodeScalars.contains(where: { $0 == "/" || $0 == "\\" }) + else { + return false + } + return (filename as NSString).lastPathComponent == filename + } } diff --git a/bitchat/Nostr/NostrProtocol.swift b/bitchat/Nostr/NostrProtocol.swift index 2e3e35d8..ead286d1 100644 --- a/bitchat/Nostr/NostrProtocol.swift +++ b/bitchat/Nostr/NostrProtocol.swift @@ -731,7 +731,7 @@ struct NostrProtocol { } // Perform ECDH - let sharedSecret = try keyAgreementPrivateKey.sharedSecretFromKeyAgreement( + let sharedSecret = keyAgreementPrivateKey.sharedSecretFromKeyAgreement( with: keyAgreementPublicKey, format: .compressed ) diff --git a/bitchat/Resources/Globe/world_borders.geojson b/bitchat/Resources/Globe/world_borders.geojson new file mode 100644 index 00000000..a8cddd07 --- /dev/null +++ b/bitchat/Resources/Globe/world_borders.geojson @@ -0,0 +1 @@ +{"type":"GeometryCollection","geometries":[{"type":"LineString","coordinates":[[-130.54,54.8],[-129.98,55.28],[-130.01,55.92],[-131.71,56.55],[-132.73,57.69],[-133.36,58.41],[-134.27,58.86],[-134.94,59.27],[-135.48,59.79],[-136.48,59.46],[-137.45,58.91],[-138.34,59.56],[-139.04,60],[-140.01,60.28],[-141.0,60.31],[-140.99,66.0],[-140.99,69.71]]},{"type":"LineString","coordinates":[[-117.13,32.54],[-115.99,32.61],[-114.72,32.72],[-114.81,32.53],[-113.3,32.04],[-111.02,31.33],[-109.04,31.34],[-108.24,31.34],[-108.24,31.75],[-106.51,31.75],[-106.14,31.4],[-105.63,31.08],[-105.04,30.64],[-104.71,30.12],[-104.46,29.57],[-103.94,29.27],[-103.11,28.97],[-102.48,29.76],[-101.66,29.78],[-100.96,29.38],[-100.46,28.7],[-100.11,28.11],[-99.52,27.54],[-99.3,26.84],[-99.02,26.37],[-98.24,26.06],[-97.53,25.84],[-97.14,25.87]]},{"type":"LineString","coordinates":[[-90.1,13.74],[-90.06,13.88],[-89.72,14.13],[-89.53,14.24],[-89.59,14.36],[-89.35,14.42]]},{"type":"LineString","coordinates":[[-92.23,14.54],[-92.2,14.83],[-92.09,15.06],[-92.23,15.25],[-91.75,16.07],[-90.46,16.07],[-90.44,16.41],[-90.6,16.47],[-90.71,16.69],[-91.08,16.92],[-91.45,17.25],[-91.0,17.25],[-91.0,17.82],[-90.07,17.82],[-89.14,17.81]]},{"type":"LineString","coordinates":[[-88.93,15.89],[-89.23,15.89],[-89.15,17.02],[-89.14,17.81]]},{"type":"LineString","coordinates":[[-89.35,14.42],[-89.06,14.34],[-88.84,14.14],[-88.54,13.98],[-88.5,13.85],[-88.07,13.96],[-87.86,13.89],[-87.72,13.79],[-87.79,13.38]]},{"type":"LineString","coordinates":[[-87.32,12.98],[-87.01,13.03],[-86.88,13.25],[-86.73,13.26],[-86.76,13.75],[-86.52,13.78],[-86.31,13.77],[-86.1,14.04],[-85.8,13.84],[-85.7,13.96],[-85.51,14.08],[-85.17,14.35],[-85.15,14.56],[-85.05,14.55],[-84.92,14.79],[-84.82,14.82],[-84.65,14.67],[-84.45,14.62],[-84.23,14.75],[-83.98,14.75],[-83.63,14.88],[-83.49,15.02],[-83.15,15.0]]},{"type":"LineString","coordinates":[[-82.97,8.23],[-82.91,8.42],[-82.83,8.63],[-82.87,8.81],[-82.72,8.93],[-82.93,9.07],[-82.93,9.48],[-82.55,9.57]]},{"type":"LineString","coordinates":[[-83.66,10.94],[-83.9,10.73],[-84.19,10.79],[-84.36,11.0],[-84.67,11.08],[-84.9,10.95],[-85.56,11.22],[-85.71,11.09]]},{"type":"LineString","coordinates":[[-77.35,8.67],[-77.47,8.52],[-77.24,7.94],[-77.43,7.64],[-77.75,7.71],[-77.88,7.22]]},{"type":"LineString","coordinates":[[-71.33,11.78],[-71.97,11.61],[-72.23,11.11],[-72.61,10.82],[-72.91,10.45],[-73.03,9.74],[-73.3,9.15],[-72.79,9.09],[-72.66,8.63],[-72.44,8.41],[-72.36,8.0],[-72.48,7.63],[-72.44,7.42],[-72.2,7.34],[-71.96,6.99],[-70.67,7.09],[-70.09,6.96],[-69.39,6.1],[-68.99,6.21],[-68.27,6.15],[-67.7,6.27],[-67.34,6.1],[-67.52,5.56],[-67.74,5.22],[-67.82,4.5],[-67.62,3.84],[-67.34,3.54],[-67.3,3.32],[-67.81,2.82],[-67.45,2.6],[-67.18,2.25],[-66.88,1.25],[-66.88,1.25]]},{"type":"LineString","coordinates":[[-75.37,-0.15],[-75.23,-0.91],[-75.55,-1.56],[-76.64,-2.61],[-77.84,-3.0],[-78.45,-3.87],[-78.64,-4.55],[-79.21,-4.96],[-79.62,-4.45],[-80.03,-4.35],[-80.44,-4.43],[-80.47,-4.06],[-80.18,-3.82],[-80.3,-3.4]]},{"type":"LineString","coordinates":[[-69.53,-10.95],[-70.09,-11.12],[-70.55,-11.01],[-70.48,-9.49],[-71.3,-10.08],[-72.18,-10.05],[-72.56,-9.52],[-73.23,-9.46],[-73.02,-9.03],[-73.57,-8.42],[-73.99,-7.52],[-73.72,-7.34],[-73.72,-6.92],[-73.12,-6.63],[-73.22,-6.09],[-72.96,-5.74],[-72.89,-5.27],[-71.75,-4.59],[-70.93,-4.4],[-70.79,-4.25],[-69.89,-4.3]]},{"type":"LineString","coordinates":[[-66.96,-54.9],[-67.56,-54.87],[-68.63,-54.87],[-68.63,-52.64]]},{"type":"LineString","coordinates":[[-68.63,-52.3],[-69.5,-52.14],[-71.91,-52.01],[-72.33,-51.43],[-72.31,-50.68],[-72.98,-50.74],[-73.33,-50.38],[-73.42,-49.32],[-72.65,-48.88],[-72.33,-48.24],[-72.45,-47.74],[-71.92,-46.88],[-71.55,-45.56],[-71.66,-44.97],[-71.22,-44.78],[-71.33,-44.41],[-71.79,-44.21],[-71.46,-43.79],[-71.92,-43.41],[-72.15,-42.25],[-71.75,-42.05],[-71.92,-40.83],[-71.68,-39.81],[-71.41,-38.92],[-70.81,-38.55],[-71.12,-37.58],[-71.12,-36.66],[-70.36,-36.01],[-70.39,-35.17],[-69.82,-34.19],[-69.81,-33.27],[-70.07,-33.09],[-70.54,-31.36],[-69.92,-30.34],[-70.01,-29.37],[-69.66,-28.46],[-69.0,-27.52],[-68.3,-26.9],[-68.59,-26.51],[-68.39,-26.18],[-68.42,-24.52],[-67.33,-24.03],[-66.99,-22.99],[-67.11,-22.74]]},{"type":"LineString","coordinates":[[-58.43,-33.91],[-58.35,-33.26],[-58.13,-33.04],[-58.14,-32.04],[-57.87,-31.02],[-57.63,-30.22]]},{"type":"LineString","coordinates":[[-54.63,-25.74],[-54.79,-26.62],[-55.7,-27.39],[-56.49,-27.55],[-57.61,-27.4],[-58.62,-27.12],[-57.63,-25.6],[-57.78,-25.16],[-58.81,-24.77],[-60.03,-24.03],[-60.85,-23.88],[-62.69,-22.25]]},{"type":"LineString","coordinates":[[-58.17,-20.18],[-58.17,-20.18],[-57.87,-20.73],[-57.94,-22.09],[-56.88,-22.28],[-56.47,-22.09],[-55.8,-22.36],[-55.61,-22.66],[-55.52,-23.57],[-55.4,-23.96],[-55.03,-24.0],[-54.65,-23.84],[-54.29,-24.02],[-54.29,-24.57],[-54.43,-25.16],[-54.63,-25.74]]},{"type":"LineString","coordinates":[[-59.76,8.37],[-60.55,7.78],[-60.64,7.42],[-60.3,7.04],[-60.54,6.86],[-61.16,6.7],[-61.14,6.23],[-61.41,5.96],[-60.73,5.2]]},{"type":"LineString","coordinates":[[-56.54,1.9],[-56.78,1.86],[-57.34,1.95],[-57.66,1.68],[-58.11,1.51],[-58.43,1.46],[-58.54,1.27],[-59.03,1.32],[-59.65,1.79],[-59.72,2.25],[-59.97,2.76],[-59.82,3.61],[-59.54,3.96],[-59.77,4.42],[-60.11,4.57],[-59.98,5.01],[-60.21,5.24],[-60.73,5.2]]},{"type":"LineString","coordinates":[[-54.52,2.31],[-55.1,2.52],[-55.57,2.42],[-55.97,2.51],[-56.07,2.22],[-55.91,2.02],[-56.0,1.82],[-56.54,1.9]]},{"type":"LineString","coordinates":[[-51.66,4.16],[-52.25,3.24],[-52.56,2.5],[-52.94,2.12],[-53.42,2.05],[-53.55,2.33],[-53.78,2.38],[-54.09,2.11],[-54.52,2.31]]},{"type":"LineString","coordinates":[[115.45,5.45],[115.41,4.96],[115.35,4.32],[114.87,4.35],[114.66,4.01],[114.2,4.53]]},{"type":"LineString","coordinates":[[-6.2,53.87],[-6.95,54.07],[-7.57,54.06],[-7.37,54.6],[-7.57,55.13]]},{"type":"LineString","coordinates":[[-16.71,13.59],[-15.62,13.62],[-15.4,13.86],[-15.08,13.88],[-14.69,13.63],[-14.38,13.63],[-14.05,13.79],[-13.84,13.51],[-14.28,13.28],[-14.71,13.3],[-15.14,13.51],[-15.51,13.28],[-15.69,13.27],[-15.93,13.13],[-16.84,13.15]]},{"type":"LineString","coordinates":[[35.55,32.39],[35.55,31.78],[35.4,31.49]]},{"type":"LineString","coordinates":[[28.98,-28.96],[29.33,-29.26],[29.02,-29.74],[28.85,-30.07],[28.29,-30.23],[28.11,-30.55],[27.75,-30.65],[27.0,-29.88],[27.53,-29.24],[28.07,-28.85],[28.54,-28.65],[28.98,-28.96]]},{"type":"LineString","coordinates":[[-8.67,27.66],[-8.67,27.59],[-8.68,27.4],[-8.69,25.88],[-11.97,25.93],[-11.94,23.37],[-12.87,23.28],[-13.12,22.77],[-12.93,21.33],[-16.85,21.33],[-17.06,21.0]]},{"type":"LineString","coordinates":[[-8.68,27.4],[-4.92,24.97],[-4.92,24.97]]},{"type":"LineString","coordinates":[[-12.17,14.62],[-12.12,13.99],[-11.93,13.42],[-11.55,13.14],[-11.47,12.75],[-11.51,12.44]]},{"type":"LineString","coordinates":[[-13.7,12.59],[-13.72,12.25],[-13.83,12.14],[-13.74,11.81],[-13.9,11.68],[-14.12,11.68],[-14.38,11.51],[-14.69,11.53],[-15.13,11.04]]},{"type":"LineString","coordinates":[[-11.51,12.44],[-11.46,12.08],[-11.3,12.08],[-11.04,12.21],[-10.87,12.18],[-10.59,11.92],[-10.17,11.84],[-9.89,12.06],[-9.57,12.19],[-9.33,12.33],[-9.13,12.31],[-8.91,12.09],[-8.79,11.81],[-8.38,11.39],[-8.58,11.14],[-8.62,10.81],[-8.41,10.91],[-8.28,10.79],[-8.34,10.49],[-8.03,10.21],[-8.03,10.21]]},{"type":"LineString","coordinates":[[-11.44,6.79],[-11.2,7.11],[-11.15,7.4],[-10.7,7.94],[-10.23,8.41]]},{"type":"LineString","coordinates":[[-8.44,7.69],[-8.49,7.4],[-8.39,6.91],[-8.6,6.47],[-8.31,6.19],[-7.99,6.13],[-7.57,5.71],[-7.54,5.31],[-7.64,5.19],[-7.71,4.36]]},{"type":"LineString","coordinates":[[8.42,36.95],[8.22,36.43],[8.38,35.48],[8.14,34.66],[7.52,34.1],[7.61,33.34],[8.43,32.75],[8.44,32.51],[9.06,32.1],[9.48,30.31],[9.48,30.31]]},{"type":"LineString","coordinates":[[11.49,33.14],[11.43,32.37],[10.94,32.08],[10.64,31.76],[9.95,31.38],[10.06,30.96],[9.97,30.54],[9.48,30.31]]},{"type":"LineString","coordinates":[[25.16,31.57],[24.8,31.09],[24.96,30.66],[24.7,30.04],[25,29.24],[25,25.68],[25,22],[25,22]]},{"type":"LineString","coordinates":[[4.27,19.16],[4.27,16.85],[3.72,16.18],[3.64,15.57],[2.75,15.41],[1.39,15.32],[1.02,14.97],[0.37,14.93],[0.37,14.93]]},{"type":"LineString","coordinates":[[0.37,14.93],[0.3,14.44],[0.43,13.99],[0.99,13.34],[1.02,12.85],[2.18,12.63],[2.15,11.94],[2.15,11.94]]},{"type":"LineString","coordinates":[[-2.86,4.99],[-2.81,5.39],[-3.24,6.25],[-2.98,7.38],[-2.56,8.22],[-2.83,9.64]]},{"type":"LineString","coordinates":[[1.06,5.93],[0.84,6.28],[0.57,6.91],[0.49,7.41],[0.71,8.31],[0.46,8.68],[0.37,9.46],[0.37,10.19],[-0.05,10.71],[0.02,11.02]]},{"type":"LineString","coordinates":[[0.9,11.0],[0.77,10.47],[1.08,10.18],[1.43,9.83],[1.46,9.33],[1.66,9.13],[1.62,6.83],[1.87,6.14]]},{"type":"LineString","coordinates":[[2.15,11.94],[2.49,12.23],[2.85,12.24],[3.61,11.66],[3.61,11.66]]},{"type":"LineString","coordinates":[[3.61,11.66],[3.68,12.55],[3.97,12.96],[4.11,13.53],[4.37,13.75],[5.44,13.87],[6.45,13.49],[6.82,13.12],[7.33,13.1],[7.8,13.34],[9.01,12.83],[9.52,12.85],[10.11,13.28],[10.7,13.25],[10.99,13.39],[11.53,13.33],[12.3,13.04],[13.08,13.6],[13.32,13.56]]},{"type":"LineString","coordinates":[[36.87,22],[32.9,22],[29.02,22],[25,22]]},{"type":"LineString","coordinates":[[14.85,22.86],[15.1,21.31],[15.47,21.05],[15.49,20.73],[15.9,20.39],[15.69,19.96],[15.3,17.93],[15.25,16.63],[13.97,15.68],[13.54,14.37],[13.96,14.0],[13.95,13.35],[14.6,13.33],[14.5,12.86],[14.5,12.86]]},{"type":"LineString","coordinates":[[23.84,19.58],[23.89,15.61],[23.02,15.68],[22.57,14.94],[22.3,14.33],[22.51,14.09],[22.18,13.79],[22.3,13.37],[22.04,12.96],[21.94,12.59],[22.29,12.65],[22.5,12.26],[22.51,11.68],[22.88,11.38],[22.86,11.14]]},{"type":"LineString","coordinates":[[15.28,7.42],[14.78,6.41],[14.54,6.23],[14.46,5.45],[14.56,5.03],[14.48,4.73],[14.95,4.21],[15.04,3.85],[15.41,3.34],[15.86,3.01],[15.91,2.56],[16.01,2.27],[16.01,2.27]]},{"type":"LineString","coordinates":[[11.28,2.26],[11.29,1.06],[9.83,1.07],[9.49,1.01]]},{"type":"LineString","coordinates":[[13.08,2.27],[13.0,1.83],[13.28,1.31],[14.03,1.4],[14.28,1.2],[13.84,0.04],[14.32,-0.55],[14.43,-1.33],[14.3,-2.0],[13.99,-2.47],[13.11,-2.43],[12.58,-1.95],[12.5,-2.39],[11.82,-2.51],[11.48,-2.77],[11.86,-3.43],[11.09,-3.98]]},{"type":"LineString","coordinates":[[16.01,2.27],[16.54,3.2],[17.13,3.73],[17.81,3.56],[18.45,3.5]]},{"type":"LineString","coordinates":[[22.86,11.14],[22.98,10.71],[23.55,10.09],[23.56,9.68],[23.39,9.27],[23.46,8.95],[23.81,8.67],[23.81,8.67]]},{"type":"LineString","coordinates":[[36.43,14.42],[37.59,14.21],[37.91,14.96],[38.51,14.51],[39.1,14.74],[39.34,14.53],[40.03,14.52],[40.9,14.12],[41.16,13.77],[41.6,13.45],[42.01,12.87],[42.35,12.54],[42.35,12.54]]},{"type":"LineString","coordinates":[[43.15,11.46],[42.78,10.93],[42.78,10.93]]},{"type":"LineString","coordinates":[[29.58,-1.34],[29.82,-1.44],[30.42,-1.13],[30.42,-1.13]]},{"type":"LineString","coordinates":[[30.42,-1.13],[30.82,-1.7],[30.76,-2.29],[30.47,-2.41]]},{"type":"LineString","coordinates":[[23.91,-10.93],[24.02,-11.24],[23.9,-11.72],[24.08,-12.19],[23.93,-12.57],[24.02,-12.91],[21.93,-12.9],[21.89,-16.08],[22.56,-16.9],[23.22,-17.52]]},{"type":"LineString","coordinates":[[23.22,-17.52],[24.03,-17.3],[24.68,-17.35],[25.08,-17.58],[25.08,-17.66],[24.93,-17.72]]},{"type":"LineString","coordinates":[[32.07,-26.73],[31.87,-27.18],[31.28,-27.29],[30.69,-26.74],[30.68,-26.4],[30.95,-26.02],[31.04,-25.73],[31.33,-25.66],[31.84,-25.84]]},{"type":"LineString","coordinates":[[25.26,-17.74],[25.65,-18.54],[25.85,-18.71],[26.16,-19.29],[27.3,-20.39],[27.72,-20.5],[27.73,-20.85],[28.02,-21.49],[28.79,-21.64],[29.43,-22.09],[29.43,-22.09]]},{"type":"LineString","coordinates":[[30.27,-15.51],[30.34,-15.88],[31.17,-15.86],[31.64,-16.07],[31.85,-16.32],[32.33,-16.39],[32.85,-16.71],[32.85,-17.98],[32.65,-18.67],[32.61,-19.42],[32.77,-19.72],[32.66,-20.3],[32.51,-20.4],[32.25,-21.12],[31.19,-22.25]]},{"type":"LineString","coordinates":[[32.83,-26.74],[32.07,-26.73]]},{"type":"LineString","coordinates":[[-9.03,41.88],[-8.67,42.13],[-8.26,42.28],[-8.01,41.79],[-7.42,41.79],[-7.25,41.92],[-6.67,41.88],[-6.39,41.38],[-6.85,41.11],[-6.86,40.33],[-7.03,40.18],[-7.07,39.71],[-7.5,39.63],[-7.1,39.03],[-7.37,38.37],[-7.03,38.08],[-7.17,37.8],[-7.54,37.43],[-7.45,37.1]]},{"type":"LineString","coordinates":[[2.99,42.47],[1.83,42.34],[0.7,42.8],[0.34,42.58],[-1.5,43.03],[-1.9,43.42]]},{"type":"LineString","coordinates":[[9.92,54.98],[9.28,54.83],[8.53,54.96]]},{"type":"LineString","coordinates":[[6.19,49.46],[6.66,49.2],[8.1,49.02],[7.59,48.33],[7.47,47.62],[7.47,47.62]]},{"type":"LineString","coordinates":[[14.12,53.76],[14.35,53.25],[14.07,52.98],[14.44,52.62],[14.69,52.09],[14.61,51.75],[15.02,51.11],[15.02,51.11]]},{"type":"LineString","coordinates":[[9.59,47.53],[9.63,47.35],[9.48,47.1],[9.93,46.92],[10.44,46.89]]},{"type":"LineString","coordinates":[[10.44,46.89],[11.05,46.75],[11.16,46.94],[12.15,47.12],[12.38,46.77],[13.81,46.51]]},{"type":"LineString","coordinates":[[19.66,54.43],[20.89,54.31],[22.73,54.33],[23.24,54.22],[23.48,53.91],[23.53,53.47],[23.8,53.09],[23.8,52.69],[23.2,52.49],[23.51,52.02],[23.53,51.58],[24.03,50.71],[23.92,50.42],[23.43,50.31],[22.52,49.48],[22.78,49.03],[22.56,49.09],[21.61,49.47],[20.89,49.33],[20.42,49.43],[19.83,49.22],[19.32,49.57],[18.91,49.44],[18.85,49.5],[18.39,49.99],[17.65,50.05],[17.55,50.36],[16.87,50.47],[16.72,50.22],[16.18,50.42],[16.24,50.7],[15.49,50.78],[15.02,51.11]]},{"type":"LineString","coordinates":[[24.31,57.79],[25.16,57.97],[25.6,57.85],[26.46,57.48],[27.29,57.47],[27.29,57.47]]},{"type":"LineString","coordinates":[[27.98,59.48],[28.13,59.3],[27.42,58.72],[27.72,57.79],[27.29,57.47]]},{"type":"LineString","coordinates":[[28.18,56.17],[29.23,55.92],[29.37,55.67],[29.9,55.79],[30.87,55.55],[30.97,55.08],[30.76,54.81],[31.38,54.16],[31.79,53.97],[31.73,53.79],[32.41,53.62],[32.69,53.35],[32.3,53.13],[31.5,53.17],[31.31,53.07],[31.54,52.74],[31.79,52.1],[31.79,52.1]]},{"type":"LineString","coordinates":[[6.91,53.48],[7.09,53.14],[6.84,52.23],[6.59,51.85],[5.99,51.85],[6.16,50.8]]},{"type":"LineString","coordinates":[[6.16,50.8],[6.04,50.13]]},{"type":"LineString","coordinates":[[6.04,50.13],[6.24,49.9],[6.19,49.46],[6.19,49.46]]},{"type":"LineString","coordinates":[[21.27,55.19],[22.32,55.02],[22.76,54.86],[22.65,54.58],[22.73,54.33]]},{"type":"LineString","coordinates":[[21.06,56.03],[22.2,56.34],[23.88,56.27],[24.86,56.37],[25.0,56.16],[25.53,56.1],[26.49,55.62]]},{"type":"LineString","coordinates":[[18.85,49.5],[18.55,49.49],[18.4,49.31],[18.17,49.27],[18.11,49.04],[17.91,49.0],[17.89,48.9],[17.55,48.8],[17.1,48.82],[16.96,48.6]]},{"type":"LineString","coordinates":[[16.96,48.6],[16.88,48.47],[16.98,48.12]]},{"type":"LineString","coordinates":[[22.09,48.42],[22.64,48.15],[22.71,47.88],[22.1,47.67],[21.63,46.99],[21.02,46.32],[20.22,46.13],[19.6,46.17],[18.83,45.91],[18.46,45.76],[17.63,45.95],[16.88,46.38],[16.56,46.5],[16.37,46.84],[16.2,46.85]]},{"type":"LineString","coordinates":[[18.45,42.48],[18.56,42.65],[17.67,43.03],[17.3,43.45],[16.92,43.67],[16.46,44.04],[16.24,44.35],[15.75,44.82],[15.96,45.23],[16.32,45.0],[16.53,45.21],[17.0,45.23],[17.86,45.07],[18.55,45.08],[19.01,44.86]]},{"type":"LineString","coordinates":[[22.56,49.09],[22.28,48.83],[22.09,48.42],[21.87,48.32],[20.8,48.62],[20.47,48.56],[20.24,48.33],[19.77,48.2],[19.66,48.27],[19.17,48.11],[18.78,48.08],[18.7,47.88],[17.86,47.76],[17.49,47.87],[16.98,48.12]]},{"type":"LineString","coordinates":[[16.56,46.5],[15.77,46.24],[15.67,45.83],[15.32,45.73],[15.33,45.45],[14.94,45.47],[14.6,45.63],[14.41,45.47],[13.72,45.5]]},{"type":"LineString","coordinates":[[26.62,48.22],[26.92,48.12],[27.23,47.83],[27.55,47.41],[28.13,46.81],[28.16,46.37],[28.05,45.94],[28.23,45.49]]},{"type":"LineString","coordinates":[[28.56,43.71],[27.97,43.81],[27.24,44.18],[26.07,43.94],[25.57,43.69],[24.1,43.74],[23.33,43.9],[22.94,43.82],[22.66,44.23],[22.66,44.23]]},{"type":"LineString","coordinates":[[22.66,44.23],[22.41,44.01],[22.5,43.64],[22.99,43.21],[22.6,42.9],[22.44,42.58],[22.54,42.46],[22.38,42.32],[22.36,42.32]]},{"type":"LineString","coordinates":[[22.71,47.88],[23.14,48.1],[23.76,47.99],[24.4,47.98],[24.87,47.74],[25.21,47.89],[25.95,47.99],[26.2,48.22],[26.62,48.22]]},{"type":"LineString","coordinates":[[31.79,52.1],[32.16,52.06],[32.41,52.29],[32.72,52.24],[33.75,52.34],[34.39,51.77],[34.14,51.57],[34.22,51.26],[35.02,51.21],[35.38,50.77],[35.36,50.58],[36.63,50.23],[37.39,50.38],[38.01,49.92],[38.6,49.93],[40.07,49.6],[40.08,49.31],[39.67,48.78],[39.9,48.23],[39.74,47.9],[38.77,47.83],[38.26,47.55],[38.22,47.1]]},{"type":"LineString","coordinates":[[28.0,42.01],[27.14,42.14],[26.12,41.83],[26.11,41.33],[25.2,41.23],[24.49,41.58],[23.69,41.31],[22.95,41.34],[22.88,42.0],[22.38,42.32]]},{"type":"LineString","coordinates":[[22.95,41.34],[22.76,41.3],[22.6,41.13],[22.06,41.15],[21.67,40.93],[21.02,40.84]]},{"type":"LineString","coordinates":[[26.12,41.83],[26.6,41.56],[26.29,40.94],[26.06,40.82]]},{"type":"LineString","coordinates":[[21.02,40.84],[21,40.58],[20.68,40.44],[20.61,40.11],[20.15,39.62]]},{"type":"LineString","coordinates":[[41.55,41.54],[42.62,41.58],[43.58,41.09]]},{"type":"LineString","coordinates":[[39.95,43.44],[40.08,43.55],[40.92,43.38],[42.39,43.22],[43.76,42.74],[43.93,42.55],[44.54,42.71],[45.47,42.5],[45.78,42.09],[46.4,41.86],[46.15,41.72],[46.64,41.18],[46.5,41.06],[45.96,41.12],[45.22,41.41],[44.97,41.25]]},{"type":"LineString","coordinates":[[28.59,69.06],[28.45,68.36],[29.98,67.7],[29.05,66.94],[30.22,65.81],[29.54,64.95],[30.44,64.2],[30.04,63.55],[31.52,62.87],[31.14,62.36],[30.21,61.78],[28.07,60.5]]},{"type":"LineString","coordinates":[[35.4,31.48],[35.42,31.1],[34.92,29.5]]},{"type":"LineString","coordinates":[[38.79,33.38],[39.2,32.16],[39.2,32.16]]},{"type":"LineString","coordinates":[[47.97,29.98],[47.3,30.06],[46.57,29.1],[46.57,29.1]]},{"type":"LineString","coordinates":[[48.57,29.93],[48.01,30.45],[48.0,30.99],[47.69,30.98],[47.85,31.71],[47.33,32.47],[46.11,33.02],[45.42,33.97],[45.65,34.75],[46.15,35.09],[46.08,35.68],[45.42,35.98],[44.77,37.17]]},{"type":"LineString","coordinates":[[53.92,37.2],[54.8,37.39],[55.51,37.96],[56.18,37.94],[56.62,38.12],[57.33,38.03],[58.44,37.52],[59.23,37.41],[60.38,36.53],[61.12,36.49],[61.21,35.65]]},{"type":"LineString","coordinates":[[53.11,16.65],[52.78,17.35],[52,19],[52,19]]},{"type":"LineString","coordinates":[[42.78,16.35],[43.22,16.67],[43.12,17.09],[43.38,17.58],[43.79,17.32],[44.06,17.41],[45.22,17.43],[45.4,17.33],[46.37,17.23],[46.75,17.28],[47,16.95],[47.47,17.12],[48.18,18.17],[49.12,18.62],[52,19]]},{"type":"LineString","coordinates":[[20.65,69.11],[21.98,68.62],[23.54,67.94],[23.57,66.4],[23.9,66.01]]},{"type":"LineString","coordinates":[[48.42,28.55],[47.71,28.53],[47.46,29.0],[46.57,29.1]]},{"type":"LineString","coordinates":[[51.39,24.63],[51.11,24.56],[50.81,24.75]]},{"type":"LineString","coordinates":[[56.07,26.06],[56.26,25.71]]},{"type":"LineString","coordinates":[[56.4,24.92],[55.89,24.92],[55.8,24.27],[55.98,24.13],[55.53,23.93],[55.53,23.52],[55.23,23.11],[55.21,22.71],[55.21,22.71]]},{"type":"LineString","coordinates":[[49.1,46.4],[48.59,46.56],[48.69,47.08],[48.06,47.74],[47.32,47.72],[46.47,48.39],[47.04,49.15],[46.75,49.36],[47.55,50.45],[48.58,49.87],[48.7,50.61],[50.77,51.69],[52.33,51.72],[54.53,51.03],[55.72,50.62],[56.78,51.04],[58.36,51.06],[59.64,50.55],[59.93,50.84],[61.34,50.8],[61.59,51.27],[59.97,51.96],[60.93,52.45],[60.74,52.72],[61.7,52.98],[60.98,53.67],[61.44,54.01],[65.18,54.35],[65.67,54.6],[68.17,54.97],[69.07,55.39],[70.87,55.17],[71.18,54.13],[72.22,54.38],[73.51,54.04],[73.43,53.49],[74.38,53.55],[76.89,54.49],[76.53,54.18],[77.8,53.4],[80.04,50.86],[80.57,51.39],[81.95,50.81],[83.38,51.07],[83.94,50.89],[84.42,50.31],[85.12,50.12],[85.54,49.69],[86.83,49.83],[87.36,49.22]]},{"type":"LineString","coordinates":[[70.96,42.27],[71.26,42.17],[70.42,41.52],[71.16,41.14],[71.87,41.39],[73.06,40.87],[71.77,40.15],[71.01,40.24],[70.6,40.22],[70.46,40.5],[70.67,40.96],[69.33,40.73],[69.01,40.09],[68.54,39.53],[67.7,39.58],[67.44,39.14],[68.18,38.9],[68.39,38.16],[67.83,37.15],[67.83,37.15]]},{"type":"LineString","coordinates":[[66.52,37.36],[66.22,37.39],[65.75,37.66],[65.59,37.31],[64.75,37.11],[64.55,36.31],[63.98,36.01],[63.19,35.86],[62.98,35.4],[62.23,35.27],[61.21,35.65]]},{"type":"LineString","coordinates":[[67.83,37.15],[68.14,37.02],[68.86,37.34],[69.2,37.15],[69.52,37.61],[70.12,37.59],[70.27,37.74],[70.38,38.14],[70.81,38.49],[71.35,38.26],[71.24,37.95],[71.54,37.91],[71.45,37.07],[71.84,36.74],[72.19,36.95],[72.64,37.05],[73.26,37.5],[73.95,37.42],[74.98,37.42]]},{"type":"LineString","coordinates":[[80.26,42.35],[80.12,42.12],[78.54,41.58],[78.19,41.19],[76.9,41.07],[76.53,40.43],[75.47,40.56],[74.78,40.37],[73.82,39.89],[73.96,39.66],[73.68,39.43]]},{"type":"LineString","coordinates":[[73.68,39.43],[73.93,38.51],[74.26,38.61],[74.86,38.38],[74.83,37.99],[74.98,37.42]]},{"type":"LineString","coordinates":[[74.45,32.76],[75.26,32.27],[75.26,32.27]]},{"type":"LineString","coordinates":[[97.33,28.26],[97.4,27.88],[97.05,27.7],[97.13,27.08],[96.42,27.26],[95.12,26.57],[95.16,26.0],[94.6,25.16],[94.55,24.68],[94.11,23.85],[93.33,24.08],[93.29,23.04],[93.06,22.7],[93.17,22.28],[92.67,22.04]]},{"type":"LineString","coordinates":[[88.12,27.88],[86.95,27.97],[85.82,28.2],[85.01,28.64],[84.23,28.84],[83.9,29.32],[83.34,29.46],[82.33,30.12],[81.53,30.42],[81.11,30.18]]},{"type":"LineString","coordinates":[[88.81,27.3],[89.48,28.04],[90.02,28.3],[90.73,28.06],[91.26,28.04],[91.7,27.77]]},{"type":"LineString","coordinates":[[92.37,20.67],[92.3,21.48],[92.65,21.32],[92.67,22.04]]},{"type":"LineString","coordinates":[[97.33,28.26],[97.91,28.34],[98.25,27.75],[98.68,27.51],[98.71,26.74],[98.67,25.92],[97.72,25.08],[97.6,23.9],[98.66,24.06],[98.9,23.14],[99.53,22.95],[99.24,22.12],[99.98,21.74],[100.42,21.56],[101.15,21.85],[101.18,21.44],[101.18,21.44]]},{"type":"LineString","coordinates":[[100.12,20.42],[100.55,20.11],[100.61,19.51],[101.28,19.46],[101.04,18.41],[101.06,17.51],[102.11,18.11],[102.41,17.93],[103.0,17.96],[103.2,18.31],[103.96,18.24],[104.72,17.43],[104.78,16.44],[105.59,15.57],[105.54,14.72],[105.22,14.27],[105.22,14.27],[104.28,14.42],[102.99,14.23],[102.35,13.39],[102.58,12.19]]},{"type":"LineString","coordinates":[[101.18,21.44],[101.27,21.2],[101.8,21.17],[101.65,22.32],[102.17,22.46]]},{"type":"LineString","coordinates":[[107.38,14.2],[107.61,13.54],[107.49,12.34],[105.81,11.57],[106.25,10.96],[105.2,10.89],[104.33,10.49]]},{"type":"LineString","coordinates":[[102.17,22.46],[102.71,22.71],[103.5,22.7],[104.48,22.82],[105.33,23.35],[105.81,22.98],[106.73,22.79],[106.57,22.22],[107.04,21.81],[108.05,21.55]]},{"type":"LineString","coordinates":[[102.14,6.22],[101.81,5.81],[101.15,5.69],[101.08,6.2],[100.26,6.64],[100.09,6.46]]},{"type":"LineString","coordinates":[[117.88,4.14],[117.02,4.31],[115.87,4.31],[115.52,3.17],[115.13,2.82],[114.62,1.43],[113.81,1.22],[112.86,1.5],[112.38,1.41],[111.8,0.9],[111.16,0.98],[110.51,0.77],[109.83,1.34],[109.66,2.01]]},{"type":"LineString","coordinates":[[87.75,49.3],[88.81,49.47],[90.71,50.33],[92.23,50.8],[93.1,50.5],[94.15,50.48],[94.82,50.01],[95.81,49.98],[97.26,49.73],[98.23,50.42],[97.83,51.01],[98.86,52.05],[99.98,51.63],[100.89,51.52],[102.07,51.26],[102.26,50.51],[103.68,50.09],[104.62,50.28],[105.89,50.41],[106.89,50.27],[107.87,49.79],[108.48,49.28],[109.4,49.29],[110.66,49.13],[111.58,49.38],[112.9,49.54],[114.36,50.25],[114.96,50.14],[115.49,49.81],[116.68,49.89]]},{"type":"LineString","coordinates":[[124.27,39.93],[125.08,40.57],[126.18,41.11],[126.87,41.82],[127.34,41.5],[128.21,41.47],[128.05,41.99],[129.6,42.42],[129.99,42.99],[130.64,42.4]]},{"type":"LineString","coordinates":[[128.35,38.61],[128.21,38.37],[127.78,38.3],[127.07,38.26],[126.68,37.8],[126.24,37.84],[126.17,37.75]]},{"type":"LineString","coordinates":[[124.97,-8.89],[125.07,-9.09],[125.09,-9.39]]},{"type":"LineString","coordinates":[[141.0,-2.6],[141.02,-5.86],[141.03,-9.12]]},{"type":"LineString","coordinates":[[11.91,-5.04],[12.32,-4.61],[12.62,-4.44],[13.0,-4.78]]},{"type":"LineString","coordinates":[[19.01,44.86],[19.37,44.86],[19.12,44.42],[19.6,44.04],[19.45,43.57],[19.22,43.52]]},{"type":"LineString","coordinates":[[48.58,41.81],[47.99,41.41],[47.82,41.15],[47.37,41.22],[46.69,41.83],[46.4,41.86]]},{"type":"LineString","coordinates":[[42.35,37.23],[41.84,36.61],[41.29,36.36],[41.38,35.63],[41.01,34.42],[38.79,33.38],[38.79,33.38]]},{"type":"LineString","coordinates":[[35.82,33.28],[35.55,33.26],[35.55,33.26]]},{"type":"LineString","coordinates":[[32.73,35.14],[32.92,35.09],[33.19,35.17],[33.38,35.16],[33.46,35.1],[33.48,35.0],[33.53,35.04],[33.68,35.02],[33.87,35.09],[33.97,35.06]]},{"type":"LineString","coordinates":[[19.22,43.52],[19.48,43.35],[19.63,43.21],[19.96,43.11],[20.34,42.9],[20.26,42.81]]},{"type":"LineString","coordinates":[[44.97,41.25],[45.18,40.99],[45.56,40.81],[45.36,40.56],[45.89,40.22],[45.61,39.9],[46.03,39.63],[46.48,39.46],[46.51,38.77],[46.51,38.77]]},{"type":"LineString","coordinates":[[-122.84,49],[-120,49],[-117.03,49],[-116.05,49],[-113,49],[-110.05,49],[-107.05,49],[-104.05,49.0],[-100.65,49],[-97.23,49.0],[-95.16,49],[-95.16,49.38],[-94.82,49.39],[-94.64,48.84],[-94.33,48.67],[-93.63,48.61],[-92.61,48.45],[-91.64,48.14],[-90.83,48.27],[-89.6,48.01],[-89.27,48.02],[-88.38,48.3],[-87.44,47.94],[-86.46,47.55],[-85.65,47.22],[-84.88,46.9],[-84.78,46.64],[-84.54,46.54],[-84.6,46.44],[-84.34,46.41],[-84.14,46.51],[-84.09,46.28],[-83.89,46.12],[-83.62,46.12],[-83.47,45.99],[-83.59,45.82],[-82.55,45.35],[-82.34,44.44],[-82.14,43.57],[-82.43,42.98],[-82.9,42.43],[-83.12,42.08],[-83.14,41.98],[-83.03,41.83],[-82.69,41.68],[-82.44,41.68],[-81.28,42.21],[-80.25,42.37],[-78.94,42.86],[-78.92,42.97],[-79.01,43.27],[-79.17,43.47],[-78.72,43.63],[-77.74,43.63],[-76.82,43.63],[-76.5,44.02],[-76.38,44.1],[-75.32,44.82],[-74.87,45.0],[-73.35,45.01],[-71.51,45.01],[-71.41,45.26],[-71.08,45.31],[-70.66,45.46],[-70.31,45.91],[-70.0,46.69],[-69.24,47.45],[-68.91,47.19],[-68.23,47.35],[-67.79,47.07],[-67.79,45.7],[-67.14,45.14]]},{"type":"LineString","coordinates":[[38.41,18.0],[37.9,17.43],[37.17,17.26],[36.85,16.96],[36.75,16.29],[36.32,14.82],[36.43,14.42],[36.43,14.42]]},{"type":"LineString","coordinates":[[47.79,8.0],[44.96,5.0],[43.66,4.96],[42.77,4.25],[42.13,4.23],[41.86,3.92]]},{"type":"LineString","coordinates":[[41.86,3.92],[41.17,3.92],[40.77,4.26],[39.85,3.84],[39.56,3.42],[38.89,3.5],[38.67,3.62],[38.44,3.59],[38.12,3.6],[36.86,4.45],[36.16,4.45],[35.82,4.78]]},{"type":"LineString","coordinates":[[39.2,-4.68],[37.77,-3.68],[37.7,-3.1],[34.07,-1.06],[33.9,-0.95]]},{"type":"LineString","coordinates":[[-8.67,27.66],[-8.82,27.66],[-8.79,27.12],[-9.41,27.09],[-9.74,26.86],[-10.19,26.86],[-10.55,26.99],[-11.39,26.88],[-11.72,26.1],[-12.03,26.03],[-12.5,24.77],[-13.89,23.69],[-14.22,22.31],[-14.63,21.86],[-14.75,21.5],[-17.0,21.42]]},{"type":"LineString","coordinates":[[11.03,58.86],[11.47,59.43],[12.3,60.12],[12.63,61.29],[11.99,61.8],[11.93,63.13],[12.58,64.07],[13.57,64.05],[13.92,64.45],[13.56,64.79],[15.11,66.19],[16.11,67.3],[16.77,68.01],[17.73,68.01],[17.99,68.57],[19.88,68.41],[20.03,69.07],[20.65,69.11],[20.65,69.11]]},{"type":"LineString","coordinates":[[40.32,-10.32],[39.52,-10.9],[38.43,-11.29],[37.83,-11.27],[37.47,-11.57],[36.78,-11.59],[36.51,-11.72],[35.31,-11.44],[34.56,-11.52]]},{"type":"LineString","coordinates":[[32.76,-9.23],[33.23,-9.68],[33.49,-10.53],[33.32,-10.8],[33.11,-11.61],[33.31,-12.44],[32.99,-12.78],[32.69,-13.71],[33.21,-13.97],[33.21,-13.97]]},{"type":"LineString","coordinates":[[34.56,-11.52],[34.28,-12.28],[34.56,-13.58],[34.91,-13.57],[35.27,-13.89],[35.69,-14.61],[35.77,-15.9],[35.34,-16.11],[35.03,-16.8],[34.38,-16.18],[34.31,-15.48],[34.52,-15.01],[34.46,-14.61],[34.06,-14.36],[33.79,-14.45],[33.21,-13.97]]},{"type":"LineString","coordinates":[[30.83,3.51],[30.77,2.34],[31.17,2.2],[30.85,1.85],[30.47,1.58],[30.09,1.06],[29.88,0.6],[29.82,-0.21],[29.59,-0.59],[29.58,-1.34]]},{"type":"LineString","coordinates":[[30.47,-2.41],[30.53,-2.81],[30.74,-3.03],[30.75,-3.36],[30.51,-3.57],[30.12,-4.09],[29.75,-4.45],[29.34,-4.5]]},{"type":"LineString","coordinates":[[20.26,42.81],[20.5,42.88],[20.64,43.22],[20.81,43.27],[20.96,43.13],[21.14,43.07],[21.27,42.91],[21.44,42.86],[21.63,42.68],[21.78,42.68],[21.66,42.44],[21.54,42.32],[21.58,42.25]]},{"type":"LineString","coordinates":[[-71.71,18.05],[-71.69,18.32],[-71.95,18.62],[-71.7,18.79],[-71.62,19.17],[-71.71,19.71]]},{"type":"LineString","coordinates":[[48.95,11.41],[48.94,11.39],[48.94,10.98],[48.94,9.97],[48.94,9.45],[48.49,8.84],[47.79,8.0]]},{"type":"LineString","coordinates":[[-69.59,-17.58],[-69.86,-18.09],[-70.37,-18.35]]},{"type":"LineString","coordinates":[[34.92,29.5],[34.27,31.22]]},{"type":"LineString","coordinates":[[35.72,32.71],[35.55,32.4]]},{"type":"LineString","coordinates":[[35.82,33.28],[36.07,33.82],[36.61,34.2],[36.45,34.59],[36.0,34.64]]},{"type":"LineString","coordinates":[[35.55,32.4],[35.55,32.39],[35.18,32.53],[34.97,31.87],[35.23,31.75],[34.97,31.62],[34.93,31.35],[35.4,31.49],[35.4,31.48]]},{"type":"LineString","coordinates":[[35.7,32.72],[35.84,32.87],[35.82,33.28],[35.82,33.28]]},{"type":"LineString","coordinates":[[29.0,9.6],[29.52,9.79],[29.62,10.08],[30.0,10.29],[30.84,9.71],[31.35,9.81],[31.85,10.53],[32.4,11.08],[32.31,11.68],[32.07,11.97],[32.67,12.02],[32.74,12.25],[33.21,12.18],[33.09,11.44],[33.21,10.72],[33.72,10.33],[33.84,9.98],[33.82,9.48],[33.96,9.46]]},{"type":"LineString","coordinates":[[23.89,8.62],[24.54,8.92],[24.79,9.81],[25.07,10.27],[25.79,10.41],[25.96,10.14],[26.48,9.55],[26.75,9.47],[27.11,9.64],[27.83,9.6]]},{"type":"LineString","coordinates":[[34.01,4.25],[33.39,3.79],[32.69,3.79],[31.88,3.56],[31.25,3.78],[30.83,3.51],[30.83,3.51]]},{"type":"LineString","coordinates":[[27.83,9.6],[27.97,9.4],[28.97,9.4],[29.0,9.6]]},{"type":"LineString","coordinates":[[35.9,4.61],[34.41,4.63],[34.01,4.25]]},{"type":"LineString","coordinates":[[35.82,4.78],[35.82,5.34],[35.3,5.51]]},{"type":"LineString","coordinates":[[33.94,-9.69],[33.74,-9.42],[32.76,-9.23]]},{"type":"LineString","coordinates":[[34.56,-11.52],[34.28,-10.16],[33.94,-9.69]]},{"type":"LineString","coordinates":[[-2.17,35.17],[-1.79,34.53],[-1.73,33.92],[-1.39,32.86],[-1.12,32.65],[-1.31,32.26]]},{"type":"LineString","coordinates":[[-1.31,32.26],[-2.62,32.09],[-3.07,31.72],[-3.65,31.64],[-3.69,30.9],[-4.86,30.5],[-5.24,30.0],[-6.06,29.73],[-7.06,29.58],[-8.67,28.84],[-8.67,27.66]]},{"type":"LineString","coordinates":[[75.16,37.13],[75.9,36.67],[75.9,36.67]]},{"type":"LineString","coordinates":[[78.81,33.51],[79.21,32.99]]},{"type":"LineString","coordinates":[[77.84,35.49],[78.91,34.32],[78.81,33.51]]},{"type":"LineString","coordinates":[[91.7,27.77],[92.5,27.9],[93.41,28.64],[94.57,29.28],[95.4,29.03],[96.12,29.45],[96.59,28.83],[96.25,28.41],[97.33,28.26]]},{"type":"LineString","coordinates":[[-57.15,5.97],[-57.31,5.07],[-57.91,4.81],[-57.86,4.58],[-58.04,4.06],[-57.6,3.33]]},{"type":"LineString","coordinates":[[-53.96,5.76],[-54.48,4.9],[-54.4,4.21],[-54.01,3.62],[-54.18,3.19]]},{"type":"LineString","coordinates":[[-57.6,3.33],[-57.28,3.33],[-57.15,2.77],[-56.54,1.9]]},{"type":"LineString","coordinates":[[-54.18,3.19],[-54.27,2.73],[-54.52,2.31]]},{"type":"LineString","coordinates":[[42.78,10.93],[42.56,10.57],[42.93,10.02],[43.3,9.54],[43.68,9.18],[46.95,8.0],[47.79,8.0]]},{"type":"LineString","coordinates":[[41.86,3.92],[40.98,2.78],[40.99,-0.86],[41.59,-1.68]]},{"type":"LineString","coordinates":[[77.84,35.49],[77.29,35.05],[77.29,35.05]]},{"type":"LineString","coordinates":[[33.44,45.97],[33.7,46.22],[34.41,46.01],[34.73,45.97],[34.86,45.77],[35.01,45.74]]},{"type":"LineString","coordinates":[[75.26,32.27],[74.41,31.69],[74.42,30.98],[73.45,29.98],[72.82,28.96],[71.78,27.91],[70.62,27.99],[69.51,26.94],[70.17,26.49],[70.28,25.72],[70.84,25.22],[71.04,24.36],[68.84,24.36],[68.18,23.69]]},{"type":"LineString","coordinates":[[-60.73,5.2],[-60.73,5.2],[-60.6,4.92],[-60.97,4.54],[-62.09,4.16],[-62.8,4.01],[-63.09,3.77],[-63.89,4.02],[-64.63,4.15],[-64.82,4.06],[-64.37,3.8],[-64.41,3.13],[-64.27,2.5],[-63.42,2.41],[-63.37,2.2],[-64.08,1.92],[-64.2,1.49],[-64.61,1.33],[-65.35,1.1],[-65.55,0.79],[-66.33,0.72],[-66.88,1.25]]},{"type":"LineString","coordinates":[[44.79,39.71],[44.79,39.71],[45.0,39.74],[45.3,39.47],[45.74,39.47],[45.74,39.32],[46.14,38.74]]},{"type":"LineString","coordinates":[[46.51,38.77],[46.14,38.74]]},{"type":"LineString","coordinates":[[44.97,41.25],[43.58,41.09]]},{"type":"LineString","coordinates":[[43.58,41.09],[43.75,40.74],[43.66,40.25],[44.4,40.01],[44.79,39.71],[44.79,39.71]]},{"type":"LineString","coordinates":[[44.79,39.71],[44.11,39.43],[44.42,38.28],[44.23,37.97],[44.77,37.17]]},{"type":"LineString","coordinates":[[44.77,37.17],[44.77,37.17],[44.29,37.0],[43.94,37.26],[42.78,37.39],[42.35,37.23],[42.35,37.23]]},{"type":"LineString","coordinates":[[42.35,37.23],[41.21,37.07],[40.67,37.09],[39.52,36.72],[38.7,36.71],[38.17,36.9],[37.07,36.62],[36.74,36.82],[36.69,36.26],[36.42,36.04],[36.15,35.82]]},{"type":"LineString","coordinates":[[38.79,33.38],[36.83,32.31],[35.72,32.71],[35.7,32.72]]},{"type":"LineString","coordinates":[[39.2,32.16],[39.0,32.01],[37.0,31.51],[38.0,30.51],[37.67,30.34],[37.5,30.0],[36.74,29.87],[36.5,29.51],[36.07,29.2],[34.96,29.36]]},{"type":"LineString","coordinates":[[46.57,29.1],[44.71,29.18],[41.89,31.19],[40.4,31.89],[39.2,32.16]]},{"type":"LineString","coordinates":[[52,19],[55,20],[55.67,22],[55.21,22.71]]},{"type":"LineString","coordinates":[[55.21,22.71],[55.01,22.5],[52.0,23.0],[51.62,24.01],[51.58,24.25]]},{"type":"LineString","coordinates":[[61.21,35.65],[60.8,34.4],[60.53,33.68],[60.96,33.53],[60.54,32.98],[60.86,32.18],[60.94,31.55],[61.7,31.38],[61.78,30.74],[60.87,29.83]]},{"type":"LineString","coordinates":[[60.87,29.83],[60.87,29.83],[61.37,29.3],[61.77,28.7],[62.73,28.26],[62.76,27.38],[63.23,27.22],[63.32,26.76],[61.87,26.24],[61.5,25.08]]},{"type":"LineString","coordinates":[[67.83,37.15],[67.08,37.36],[66.52,37.36],[66.52,37.36]]},{"type":"LineString","coordinates":[[66.52,37.36],[66.55,37.97],[65.22,38.4],[64.17,38.89],[63.52,39.36],[62.37,40.05],[61.88,41.08],[61.55,41.27],[60.47,41.22],[60.08,41.43],[59.98,42.22],[58.63,42.75],[57.79,42.17],[56.93,41.83],[57.1,41.32],[55.97,41.31]]},{"type":"LineString","coordinates":[[74.98,37.42],[74.98,37.42],[75.16,37.13],[75.16,37.13]]},{"type":"LineString","coordinates":[[75.16,37.13],[74.58,37.02],[74.07,36.84],[72.92,36.72],[71.85,36.51],[71.26,36.07],[71.5,35.65],[71.61,35.15],[71.12,34.73],[71.16,34.35],[70.88,33.99],[69.93,34.02],[70.32,33.36],[69.69,33.11],[69.26,32.5],[69.32,31.9],[68.93,31.62],[68.56,31.71],[67.79,31.58],[67.68,31.3],[66.94,31.3],[66.38,30.74],[66.35,29.89],[65.05,29.47],[64.35,29.56],[64.15,29.34],[63.55,29.47],[62.55,29.32],[60.87,29.83]]},{"type":"LineString","coordinates":[[73.68,39.43],[71.78,39.28],[70.55,39.6],[69.46,39.53],[69.56,40.1],[70.65,39.94],[71.01,40.24]]},{"type":"LineString","coordinates":[[87.36,49.22],[86.6,48.55],[85.77,48.46],[85.72,47.45],[85.16,47.0],[83.18,47.33],[82.46,45.54],[81.95,45.32],[79.97,44.92],[80.87,43.18],[80.18,42.92],[80.26,42.35],[80.26,42.35]]},{"type":"LineString","coordinates":[[80.26,42.35],[79.64,42.5],[79.14,42.86],[77.66,42.96],[76.0,42.99],[75.64,42.88],[74.21,43.3],[73.65,43.09],[73.49,42.5],[71.84,42.85],[71.19,42.7],[70.96,42.27]]},{"type":"LineString","coordinates":[[70.96,42.27],[70.96,42.27],[70.39,42.08],[69.07,41.38],[68.63,40.67],[68.26,40.66],[67.99,41.14],[66.71,41.17],[66.51,41.99],[66.02,41.99],[66.1,43.0],[64.9,43.73],[63.19,43.65],[62.01,43.5],[61.06,44.41],[60.24,44.78],[58.69,45.5],[58.5,45.59],[55.93,45.0],[55.97,41.31],[55.97,41.31]]},{"type":"LineString","coordinates":[[55.97,41.31],[55.46,41.26],[54.76,42.04],[54.08,42.32],[52.94,42.12],[52.5,41.78]]},{"type":"LineString","coordinates":[[76.65,35.79],[77.84,35.49]]},{"type":"LineString","coordinates":[[81.11,30.18],[80.48,29.73],[80.09,28.79],[81.06,28.42],[82,27.93],[83.3,27.36],[84.68,27.23],[85.25,26.73],[86.02,26.63],[87.23,26.4],[88.06,26.41],[88.17,26.81],[88.04,27.45],[88.12,27.88]]},{"type":"LineString","coordinates":[[88.81,27.3],[88.84,27.1],[89.74,26.72],[90.37,26.88],[91.22,26.81],[92.03,26.84],[92.1,27.45],[91.7,27.77]]},{"type":"LineString","coordinates":[[88.12,27.88],[88.12,27.88],[88.73,28.09],[88.73,28.09],[88.81,27.3],[88.81,27.3]]},{"type":"LineString","coordinates":[[92.67,22.04],[92.15,23.63],[91.87,23.62],[91.71,22.99],[91.16,23.5],[91.47,24.07],[91.92,24.13],[92.38,24.98],[91.8,25.15],[90.87,25.13],[89.92,25.27],[89.83,25.97],[89.36,26.01],[88.56,26.45],[88.21,25.77],[88.93,25.24],[88.31,24.87],[88.08,24.5],[88.7,24.23],[88.53,23.63],[88.88,22.88],[89.03,22.06]]},{"type":"LineString","coordinates":[[101.18,21.44],[100.33,20.79],[100.12,20.42],[100.12,20.42]]},{"type":"LineString","coordinates":[[100.12,20.42],[99.54,20.19],[98.96,19.75],[98.25,19.71],[97.8,18.63],[97.38,18.45],[97.86,17.57],[98.49,16.84],[98.9,16.18],[98.54,15.31],[98.19,15.12],[98.43,14.62],[99.1,13.83],[99.21,13.27],[99.2,12.8],[99.59,11.89],[99.04,10.96],[98.55,9.93]]},{"type":"LineString","coordinates":[[102.17,22.46],[102.17,22.46],[102.75,21.68],[103.2,20.77],[104.44,20.76],[104.82,19.89],[104.18,19.62],[103.9,19.27],[105.09,18.67],[105.93,17.49],[106.56,16.6],[107.31,15.91],[107.56,15.2],[107.38,14.2],[107.38,14.2]]},{"type":"LineString","coordinates":[[107.38,14.2],[106.5,14.57],[106.04,13.88],[105.22,14.27]]},{"type":"LineString","coordinates":[[130.64,42.4],[130.78,42.22]]},{"type":"LineString","coordinates":[[27.29,57.47],[27.77,57.24],[27.86,56.76],[28.18,56.17],[28.18,56.17]]},{"type":"LineString","coordinates":[[28.18,56.17],[27.1,55.78],[26.49,55.62]]},{"type":"LineString","coordinates":[[31.79,52.1],[30.93,52.04],[30.62,51.82],[30.56,51.32],[30.16,51.42],[29.25,51.37],[28.99,51.6],[28.62,51.43],[28.24,51.57],[27.45,51.59],[26.34,51.83],[25.33,51.91],[24.55,51.89],[24.01,51.62],[23.53,51.58]]},{"type":"LineString","coordinates":[[26.49,55.62],[26.49,55.62],[26.59,55.17],[25.77,54.85],[25.54,54.28],[24.45,53.91],[23.48,53.91]]},{"type":"LineString","coordinates":[[20.65,69.11],[21.24,69.37],[22.36,68.84],[23.66,68.89],[24.74,68.65],[25.69,69.09],[26.18,69.83],[27.73,70.16],[29.02,69.77],[28.59,69.06],[28.59,69.06]]},{"type":"LineString","coordinates":[[28.59,69.06],[29.4,69.16],[31.1,69.56]]},{"type":"LineString","coordinates":[[26.62,48.22],[26.62,48.22],[26.86,48.37],[27.52,48.47],[28.26,48.16],[28.67,48.12],[29.12,47.85],[29.05,47.51],[29.42,47.35],[29.56,46.93],[29.91,46.67],[29.84,46.53],[30.02,46.42],[29.76,46.35],[29.17,46.38],[29.07,46.52],[28.86,46.44],[28.93,46.26],[28.66,45.94],[28.49,45.6],[28.23,45.49]]},{"type":"LineString","coordinates":[[28.23,45.49],[28.23,45.49],[28.68,45.3],[29.15,45.46],[29.6,45.29]]},{"type":"LineString","coordinates":[[22.66,44.23],[22.47,44.41],[22.71,44.58],[22.46,44.7],[22.15,44.48],[21.56,44.77],[21.48,45.18],[20.87,45.42],[20.76,45.73],[20.22,46.13]]},{"type":"LineString","coordinates":[[21.02,40.84],[21.02,40.84],[20.61,41.09],[20.46,41.52],[20.59,41.86]]},{"type":"LineString","coordinates":[[21.58,42.25],[21.58,42.25],[21.35,42.21],[20.76,42.05],[20.72,41.85],[20.59,41.86]]},{"type":"LineString","coordinates":[[20.59,41.86],[20.59,41.86],[20.52,42.22],[20.28,42.32],[20.07,42.59]]},{"type":"LineString","coordinates":[[20.07,42.59],[20.07,42.59],[19.8,42.5],[19.74,42.69],[19.3,42.2],[19.37,41.88]]},{"type":"LineString","coordinates":[[22.36,42.32],[21.92,42.3],[21.58,42.25]]},{"type":"LineString","coordinates":[[20.26,42.81],[20.26,42.81],[20.07,42.59]]},{"type":"LineString","coordinates":[[19.22,43.52],[19.03,43.43],[18.71,43.2],[18.56,42.65]]},{"type":"LineString","coordinates":[[19.01,44.86],[19.39,45.24],[19.07,45.52],[18.83,45.91]]},{"type":"LineString","coordinates":[[15.02,51.11],[14.57,51.0],[14.31,51.12],[14.06,50.93],[13.34,50.73],[12.97,50.48],[12.24,50.27],[12.42,49.97],[12.52,49.55],[13.03,49.31],[13.6,48.88],[13.6,48.88]]},{"type":"LineString","coordinates":[[13.6,48.88],[13.24,48.42],[12.88,48.29],[13.03,47.64],[12.93,47.47],[12.62,47.67],[12.14,47.7],[11.43,47.52],[10.54,47.57],[10.4,47.3],[9.9,47.58],[9.59,47.53],[9.59,47.53]]},{"type":"LineString","coordinates":[[9.59,47.53],[8.52,47.83],[8.32,47.61],[7.47,47.62]]},{"type":"LineString","coordinates":[[16.96,48.6],[16.5,48.79],[16.03,48.73],[15.25,49.04],[14.9,48.96],[14.34,48.56],[13.6,48.88]]},{"type":"LineString","coordinates":[[16.98,48.12],[16.9,47.71],[16.34,47.71],[16.53,47.5],[16.2,46.85],[16.2,46.85]]},{"type":"LineString","coordinates":[[16.2,46.85],[16.01,46.68],[15.14,46.66],[14.63,46.43],[13.81,46.51]]},{"type":"LineString","coordinates":[[13.81,46.51],[13.7,46.02],[13.94,45.59]]},{"type":"LineString","coordinates":[[10.44,46.89],[10.36,46.48],[9.92,46.31],[9.18,46.44],[8.97,46.04],[8.49,46.01],[8.32,46.16],[7.76,45.82],[7.27,45.78],[6.84,45.99]]},{"type":"LineString","coordinates":[[7.47,47.62],[7.19,47.45],[6.74,47.54],[6.77,47.29],[6.04,46.73],[6.02,46.27],[6.5,46.43],[6.84,45.99]]},{"type":"LineString","coordinates":[[6.84,45.99],[6.84,45.99],[6.8,45.71],[7.1,45.33],[6.75,45.03],[7.01,44.25],[7.55,44.13],[7.44,43.69]]},{"type":"LineString","coordinates":[[6.04,50.13],[6.04,50.13],[5.78,50.09],[5.67,49.53],[5.67,49.53]]},{"type":"LineString","coordinates":[[5.67,49.53],[4.8,49.99],[4.29,49.91],[3.59,50.38],[3.12,50.78],[2.66,50.8],[2.51,51.15]]},{"type":"LineString","coordinates":[[6.16,50.8],[6.16,50.8],[5.61,51.04],[4.97,51.48],[4.05,51.27],[3.31,51.35]]},{"type":"LineString","coordinates":[[-4.92,24.97],[-6.45,24.96],[-5.97,20.64],[-5.49,16.33],[-5.32,16.2],[-5.54,15.5],[-9.55,15.49],[-9.7,15.26],[-10.09,15.33],[-10.65,15.13],[-11.35,15.41],[-11.67,15.39],[-11.83,14.8],[-12.17,14.62],[-12.17,14.62]]},{"type":"LineString","coordinates":[[-12.17,14.62],[-12.83,15.3],[-13.44,16.04],[-14.1,16.3],[-14.58,16.6],[-15.14,16.59],[-15.62,16.37],[-16.12,16.46],[-16.46,16.14]]},{"type":"LineString","coordinates":[[9.48,30.31],[9.81,29.42],[9.86,28.96],[9.68,28.14],[9.76,27.69],[9.63,27.14],[9.72,26.51],[9.32,26.09],[9.91,25.37],[9.95,24.94],[10.3,24.38],[10.77,24.56],[11.56,24.1],[12.0,23.47],[12.0,23.47]]},{"type":"LineString","coordinates":[[12.0,23.47],[8.57,21.57],[5.68,19.6],[4.27,19.16]]},{"type":"LineString","coordinates":[[4.27,19.16],[4.27,19.16],[3.16,19.06],[3.15,19.69],[2.68,19.86],[2.06,20.14],[1.82,20.61],[-1.55,22.79],[-4.92,24.97]]},{"type":"LineString","coordinates":[[14.85,22.86],[14.14,22.49],[13.58,23.04],[12.0,23.47]]},{"type":"LineString","coordinates":[[25,22],[25,20.0],[23.85,20],[23.84,19.58]]},{"type":"LineString","coordinates":[[23.84,19.58],[19.85,21.5],[15.86,23.41],[14.85,22.86]]},{"type":"LineString","coordinates":[[22.86,11.14],[22.23,10.97],[21.72,10.57],[21.0,9.48],[20.06,9.01],[19.09,9.07],[18.81,8.98],[18.91,8.63],[18.39,8.28],[17.96,7.89],[16.71,7.51],[16.46,7.73],[16.29,7.75],[16.11,7.5],[15.28,7.42]]},{"type":"LineString","coordinates":[[15.28,7.42],[15.28,7.42],[15.44,7.69],[15.12,8.38],[14.98,8.8],[14.54,8.97],[13.95,9.55],[14.17,10.02],[14.63,9.92],[14.91,9.99],[15.47,9.98],[14.92,10.89],[14.96,11.56],[14.89,12.22],[14.5,12.86]]},{"type":"LineString","coordinates":[[14.5,12.86],[14.21,12.8],[14.18,12.48]]},{"type":"LineString","coordinates":[[14.18,12.48],[14.58,12.09],[14.47,11.9],[14.42,11.57],[13.57,10.8],[13.31,10.16],[13.17,9.64],[12.96,9.42],[12.75,8.72],[12.22,8.31],[12.06,7.8],[11.84,7.4],[11.75,6.98],[11.06,6.64],[10.5,7.06],[10.12,7.04],[9.52,6.45],[9.23,6.44],[8.76,5.48],[8.5,4.77]]},{"type":"LineString","coordinates":[[-11.51,12.44],[-11.51,12.44],[-11.66,12.39],[-12.2,12.47],[-12.28,12.35],[-12.5,12.33],[-13.22,12.58],[-13.7,12.59]]},{"type":"LineString","coordinates":[[-8.03,10.21],[-8.23,10.13],[-8.31,9.79],[-8.08,9.38],[-7.83,8.58],[-8.2,8.46],[-8.3,8.32],[-8.22,8.12],[-8.28,7.69],[-8.44,7.69]]},{"type":"LineString","coordinates":[[-8.44,7.69],[-8.44,7.69],[-8.72,7.71],[-8.93,7.31],[-9.21,7.31],[-9.4,7.53],[-9.34,7.93],[-9.76,8.54],[-10.02,8.43],[-10.23,8.41]]},{"type":"LineString","coordinates":[[-10.23,8.41],[-10.23,8.41],[-10.51,8.35],[-10.49,8.72],[-10.65,8.98],[-10.62,9.27],[-10.84,9.69],[-11.12,10.05],[-11.92,10.05],[-12.15,9.86],[-12.43,9.84],[-12.6,9.62],[-12.71,9.34],[-13.25,8.9]]},{"type":"LineString","coordinates":[[0.37,14.93],[-0.27,14.92],[-0.52,15.12],[-1.07,14.97],[-2.0,14.56],[-2.19,14.25],[-2.97,13.8],[-3.1,13.54],[-3.52,13.34],[-4.01,13.47],[-4.28,13.23],[-4.43,12.54],[-5.22,11.71],[-5.2,11.38],[-5.47,10.95],[-5.4,10.37],[-5.4,10.37]]},{"type":"LineString","coordinates":[[-5.4,10.37],[-5.82,10.22],[-6.05,10.1],[-6.21,10.52],[-6.49,10.41],[-6.67,10.43],[-6.85,10.14],[-7.62,10.15],[-7.9,10.3],[-8.03,10.21]]},{"type":"LineString","coordinates":[[2.15,11.94],[1.94,11.64],[1.45,11.55],[1.24,11.11],[0.9,11.0],[0.9,11.0]]},{"type":"LineString","coordinates":[[0.9,11.0],[0.02,11.02]]},{"type":"LineString","coordinates":[[-2.83,9.64],[-3.51,9.9],[-3.98,9.86],[-4.33,9.61],[-4.78,9.82],[-4.95,10.15],[-5.4,10.37]]},{"type":"LineString","coordinates":[[0.02,11.02],[0.02,11.02],[-0.44,11.1],[-0.76,10.94],[-1.2,11.01],[-2.94,10.96],[-2.96,10.4],[-2.83,9.64],[-2.83,9.64]]},{"type":"LineString","coordinates":[[3.61,11.66],[3.57,11.33],[3.8,10.73],[3.6,10.33],[3.71,10.06],[3.22,9.44],[2.91,9.14],[2.72,8.51],[2.75,7.87],[2.69,6.26]]},{"type":"LineString","coordinates":[[16.01,2.27],[15.94,1.73],[15.15,1.96],[14.34,2.23],[13.08,2.27],[13.08,2.27]]},{"type":"LineString","coordinates":[[13.08,2.27],[12.95,2.32],[12.36,2.19],[11.75,2.33],[11.28,2.26],[11.28,2.26]]},{"type":"LineString","coordinates":[[11.28,2.26],[9.65,2.28]]},{"type":"LineString","coordinates":[[23.81,8.67],[24.57,8.23],[25.11,7.83],[25.12,7.5],[25.8,6.98],[26.21,6.55],[26.47,5.95],[27.21,5.55],[27.37,5.23],[27.37,5.23]]},{"type":"LineString","coordinates":[[27.37,5.23],[27.04,5.13],[26.4,5.15],[25.65,5.26],[25.28,5.17],[25.13,4.93],[24.81,4.9],[24.41,5.11],[23.3,4.61],[22.84,4.71],[22.7,4.63],[22.41,4.03],[21.66,4.22],[20.93,4.32],[20.29,4.69],[19.47,5.03],[18.93,4.71],[18.54,4.2],[18.45,3.5]]},{"type":"LineString","coordinates":[[36.43,14.42],[36.27,13.56],[35.86,12.58],[35.26,12.08],[34.83,11.32],[34.73,10.91],[34.26,10.63],[33.96,9.58],[33.96,9.58]]},{"type":"LineString","coordinates":[[33.96,9.58],[33.97,8.68],[33.83,8.38],[33.29,8.35],[32.95,7.78],[33.57,7.71],[34.08,7.23],[34.25,6.83],[34.71,6.59],[35.3,5.51]]},{"type":"LineString","coordinates":[[42.35,12.54],[42.78,12.46],[43.08,12.7]]},{"type":"LineString","coordinates":[[42.78,10.93],[42.55,11.11],[42.31,11.03],[41.76,11.05],[41.74,11.36],[41.66,11.63],[42,12.1],[42.35,12.54]]},{"type":"LineString","coordinates":[[33.9,-0.95],[33.9,-0.95],[33.89,0.11],[34.18,0.52],[34.67,1.18],[35.04,1.91],[34.6,3.05],[34.48,3.56],[34.01,4.25]]},{"type":"LineString","coordinates":[[30.83,3.51],[29.95,4.17],[29.72,4.6],[29.16,4.39],[28.7,4.46],[28.43,4.29],[27.98,4.41],[27.37,5.23]]},{"type":"LineString","coordinates":[[18.45,3.5],[18.45,3.5],[18.39,2.9],[18.09,2.37],[17.9,1.74],[17.77,0.86],[17.83,0.29],[17.66,-0.06],[17.64,-0.42],[17.52,-0.74],[16.87,-1.23],[16.41,-1.74],[15.97,-2.71],[16.01,-3.54],[15.75,-3.86],[15.17,-4.34],[14.58,-4.97],[14.21,-4.79],[14.14,-4.51],[13.6,-4.5],[13.26,-4.88],[13.0,-4.78]]},{"type":"LineString","coordinates":[[13.0,-4.78],[13.0,-4.78],[12.63,-4.99],[12.47,-5.25],[12.44,-5.68],[12.18,-5.79]]},{"type":"LineString","coordinates":[[29.58,-1.34],[29.29,-1.62],[29.25,-2.22],[29.12,-2.29],[29.02,-2.84]]},{"type":"LineString","coordinates":[[29.02,-2.84],[29.28,-3.29],[29.34,-4.5]]},{"type":"LineString","coordinates":[[29.34,-4.5],[29.52,-5.42],[29.42,-5.94],[29.62,-6.52],[30.2,-7.08],[30.74,-8.34]]},{"type":"LineString","coordinates":[[30.74,-8.34],[30.35,-8.24],[29.0,-8.41],[28.73,-8.53],[28.45,-9.16],[28.67,-9.61],[28.5,-10.79],[28.37,-11.79],[28.64,-11.97],[29.34,-12.36],[29.62,-12.18],[29.7,-13.26],[28.93,-13.25],[28.52,-12.7],[28.16,-12.27],[27.39,-12.13],[27.16,-11.61],[26.55,-11.92],[25.75,-11.78],[25.42,-11.33],[24.78,-11.24],[24.31,-11.26],[24.26,-10.95],[23.91,-10.93]]},{"type":"LineString","coordinates":[[23.91,-10.93],[23.46,-10.87],[22.84,-11.02],[22.4,-10.99],[22.16,-11.08],[22.21,-9.89],[21.88,-9.52],[21.8,-8.91],[21.95,-8.31],[21.75,-7.92],[21.73,-7.29],[20.51,-7.3],[20.6,-6.94],[20.09,-6.94],[20.04,-7.12],[19.42,-7.16],[19.17,-7.74],[19.02,-7.99],[18.46,-7.85],[18.13,-7.99],[17.47,-8.07],[17.09,-7.55],[16.86,-7.22],[16.57,-6.62],[16.33,-5.88],[13.38,-5.86],[13.02,-5.98],[12.74,-5.97],[12.32,-6.1]]},{"type":"LineString","coordinates":[[30.47,-2.41],[30.47,-2.41],[29.94,-2.35],[29.63,-2.92],[29.02,-2.84]]},{"type":"LineString","coordinates":[[30.42,-1.13],[30.77,-1.01],[31.87,-1.03],[33.9,-0.95]]},{"type":"LineString","coordinates":[[32.76,-9.23],[32.19,-8.93],[31.56,-8.76],[31.16,-8.59],[30.74,-8.34]]},{"type":"LineString","coordinates":[[33.21,-13.97],[30.18,-14.8],[30.27,-15.51]]},{"type":"LineString","coordinates":[[30.27,-15.51],[30.27,-15.51],[29.52,-15.64],[28.95,-16.04],[28.83,-16.39],[28.47,-16.47],[27.6,-17.29],[27.04,-17.94],[26.71,-17.96],[26.38,-17.85],[25.26,-17.74],[25.08,-17.66]]},{"type":"LineString","coordinates":[[23.22,-17.52],[21.38,-17.93],[18.96,-17.79],[18.26,-17.31],[14.21,-17.35],[14.06,-17.42],[13.46,-16.97],[12.81,-16.94],[12.22,-17.11],[11.73,-17.3]]},{"type":"LineString","coordinates":[[24.93,-17.72],[24.52,-17.89],[24.22,-17.89],[23.58,-18.28],[23.2,-17.87],[21.66,-18.22],[20.91,-18.25],[20.88,-21.81],[19.9,-21.85],[19.9,-24.77],[19.9,-24.77]]},{"type":"LineString","coordinates":[[29.43,-22.09],[28.02,-22.83],[27.12,-23.57],[26.79,-24.24],[26.49,-24.62],[25.94,-24.7],[25.77,-25.17],[25.66,-25.49],[25.03,-25.72],[24.21,-25.67],[23.73,-25.39],[23.31,-25.27],[22.82,-25.5],[22.58,-25.98],[22.11,-26.28],[21.61,-26.73],[20.89,-26.83],[20.67,-26.48],[20.76,-25.87],[20.17,-24.92],[19.9,-24.77]]},{"type":"LineString","coordinates":[[31.19,-22.25],[31.19,-22.25],[30.66,-22.15],[30.32,-22.27],[29.84,-22.1],[29.43,-22.09]]},{"type":"LineString","coordinates":[[32.07,-26.73],[32.07,-26.73],[31.99,-26.29],[31.84,-25.84]]},{"type":"LineString","coordinates":[[31.84,-25.84],[31.84,-25.84],[31.75,-25.48],[31.93,-24.37],[31.67,-23.66],[31.19,-22.25]]},{"type":"LineString","coordinates":[[-89.14,17.81],[-89.14,17.81],[-89.15,17.96],[-89.03,18.0],[-88.85,17.88],[-88.49,18.49],[-88.3,18.5]]},{"type":"LineString","coordinates":[[-89.35,14.42],[-89.15,14.68],[-89.23,14.87],[-89.15,15.07],[-88.68,15.35],[-88.23,15.73]]},{"type":"LineString","coordinates":[[-66.88,1.25],[-67.07,1.13],[-67.26,1.72],[-67.54,2.04],[-67.87,1.69],[-69.82,1.71],[-69.8,1.09],[-69.22,0.99],[-69.25,0.6],[-69.45,0.71],[-70.02,0.54],[-70.02,-0.19],[-69.58,-0.55],[-69.42,-1.12],[-69.44,-1.56],[-69.89,-4.3],[-69.89,-4.3]]},{"type":"LineString","coordinates":[[-69.89,-4.3],[-70.39,-3.77],[-70.69,-3.74],[-70.05,-2.73],[-70.81,-2.26],[-71.41,-2.34],[-71.77,-2.17],[-72.33,-2.43],[-73.07,-2.31],[-73.66,-1.26],[-74.12,-1.0],[-74.44,-0.53],[-75.11,-0.06],[-75.37,-0.15],[-75.37,-0.15]]},{"type":"LineString","coordinates":[[-75.37,-0.15],[-75.8,0.08],[-76.29,0.42],[-76.58,0.26],[-77.42,0.4],[-77.67,0.83],[-77.86,0.81],[-78.86,1.38]]},{"type":"LineString","coordinates":[[-67.11,-22.74],[-67.11,-22.74],[-67.83,-22.87],[-68.22,-21.49],[-68.76,-20.37],[-68.44,-19.41],[-68.97,-18.98],[-69.1,-18.26],[-69.59,-17.58]]},{"type":"LineString","coordinates":[[-58.17,-20.18],[-58.18,-19.87],[-59.12,-19.36],[-60.04,-19.34],[-61.79,-19.63],[-62.27,-20.51],[-62.29,-21.05],[-62.69,-22.25]]},{"type":"LineString","coordinates":[[-54.63,-25.74],[-54.63,-25.74],[-54.13,-25.55],[-53.63,-26.12],[-53.65,-26.92],[-54.49,-27.47],[-55.16,-27.88],[-56.29,-28.85],[-57.63,-30.22]]},{"type":"LineString","coordinates":[[-57.63,-30.22],[-57.63,-30.22],[-56.98,-30.11],[-55.97,-30.88],[-55.6,-30.85],[-54.57,-31.49],[-53.79,-32.05],[-53.21,-32.73],[-53.65,-33.2],[-53.37,-33.77]]},{"type":"LineString","coordinates":[[-69.59,-17.58],[-68.96,-16.5],[-69.39,-15.66],[-69.16,-15.32],[-69.34,-14.95],[-68.95,-14.45],[-68.93,-13.6],[-68.88,-12.9],[-68.67,-12.56],[-69.53,-10.95]]},{"type":"LineString","coordinates":[[13.32,13.56],[13.32,13.56],[14.0,12.46],[14.18,12.48],[14.18,12.48]]},{"type":"LineString","coordinates":[[6.19,49.46],[5.9,49.44],[5.67,49.53]]},{"type":"MultiLineString","coordinates":[[[46.14,38.74],[45.46,38.87],[44.95,39.34],[44.79,39.71]],[[46.51,38.77],[47.69,39.51],[48.06,39.58],[48.36,39.29],[48.01,38.79],[48.63,38.27],[48.88,38.32]]]},{"type":"LineString","coordinates":[[-13.7,12.59],[-13.7,12.59],[-15.55,12.63],[-15.82,12.52],[-16.15,12.55],[-16.68,12.38]]},{"type":"LineString","coordinates":[[19.9,-24.77],[19.89,-28.46],[19.0,-28.97],[18.46,-29.05],[17.84,-28.86],[17.39,-28.78],[17.22,-28.36],[16.82,-28.08],[16.34,-28.58]]},{"type":"LineString","coordinates":[[-62.69,-22.25],[-62.69,-22.25],[-62.85,-22.03],[-63.99,-21.99],[-64.38,-22.8],[-64.96,-22.08],[-66.27,-21.83],[-67.11,-22.74]]},{"type":"MultiLineString","coordinates":[[[-69.53,-10.95],[-69.53,-10.95],[-68.79,-11.04],[-68.27,-11.01],[-68.05,-10.71],[-67.17,-10.31],[-66.65,-9.93],[-65.34,-9.76],[-65.44,-10.51],[-65.32,-10.9],[-65.4,-11.57],[-64.32,-12.46],[-63.2,-12.63],[-62.8,-13.0],[-62.13,-13.2],[-61.71,-13.49],[-61.08,-13.48],[-60.5,-13.78],[-60.46,-14.35],[-60.26,-14.65],[-60.25,-15.08],[-60.54,-15.09],[-60.16,-16.26],[-58.24,-16.3],[-58.39,-16.88],[-58.28,-17.27],[-57.73,-17.55],[-57.5,-18.17],[-57.68,-18.96],[-57.95,-19.4],[-57.85,-19.97],[-57.85,-19.97],[-58.17,-20.18]],[[-57.85,-19.97],[-58.17,-20.18]]]},{"type":"LineString","coordinates":[[75.9,36.67],[76.19,35.9],[76.65,35.79]]},{"type":"LineString","coordinates":[[79.21,32.99],[79.21,32.99],[79.18,32.48],[79.18,32.48]]},{"type":"LineString","coordinates":[[79.18,32.48],[78.46,32.62],[78.55,32.27]]},{"type":"LineString","coordinates":[[78.55,32.27],[78.65,31.85]]},{"type":"LineString","coordinates":[[78.65,31.85],[78.74,31.52],[78.88,31.43]]},{"type":"LineString","coordinates":[[78.88,31.43],[79.37,31.11]]},{"type":"LineString","coordinates":[[79.37,31.11],[79.72,30.88],[79.81,30.84]]},{"type":"LineString","coordinates":[[79.81,30.84],[80.26,30.61]]},{"type":"LineString","coordinates":[[80.26,30.61],[81.11,30.18],[81.11,30.18]]},{"type":"LineString","coordinates":[[36.7,45.61],[36.58,45.2],[36.64,44.95]]},{"type":"LineString","coordinates":[[87.36,49.22],[87.75,49.3],[88.01,48.6],[88.85,48.07],[90.28,47.69],[90.97,46.89],[90.59,45.72],[90.95,45.29],[92.13,45.12],[93.48,44.98],[94.69,44.35],[95.31,44.24],[95.76,43.32],[96.35,42.73],[97.45,42.75],[99.52,42.52],[100.85,42.66],[101.83,42.51],[103.31,41.91],[104.52,41.91],[104.97,41.6],[106.13,42.13],[107.74,42.48],[109.24,42.52],[110.41,42.87],[111.13,43.41],[111.83,43.74],[111.67,44.07],[111.35,44.46],[111.87,45.1],[112.44,45.01],[113.46,44.81],[114.46,45.34],[115.99,45.73],[116.72,46.39],[117.42,46.67],[118.87,46.81],[119.66,46.69],[119.77,47.05],[118.87,47.75],[118.06,48.07],[117.3,47.7],[116.31,47.85],[115.74,47.73],[115.49,48.14],[116.19,49.13],[116.68,49.89],[116.68,49.89]]},{"type":"LineString","coordinates":[[116.68,49.89],[116.68,49.89],[117.88,49.51],[119.29,50.14],[119.28,50.58],[120.18,51.64],[120.74,51.96],[120.73,52.52],[120.18,52.75],[121.0,53.25],[122.25,53.43],[123.57,53.46],[125.07,53.16],[125.95,52.79],[126.56,51.78],[126.94,51.35],[127.29,50.74],[127.66,49.76],[129.4,49.44],[130.58,48.73],[130.99,47.79],[132.51,47.79],[133.37,48.18],[135.03,48.48],[134.5,47.58],[134.11,47.21],[133.77,46.12],[133.1,45.14],[131.88,45.32],[131.03,44.97],[131.29,44.11],[131.14,42.93],[130.63,42.9],[130.64,42.4]]},{"type":"LineString","coordinates":[[35.55,33.26],[35.46,33.09],[35.13,33.09]]},{"type":"LineString","coordinates":[[75.14,34.6],[74.24,34.75],[73.75,34.32],[74.1,33.44],[74.45,32.76]]},{"type":"LineString","coordinates":[[77.29,35.05],[76.87,34.65],[75.76,34.5],[75.14,34.6]]}]} \ No newline at end of file diff --git a/bitchat/Resources/Globe/world_cities.geojson b/bitchat/Resources/Globe/world_cities.geojson new file mode 100644 index 00000000..435f8654 --- /dev/null +++ b/bitchat/Resources/Globe/world_cities.geojson @@ -0,0 +1 @@ +{"cities":[{"n":"Bombo","r":10,"cap":0,"mega":0,"pop":75000,"lon":32.533,"lat":0.583},{"n":"Fort Portal","r":10,"cap":0,"mega":0,"pop":42670,"lon":30.275,"lat":0.671},{"n":"Potenza","r":10,"cap":0,"mega":0,"pop":69060,"lon":15.799,"lat":40.642},{"n":"Campobasso","r":10,"cap":0,"mega":0,"pop":50762,"lon":14.656,"lat":41.563},{"n":"Aosta","r":10,"cap":0,"mega":0,"pop":34062,"lon":7.315,"lat":45.737},{"n":"Mariehamn","r":10,"cap":0,"mega":0,"pop":10682,"lon":19.949,"lat":60.097},{"n":"Ramallah","r":10,"cap":0,"mega":0,"pop":24599,"lon":35.206,"lat":31.903},{"n":"Vatican City","r":8,"cap":1,"mega":0,"pop":832,"lon":12.453,"lat":41.903},{"n":"Poitier","r":8,"cap":0,"mega":0,"pop":85960,"lon":0.333,"lat":46.583},{"n":"Clermont-Ferrand","r":8,"cap":0,"mega":0,"pop":233050,"lon":3.08,"lat":45.78},{"n":"Besancon","r":8,"cap":0,"mega":0,"pop":128426,"lon":6.03,"lat":47.23},{"n":"Artigas Base","r":8,"cap":0,"mega":0,"pop":60,"lon":-58.864,"lat":-62.174},{"n":"Chipata","r":7,"cap":0,"mega":0,"pop":85963,"lon":32.64,"lat":-13.63},{"n":"Jinja","r":7,"cap":0,"mega":0,"pop":301619,"lon":33.2,"lat":0.44},{"n":"Arua","r":7,"cap":0,"mega":0,"pop":250000,"lon":30.9,"lat":3.02},{"n":"Mbale","r":7,"cap":0,"mega":0,"pop":402368,"lon":34.17,"lat":1.09},{"n":"Moroto","r":7,"cap":0,"mega":0,"pop":371,"lon":34.64,"lat":2.54},{"n":"Masaka","r":7,"cap":0,"mega":0,"pop":65373,"lon":31.73,"lat":-0.33},{"n":"Mbarara","r":7,"cap":0,"mega":0,"pop":83700,"lon":30.65,"lat":-0.6},{"n":"Otjiwarongo","r":7,"cap":0,"mega":0,"pop":24815,"lon":16.64,"lat":-20.46},{"n":"Bologna","r":7,"cap":0,"mega":0,"pop":488172,"lon":11.34,"lat":44.5},{"n":"Cagliari","r":7,"cap":0,"mega":0,"pop":291511,"lon":9.104,"lat":39.222},{"n":"Catanzaro","r":7,"cap":0,"mega":0,"pop":95251,"lon":16.6,"lat":38.9},{"n":"Bari","r":7,"cap":0,"mega":0,"pop":500577,"lon":16.873,"lat":41.114},{"n":"L'Aquila","r":7,"cap":0,"mega":0,"pop":68503,"lon":13.39,"lat":42.35},{"n":"Ancona","r":7,"cap":0,"mega":0,"pop":100507,"lon":13.5,"lat":43.6},{"n":"Perugia","r":7,"cap":0,"mega":0,"pop":149125,"lon":12.39,"lat":43.11},{"n":"Trieste","r":7,"cap":0,"mega":0,"pop":216035,"lon":13.8,"lat":45.65},{"n":"Trento","r":7,"cap":0,"mega":0,"pop":107808,"lon":11.12,"lat":46.08},{"n":"Fort-de-France","r":7,"cap":0,"mega":0,"pop":253995,"lon":-61.08,"lat":14.61},{"n":"Gifu","r":7,"cap":0,"mega":0,"pop":412895,"lon":136.763,"lat":35.423},{"n":"Saint-Laurent-du-Maroni","r":7,"cap":0,"mega":0,"pop":24287,"lon":-54.033,"lat":5.498},{"n":"Caen","r":7,"cap":0,"mega":0,"pop":190099,"lon":-0.35,"lat":49.184},{"n":"Nantes","r":7,"cap":0,"mega":0,"pop":438537,"lon":-1.59,"lat":47.21},{"n":"Ajaccio","r":7,"cap":0,"mega":0,"pop":54364,"lon":8.728,"lat":41.927},{"n":"Montpellier","r":7,"cap":0,"mega":0,"pop":327254,"lon":3.87,"lat":43.61},{"n":"Dijon","r":7,"cap":0,"mega":0,"pop":169946,"lon":5.03,"lat":47.33},{"n":"Orleans","r":7,"cap":0,"mega":0,"pop":217301,"lon":1.9,"lat":47.9},{"n":"Rouen","r":7,"cap":0,"mega":0,"pop":532559,"lon":1.08,"lat":49.43},{"n":"Reims","r":7,"cap":0,"mega":0,"pop":196565,"lon":4.03,"lat":49.25},{"n":"Amiens","r":7,"cap":0,"mega":0,"pop":143086,"lon":2.3,"lat":49.9},{"n":"Nancy","r":7,"cap":0,"mega":0,"pop":268976,"lon":6.2,"lat":48.684},{"n":"Basse-terre","r":7,"cap":0,"mega":0,"pop":307,"lon":-61.705,"lat":16.01},{"n":"Novi Sad","r":7,"cap":0,"mega":0,"pop":225457,"lon":19.85,"lat":45.25},{"n":"Banja Luka","r":7,"cap":0,"mega":0,"pop":221738,"lon":17.18,"lat":44.78},{"n":"George Town","r":7,"cap":0,"mega":0,"pop":4268,"lon":-81.372,"lat":19.295},{"n":"Grand Turk","r":7,"cap":0,"mega":0,"pop":5801,"lon":-71.136,"lat":21.466},{"n":"Douglas","r":7,"cap":0,"mega":0,"pop":35854,"lon":-4.48,"lat":54.149},{"n":"San Marino","r":7,"cap":1,"mega":0,"pop":29579,"lon":12.442,"lat":43.936},{"n":"Willemstad","r":7,"cap":0,"mega":0,"pop":146813,"lon":-68.872,"lat":12.112},{"n":"Oranjestad","r":7,"cap":0,"mega":0,"pop":68775,"lon":-70.026,"lat":12.522},{"n":"Vaduz","r":7,"cap":1,"mega":0,"pop":36281,"lon":9.517,"lat":47.134},{"n":"Capitan Arturo Prat Station","r":7,"cap":0,"mega":0,"pop":41,"lon":-59.683,"lat":-62.5},{"n":"Marambio Base","r":7,"cap":0,"mega":0,"pop":150,"lon":-56.65,"lat":-64.233},{"n":"Zucchelli Station","r":7,"cap":0,"mega":0,"pop":80,"lon":164.219,"lat":-74.619},{"n":"Rothera Station","r":7,"cap":0,"mega":0,"pop":130,"lon":-68.124,"lat":-67.565},{"n":"Palmer Station","r":7,"cap":0,"mega":0,"pop":46,"lon":-64.047,"lat":-64.762},{"n":"Base Presidente Montalva","r":7,"cap":0,"mega":0,"pop":150,"lon":-58.908,"lat":-62.183},{"n":"Carlini Base","r":7,"cap":0,"mega":0,"pop":60,"lon":-58.65,"lat":-62.224},{"n":"King Sejong Station","r":7,"cap":0,"mega":0,"pop":90,"lon":-58.772,"lat":-62.225},{"n":"Great Wall Station","r":7,"cap":0,"mega":0,"pop":40,"lon":-58.967,"lat":-62.216},{"n":"Escudero Base","r":7,"cap":0,"mega":0,"pop":20,"lon":-58.953,"lat":-62.195},{"n":"Elephant Island","r":7,"cap":0,"mega":0,"pop":6,"lon":-58.0,"lat":-62.0},{"n":"Scott Base","r":7,"cap":0,"mega":0,"pop":85,"lon":166.749,"lat":-77.847},{"n":"McMurdo Station","r":7,"cap":0,"mega":0,"pop":1000,"lon":166.869,"lat":-77.732},{"n":"Zhongshan Station","r":7,"cap":0,"mega":0,"pop":60,"lon":76.339,"lat":-69.434},{"n":"Vostok","r":7,"cap":0,"mega":0,"pop":25,"lon":106.8,"lat":-78.466},{"n":"Peter I Island","r":7,"cap":0,"mega":0,"pop":1,"lon":-90.584,"lat":-68.795},{"n":"Mirny Station","r":7,"cap":0,"mega":0,"pop":169,"lon":93.006,"lat":-66.576},{"n":"Mawson Station","r":7,"cap":0,"mega":0,"pop":60,"lon":62.875,"lat":-67.615},{"n":"Davis Station","r":7,"cap":0,"mega":0,"pop":70,"lon":78.141,"lat":-68.778},{"n":"Concordia Research Station","r":7,"cap":0,"mega":0,"pop":30,"lon":124.167,"lat":-74.666},{"n":"Casey Station","r":7,"cap":0,"mega":0,"pop":200,"lon":110.536,"lat":-66.286},{"n":"AmundseniScott South Pole Station","r":7,"cap":0,"mega":0,"pop":200,"lon":176.994,"lat":-90},{"n":"Wasa Station","r":7,"cap":0,"mega":0,"pop":10,"lon":-13.417,"lat":-73.05},{"n":"Troll Station","r":7,"cap":0,"mega":0,"pop":44,"lon":2.533,"lat":-72.016},{"n":"Svea Station","r":7,"cap":0,"mega":0,"pop":10,"lon":-11.217,"lat":-74.583},{"n":"Novolazarevskaya Station","r":7,"cap":0,"mega":0,"pop":70,"lon":-11.85,"lat":-71.301},{"n":"Neumayer Station III","r":7,"cap":0,"mega":0,"pop":40,"lon":-7.838,"lat":-70.89},{"n":"Maitri Station","r":7,"cap":0,"mega":0,"pop":65,"lon":11.73,"lat":-70.782},{"n":"Halley Station","r":7,"cap":0,"mega":0,"pop":70,"lon":-26.474,"lat":-76.092},{"n":"Belgrano II Base","r":7,"cap":0,"mega":0,"pop":100,"lon":-34.617,"lat":-77.866},{"n":"Sobral Base","r":7,"cap":0,"mega":0,"pop":40,"lon":-40.502,"lat":-81.179},{"n":"Aboa Station","r":7,"cap":0,"mega":0,"pop":18,"lon":-13.417,"lat":-75.05},{"n":"San Martin Base","r":7,"cap":0,"mega":0,"pop":20,"lon":-67.1,"lat":-68.116},{"n":"Gen. O'Higgins Base","r":7,"cap":0,"mega":0,"pop":44,"lon":-57.89,"lat":-63.328},{"n":"Esperanza Station","r":7,"cap":0,"mega":0,"pop":250,"lon":-57.026,"lat":-63.375},{"n":"Orcadas Station","r":7,"cap":0,"mega":0,"pop":45,"lon":-44.733,"lat":-60.733},{"n":"Signy Research Station","r":7,"cap":0,"mega":0,"pop":8,"lon":-45.601,"lat":-60.631},{"n":"Dumont d'Urville Station","r":7,"cap":0,"mega":0,"pop":120,"lon":139.964,"lat":-66.775},{"n":"Showa Station","r":7,"cap":0,"mega":0,"pop":60,"lon":39.746,"lat":-69.03},{"n":"Gibraltar","r":6,"cap":0,"mega":0,"pop":187083,"lon":-5.346,"lat":36.128},{"n":"Lobamba","r":6,"cap":0,"mega":0,"pop":9782,"lon":31.2,"lat":-26.467},{"n":"Edinburgh","r":6,"cap":0,"mega":0,"pop":504966,"lon":-3.219,"lat":55.948},{"n":"Cardiff","r":6,"cap":0,"mega":0,"pop":861400,"lon":-3.168,"lat":51.483},{"n":"Longyearbyen","r":6,"cap":0,"mega":0,"pop":1232,"lon":15.621,"lat":78.221},{"n":"Luxembourg","r":6,"cap":1,"mega":0,"pop":107260,"lon":6.13,"lat":49.612},{"n":"Turin","r":6,"cap":0,"mega":1,"pop":1652000,"lon":7.668,"lat":45.072},{"n":"Noumea","r":6,"cap":0,"mega":0,"pop":93060,"lon":166.444,"lat":-22.263},{"n":"Matsuyama","r":6,"cap":0,"mega":0,"pop":533541,"lon":132.766,"lat":33.846},{"n":"Rennes","r":6,"cap":0,"mega":0,"pop":209375,"lon":-1.67,"lat":48.1},{"n":"Toulouse","r":6,"cap":0,"mega":1,"pop":847000,"lon":1.448,"lat":43.622},{"n":"Limoges","r":6,"cap":0,"mega":0,"pop":152199,"lon":1.25,"lat":45.83},{"n":"Lille","r":6,"cap":0,"mega":1,"pop":1044000,"lon":3.078,"lat":50.652},{"n":"Strasbourg","r":6,"cap":0,"mega":0,"pop":439972,"lon":7.75,"lat":48.58},{"n":"Batumi","r":6,"cap":0,"mega":0,"pop":155542,"lon":41.63,"lat":41.6},{"n":"Funchal","r":6,"cap":0,"mega":0,"pop":204767,"lon":-16.88,"lat":32.65},{"n":"El Fasher","r":6,"cap":0,"mega":0,"pop":252609,"lon":25.35,"lat":13.63},{"n":"Keetmanshoop","r":6,"cap":0,"mega":0,"pop":18039,"lon":18.13,"lat":-26.574},{"n":"Swakopmund","r":6,"cap":0,"mega":0,"pop":29491,"lon":14.535,"lat":-22.669},{"n":"Genoa","r":6,"cap":0,"mega":0,"pop":647497,"lon":8.93,"lat":44.41},{"n":"Sukhumi","r":6,"cap":0,"mega":0,"pop":81546,"lon":41.02,"lat":43.02},{"n":"Palikir","r":6,"cap":1,"mega":0,"pop":4645,"lon":158.15,"lat":6.917},{"n":"Majuro","r":6,"cap":1,"mega":0,"pop":25400,"lon":171.38,"lat":7.103},{"n":"Agana","r":6,"cap":0,"mega":0,"pop":122411,"lon":144.75,"lat":13.47},{"n":"Funafuti","r":6,"cap":1,"mega":0,"pop":4749,"lon":179.217,"lat":-8.517},{"n":"Melekeok","r":6,"cap":1,"mega":0,"pop":7026,"lon":134.627,"lat":7.487},{"n":"Bir Lehlou","r":6,"cap":0,"mega":0,"pop":500,"lon":-9.653,"lat":26.119},{"n":"Monaco","r":6,"cap":1,"mega":0,"pop":36371,"lon":7.407,"lat":43.74},{"n":"Tarawa","r":6,"cap":1,"mega":0,"pop":28802,"lon":173.018,"lat":1.338},{"n":"Moroni","r":6,"cap":1,"mega":0,"pop":128698,"lon":43.24,"lat":-11.704},{"n":"Macau","r":6,"cap":0,"mega":0,"pop":568700,"lon":113.544,"lat":22.189},{"n":"Andorra","r":6,"cap":1,"mega":0,"pop":53998,"lon":1.527,"lat":42.511},{"n":"San Bernardino","r":4,"cap":0,"mega":1,"pop":1745000,"lon":-117.302,"lat":34.122},{"n":"Bridgeport","r":4,"cap":0,"mega":1,"pop":1018000,"lon":-73.202,"lat":41.182},{"n":"Rochester","r":4,"cap":0,"mega":1,"pop":755000,"lon":-77.622,"lat":43.172},{"n":"Manchester","r":4,"cap":0,"mega":1,"pop":2230000,"lon":-2.249,"lat":53.475},{"n":"Gujranwala","r":4,"cap":0,"mega":1,"pop":1513000,"lon":74.183,"lat":32.162},{"n":"Incheon","r":4,"cap":0,"mega":1,"pop":2550000,"lon":126.64,"lat":37.478},{"n":"Benin City","r":4,"cap":0,"mega":1,"pop":1190000,"lon":5.618,"lat":6.342},{"n":"Xiamen","r":4,"cap":0,"mega":1,"pop":2519000,"lon":118.078,"lat":24.452},{"n":"Nanchong","r":4,"cap":0,"mega":1,"pop":2174000,"lon":106.128,"lat":30.782},{"n":"Neijiang","r":4,"cap":0,"mega":1,"pop":1466000,"lon":105.048,"lat":29.582},{"n":"Nanyang","r":4,"cap":0,"mega":1,"pop":1944000,"lon":112.528,"lat":33.002},{"n":"Jinxi","r":4,"cap":0,"mega":1,"pop":2426000,"lon":120.828,"lat":40.752},{"n":"Yantai","r":4,"cap":0,"mega":1,"pop":2116000,"lon":121.398,"lat":37.532},{"n":"Zaozhuang","r":4,"cap":0,"mega":1,"pop":2145000,"lon":117.568,"lat":34.882},{"n":"Suzhou","r":4,"cap":0,"mega":1,"pop":1650000,"lon":120.618,"lat":31.302},{"n":"Xuzhou","r":4,"cap":0,"mega":1,"pop":2091000,"lon":117.178,"lat":34.282},{"n":"Wuxi","r":4,"cap":0,"mega":1,"pop":1749000,"lon":120.298,"lat":31.582},{"n":"Jilin","r":4,"cap":0,"mega":1,"pop":2396000,"lon":126.548,"lat":43.852},{"n":"Chandigarh","r":4,"cap":0,"mega":1,"pop":979000,"lon":76.778,"lat":30.722},{"n":"Jammu","r":4,"cap":0,"mega":1,"pop":791000,"lon":74.845,"lat":32.714},{"n":"Sholapur","r":4,"cap":0,"mega":1,"pop":1057000,"lon":75.898,"lat":17.672},{"n":"Aurangabad","r":4,"cap":0,"mega":1,"pop":1113000,"lon":75.329,"lat":19.862},{"n":"Nasik","r":4,"cap":0,"mega":1,"pop":1473000,"lon":73.778,"lat":20.002},{"n":"Dispur","r":4,"cap":0,"mega":0,"pop":16140,"lon":91.767,"lat":26.144},{"n":"Jullundur","r":4,"cap":0,"mega":1,"pop":855000,"lon":75.567,"lat":31.337},{"n":"Allahabad","r":4,"cap":0,"mega":1,"pop":1201000,"lon":81.838,"lat":25.457},{"n":"Moradabad","r":4,"cap":0,"mega":1,"pop":787000,"lon":78.755,"lat":28.844},{"n":"Ghaziabad","r":4,"cap":0,"mega":1,"pop":1341000,"lon":77.406,"lat":28.662},{"n":"Agra","r":4,"cap":0,"mega":1,"pop":1592000,"lon":78.013,"lat":27.172},{"n":"Aligarh","r":4,"cap":0,"mega":1,"pop":805000,"lon":78.06,"lat":27.894},{"n":"Meerut","r":4,"cap":0,"mega":1,"pop":1398000,"lon":77.698,"lat":29.002},{"n":"Dhanbad","r":4,"cap":0,"mega":1,"pop":1246000,"lon":86.418,"lat":23.802},{"n":"Gwalior","r":4,"cap":0,"mega":1,"pop":978000,"lon":78.169,"lat":26.2},{"n":"Vadodara","r":4,"cap":0,"mega":1,"pop":1756000,"lon":73.178,"lat":22.312},{"n":"Rajkot","r":4,"cap":0,"mega":1,"pop":1260000,"lon":70.798,"lat":22.312},{"n":"Durazno","r":4,"cap":0,"mega":0,"pop":34037,"lon":-56.51,"lat":-33.41},{"n":"International Falls","r":4,"cap":0,"mega":0,"pop":15240,"lon":-93.411,"lat":48.601},{"n":"St. Paul","r":4,"cap":0,"mega":0,"pop":734854,"lon":-93.085,"lat":44.944},{"n":"Billings","r":4,"cap":0,"mega":0,"pop":104552,"lon":-108.54,"lat":45.788},{"n":"Great Falls","r":4,"cap":0,"mega":0,"pop":66558,"lon":-111.3,"lat":47.5},{"n":"Missoula","r":4,"cap":0,"mega":0,"pop":72856,"lon":-113.993,"lat":46.872},{"n":"Minot","r":4,"cap":0,"mega":0,"pop":39439,"lon":-101.296,"lat":48.232},{"n":"Fargo","r":4,"cap":0,"mega":0,"pop":162842,"lon":-96.789,"lat":46.877},{"n":"Hilo","r":4,"cap":0,"mega":0,"pop":52391,"lon":-155.082,"lat":19.706},{"n":"Olympia","r":4,"cap":0,"mega":0,"pop":156984,"lon":-122.899,"lat":47.038},{"n":"Spokane","r":4,"cap":0,"mega":0,"pop":347705,"lon":-117.42,"lat":47.67},{"n":"Vancouver","r":4,"cap":0,"mega":0,"pop":525802,"lon":-122.64,"lat":45.63},{"n":"Flagstaff","r":4,"cap":0,"mega":0,"pop":63993,"lon":-111.651,"lat":35.198},{"n":"Tucson","r":4,"cap":0,"mega":1,"pop":823000,"lon":-110.892,"lat":32.207},{"n":"Santa Barbara","r":4,"cap":0,"mega":0,"pop":181632,"lon":-119.717,"lat":34.411},{"n":"Fresno","r":4,"cap":0,"mega":0,"pop":616353,"lon":-119.773,"lat":36.748},{"n":"Eureka","r":4,"cap":0,"mega":0,"pop":42398,"lon":-124.15,"lat":40.793},{"n":"Colorado Springs","r":4,"cap":0,"mega":0,"pop":493654,"lon":-104.792,"lat":38.863},{"n":"Reno","r":4,"cap":0,"mega":0,"pop":328585,"lon":-119.82,"lat":39.53},{"n":"Elko","r":4,"cap":0,"mega":0,"pop":19252,"lon":-115.762,"lat":40.833},{"n":"Albuquerque","r":4,"cap":0,"mega":0,"pop":898642,"lon":-106.641,"lat":35.105},{"n":"Salem","r":4,"cap":0,"mega":0,"pop":229010,"lon":-123.024,"lat":44.928},{"n":"Casper","r":4,"cap":0,"mega":0,"pop":60791,"lon":-106.323,"lat":42.847},{"n":"Topeka","r":4,"cap":0,"mega":0,"pop":132091,"lon":-95.67,"lat":39.05},{"n":"Kansas City","r":4,"cap":0,"mega":1,"pop":1469000,"lon":-94.606,"lat":39.109},{"n":"Tulsa","r":4,"cap":0,"mega":0,"pop":946962,"lon":-95.93,"lat":36.12},{"n":"Sioux Falls","r":4,"cap":0,"mega":0,"pop":155724,"lon":-96.73,"lat":43.55},{"n":"Shreveport","r":4,"cap":0,"mega":0,"pop":248053,"lon":-93.77,"lat":32.5},{"n":"Baton Rouge","r":4,"cap":0,"mega":0,"pop":422072,"lon":-91.14,"lat":30.458},{"n":"Ft. Worth","r":4,"cap":0,"mega":0,"pop":1440454,"lon":-97.34,"lat":32.74},{"n":"Corpus Christi","r":4,"cap":0,"mega":0,"pop":277454,"lon":-97.402,"lat":27.743},{"n":"Austin","r":4,"cap":0,"mega":1,"pop":1161000,"lon":-97.745,"lat":30.269},{"n":"Amarillo","r":4,"cap":0,"mega":0,"pop":181766,"lon":-101.83,"lat":35.23},{"n":"El Paso","r":4,"cap":0,"mega":1,"pop":753000,"lon":-106.512,"lat":31.782},{"n":"Laredo","r":4,"cap":0,"mega":0,"pop":434768,"lon":-99.507,"lat":27.506},{"n":"Merida","r":4,"cap":0,"mega":0,"pop":345489,"lon":-71.183,"lat":8.57},{"n":"Burlington","r":4,"cap":0,"mega":0,"pop":93807,"lon":-73.212,"lat":44.476},{"n":"Montgomery","r":4,"cap":0,"mega":0,"pop":198325,"lon":-86.279,"lat":32.362},{"n":"Tallahassee","r":4,"cap":0,"mega":0,"pop":221222,"lon":-84.28,"lat":30.45},{"n":"Orlando","r":4,"cap":0,"mega":1,"pop":1350000,"lon":-81.382,"lat":28.512},{"n":"Jacksonville","r":4,"cap":0,"mega":1,"pop":988000,"lon":-81.672,"lat":30.332},{"n":"Savannah","r":4,"cap":0,"mega":0,"pop":180187,"lon":-81.11,"lat":32.021},{"n":"Columbia","r":4,"cap":0,"mega":0,"pop":398093,"lon":-81.031,"lat":33.997},{"n":"Indianapolis","r":4,"cap":0,"mega":1,"pop":1436000,"lon":-86.172,"lat":39.752},{"n":"Wilmington","r":4,"cap":0,"mega":0,"pop":161560,"lon":-77.945,"lat":34.226},{"n":"Knoxville","r":4,"cap":0,"mega":0,"pop":655400,"lon":-83.92,"lat":35.97},{"n":"Richmond","r":4,"cap":0,"mega":1,"pop":912000,"lon":-77.452,"lat":37.552},{"n":"Charleston","r":4,"cap":0,"mega":0,"pop":123799,"lon":-81.633,"lat":38.35},{"n":"Baltimore","r":4,"cap":0,"mega":1,"pop":2255000,"lon":-76.615,"lat":39.282},{"n":"Syracuse","r":4,"cap":0,"mega":0,"pop":662577,"lon":-76.15,"lat":43.05},{"n":"Puerto Ayacucho","r":4,"cap":0,"mega":0,"pop":52526,"lon":-67.624,"lat":5.664},{"n":"Port-of-Spain","r":4,"cap":1,"mega":0,"pop":294934,"lon":-61.517,"lat":10.652},{"n":"Augusta","r":4,"cap":0,"mega":0,"pop":24042,"lon":-69.78,"lat":44.311},{"n":"Sault Ste. Marie","r":4,"cap":0,"mega":0,"pop":83805,"lon":-84.345,"lat":46.495},{"n":"Atakpame","r":4,"cap":0,"mega":0,"pop":80683,"lon":1.12,"lat":7.53},{"n":"Sousse","r":4,"cap":0,"mega":0,"pop":327004,"lon":10.625,"lat":35.83},{"n":"Taizz","r":4,"cap":0,"mega":1,"pop":751000,"lon":44.037,"lat":13.606},{"n":"Sitka","r":4,"cap":0,"mega":0,"pop":8931,"lon":-135.328,"lat":57.06},{"n":"Lvov","r":4,"cap":0,"mega":0,"pop":803880,"lon":24.03,"lat":49.835},{"n":"Odessa","r":4,"cap":0,"mega":1,"pop":991000,"lon":30.708,"lat":46.492},{"n":"Zhytomyr","r":4,"cap":0,"mega":0,"pop":282192,"lon":28.662,"lat":50.246},{"n":"Dnipro","r":4,"cap":0,"mega":1,"pop":1050000,"lon":34.998,"lat":48.482},{"n":"Donetsk","r":4,"cap":0,"mega":1,"pop":988000,"lon":37.828,"lat":48.002},{"n":"Kharkiv","r":4,"cap":0,"mega":1,"pop":1461000,"lon":36.248,"lat":50.002},{"n":"Turkmenbasy","r":4,"cap":0,"mega":0,"pop":68292,"lon":52.97,"lat":40.023},{"n":"Bukhara","r":4,"cap":0,"mega":0,"pop":319476,"lon":64.43,"lat":39.78},{"n":"Nukus","r":4,"cap":0,"mega":0,"pop":230006,"lon":59.615,"lat":42.47},{"n":"Turkmenabat","r":4,"cap":0,"mega":0,"pop":234817,"lon":63.58,"lat":39.11},{"n":"Mary","r":4,"cap":0,"mega":0,"pop":178708,"lon":61.833,"lat":37.6},{"n":"Andijon","r":4,"cap":0,"mega":0,"pop":650000,"lon":72.34,"lat":40.79},{"n":"Haiphong","r":4,"cap":0,"mega":1,"pop":1969000,"lon":106.678,"lat":20.832},{"n":"Da Nang","r":4,"cap":0,"mega":0,"pop":1000000,"lon":108.25,"lat":16.06},{"n":"Kabwe","r":4,"cap":0,"mega":0,"pop":188979,"lon":28.45,"lat":-14.44},{"n":"Mufulira","r":4,"cap":0,"mega":0,"pop":153624,"lon":28.26,"lat":-12.55},{"n":"Kitwe","r":4,"cap":0,"mega":0,"pop":404901,"lon":28.22,"lat":-12.81},{"n":"Livingstone","r":4,"cap":0,"mega":0,"pop":165480,"lon":25.86,"lat":-17.86},{"n":"Chitungwiza","r":4,"cap":0,"mega":0,"pop":340360,"lon":31.1,"lat":-18.0},{"n":"Douala","r":4,"cap":0,"mega":1,"pop":1906000,"lon":9.708,"lat":4.062},{"n":"Birmingham","r":4,"cap":0,"mega":1,"pop":2285000,"lon":-1.922,"lat":52.477},{"n":"Belfast","r":4,"cap":0,"mega":0,"pop":450406,"lon":-5.928,"lat":54.594},{"n":"Izmir","r":4,"cap":0,"mega":1,"pop":2587000,"lon":27.15,"lat":38.438},{"n":"Bursa","r":4,"cap":0,"mega":1,"pop":1492000,"lon":29.068,"lat":40.202},{"n":"Samsun","r":4,"cap":0,"mega":0,"pop":609339,"lon":36.344,"lat":41.28},{"n":"Konya","r":4,"cap":0,"mega":1,"pop":919000,"lon":32.473,"lat":37.877},{"n":"Adana","r":4,"cap":0,"mega":1,"pop":1293000,"lon":35.318,"lat":36.997},{"n":"Gulu","r":4,"cap":0,"mega":0,"pop":146858,"lon":32.28,"lat":2.78},{"n":"Kigali","r":4,"cap":1,"mega":1,"pop":860000,"lon":30.059,"lat":-1.952},{"n":"Cottica","r":4,"cap":0,"mega":0,"pop":29210,"lon":-54.233,"lat":3.85},{"n":"Cordoba","r":4,"cap":0,"mega":0,"pop":321376,"lon":-4.77,"lat":37.88},{"n":"Maradi","r":4,"cap":0,"mega":0,"pop":232555,"lon":7.096,"lat":13.492},{"n":"Tahoua","r":4,"cap":0,"mega":0,"pop":115956,"lon":5.26,"lat":14.9},{"n":"Constanta","r":4,"cap":0,"mega":0,"pop":303399,"lon":28.61,"lat":44.203},{"n":"Lulea","r":4,"cap":0,"mega":0,"pop":48638,"lon":22.158,"lat":65.597},{"n":"Sundsvall","r":4,"cap":0,"mega":0,"pop":73389,"lon":17.317,"lat":62.4},{"n":"Iasi","r":4,"cap":0,"mega":0,"pop":325914,"lon":27.575,"lat":47.168},{"n":"Surat Thani","r":4,"cap":0,"mega":0,"pop":157627,"lon":99.34,"lat":9.15},{"n":"Chiang Mai","r":4,"cap":0,"mega":0,"pop":397211,"lon":98.98,"lat":18.8},{"n":"Nakhon Ratchasima","r":4,"cap":0,"mega":0,"pop":334984,"lon":102.1,"lat":15.0},{"n":"Mbabane","r":4,"cap":1,"mega":0,"pop":90138,"lon":31.133,"lat":-26.317},{"n":"Piura","r":4,"cap":0,"mega":0,"pop":396932,"lon":-80.63,"lat":-5.21},{"n":"Arequipa","r":4,"cap":0,"mega":1,"pop":815000,"lon":-71.532,"lat":-16.418},{"n":"Chimbote","r":4,"cap":0,"mega":0,"pop":349846,"lon":-78.57,"lat":-9.07},{"n":"Pucallpa","r":4,"cap":0,"mega":0,"pop":310750,"lon":-74.535,"lat":-8.369},{"n":"Iquitos","r":4,"cap":0,"mega":0,"pop":458729,"lon":-73.25,"lat":-3.75},{"n":"Huancayo","r":4,"cap":0,"mega":0,"pop":412733,"lon":-75.2,"lat":-12.08},{"n":"Ciudad del Este","r":4,"cap":0,"mega":0,"pop":320872,"lon":-54.616,"lat":-25.517},{"n":"Ponta Delgada","r":4,"cap":0,"mega":0,"pop":61526,"lon":-25.667,"lat":37.748},{"n":"Vigo","r":4,"cap":0,"mega":0,"pop":378952,"lon":-8.73,"lat":42.22},{"n":"Bilbao","r":4,"cap":0,"mega":0,"pop":875552,"lon":-2.93,"lat":43.25},{"n":"Kaolack","r":4,"cap":0,"mega":0,"pop":277812,"lon":-16.1,"lat":14.15},{"n":"Kaedi","r":4,"cap":0,"mega":0,"pop":21656,"lon":-13.5,"lat":16.15},{"n":"Geneina","r":4,"cap":0,"mega":0,"pop":162981,"lon":22.44,"lat":13.45},{"n":"Medina","r":4,"cap":0,"mega":1,"pop":1010000,"lon":39.578,"lat":24.502},{"n":"Tabuk","r":4,"cap":0,"mega":0,"pop":547957,"lon":36.555,"lat":28.384},{"n":"Juba","r":4,"cap":0,"mega":0,"pop":111975,"lon":31.58,"lat":4.83},{"n":"Malakal","r":4,"cap":0,"mega":0,"pop":160765,"lon":31.656,"lat":9.537},{"n":"Omdurman","r":4,"cap":0,"mega":0,"pop":2395159,"lon":32.48,"lat":15.617},{"n":"El Obeid","r":4,"cap":0,"mega":0,"pop":393311,"lon":30.217,"lat":13.183},{"n":"The Hague","r":4,"cap":0,"mega":0,"pop":1406000,"lon":4.27,"lat":52.08},{"n":"Kristiansand","r":4,"cap":0,"mega":0,"pop":63814,"lon":7.975,"lat":58.146},{"n":"Ljubljana","r":4,"cap":1,"mega":0,"pop":314807,"lon":14.515,"lat":46.055},{"n":"Bratislava","r":4,"cap":1,"mega":0,"pop":423737,"lon":17.117,"lat":48.15},{"n":"Hammerfest","r":4,"cap":0,"mega":0,"pop":10000,"lon":23.688,"lat":70.661},{"n":"Doha","r":4,"cap":1,"mega":0,"pop":1450000,"lon":51.533,"lat":25.287},{"n":"Quetta","r":4,"cap":0,"mega":1,"pop":768000,"lon":67.023,"lat":30.222},{"n":"Larkana","r":4,"cap":0,"mega":0,"pop":364033,"lon":68.207,"lat":27.562},{"n":"Springbok","r":4,"cap":0,"mega":0,"pop":10438,"lon":17.883,"lat":-29.667},{"n":"Upington","r":4,"cap":0,"mega":0,"pop":71373,"lon":21.23,"lat":-28.46},{"n":"Worcester","r":4,"cap":0,"mega":0,"pop":127597,"lon":19.44,"lat":-33.64},{"n":"George","r":4,"cap":0,"mega":0,"pop":174582,"lon":22.45,"lat":-33.95},{"n":"Tete","r":4,"cap":0,"mega":0,"pop":129316,"lon":33.58,"lat":-16.17},{"n":"Pemba","r":4,"cap":0,"mega":0,"pop":110643,"lon":40.532,"lat":-12.983},{"n":"Nampula","r":4,"cap":0,"mega":0,"pop":388526,"lon":39.293,"lat":-15.136},{"n":"Welkom","r":4,"cap":0,"mega":0,"pop":431944,"lon":26.73,"lat":-27.97},{"n":"Xai-Xai","r":4,"cap":0,"mega":0,"pop":128805,"lon":33.64,"lat":-25.04},{"n":"Goroka","r":4,"cap":0,"mega":0,"pop":39699,"lon":145.385,"lat":-6.083},{"n":"Mt. Hagen","r":4,"cap":0,"mega":0,"pop":59064,"lon":144.217,"lat":-5.863},{"n":"Rabaul","r":4,"cap":0,"mega":0,"pop":8074,"lon":152.143,"lat":-4.205},{"n":"Lae","r":4,"cap":0,"mega":0,"pop":131052,"lon":146.99,"lat":-6.733},{"n":"David","r":4,"cap":0,"mega":0,"pop":110037,"lon":-82.433,"lat":8.433},{"n":"Oujda","r":4,"cap":0,"mega":0,"pop":409391,"lon":-1.91,"lat":34.69},{"n":"Safi","r":4,"cap":0,"mega":0,"pop":353476,"lon":-9.24,"lat":32.32},{"n":"Podgorica","r":4,"cap":1,"mega":0,"pop":145850,"lon":19.266,"lat":42.466},{"n":"Quelimane","r":4,"cap":0,"mega":0,"pop":188964,"lon":36.89,"lat":-17.88},{"n":"East London","r":4,"cap":0,"mega":0,"pop":338627,"lon":27.87,"lat":-32.97},{"n":"Middelburg","r":4,"cap":0,"mega":0,"pop":18164,"lon":25.01,"lat":-31.5},{"n":"Naltchik","r":4,"cap":0,"mega":0,"pop":307866,"lon":43.618,"lat":43.498},{"n":"Stavropol","r":4,"cap":0,"mega":0,"pop":363064,"lon":41.98,"lat":45.05},{"n":"Ugolnye Kopi","r":4,"cap":0,"mega":0,"pop":3367,"lon":177.7,"lat":64.733},{"n":"Kaliningrad","r":4,"cap":0,"mega":0,"pop":434954,"lon":20.497,"lat":54.7},{"n":"Pskov","r":4,"cap":0,"mega":0,"pop":201990,"lon":28.33,"lat":57.83},{"n":"Bryansk","r":4,"cap":0,"mega":0,"pop":427236,"lon":34.43,"lat":53.26},{"n":"Smolensk","r":4,"cap":0,"mega":0,"pop":320991,"lon":32.047,"lat":54.783},{"n":"Petrozavodsk","r":4,"cap":0,"mega":0,"pop":265025,"lon":34.361,"lat":61.781},{"n":"Tver","r":4,"cap":0,"mega":0,"pop":400212,"lon":35.89,"lat":56.86},{"n":"Vologda","r":4,"cap":0,"mega":0,"pop":294889,"lon":39.92,"lat":59.21},{"n":"Yaroslavl","r":4,"cap":0,"mega":0,"pop":606730,"lon":39.87,"lat":57.62},{"n":"Rostov","r":4,"cap":0,"mega":1,"pop":1052000,"lon":39.711,"lat":47.237},{"n":"Sochi","r":4,"cap":0,"mega":0,"pop":327608,"lon":39.73,"lat":43.59},{"n":"Krasnodar","r":4,"cap":0,"mega":0,"pop":649851,"lon":39.0,"lat":45.02},{"n":"Penza","r":4,"cap":0,"mega":0,"pop":512602,"lon":45.0,"lat":53.18},{"n":"Ryazan","r":4,"cap":0,"mega":0,"pop":520173,"lon":39.72,"lat":54.62},{"n":"Voronezh","r":4,"cap":0,"mega":1,"pop":844000,"lon":39.187,"lat":51.665},{"n":"Magnitogorsk","r":4,"cap":0,"mega":0,"pop":413351,"lon":58.98,"lat":53.423},{"n":"Chelyabinsk","r":4,"cap":0,"mega":1,"pop":1091000,"lon":61.437,"lat":55.157},{"n":"Vorkuta","r":4,"cap":0,"mega":0,"pop":80039,"lon":64.01,"lat":67.5},{"n":"Kirov","r":4,"cap":0,"mega":0,"pop":457437,"lon":49.67,"lat":58.59},{"n":"Nizhny Tagil","r":4,"cap":0,"mega":0,"pop":381116,"lon":59.975,"lat":57.92},{"n":"Astrakhan","r":4,"cap":0,"mega":0,"pop":502533,"lon":48.055,"lat":46.349},{"n":"Orenburg","r":4,"cap":0,"mega":0,"pop":550204,"lon":55.11,"lat":51.78},{"n":"Saratov","r":4,"cap":0,"mega":1,"pop":843000,"lon":46.028,"lat":51.582},{"n":"Ulyanovsk","r":4,"cap":0,"mega":0,"pop":640680,"lon":48.41,"lat":54.33},{"n":"Omsk","r":4,"cap":0,"mega":1,"pop":1135000,"lon":73.398,"lat":54.992},{"n":"Tyumen","r":4,"cap":0,"mega":0,"pop":519119,"lon":65.53,"lat":57.14},{"n":"Novokuznetsk","r":4,"cap":0,"mega":0,"pop":539616,"lon":87.115,"lat":53.75},{"n":"Kemerovo","r":4,"cap":0,"mega":0,"pop":477090,"lon":86.09,"lat":55.34},{"n":"Groznyy","r":4,"cap":0,"mega":0,"pop":226100,"lon":45.699,"lat":43.319},{"n":"Kandy","r":4,"cap":0,"mega":0,"pop":111701,"lon":80.67,"lat":7.28},{"n":"Sri Jawewardenepura Kotte","r":4,"cap":0,"mega":0,"pop":115826,"lon":79.95,"lat":6.9},{"n":"Daejeon","r":4,"cap":0,"mega":1,"pop":1468000,"lon":127.423,"lat":36.337},{"n":"Gwangju","r":4,"cap":0,"mega":1,"pop":1440000,"lon":126.908,"lat":35.173},{"n":"Busan","r":4,"cap":0,"mega":1,"pop":3480000,"lon":129.008,"lat":35.097},{"n":"Zamboanga","r":4,"cap":0,"mega":1,"pop":773000,"lon":122.078,"lat":6.922},{"n":"Laoag","r":4,"cap":0,"mega":0,"pop":207048,"lon":120.594,"lat":18.199},{"n":"Baguio City","r":4,"cap":0,"mega":0,"pop":447824,"lon":120.57,"lat":16.43},{"n":"General Santos","r":4,"cap":0,"mega":0,"pop":950530,"lon":125.175,"lat":6.111},{"n":"Ust-Ulimsk","r":4,"cap":0,"mega":0,"pop":100271,"lon":102.633,"lat":57.99},{"n":"Angarsk","r":4,"cap":0,"mega":0,"pop":243158,"lon":103.92,"lat":52.56},{"n":"Abakan","r":4,"cap":0,"mega":0,"pop":167289,"lon":91.445,"lat":53.704},{"n":"Norilsk","r":4,"cap":0,"mega":0,"pop":165873,"lon":88.225,"lat":69.34},{"n":"Khatanga","r":4,"cap":0,"mega":0,"pop":3205,"lon":102.465,"lat":72.041},{"n":"Kyzyl","r":4,"cap":0,"mega":0,"pop":108240,"lon":94.383,"lat":51.707},{"n":"Ulan Ude","r":4,"cap":0,"mega":0,"pop":360278,"lon":107.625,"lat":51.825},{"n":"Blagoveshchensk","r":4,"cap":0,"mega":0,"pop":221296,"lon":127.533,"lat":50.267},{"n":"Bukachacha","r":4,"cap":0,"mega":0,"pop":3372,"lon":116.917,"lat":52.983},{"n":"Dalnegorsk","r":4,"cap":0,"mega":0,"pop":8123,"lon":135.517,"lat":44.537},{"n":"Ambarchik","r":4,"cap":0,"mega":0,"pop":0,"lon":162.334,"lat":69.651},{"n":"Batagay","r":4,"cap":0,"mega":0,"pop":4266,"lon":134.635,"lat":67.656},{"n":"Chokurdakh","r":4,"cap":0,"mega":0,"pop":2506,"lon":147.895,"lat":70.618},{"n":"Ust Nera","r":4,"cap":0,"mega":0,"pop":9148,"lon":143.2,"lat":64.567},{"n":"Lensk","r":4,"cap":0,"mega":0,"pop":25589,"lon":114.947,"lat":60.725},{"n":"Aldan","r":4,"cap":0,"mega":0,"pop":24426,"lon":125.389,"lat":58.603},{"n":"Mirnyy","r":4,"cap":0,"mega":0,"pop":40308,"lon":113.961,"lat":62.54},{"n":"Zhigansk","r":4,"cap":0,"mega":0,"pop":3237,"lon":123.371,"lat":66.77},{"n":"Okhotsk","r":4,"cap":0,"mega":0,"pop":5570,"lon":143.217,"lat":59.383},{"n":"Khabarovsk","r":4,"cap":0,"mega":0,"pop":579000,"lon":135.12,"lat":48.455},{"n":"Okha","r":4,"cap":0,"mega":0,"pop":26560,"lon":142.948,"lat":53.574},{"n":"Yuzhno Sakhalinsk","r":4,"cap":0,"mega":0,"pop":176484,"lon":142.74,"lat":46.965},{"n":"Mexicali","r":4,"cap":0,"mega":1,"pop":885000,"lon":-115.482,"lat":32.652},{"n":"La Paz","r":4,"cap":0,"mega":0,"pop":189767,"lon":-110.32,"lat":24.14},{"n":"Torreon","r":4,"cap":0,"mega":1,"pop":1144000,"lon":-103.422,"lat":25.572},{"n":"Culiacan","r":4,"cap":0,"mega":1,"pop":809000,"lon":-107.382,"lat":24.832},{"n":"Nogales","r":4,"cap":0,"mega":0,"pop":178097,"lon":-110.945,"lat":31.305},{"n":"Hermosillo","r":4,"cap":0,"mega":0,"pop":595811,"lon":-110.954,"lat":29.099},{"n":"Guaymas","r":4,"cap":0,"mega":0,"pop":103449,"lon":-110.89,"lat":27.93},{"n":"San Luis Potosi","r":4,"cap":0,"mega":1,"pop":992000,"lon":-101.002,"lat":22.172},{"n":"Matamoros","r":4,"cap":0,"mega":0,"pop":538785,"lon":-97.5,"lat":25.88},{"n":"Nuevo Laredo","r":4,"cap":0,"mega":0,"pop":349550,"lon":-99.55,"lat":27.5},{"n":"Colima","r":4,"cap":0,"mega":0,"pop":223287,"lon":-103.72,"lat":19.23},{"n":"Campeche","r":4,"cap":0,"mega":0,"pop":205212,"lon":-90.5,"lat":19.83},{"n":"Oaxaca","r":4,"cap":0,"mega":0,"pop":530728,"lon":-96.67,"lat":17.083},{"n":"Leon","r":4,"cap":0,"mega":1,"pop":1488000,"lon":-101.702,"lat":21.152},{"n":"Maiduguri","r":4,"cap":0,"mega":1,"pop":896000,"lon":13.158,"lat":11.852},{"n":"Port Harcourt","r":4,"cap":0,"mega":1,"pop":1020000,"lon":7.008,"lat":4.812},{"n":"Makurdi","r":4,"cap":0,"mega":0,"pop":292645,"lon":8.53,"lat":7.73},{"n":"Ibadan","r":4,"cap":0,"mega":1,"pop":2628000,"lon":3.928,"lat":7.382},{"n":"Ogbomosho","r":4,"cap":0,"mega":1,"pop":951000,"lon":4.238,"lat":8.132},{"n":"Warri","r":4,"cap":0,"mega":0,"pop":830106,"lon":5.76,"lat":5.52},{"n":"Kaduna","r":4,"cap":0,"mega":1,"pop":1442000,"lon":7.438,"lat":10.522},{"n":"Gdansk","r":4,"cap":0,"mega":0,"pop":740000,"lon":18.64,"lat":54.36},{"n":"Krakow","r":4,"cap":0,"mega":1,"pop":756000,"lon":19.958,"lat":50.062},{"n":"Dalandzadgad","r":4,"cap":0,"mega":0,"pop":15093,"lon":104.44,"lat":43.584},{"n":"Wonsan","r":4,"cap":0,"mega":0,"pop":329207,"lon":127.431,"lat":39.16},{"n":"Sinuiju","r":4,"cap":0,"mega":0,"pop":288112,"lon":124.421,"lat":40.086},{"n":"Dund-Us","r":4,"cap":0,"mega":0,"pop":30500,"lon":91.633,"lat":48.017},{"n":"Choybalsan","r":4,"cap":0,"mega":0,"pop":33376,"lon":114.506,"lat":48.067},{"n":"Luderitz","r":4,"cap":0,"mega":0,"pop":15137,"lon":15.159,"lat":-26.648},{"n":"Walvis Bay","r":4,"cap":0,"mega":0,"pop":52058,"lon":14.505,"lat":-22.958},{"n":"Mwanza","r":4,"cap":0,"mega":0,"pop":493944,"lon":32.93,"lat":-2.52},{"n":"Morogoro","r":4,"cap":0,"mega":0,"pop":250902,"lon":37.66,"lat":-6.82},{"n":"Dodoma","r":4,"cap":0,"mega":0,"pop":218269,"lon":35.75,"lat":-6.183},{"n":"Arusha","r":4,"cap":0,"mega":0,"pop":341136,"lon":36.67,"lat":-3.36},{"n":"Bern","r":4,"cap":1,"mega":0,"pop":275329,"lon":7.467,"lat":46.917},{"n":"Malmo","r":4,"cap":0,"mega":0,"pop":269349,"lon":13.023,"lat":55.599},{"n":"Laayoune","r":4,"cap":0,"mega":0,"pop":188084,"lon":-13.2,"lat":27.15},{"n":"Ternate","r":4,"cap":0,"mega":0,"pop":187521,"lon":127.363,"lat":0.793},{"n":"Ambon","r":4,"cap":0,"mega":0,"pop":355596,"lon":128.2,"lat":-3.717},{"n":"Raba","r":4,"cap":0,"mega":0,"pop":106101,"lon":118.767,"lat":-8.45},{"n":"Jayapura","r":4,"cap":0,"mega":0,"pop":169341,"lon":140.7,"lat":-2.533},{"n":"Florence","r":4,"cap":0,"mega":0,"pop":1500000,"lon":11.25,"lat":43.78},{"n":"Catania","r":4,"cap":0,"mega":0,"pop":674542,"lon":15.08,"lat":37.5},{"n":"Pristina","r":4,"cap":1,"mega":0,"pop":465186,"lon":21.166,"lat":42.667},{"n":"Meru","r":4,"cap":0,"mega":0,"pop":47226,"lon":37.64,"lat":0.06},{"n":"Eldoret","r":4,"cap":0,"mega":0,"pop":353381,"lon":35.27,"lat":0.52},{"n":"Banda Aceh","r":4,"cap":0,"mega":0,"pop":513698,"lon":95.32,"lat":5.55},{"n":"George Town","r":4,"cap":0,"mega":0,"pop":2500000,"lon":100.329,"lat":5.414},{"n":"Zhangye","r":4,"cap":0,"mega":0,"pop":230728,"lon":100.45,"lat":38.93},{"n":"Wuwei","r":4,"cap":0,"mega":0,"pop":493092,"lon":102.641,"lat":37.928},{"n":"Dunhuang","r":4,"cap":0,"mega":0,"pop":140094,"lon":94.662,"lat":40.143},{"n":"Tianshui","r":4,"cap":0,"mega":1,"pop":1225000,"lon":105.918,"lat":34.602},{"n":"Dulan","r":4,"cap":0,"mega":0,"pop":100,"lon":98.267,"lat":36.167},{"n":"Golmud","r":4,"cap":0,"mega":0,"pop":107092,"lon":94.883,"lat":36.417},{"n":"Yulin","r":4,"cap":0,"mega":1,"pop":1127000,"lon":110.148,"lat":22.632},{"n":"Bose","r":4,"cap":0,"mega":0,"pop":175282,"lon":106.613,"lat":23.9},{"n":"Wuzhou","r":4,"cap":0,"mega":0,"pop":442315,"lon":111.32,"lat":23.48},{"n":"Liupanshui","r":4,"cap":0,"mega":0,"pop":1221000,"lon":104.831,"lat":26.596},{"n":"Quanzhou","r":4,"cap":0,"mega":1,"pop":1463000,"lon":118.578,"lat":24.902},{"n":"Hefei","r":4,"cap":0,"mega":1,"pop":2035000,"lon":117.278,"lat":31.852},{"n":"Suzhou","r":4,"cap":0,"mega":1,"pop":1964000,"lon":116.977,"lat":33.638},{"n":"Zhanjiang","r":4,"cap":0,"mega":1,"pop":1590000,"lon":110.378,"lat":21.202},{"n":"Shaoguan","r":4,"cap":0,"mega":0,"pop":720266,"lon":113.58,"lat":24.8},{"n":"Balikpapan","r":4,"cap":0,"mega":0,"pop":445905,"lon":116.83,"lat":-1.25},{"n":"Kuching","r":4,"cap":0,"mega":0,"pop":570407,"lon":110.33,"lat":1.53},{"n":"Antsiranana","r":4,"cap":0,"mega":0,"pop":82937,"lon":49.312,"lat":-12.277},{"n":"Fianarantsoa","r":4,"cap":0,"mega":0,"pop":184184,"lon":47.083,"lat":-21.433},{"n":"Mahajanga","r":4,"cap":0,"mega":0,"pop":154657,"lon":46.345,"lat":-15.67},{"n":"Toliara","r":4,"cap":0,"mega":0,"pop":115319,"lon":43.69,"lat":-23.357},{"n":"Surakarta","r":4,"cap":0,"mega":0,"pop":555308,"lon":110.825,"lat":-7.565},{"n":"Bandar Lampung","r":4,"cap":0,"mega":1,"pop":865000,"lon":105.268,"lat":-5.428},{"n":"Tanjungpandan","r":4,"cap":0,"mega":0,"pop":62374,"lon":107.65,"lat":-2.75},{"n":"Malang","r":4,"cap":0,"mega":1,"pop":805000,"lon":112.608,"lat":-7.978},{"n":"Kupang","r":4,"cap":0,"mega":0,"pop":282396,"lon":123.583,"lat":-10.179},{"n":"Parepare","r":4,"cap":0,"mega":0,"pop":87776,"lon":119.633,"lat":-4.017},{"n":"Cuenca","r":4,"cap":0,"mega":0,"pop":286878,"lon":-79.0,"lat":-2.9},{"n":"Santa Cruz","r":4,"cap":0,"mega":0,"pop":11262,"lon":-90.35,"lat":-0.533},{"n":"Puerto Limon","r":4,"cap":0,"mega":0,"pop":85001,"lon":-83.033,"lat":10.0},{"n":"Santiago de Cuba","r":4,"cap":0,"mega":0,"pop":555865,"lon":-75.821,"lat":20.025},{"n":"Santiago","r":4,"cap":0,"mega":0,"pop":1550753,"lon":-70.67,"lat":19.5},{"n":"Manizales","r":4,"cap":0,"mega":0,"pop":375848,"lon":-75.52,"lat":5.06},{"n":"Pasto","r":4,"cap":0,"mega":0,"pop":382236,"lon":-77.281,"lat":1.214},{"n":"Barranquilla","r":4,"cap":0,"mega":1,"pop":1798000,"lon":-74.802,"lat":10.962},{"n":"Roseau","r":4,"cap":1,"mega":0,"pop":23336,"lon":-61.387,"lat":15.301},{"n":"Mbandaka","r":4,"cap":0,"mega":0,"pop":274996,"lon":18.26,"lat":0.04},{"n":"Moundou","r":4,"cap":0,"mega":0,"pop":156705,"lon":16.09,"lat":8.55},{"n":"Suez","r":4,"cap":0,"mega":0,"pop":508335,"lon":32.55,"lat":30.005},{"n":"Bur Said","r":4,"cap":0,"mega":0,"pop":623864,"lon":32.29,"lat":31.26},{"n":"El Faiyum","r":4,"cap":0,"mega":0,"pop":316772,"lon":30.84,"lat":29.31},{"n":"Aswan","r":4,"cap":0,"mega":0,"pop":313442,"lon":32.899,"lat":24.088},{"n":"Asyut","r":4,"cap":0,"mega":0,"pop":420585,"lon":31.18,"lat":27.19},{"n":"Kisangani","r":4,"cap":0,"mega":0,"pop":578470,"lon":25.22,"lat":0.52},{"n":"Assab","r":4,"cap":0,"mega":0,"pop":105496,"lon":42.73,"lat":13.01},{"n":"Djibouti","r":4,"cap":1,"mega":0,"pop":923000,"lon":43.148,"lat":11.595},{"n":"Dresden","r":4,"cap":0,"mega":0,"pop":617515,"lon":13.75,"lat":51.05},{"n":"Xigaze","r":4,"cap":0,"mega":0,"pop":80000,"lon":88.883,"lat":29.25},{"n":"Shache","r":4,"cap":0,"mega":0,"pop":851374,"lon":77.25,"lat":38.426},{"n":"Yining","r":4,"cap":0,"mega":0,"pop":542507,"lon":81.35,"lat":43.9},{"n":"Altay","r":4,"cap":0,"mega":0,"pop":142000,"lon":88.117,"lat":47.867},{"n":"Putrajaya","r":4,"cap":0,"mega":0,"pop":67964,"lon":101.695,"lat":2.933},{"n":"Shizuishan","r":4,"cap":0,"mega":0,"pop":136570,"lon":106.769,"lat":39.233},{"n":"Yulin","r":4,"cap":0,"mega":0,"pop":155960,"lon":109.733,"lat":38.283},{"n":"Ankang","r":4,"cap":0,"mega":0,"pop":1100000,"lon":109.02,"lat":32.68},{"n":"Houma","r":4,"cap":0,"mega":0,"pop":102400,"lon":111.21,"lat":35.62},{"n":"Yueyang","r":4,"cap":0,"mega":1,"pop":826000,"lon":113.098,"lat":29.382},{"n":"Hengyang","r":4,"cap":0,"mega":1,"pop":1016000,"lon":112.588,"lat":26.882},{"n":"Mianyang","r":4,"cap":0,"mega":1,"pop":1396000,"lon":104.69,"lat":31.465},{"n":"Xichang","r":4,"cap":0,"mega":0,"pop":379993,"lon":102.3,"lat":27.88},{"n":"Baoshan","r":4,"cap":0,"mega":0,"pop":1000000,"lon":99.15,"lat":25.12},{"n":"Gejiu","r":4,"cap":0,"mega":0,"pop":149105,"lon":103.15,"lat":23.38},{"n":"Shijiazhuang","r":4,"cap":0,"mega":1,"pop":2417000,"lon":114.478,"lat":38.052},{"n":"Handan","r":4,"cap":0,"mega":1,"pop":1631000,"lon":114.478,"lat":36.582},{"n":"Anshan","r":4,"cap":0,"mega":1,"pop":1639000,"lon":122.938,"lat":41.117},{"n":"Dalian","r":4,"cap":0,"mega":1,"pop":3167000,"lon":121.628,"lat":38.925},{"n":"Qingdao","r":4,"cap":0,"mega":1,"pop":2866000,"lon":120.328,"lat":36.092},{"n":"Linyi","r":4,"cap":0,"mega":1,"pop":2082000,"lon":118.328,"lat":35.082},{"n":"Huaiyin","r":4,"cap":0,"mega":1,"pop":1264000,"lon":119.066,"lat":33.585},{"n":"Wenzhou","r":4,"cap":0,"mega":1,"pop":2350000,"lon":120.648,"lat":28.022},{"n":"Ningbo","r":4,"cap":0,"mega":1,"pop":1923000,"lon":121.548,"lat":29.882},{"n":"Fukuoka","r":4,"cap":0,"mega":1,"pop":2792000,"lon":130.408,"lat":33.597},{"n":"Miyazaki","r":4,"cap":0,"mega":0,"pop":324384,"lon":131.418,"lat":31.918},{"n":"Naha","r":4,"cap":0,"mega":0,"pop":905238,"lon":127.673,"lat":26.207},{"n":"Kochi","r":4,"cap":0,"mega":0,"pop":335570,"lon":133.538,"lat":33.562},{"n":"Gorontalo","r":4,"cap":0,"mega":0,"pop":365497,"lon":123.07,"lat":0.55},{"n":"Tongliao","r":4,"cap":0,"mega":1,"pop":884000,"lon":122.268,"lat":43.622},{"n":"Hohhot","r":4,"cap":0,"mega":1,"pop":1726000,"lon":111.658,"lat":40.822},{"n":"Chifeng","r":4,"cap":0,"mega":1,"pop":1277000,"lon":118.948,"lat":42.272},{"n":"Ulanhot","r":4,"cap":0,"mega":0,"pop":241894,"lon":122.08,"lat":46.08},{"n":"Hailar","r":4,"cap":0,"mega":0,"pop":231171,"lon":119.7,"lat":49.2},{"n":"Jiamusi","r":4,"cap":0,"mega":1,"pop":1020000,"lon":130.348,"lat":46.832},{"n":"Beian","r":4,"cap":0,"mega":0,"pop":154936,"lon":126.529,"lat":48.246},{"n":"Daqing","r":4,"cap":0,"mega":1,"pop":1693000,"lon":124.998,"lat":46.582},{"n":"Jixi","r":4,"cap":0,"mega":1,"pop":965000,"lon":130.968,"lat":45.302},{"n":"Nagoya","r":4,"cap":0,"mega":1,"pop":3230000,"lon":136.913,"lat":35.157},{"n":"Nagano","r":4,"cap":0,"mega":0,"pop":594311,"lon":138.17,"lat":36.65},{"n":"Kushiro","r":4,"cap":0,"mega":0,"pop":198566,"lon":144.375,"lat":42.975},{"n":"Hakodate","r":4,"cap":0,"mega":0,"pop":302984,"lon":140.74,"lat":41.795},{"n":"Kyoto","r":4,"cap":0,"mega":1,"pop":1805000,"lon":135.748,"lat":35.032},{"n":"Sendai","r":4,"cap":0,"mega":1,"pop":2250000,"lon":140.87,"lat":38.268},{"n":"Sakata","r":4,"cap":0,"mega":0,"pop":100446,"lon":139.85,"lat":38.92},{"n":"Bandundu","r":4,"cap":0,"mega":0,"pop":118211,"lon":17.38,"lat":-3.31},{"n":"Kananga","r":4,"cap":0,"mega":1,"pop":765000,"lon":22.398,"lat":-5.888},{"n":"Kasongo","r":4,"cap":0,"mega":0,"pop":63000,"lon":26.66,"lat":-4.45},{"n":"Mbuji-Mayi","r":4,"cap":0,"mega":1,"pop":1295000,"lon":23.598,"lat":-6.148},{"n":"Kalemie","r":4,"cap":0,"mega":0,"pop":206257,"lon":29.2,"lat":-5.933},{"n":"Butembo","r":4,"cap":0,"mega":0,"pop":286403,"lon":29.28,"lat":0.13},{"n":"Goma","r":4,"cap":0,"mega":0,"pop":144124,"lon":29.222,"lat":-1.679},{"n":"Mzuzu","r":4,"cap":0,"mega":0,"pop":110201,"lon":34.02,"lat":-11.46},{"n":"Blantyre","r":4,"cap":0,"mega":0,"pop":584877,"lon":34.99,"lat":-15.79},{"n":"Quetzaltenango","r":4,"cap":0,"mega":0,"pop":575263,"lon":-91.52,"lat":14.83},{"n":"Banjul","r":4,"cap":1,"mega":0,"pop":43094,"lon":-16.592,"lat":13.454},{"n":"Faridabad","r":4,"cap":0,"mega":1,"pop":1394000,"lon":77.315,"lat":28.435},{"n":"Srinagar","r":4,"cap":0,"mega":1,"pop":1140000,"lon":74.828,"lat":34.069},{"n":"Vijayawada","r":4,"cap":0,"mega":1,"pop":1137000,"lon":80.628,"lat":16.522},{"n":"Thiruvananthapuram","r":4,"cap":0,"mega":1,"pop":954000,"lon":76.925,"lat":8.516},{"n":"Kochi","r":4,"cap":0,"mega":1,"pop":1519000,"lon":76.222,"lat":10.017},{"n":"Cuttack","r":4,"cap":0,"mega":0,"pop":580000,"lon":85.89,"lat":20.47},{"n":"Hubballi","r":4,"cap":0,"mega":1,"pop":890000,"lon":75.123,"lat":15.362},{"n":"Mangaluru","r":4,"cap":0,"mega":0,"pop":776632,"lon":74.85,"lat":12.9},{"n":"Mysuru","r":4,"cap":0,"mega":1,"pop":887000,"lon":76.658,"lat":12.312},{"n":"Kalaburagi","r":4,"cap":0,"mega":0,"pop":483615,"lon":76.82,"lat":17.35},{"n":"Kolhapur","r":4,"cap":0,"mega":0,"pop":750000,"lon":74.22,"lat":16.7},{"n":"Nanded","r":4,"cap":0,"mega":0,"pop":623708,"lon":77.308,"lat":19.197},{"n":"Akola","r":4,"cap":0,"mega":0,"pop":503502,"lon":77.01,"lat":20.71},{"n":"Guwahati","r":4,"cap":0,"mega":1,"pop":983000,"lon":91.768,"lat":26.162},{"n":"Kayes","r":4,"cap":0,"mega":0,"pop":62521,"lon":13.28,"lat":-4.18},{"n":"Franceville","r":4,"cap":0,"mega":0,"pop":42967,"lon":13.583,"lat":-1.633},{"n":"Bordeaux","r":4,"cap":0,"mega":1,"pop":803000,"lon":-0.597,"lat":44.852},{"n":"Marseille","r":4,"cap":0,"mega":1,"pop":1400000,"lon":5.373,"lat":43.292},{"n":"Le Havre","r":4,"cap":0,"mega":0,"pop":242124,"lon":0.105,"lat":49.505},{"n":"Gao","r":4,"cap":0,"mega":0,"pop":116967,"lon":-0.05,"lat":16.267},{"n":"Coihaique","r":4,"cap":0,"mega":0,"pop":45787,"lon":-72.07,"lat":-45.57},{"n":"Arica","r":4,"cap":0,"mega":0,"pop":185999,"lon":-70.29,"lat":-18.5},{"n":"Copiapo","r":4,"cap":0,"mega":0,"pop":129280,"lon":-70.33,"lat":-27.372},{"n":"La Serena","r":4,"cap":0,"mega":0,"pop":154521,"lon":-71.25,"lat":-29.9},{"n":"Los Angeles","r":4,"cap":0,"mega":0,"pop":145239,"lon":-72.347,"lat":-37.48},{"n":"Narsarsuaq","r":4,"cap":0,"mega":0,"pop":145,"lon":-45.417,"lat":61.167},{"n":"Sisimiut","r":4,"cap":0,"mega":0,"pop":5227,"lon":-53.667,"lat":66.95},{"n":"Upernavik","r":4,"cap":0,"mega":0,"pop":1129,"lon":-56.142,"lat":72.709},{"n":"Qaanaaq","r":4,"cap":0,"mega":0,"pop":616,"lon":-69.23,"lat":77.467},{"n":"Nouadhibou","r":4,"cap":0,"mega":0,"pop":86738,"lon":-17.056,"lat":20.9},{"n":"Kayes","r":4,"cap":0,"mega":0,"pop":77207,"lon":-11.44,"lat":14.45},{"n":"Ayoun el Atrous","r":4,"cap":0,"mega":0,"pop":1423,"lon":-9.617,"lat":16.667},{"n":"Segou","r":4,"cap":0,"mega":0,"pop":122952,"lon":-6.26,"lat":13.44},{"n":"Skopje","r":4,"cap":1,"mega":0,"pop":494087,"lon":21.433,"lat":42.0},{"n":"Al Jawf","r":4,"cap":0,"mega":0,"pop":24132,"lon":23.29,"lat":24.2},{"n":"Tmassah","r":4,"cap":0,"mega":0,"pop":500,"lon":15.8,"lat":26.367},{"n":"Misratah","r":4,"cap":0,"mega":0,"pop":386120,"lon":15.1,"lat":32.38},{"n":"Zuwarah","r":4,"cap":0,"mega":0,"pop":180310,"lon":12.079,"lat":32.934},{"n":"Kirkuk","r":4,"cap":0,"mega":0,"pop":601433,"lon":44.392,"lat":35.472},{"n":"Mosul","r":4,"cap":0,"mega":1,"pop":1316000,"lon":43.143,"lat":36.347},{"n":"An Najaf","r":4,"cap":0,"mega":0,"pop":665552,"lon":44.335,"lat":32.0},{"n":"Bahir Dar","r":4,"cap":0,"mega":0,"pop":206748,"lon":37.383,"lat":11.6},{"n":"Mekele","r":4,"cap":0,"mega":0,"pop":95856,"lon":39.47,"lat":13.5},{"n":"Dire Dawa","r":4,"cap":0,"mega":0,"pop":252279,"lon":41.86,"lat":9.59},{"n":"Rovaniemi","r":4,"cap":0,"mega":0,"pop":34781,"lon":25.716,"lat":66.5},{"n":"Vaasa","r":4,"cap":0,"mega":0,"pop":57014,"lon":21.6,"lat":63.1},{"n":"Tampere","r":4,"cap":0,"mega":0,"pop":259279,"lon":23.75,"lat":61.5},{"n":"Aqtobe","r":4,"cap":0,"mega":0,"pop":262457,"lon":57.17,"lat":50.28},{"n":"Rudny","r":4,"cap":0,"mega":0,"pop":124000,"lon":63.13,"lat":52.953},{"n":"Qyzylorda","r":4,"cap":0,"mega":0,"pop":300000,"lon":65.465,"lat":44.8},{"n":"Atyrau","r":4,"cap":0,"mega":0,"pop":182753,"lon":51.92,"lat":47.113},{"n":"Ekibastuz","r":4,"cap":0,"mega":0,"pop":127868,"lon":75.32,"lat":51.73},{"n":"Pavlodar","r":4,"cap":0,"mega":0,"pop":329002,"lon":76.95,"lat":52.3},{"n":"Semey","r":4,"cap":0,"mega":0,"pop":311353,"lon":80.275,"lat":50.435},{"n":"Oskemen","r":4,"cap":0,"mega":0,"pop":319067,"lon":82.615,"lat":49.99},{"n":"Yazd","r":4,"cap":0,"mega":0,"pop":477905,"lon":54.37,"lat":31.92},{"n":"Ahvaz","r":4,"cap":0,"mega":1,"pop":996000,"lon":48.718,"lat":31.282},{"n":"Basra","r":4,"cap":0,"mega":1,"pop":870000,"lon":47.812,"lat":30.515},{"n":"Bandar-e-Abbas","r":4,"cap":0,"mega":0,"pop":461499,"lon":56.272,"lat":27.204},{"n":"Hamadan","r":4,"cap":0,"mega":0,"pop":528256,"lon":48.515,"lat":34.796},{"n":"Tabriz","r":4,"cap":0,"mega":1,"pop":1413000,"lon":46.299,"lat":38.088},{"n":"Ludhiana","r":4,"cap":0,"mega":1,"pop":1649000,"lon":75.87,"lat":30.93},{"n":"Kota","r":4,"cap":0,"mega":1,"pop":827000,"lon":75.833,"lat":25.182},{"n":"Jodhpur","r":4,"cap":0,"mega":1,"pop":995000,"lon":73.015,"lat":26.294},{"n":"Shymkent","r":4,"cap":0,"mega":0,"pop":465392,"lon":69.595,"lat":42.32},{"n":"Taraz","r":4,"cap":0,"mega":0,"pop":358153,"lon":71.365,"lat":42.9},{"n":"Lucknow","r":4,"cap":0,"mega":1,"pop":2695000,"lon":80.913,"lat":26.857},{"n":"Saharanpur","r":4,"cap":0,"mega":0,"pop":484873,"lon":77.55,"lat":29.97},{"n":"Ranchi","r":4,"cap":0,"mega":1,"pop":1044000,"lon":85.328,"lat":23.372},{"n":"Bhagalpur","r":4,"cap":0,"mega":0,"pop":361548,"lon":86.98,"lat":25.23},{"n":"Raipur","r":4,"cap":0,"mega":1,"pop":875000,"lon":81.633,"lat":21.237},{"n":"Jabalpur","r":4,"cap":0,"mega":1,"pop":1285000,"lon":79.953,"lat":23.177},{"n":"Indore","r":4,"cap":0,"mega":1,"pop":2026000,"lon":75.863,"lat":22.717},{"n":"Puducherry","r":4,"cap":0,"mega":0,"pop":227411,"lon":79.83,"lat":11.935},{"n":"Salem","r":4,"cap":0,"mega":1,"pop":873000,"lon":78.178,"lat":11.672},{"n":"Tiruchirappalli","r":4,"cap":0,"mega":1,"pop":951000,"lon":78.688,"lat":10.801},{"n":"Pointe-Noire","r":4,"cap":0,"mega":0,"pop":659084,"lon":11.88,"lat":-4.77},{"n":"Kankan","r":4,"cap":0,"mega":0,"pop":114009,"lon":-9.31,"lat":10.39},{"n":"Nzerekore","r":4,"cap":0,"mega":0,"pop":168121,"lon":-8.83,"lat":7.76},{"n":"Bouake","r":4,"cap":0,"mega":0,"pop":567481,"lon":-5.03,"lat":7.69},{"n":"St.-Denis","r":4,"cap":0,"mega":0,"pop":190047,"lon":55.448,"lat":-20.879},{"n":"Rio Branco","r":4,"cap":0,"mega":0,"pop":257642,"lon":-67.8,"lat":-9.967},{"n":"Sao Luis","r":4,"cap":0,"mega":1,"pop":1038000,"lon":-44.268,"lat":-2.514},{"n":"Porto Velho","r":4,"cap":0,"mega":0,"pop":306180,"lon":-63.9,"lat":-8.75},{"n":"Alvorada","r":4,"cap":0,"mega":0,"pop":10232,"lon":-49.082,"lat":-12.47},{"n":"Corumba","r":4,"cap":0,"mega":0,"pop":96520,"lon":-57.65,"lat":-19.016},{"n":"Belo Horizonte","r":4,"cap":0,"mega":1,"pop":5575000,"lon":-43.917,"lat":-19.913},{"n":"Montes Claros","r":4,"cap":0,"mega":0,"pop":332379,"lon":-43.86,"lat":-16.72},{"n":"Uberlandia","r":4,"cap":0,"mega":0,"pop":563536,"lon":-48.28,"lat":-18.9},{"n":"Colider","r":4,"cap":0,"mega":0,"pop":27139,"lon":-55.451,"lat":-10.817},{"n":"Alta Floresta","r":4,"cap":0,"mega":0,"pop":40466,"lon":-55.91,"lat":-9.9},{"n":"Cuiaba","r":4,"cap":0,"mega":1,"pop":806000,"lon":-56.087,"lat":-15.568},{"n":"Pelotas","r":4,"cap":0,"mega":0,"pop":320674,"lon":-52.33,"lat":-31.75},{"n":"Caxias do Sul","r":4,"cap":0,"mega":0,"pop":381270,"lon":-51.17,"lat":-29.18},{"n":"Ponta Grossa","r":4,"cap":0,"mega":0,"pop":292177,"lon":-50.16,"lat":-25.09},{"n":"Teresina","r":4,"cap":0,"mega":1,"pop":907000,"lon":-42.782,"lat":-5.093},{"n":"Maceio","r":4,"cap":0,"mega":1,"pop":1186000,"lon":-35.732,"lat":-9.618},{"n":"Vitoria da Conquista","r":4,"cap":0,"mega":0,"pop":308204,"lon":-40.84,"lat":-14.85},{"n":"Barreiras","r":4,"cap":0,"mega":0,"pop":158292,"lon":-45.0,"lat":-12.14},{"n":"Vila Velha","r":4,"cap":0,"mega":0,"pop":1209091,"lon":-40.29,"lat":-20.338},{"n":"Natal","r":4,"cap":0,"mega":1,"pop":1088000,"lon":-35.242,"lat":-5.778},{"n":"Thompson","r":4,"cap":0,"mega":0,"pop":13727,"lon":-97.867,"lat":55.75},{"n":"Brandon","r":4,"cap":0,"mega":0,"pop":28418,"lon":-99.95,"lat":49.833},{"n":"Fort Smith","r":4,"cap":0,"mega":0,"pop":518,"lon":-111.883,"lat":60.0},{"n":"Fort McMurray","r":4,"cap":0,"mega":0,"pop":21863,"lon":-111.383,"lat":56.733},{"n":"Peace River","r":4,"cap":0,"mega":0,"pop":5340,"lon":-117.283,"lat":56.233},{"n":"Fort St. John","r":4,"cap":0,"mega":0,"pop":18776,"lon":-120.833,"lat":56.25},{"n":"Iqaluit","r":4,"cap":0,"mega":0,"pop":6124,"lon":-68.5,"lat":63.75},{"n":"Cambridge Bay","r":4,"cap":0,"mega":0,"pop":1477,"lon":-105.033,"lat":69.117},{"n":"Kugluktuk","r":4,"cap":0,"mega":0,"pop":1302,"lon":-115.125,"lat":67.799},{"n":"Chesterfield Inlet","r":4,"cap":0,"mega":0,"pop":374,"lon":-90.7,"lat":63.338},{"n":"Arviat","r":4,"cap":0,"mega":0,"pop":1868,"lon":-94.059,"lat":61.109},{"n":"Taloyoak","r":4,"cap":0,"mega":0,"pop":774,"lon":-93.533,"lat":69.533},{"n":"Igloolik","r":4,"cap":0,"mega":0,"pop":1612,"lon":-81.794,"lat":69.257},{"n":"Dawson City","r":4,"cap":0,"mega":0,"pop":1319,"lon":-139.417,"lat":64.067},{"n":"Timmins","r":4,"cap":0,"mega":0,"pop":34974,"lon":-81.333,"lat":48.467},{"n":"North Bay","r":4,"cap":0,"mega":0,"pop":50170,"lon":-79.45,"lat":46.3},{"n":"Kuujjuarapik","r":4,"cap":0,"mega":0,"pop":1243,"lon":-77.766,"lat":55.281},{"n":"Kuujjuaq","r":4,"cap":0,"mega":0,"pop":1273,"lon":-68.4,"lat":58.1},{"n":"Sydney","r":4,"cap":0,"mega":0,"pop":37538,"lon":-60.18,"lat":46.066},{"n":"Labrador City","r":4,"cap":0,"mega":0,"pop":10313,"lon":-66.916,"lat":52.941},{"n":"Ebolowa","r":4,"cap":0,"mega":0,"pop":87875,"lon":11.15,"lat":2.9},{"n":"Bambari","r":4,"cap":0,"mega":0,"pop":62098,"lon":20.667,"lat":5.762},{"n":"Venice","r":4,"cap":0,"mega":0,"pop":270816,"lon":12.335,"lat":45.439},{"n":"El Calafate","r":4,"cap":0,"mega":0,"pop":8000,"lon":-72.3,"lat":-50.333},{"n":"San Juan","r":4,"cap":0,"mega":0,"pop":447048,"lon":-68.52,"lat":-31.55},{"n":"Rawson","r":4,"cap":0,"mega":0,"pop":26335,"lon":-65.1,"lat":-43.3},{"n":"Neuquen","r":4,"cap":0,"mega":0,"pop":242092,"lon":-68.06,"lat":-38.95},{"n":"Trinidad","r":4,"cap":0,"mega":0,"pop":84259,"lon":-64.9,"lat":-14.833},{"n":"Santa Rosa","r":4,"cap":0,"mega":0,"pop":111424,"lon":-64.3,"lat":-36.62},{"n":"San Carlos de Bariloche","r":4,"cap":0,"mega":0,"pop":95394,"lon":-71.3,"lat":-41.15},{"n":"Salta","r":4,"cap":0,"mega":0,"pop":512686,"lon":-65.417,"lat":-24.783},{"n":"Tucuman","r":4,"cap":0,"mega":1,"pop":830000,"lon":-65.219,"lat":-26.814},{"n":"Formosa","r":4,"cap":0,"mega":0,"pop":221383,"lon":-58.183,"lat":-26.173},{"n":"Santa Fe","r":4,"cap":0,"mega":0,"pop":489505,"lon":-60.69,"lat":-31.624},{"n":"Rosario","r":4,"cap":0,"mega":1,"pop":1203000,"lon":-60.668,"lat":-32.949},{"n":"Campinas","r":4,"cap":0,"mega":1,"pop":2791000,"lon":-47.056,"lat":-22.908},{"n":"Sorocaba","r":4,"cap":0,"mega":0,"pop":563281,"lon":-47.47,"lat":-23.49},{"n":"Ribeirao Preto","r":4,"cap":0,"mega":0,"pop":551267,"lon":-47.83,"lat":-21.17},{"n":"Petrolina","r":4,"cap":0,"mega":0,"pop":260985,"lon":-40.51,"lat":-9.38},{"n":"Bamenda","r":4,"cap":0,"mega":0,"pop":445299,"lon":10.15,"lat":5.96},{"n":"Garoua","r":4,"cap":0,"mega":0,"pop":436899,"lon":13.39,"lat":9.3},{"n":"Herat","r":4,"cap":0,"mega":0,"pop":481009,"lon":62.17,"lat":34.33},{"n":"Mazar-e Sharif","r":4,"cap":0,"mega":0,"pop":458151,"lon":67.1,"lat":36.7},{"n":"Battambang","r":4,"cap":0,"mega":0,"pop":154773,"lon":103.2,"lat":13.1},{"n":"Siem Reap","r":4,"cap":0,"mega":0,"pop":109398,"lon":103.85,"lat":13.367},{"n":"Malanje","r":4,"cap":0,"mega":0,"pop":125856,"lon":16.34,"lat":-9.54},{"n":"Benguela","r":4,"cap":0,"mega":0,"pop":151226,"lon":13.407,"lat":-12.578},{"n":"Lubango","r":4,"cap":0,"mega":0,"pop":125632,"lon":13.49,"lat":-14.91},{"n":"Namibe","r":4,"cap":0,"mega":0,"pop":132900,"lon":12.16,"lat":-15.19},{"n":"Tarija","r":4,"cap":0,"mega":0,"pop":159269,"lon":-64.75,"lat":-21.517},{"n":"Bridgetown","r":4,"cap":1,"mega":0,"pop":191152,"lon":-59.617,"lat":13.102},{"n":"Annaba","r":4,"cap":0,"mega":0,"pop":503524,"lon":7.76,"lat":36.92},{"n":"Parakou","r":4,"cap":0,"mega":0,"pop":188853,"lon":2.62,"lat":9.34},{"n":"Porto-Novo","r":4,"cap":0,"mega":0,"pop":300000,"lon":2.617,"lat":6.483},{"n":"Constantine","r":4,"cap":0,"mega":0,"pop":605179,"lon":6.6,"lat":36.36},{"n":"Brest","r":4,"cap":0,"mega":0,"pop":300715,"lon":23.7,"lat":52.1},{"n":"Khulna","r":4,"cap":0,"mega":1,"pop":1553000,"lon":89.558,"lat":22.842},{"n":"Francistown","r":4,"cap":0,"mega":0,"pop":89979,"lon":27.5,"lat":-21.17},{"n":"Mahalapye","r":4,"cap":0,"mega":0,"pop":50744,"lon":26.82,"lat":-23.1},{"n":"Serowe","r":4,"cap":0,"mega":0,"pop":48573,"lon":26.71,"lat":-22.39},{"n":"Katherine","r":4,"cap":0,"mega":0,"pop":10141,"lon":132.267,"lat":-14.467},{"n":"Busselton","r":4,"cap":0,"mega":0,"pop":10214,"lon":115.349,"lat":-33.656},{"n":"Mandurah","r":4,"cap":0,"mega":0,"pop":73356,"lon":115.747,"lat":-32.523},{"n":"Broome","r":4,"cap":0,"mega":0,"pop":13218,"lon":122.231,"lat":-17.962},{"n":"Kalgoorlie","r":4,"cap":0,"mega":0,"pop":36852,"lon":121.46,"lat":-30.735},{"n":"Albany","r":4,"cap":0,"mega":0,"pop":26445,"lon":117.892,"lat":-35.017},{"n":"Port Hedland","r":4,"cap":0,"mega":0,"pop":14288,"lon":118.606,"lat":-20.31},{"n":"Karratha","r":4,"cap":0,"mega":0,"pop":16796,"lon":116.87,"lat":-20.73},{"n":"Geraldton","r":4,"cap":0,"mega":0,"pop":27258,"lon":114.6,"lat":-28.767},{"n":"Griffith","r":4,"cap":0,"mega":0,"pop":15455,"lon":146.04,"lat":-34.29},{"n":"Orange","r":4,"cap":0,"mega":0,"pop":39329,"lon":149.1,"lat":-33.28},{"n":"Dubbo","r":4,"cap":0,"mega":0,"pop":31574,"lon":148.597,"lat":-32.26},{"n":"Armidale","r":4,"cap":0,"mega":0,"pop":22673,"lon":151.667,"lat":-30.512},{"n":"Broken Hill","r":4,"cap":0,"mega":0,"pop":17395,"lon":141.433,"lat":-31.95},{"n":"Port Lincoln","r":4,"cap":0,"mega":0,"pop":13630,"lon":135.867,"lat":-34.733},{"n":"Whyalla","r":4,"cap":0,"mega":0,"pop":22559,"lon":137.561,"lat":-33.025},{"n":"Portland","r":4,"cap":0,"mega":0,"pop":11808,"lon":141.59,"lat":-38.34},{"n":"Bendigo","r":4,"cap":0,"mega":0,"pop":81657,"lon":144.28,"lat":-36.76},{"n":"Wangaratta","r":4,"cap":0,"mega":0,"pop":14022,"lon":146.3,"lat":-36.36},{"n":"Windorah","r":4,"cap":0,"mega":0,"pop":158,"lon":142.65,"lat":-25.433},{"n":"Mount Isa","r":4,"cap":0,"mega":0,"pop":33200,"lon":139.49,"lat":-20.724},{"n":"Rockhampton","r":4,"cap":0,"mega":0,"pop":65850,"lon":150.52,"lat":-23.364},{"n":"Cairns","r":4,"cap":0,"mega":0,"pop":154225,"lon":145.763,"lat":-16.888},{"n":"Gold Coast","r":4,"cap":0,"mega":0,"pop":527660,"lon":153.448,"lat":-28.082},{"n":"Devonport","r":4,"cap":0,"mega":0,"pop":19317,"lon":146.331,"lat":-41.193},{"n":"Bobo Dioulasso","r":4,"cap":0,"mega":0,"pop":360106,"lon":-4.29,"lat":11.18},{"n":"Rajshahi","r":4,"cap":0,"mega":1,"pop":810000,"lon":88.603,"lat":24.377},{"n":"Mandalay","r":4,"cap":0,"mega":1,"pop":1300000,"lon":96.083,"lat":21.972},{"n":"Sittwe","r":4,"cap":0,"mega":0,"pop":179032,"lon":92.88,"lat":20.14},{"n":"Bujumbura","r":4,"cap":1,"mega":0,"pop":331700,"lon":29.36,"lat":-3.376},{"n":"Pago Pago","r":4,"cap":0,"mega":0,"pop":12576,"lon":-170.707,"lat":-14.277},{"n":"Kingstown","r":4,"cap":1,"mega":0,"pop":49485,"lon":-61.22,"lat":13.156},{"n":"Castries","r":4,"cap":1,"mega":0,"pop":37963,"lon":-60.993,"lat":14.008},{"n":"Basseterre","r":4,"cap":1,"mega":0,"pop":21887,"lon":-62.717,"lat":17.302},{"n":"Las Palmas","r":4,"cap":0,"mega":0,"pop":378495,"lon":-15.43,"lat":28.1},{"n":"Berbera","r":4,"cap":0,"mega":0,"pop":242344,"lon":45.016,"lat":10.436},{"n":"Port Louis","r":4,"cap":1,"mega":0,"pop":595491,"lon":57.5,"lat":-20.167},{"n":"Gaza","r":4,"cap":0,"mega":0,"pop":505700,"lon":34.445,"lat":31.53},{"n":"Saint George's","r":4,"cap":1,"mega":0,"pop":33734,"lon":-61.742,"lat":12.053},{"n":"Papeete","r":4,"cap":0,"mega":0,"pop":131695,"lon":-149.567,"lat":-17.533},{"n":"Manama","r":4,"cap":1,"mega":0,"pop":563920,"lon":50.583,"lat":26.236},{"n":"Freeport","r":4,"cap":0,"mega":0,"pop":25383,"lon":-78.7,"lat":26.533},{"n":"Saint John's","r":4,"cap":1,"mega":0,"pop":35499,"lon":-61.85,"lat":17.118},{"n":"Taichung","r":4,"cap":0,"mega":1,"pop":2629323,"lon":120.682,"lat":24.152},{"n":"Napier","r":4,"cap":0,"mega":0,"pop":57800,"lon":176.926,"lat":-39.49},{"n":"Manukau","r":4,"cap":0,"mega":0,"pop":375600,"lon":174.885,"lat":-37.0},{"n":"Hamilton","r":4,"cap":0,"mega":0,"pop":148200,"lon":175.29,"lat":-37.778},{"n":"Blenheim","r":4,"cap":0,"mega":0,"pop":30300,"lon":173.955,"lat":-41.514},{"n":"Dunedin","r":4,"cap":0,"mega":0,"pop":117700,"lon":170.491,"lat":-45.885},{"n":"Leh","r":4,"cap":0,"mega":0,"pop":30870,"lon":77.572,"lat":34.162},{"n":"Amaravati","r":4,"cap":0,"mega":0,"pop":5800000,"lon":80.524,"lat":16.534},{"n":"Kozhikode","r":3,"cap":0,"mega":1,"pop":953000,"lon":75.768,"lat":11.252},{"n":"Bhubaneshwar","r":3,"cap":0,"mega":1,"pop":844000,"lon":85.825,"lat":20.272},{"n":"Jamshedpur","r":3,"cap":0,"mega":1,"pop":1300000,"lon":86.196,"lat":22.789},{"n":"Montevideo","r":3,"cap":1,"mega":1,"pop":1513000,"lon":-56.187,"lat":-34.905},{"n":"Helena","r":3,"cap":0,"mega":0,"pop":38725,"lon":-112.035,"lat":46.593},{"n":"Bismarck","r":3,"cap":0,"mega":0,"pop":63871,"lon":-100.783,"lat":46.808},{"n":"Boise","r":3,"cap":0,"mega":0,"pop":338071,"lon":-116.227,"lat":43.609},{"n":"San Jose","r":3,"cap":0,"mega":1,"pop":1668000,"lon":-121.888,"lat":37.331},{"n":"Sacramento","r":3,"cap":0,"mega":1,"pop":1604000,"lon":-121.472,"lat":38.577},{"n":"Las Vegas","r":3,"cap":0,"mega":1,"pop":1823000,"lon":-115.151,"lat":36.165},{"n":"Santa Fe","r":3,"cap":0,"mega":0,"pop":92681,"lon":-105.937,"lat":35.687},{"n":"Portland","r":3,"cap":0,"mega":1,"pop":1875000,"lon":-122.682,"lat":45.522},{"n":"Salt Lake City","r":3,"cap":0,"mega":1,"pop":966000,"lon":-111.932,"lat":40.777},{"n":"Cheyenne","r":3,"cap":0,"mega":0,"pop":72927,"lon":-104.82,"lat":41.14},{"n":"Des Moines","r":3,"cap":0,"mega":0,"pop":380655,"lon":-93.62,"lat":41.58},{"n":"Omaha","r":3,"cap":0,"mega":0,"pop":877110,"lon":-96.01,"lat":41.24},{"n":"Oklahoma City","r":3,"cap":0,"mega":1,"pop":788000,"lon":-97.521,"lat":35.472},{"n":"Pierre","r":3,"cap":0,"mega":0,"pop":13879,"lon":-100.351,"lat":44.368},{"n":"San Antonio","r":3,"cap":0,"mega":1,"pop":1473000,"lon":-98.493,"lat":29.42},{"n":"San Cristobal","r":3,"cap":0,"mega":0,"pop":438798,"lon":-72.25,"lat":7.77},{"n":"Valencia","r":3,"cap":0,"mega":1,"pop":1770000,"lon":-67.982,"lat":10.232},{"n":"Jackson","r":3,"cap":0,"mega":0,"pop":250902,"lon":-90.185,"lat":32.299},{"n":"Raleigh","r":3,"cap":0,"mega":0,"pop":1163515,"lon":-78.647,"lat":35.773},{"n":"Cleveland","r":3,"cap":0,"mega":1,"pop":1890000,"lon":-81.697,"lat":41.472},{"n":"Cincinnati","r":3,"cap":0,"mega":1,"pop":1636000,"lon":-84.459,"lat":39.164},{"n":"Nashville","r":3,"cap":0,"mega":1,"pop":877000,"lon":-86.782,"lat":36.172},{"n":"Memphis","r":3,"cap":0,"mega":1,"pop":1081000,"lon":-90.029,"lat":35.145},{"n":"Norfolk","r":3,"cap":0,"mega":0,"pop":1047869,"lon":-76.28,"lat":36.85},{"n":"Milwaukee","r":3,"cap":0,"mega":1,"pop":1388000,"lon":-87.917,"lat":43.03},{"n":"Buffalo","r":3,"cap":0,"mega":1,"pop":1016000,"lon":-78.882,"lat":42.882},{"n":"Pittsburgh","r":3,"cap":0,"mega":1,"pop":1838000,"lon":-80.002,"lat":40.432},{"n":"Ciudad Guayana","r":3,"cap":0,"mega":0,"pop":746535,"lon":-62.62,"lat":8.37},{"n":"Lome","r":3,"cap":1,"mega":1,"pop":1452000,"lon":1.221,"lat":6.134},{"n":"Tunis","r":3,"cap":1,"mega":0,"pop":2412500,"lon":10.18,"lat":36.803},{"n":"Kodiak","r":3,"cap":0,"mega":0,"pop":9461,"lon":-152.407,"lat":57.79},{"n":"Cold Bay","r":3,"cap":0,"mega":0,"pop":200,"lon":-162.715,"lat":55.2},{"n":"Bethel","r":3,"cap":0,"mega":0,"pop":6228,"lon":-161.756,"lat":60.793},{"n":"Point Hope","r":3,"cap":0,"mega":0,"pop":461,"lon":-166.808,"lat":68.348},{"n":"Utqia\u0121vik","r":3,"cap":0,"mega":0,"pop":4336,"lon":-156.789,"lat":71.291},{"n":"Nome","r":3,"cap":0,"mega":0,"pop":3485,"lon":-165.406,"lat":64.506},{"n":"Valdez","r":3,"cap":0,"mega":0,"pop":4036,"lon":-146.348,"lat":61.136},{"n":"Juneau","r":3,"cap":0,"mega":0,"pop":30711,"lon":-134.401,"lat":58.303},{"n":"Fairbanks","r":3,"cap":0,"mega":0,"pop":56993,"lon":-147.711,"lat":64.837},{"n":"Prudhoe Bay","r":3,"cap":0,"mega":0,"pop":2500,"lon":-148.669,"lat":70.292},{"n":"Sevastapol","r":3,"cap":0,"mega":0,"pop":379200,"lon":33.524,"lat":44.604},{"n":"Abu Dhabi","r":3,"cap":1,"mega":0,"pop":603492,"lon":54.367,"lat":24.467},{"n":"Ashgabat","r":3,"cap":1,"mega":0,"pop":727700,"lon":58.383,"lat":37.95},{"n":"Samarqand","r":3,"cap":0,"mega":0,"pop":708000,"lon":66.945,"lat":39.67},{"n":"Lusaka","r":3,"cap":1,"mega":1,"pop":1328000,"lon":28.281,"lat":-15.415},{"n":"Harare","r":3,"cap":1,"mega":1,"pop":1572000,"lon":31.043,"lat":-17.816},{"n":"Bulawayo","r":3,"cap":0,"mega":0,"pop":699385,"lon":28.58,"lat":-20.17},{"n":"Dili","r":3,"cap":1,"mega":0,"pop":234331,"lon":125.579,"lat":-8.559},{"n":"Port Vila","r":3,"cap":1,"mega":0,"pop":44040,"lon":168.317,"lat":-17.733},{"n":"Tegucigalpa","r":3,"cap":1,"mega":1,"pop":946000,"lon":-87.219,"lat":14.104},{"n":"Georgetown","r":3,"cap":1,"mega":0,"pop":264350,"lon":-58.167,"lat":6.802},{"n":"Reykjavik","r":3,"cap":1,"mega":0,"pop":166212,"lon":-21.937,"lat":64.143},{"n":"Port-au-Prince","r":3,"cap":1,"mega":1,"pop":1998000,"lon":-72.338,"lat":18.543},{"n":"Glasgow","r":3,"cap":0,"mega":1,"pop":1160000,"lon":-4.239,"lat":55.862},{"n":"Kampala","r":3,"cap":1,"mega":1,"pop":1420000,"lon":32.581,"lat":0.319},{"n":"Aden","r":3,"cap":0,"mega":0,"pop":1000000,"lon":45.009,"lat":12.78},{"n":"Paramaribo","r":3,"cap":1,"mega":0,"pop":254169,"lon":-55.167,"lat":5.835},{"n":"Seville","r":3,"cap":0,"mega":0,"pop":1212045,"lon":-5.98,"lat":37.405},{"n":"Zinder","r":3,"cap":0,"mega":0,"pop":230358,"lon":8.983,"lat":13.8},{"n":"Niamey","r":3,"cap":1,"mega":1,"pop":915000,"lon":2.115,"lat":13.519},{"n":"Port Sudan","r":3,"cap":0,"mega":0,"pop":489725,"lon":37.216,"lat":19.616},{"n":"Dushanbe","r":3,"cap":1,"mega":0,"pop":1086244,"lon":68.774,"lat":38.56},{"n":"Cusco","r":3,"cap":0,"mega":0,"pop":361182,"lon":-71.972,"lat":-13.525},{"n":"Tacna","r":3,"cap":0,"mega":0,"pop":280098,"lon":-70.25,"lat":-18.0},{"n":"Trujillo","r":3,"cap":0,"mega":0,"pop":765171,"lon":-79.02,"lat":-8.12},{"n":"Ica","r":3,"cap":0,"mega":0,"pop":279420,"lon":-75.725,"lat":-14.068},{"n":"Asuncion","r":3,"cap":1,"mega":1,"pop":1870000,"lon":-57.626,"lat":-25.291},{"n":"Managua","r":3,"cap":1,"mega":1,"pop":920000,"lon":-86.27,"lat":12.155},{"n":"Freetown","r":3,"cap":1,"mega":1,"pop":827000,"lon":-13.236,"lat":8.472},{"n":"Agadez","r":3,"cap":0,"mega":0,"pop":117770,"lon":7.983,"lat":16.996},{"n":"Niyala","r":3,"cap":0,"mega":0,"pop":392373,"lon":24.89,"lat":12.06},{"n":"Wau","r":3,"cap":0,"mega":0,"pop":127384,"lon":27.99,"lat":7.7},{"n":"Dongola","r":3,"cap":0,"mega":0,"pop":26404,"lon":30.483,"lat":19.167},{"n":"Kassala","r":3,"cap":0,"mega":0,"pop":401477,"lon":36.39,"lat":15.46},{"n":"Tromso","r":3,"cap":0,"mega":0,"pop":52436,"lon":18.992,"lat":69.635},{"n":"Trondheim","r":3,"cap":0,"mega":0,"pop":147139,"lon":10.417,"lat":63.417},{"n":"Bergen","r":3,"cap":0,"mega":0,"pop":213585,"lon":5.325,"lat":60.391},{"n":"Islamabad","r":3,"cap":1,"mega":1,"pop":780000,"lon":73.081,"lat":33.689},{"n":"Multan","r":3,"cap":0,"mega":1,"pop":1522000,"lon":71.453,"lat":30.202},{"n":"Hyderabad","r":3,"cap":0,"mega":1,"pop":1459000,"lon":68.373,"lat":25.382},{"n":"Peshawar","r":3,"cap":0,"mega":1,"pop":1303000,"lon":71.533,"lat":34.007},{"n":"Kathmandu","r":3,"cap":1,"mega":1,"pop":895000,"lon":85.315,"lat":27.719},{"n":"Nacala","r":3,"cap":0,"mega":0,"pop":224795,"lon":40.715,"lat":-14.519},{"n":"Bloemfontein","r":3,"cap":1,"mega":0,"pop":463064,"lon":26.23,"lat":-29.12},{"n":"Pretoria","r":3,"cap":1,"mega":1,"pop":1338000,"lon":28.227,"lat":-25.705},{"n":"Port Moresby","r":3,"cap":1,"mega":0,"pop":283733,"lon":147.193,"lat":-9.465},{"n":"Honiara","r":3,"cap":1,"mega":0,"pop":76328,"lon":159.95,"lat":-9.438},{"n":"Panama City","r":3,"cap":1,"mega":1,"pop":1281000,"lon":-79.535,"lat":8.97},{"n":"Fez","r":3,"cap":0,"mega":1,"pop":1002000,"lon":-5.002,"lat":34.057},{"n":"Rabat","r":3,"cap":1,"mega":1,"pop":1705000,"lon":-6.836,"lat":34.025},{"n":"Marrakesh","r":3,"cap":0,"mega":1,"pop":872000,"lon":-8.002,"lat":31.632},{"n":"Chisinau","r":3,"cap":1,"mega":0,"pop":688134,"lon":28.858,"lat":47.005},{"n":"Beira","r":3,"cap":0,"mega":0,"pop":530604,"lon":34.87,"lat":-19.82},{"n":"Port Elizabeth","r":3,"cap":0,"mega":1,"pop":1021000,"lon":25.598,"lat":-33.968},{"n":"Maputo","r":3,"cap":1,"mega":1,"pop":1446000,"lon":32.587,"lat":-25.953},{"n":"Tomsk","r":3,"cap":0,"mega":0,"pop":535479,"lon":84.975,"lat":56.495},{"n":"Anadyr","r":3,"cap":0,"mega":0,"pop":10332,"lon":177.475,"lat":64.737},{"n":"Murmansk","r":3,"cap":0,"mega":0,"pop":319263,"lon":33.1,"lat":68.97},{"n":"Archangel","r":3,"cap":0,"mega":0,"pop":356051,"lon":40.545,"lat":64.575},{"n":"Nizhny Novgorod","r":3,"cap":0,"mega":1,"pop":1278000,"lon":43.998,"lat":56.335},{"n":"Volgograd","r":3,"cap":0,"mega":1,"pop":984000,"lon":44.498,"lat":48.712},{"n":"Ufa","r":3,"cap":0,"mega":1,"pop":1018000,"lon":56.038,"lat":54.792},{"n":"Yekaterinburg","r":3,"cap":0,"mega":1,"pop":1313000,"lon":60.598,"lat":56.852},{"n":"Samara","r":3,"cap":0,"mega":1,"pop":1137000,"lon":50.149,"lat":53.197},{"n":"Kazan","r":3,"cap":0,"mega":1,"pop":1115000,"lon":49.124,"lat":55.752},{"n":"Surgut","r":3,"cap":0,"mega":0,"pop":400000,"lon":73.425,"lat":61.26},{"n":"Barnaul","r":3,"cap":0,"mega":0,"pop":599579,"lon":83.745,"lat":53.355},{"n":"Novosibirsk","r":3,"cap":0,"mega":1,"pop":1389000,"lon":82.958,"lat":55.032},{"n":"Mogadishu","r":3,"cap":1,"mega":1,"pop":1100000,"lon":45.365,"lat":2.069},{"n":"Muscat","r":3,"cap":1,"mega":0,"pop":734697,"lon":58.378,"lat":23.585},{"n":"Colombo","r":3,"cap":1,"mega":0,"pop":217000,"lon":79.858,"lat":6.932},{"n":"Cebu","r":3,"cap":0,"mega":1,"pop":815000,"lon":123.898,"lat":10.322},{"n":"Iloilo","r":3,"cap":0,"mega":0,"pop":387681,"lon":122.545,"lat":10.705},{"n":"Davao","r":3,"cap":0,"mega":1,"pop":1402000,"lon":125.628,"lat":7.112},{"n":"Bratsk","r":3,"cap":0,"mega":0,"pop":246348,"lon":101.615,"lat":56.157},{"n":"Irkutsk","r":3,"cap":0,"mega":0,"pop":586695,"lon":104.284,"lat":52.285},{"n":"Krasnoyarsk","r":3,"cap":0,"mega":1,"pop":925000,"lon":92.864,"lat":56.016},{"n":"Dikson","r":3,"cap":0,"mega":0,"pop":1113,"lon":80.545,"lat":73.507},{"n":"Chita","r":3,"cap":0,"mega":0,"pop":308500,"lon":113.465,"lat":52.055},{"n":"Vladivostok","r":3,"cap":0,"mega":0,"pop":587022,"lon":131.91,"lat":43.13},{"n":"Nizhneyansk","r":3,"cap":0,"mega":0,"pop":400,"lon":136.067,"lat":71.433},{"n":"Yakutsk","r":3,"cap":0,"mega":0,"pop":235600,"lon":129.735,"lat":62.035},{"n":"Tiksi","r":3,"cap":0,"mega":0,"pop":5700,"lon":128.835,"lat":71.627},{"n":"Magadan","r":3,"cap":0,"mega":0,"pop":95282,"lon":150.81,"lat":59.575},{"n":"Tijuana","r":3,"cap":0,"mega":1,"pop":1553000,"lon":-117.082,"lat":32.502},{"n":"Chihuahua","r":3,"cap":0,"mega":1,"pop":793000,"lon":-106.087,"lat":28.647},{"n":"Mazatlan","r":3,"cap":0,"mega":0,"pop":368204,"lon":-106.42,"lat":23.221},{"n":"Tampico","r":3,"cap":0,"mega":0,"pop":859419,"lon":-97.87,"lat":22.3},{"n":"Acapulco","r":3,"cap":0,"mega":0,"pop":715584,"lon":-99.916,"lat":16.85},{"n":"Veracruz","r":3,"cap":0,"mega":0,"pop":578963,"lon":-96.16,"lat":19.177},{"n":"Tuxtla Gutierrez","r":3,"cap":0,"mega":0,"pop":481128,"lon":-93.15,"lat":16.75},{"n":"Cancun","r":3,"cap":0,"mega":0,"pop":542043,"lon":-86.83,"lat":21.17},{"n":"Merida","r":3,"cap":0,"mega":1,"pop":965000,"lon":-89.619,"lat":20.969},{"n":"Enugu","r":3,"cap":0,"mega":0,"pop":688862,"lon":7.5,"lat":6.45},{"n":"Sokoto","r":3,"cap":0,"mega":0,"pop":732178,"lon":5.24,"lat":13.06},{"n":"Perm","r":3,"cap":0,"mega":1,"pop":997000,"lon":56.248,"lat":58.002},{"n":"Erdenet","r":3,"cap":0,"mega":0,"pop":79647,"lon":104.118,"lat":49.053},{"n":"Ulaanbaatar","r":3,"cap":1,"mega":1,"pop":885000,"lon":106.915,"lat":47.919},{"n":"Mbeya","r":3,"cap":0,"mega":0,"pop":291649,"lon":33.43,"lat":-8.89},{"n":"Windhoek","r":3,"cap":1,"mega":0,"pop":268132,"lon":17.084,"lat":-22.57},{"n":"Grootfontein","r":3,"cap":0,"mega":0,"pop":24099,"lon":18.117,"lat":-19.567},{"n":"Zanzibar","r":3,"cap":0,"mega":0,"pop":403658,"lon":39.2,"lat":-6.16},{"n":"Valencia","r":3,"cap":0,"mega":1,"pop":808000,"lon":-0.402,"lat":39.487},{"n":"Palana","r":3,"cap":0,"mega":0,"pop":3671,"lon":159.95,"lat":59.084},{"n":"Petropavlovsk Kamchatskiy","r":3,"cap":0,"mega":0,"pop":187282,"lon":158.623,"lat":53.062},{"n":"Abuja","r":3,"cap":1,"mega":1,"pop":1576000,"lon":7.49,"lat":9.055},{"n":"Padang","r":3,"cap":0,"mega":1,"pop":855000,"lon":100.358,"lat":-0.958},{"n":"Bissau","r":3,"cap":1,"mega":0,"pop":403339,"lon":-15.598,"lat":11.865},{"n":"Palermo","r":3,"cap":0,"mega":1,"pop":863000,"lon":13.348,"lat":38.127},{"n":"Amman","r":3,"cap":1,"mega":1,"pop":1060000,"lon":35.931,"lat":31.952},{"n":"Vilnius","r":3,"cap":1,"mega":0,"pop":542366,"lon":25.317,"lat":54.683},{"n":"Riga","r":3,"cap":1,"mega":0,"pop":742572,"lon":24.1,"lat":56.95},{"n":"Bishkek","r":3,"cap":1,"mega":1,"pop":837000,"lon":74.583,"lat":42.875},{"n":"Jiayuguan","r":3,"cap":0,"mega":0,"pop":148279,"lon":98.3,"lat":39.82},{"n":"Xining","r":3,"cap":0,"mega":1,"pop":1048000,"lon":101.768,"lat":36.622},{"n":"Guilin","r":3,"cap":0,"mega":1,"pop":987000,"lon":110.278,"lat":25.282},{"n":"Huainan","r":3,"cap":0,"mega":1,"pop":1451000,"lon":116.978,"lat":32.632},{"n":"Shantou","r":3,"cap":0,"mega":1,"pop":1601000,"lon":116.668,"lat":23.372},{"n":"Tarakan","r":3,"cap":0,"mega":0,"pop":193069,"lon":117.633,"lat":3.3},{"n":"Mombasa","r":3,"cap":0,"mega":1,"pop":882000,"lon":39.688,"lat":-4.038},{"n":"Maseru","r":3,"cap":1,"mega":0,"pop":361324,"lon":27.483,"lat":-29.317},{"n":"Antananarivo","r":3,"cap":1,"mega":1,"pop":1697000,"lon":47.515,"lat":-18.915},{"n":"Semarang","r":3,"cap":0,"mega":1,"pop":1396000,"lon":110.418,"lat":-6.965},{"n":"Palembang","r":3,"cap":0,"mega":1,"pop":1749000,"lon":104.748,"lat":-2.978},{"n":"Bandjarmasin","r":3,"cap":0,"mega":0,"pop":603576,"lon":114.58,"lat":-3.33},{"n":"Makassar","r":3,"cap":0,"mega":1,"pop":1262000,"lon":119.43,"lat":-5.138},{"n":"Lyon","r":3,"cap":0,"mega":1,"pop":1423000,"lon":4.828,"lat":45.772},{"n":"Quito","r":3,"cap":1,"mega":1,"pop":1701000,"lon":-78.502,"lat":-0.213},{"n":"San Jose","r":3,"cap":1,"mega":1,"pop":1284000,"lon":-84.079,"lat":9.93},{"n":"San Salvador","r":3,"cap":1,"mega":1,"pop":1433000,"lon":-89.216,"lat":13.703},{"n":"Kingston","r":3,"cap":1,"mega":0,"pop":937700,"lon":-76.767,"lat":17.977},{"n":"Cartagena","r":3,"cap":0,"mega":1,"pop":887000,"lon":-75.516,"lat":10.402},{"n":"Mitu","r":3,"cap":0,"mega":0,"pop":5917,"lon":-70.174,"lat":1.198},{"n":"Bumba","r":3,"cap":0,"mega":0,"pop":160539,"lon":22.46,"lat":2.19},{"n":"Ndjamena","r":3,"cap":1,"mega":1,"pop":989000,"lon":15.047,"lat":12.115},{"n":"Abeche","r":3,"cap":0,"mega":0,"pop":158317,"lon":20.83,"lat":13.84},{"n":"Malabo","r":3,"cap":1,"mega":0,"pop":155963,"lon":8.783,"lat":3.75},{"n":"Luxor","r":3,"cap":0,"mega":0,"pop":609248,"lon":32.65,"lat":25.7},{"n":"Asmara","r":3,"cap":1,"mega":0,"pop":620802,"lon":38.933,"lat":15.333},{"n":"Zagreb","r":3,"cap":1,"mega":0,"pop":722526,"lon":16.0,"lat":45.8},{"n":"Tallinn","r":3,"cap":1,"mega":0,"pop":394024,"lon":24.728,"lat":59.434},{"n":"Lhasa","r":3,"cap":0,"mega":0,"pop":219599,"lon":91.1,"lat":29.645},{"n":"Hami","r":3,"cap":0,"mega":0,"pop":580000,"lon":93.515,"lat":42.827},{"n":"Hotan","r":3,"cap":0,"mega":0,"pop":408894,"lon":79.927,"lat":37.1},{"n":"Kashgar","r":3,"cap":0,"mega":0,"pop":506640,"lon":75.97,"lat":39.476},{"n":"Yinchuan","r":3,"cap":0,"mega":1,"pop":991000,"lon":106.271,"lat":38.47},{"n":"Pingxiang","r":3,"cap":0,"mega":1,"pop":961000,"lon":113.848,"lat":27.622},{"n":"Nagasaki","r":3,"cap":0,"mega":0,"pop":435455,"lon":129.885,"lat":32.765},{"n":"Qiqihar","r":3,"cap":0,"mega":1,"pop":1641000,"lon":123.988,"lat":47.347},{"n":"Kikwit","r":3,"cap":0,"mega":0,"pop":637736,"lon":18.85,"lat":-5.03},{"n":"Matadi","r":3,"cap":0,"mega":0,"pop":245862,"lon":13.45,"lat":-5.817},{"n":"Kolwezi","r":3,"cap":0,"mega":0,"pop":418000,"lon":25.472,"lat":-10.717},{"n":"Lubumbashi","r":3,"cap":0,"mega":1,"pop":1352000,"lon":27.478,"lat":-11.678},{"n":"Lilongwe","r":3,"cap":1,"mega":0,"pop":646750,"lon":33.783,"lat":-13.983},{"n":"Guatemala","r":3,"cap":1,"mega":1,"pop":1024000,"lon":-90.529,"lat":14.623},{"n":"Cayenne","r":3,"cap":0,"mega":0,"pop":61550,"lon":-52.33,"lat":4.933},{"n":"Libreville","r":3,"cap":1,"mega":0,"pop":578156,"lon":9.458,"lat":0.385},{"n":"Vishakhapatnam","r":3,"cap":0,"mega":1,"pop":1529000,"lon":83.22,"lat":17.683},{"n":"Suva","r":3,"cap":1,"mega":0,"pop":175399,"lon":178.442,"lat":-18.133},{"n":"Port-Gentil","r":3,"cap":0,"mega":0,"pop":116836,"lon":8.78,"lat":-0.72},{"n":"Timbuktu","r":3,"cap":0,"mega":0,"pop":68872,"lon":-3.017,"lat":16.767},{"n":"Punta Arenas","r":3,"cap":0,"mega":0,"pop":117430,"lon":-70.94,"lat":-53.165},{"n":"Iquique","r":3,"cap":0,"mega":0,"pop":227499,"lon":-70.13,"lat":-20.25},{"n":"Antofagasta","r":3,"cap":0,"mega":0,"pop":309832,"lon":-70.4,"lat":-23.65},{"n":"Valparaiso","r":3,"cap":0,"mega":1,"pop":854000,"lon":-71.617,"lat":-33.048},{"n":"Valdivia","r":3,"cap":0,"mega":0,"pop":159599,"lon":-73.233,"lat":-39.822},{"n":"Concepcion","r":3,"cap":0,"mega":0,"pop":889725,"lon":-73.05,"lat":-36.83},{"n":"Puerto Montt","r":3,"cap":0,"mega":0,"pop":174629,"lon":-72.93,"lat":-41.47},{"n":"Nuuk","r":3,"cap":0,"mega":0,"pop":14798,"lon":-51.733,"lat":64.198},{"n":"Nouakchott","r":3,"cap":1,"mega":0,"pop":742144,"lon":-15.975,"lat":18.086},{"n":"Bamako","r":3,"cap":1,"mega":1,"pop":1494000,"lon":-8.002,"lat":12.652},{"n":"Atar","r":3,"cap":0,"mega":0,"pop":44265,"lon":-13.05,"lat":20.517},{"n":"Djenne","r":3,"cap":0,"mega":0,"pop":32944,"lon":-4.55,"lat":13.9},{"n":"Sabha","r":3,"cap":0,"mega":0,"pop":100249,"lon":14.433,"lat":27.033},{"n":"Banghazi","r":3,"cap":0,"mega":1,"pop":1180000,"lon":20.065,"lat":32.119},{"n":"Thessaloniki","r":3,"cap":0,"mega":1,"pop":828000,"lon":22.883,"lat":40.698},{"n":"Beirut","r":3,"cap":1,"mega":1,"pop":1846000,"lon":35.508,"lat":33.874},{"n":"Tbilisi","r":3,"cap":1,"mega":1,"pop":1100000,"lon":44.789,"lat":41.727},{"n":"Gonder","r":3,"cap":0,"mega":0,"pop":156230,"lon":37.46,"lat":12.61},{"n":"Astana","r":3,"cap":1,"mega":0,"pop":345604,"lon":71.428,"lat":51.181},{"n":"Qaraghandy","r":3,"cap":0,"mega":0,"pop":451800,"lon":73.115,"lat":49.885},{"n":"Almaty","r":3,"cap":0,"mega":1,"pop":1209000,"lon":76.913,"lat":43.327},{"n":"Isfahan","r":3,"cap":0,"mega":1,"pop":1628000,"lon":51.698,"lat":32.702},{"n":"Shiraz","r":3,"cap":0,"mega":1,"pop":1240000,"lon":52.568,"lat":29.632},{"n":"Amritsar","r":3,"cap":0,"mega":1,"pop":1212000,"lon":74.868,"lat":31.642},{"n":"Varanasi","r":3,"cap":0,"mega":1,"pop":1352000,"lon":82.998,"lat":25.332},{"n":"Asansol","r":3,"cap":0,"mega":1,"pop":1328000,"lon":86.981,"lat":23.685},{"n":"Bhilai","r":3,"cap":0,"mega":1,"pop":1097000,"lon":81.372,"lat":21.211},{"n":"Bhopal","r":3,"cap":0,"mega":1,"pop":1727000,"lon":77.408,"lat":23.252},{"n":"Madurai","r":3,"cap":0,"mega":1,"pop":1294000,"lon":78.118,"lat":9.922},{"n":"Coimbatore","r":3,"cap":0,"mega":1,"pop":1696000,"lon":76.948,"lat":11.002},{"n":"Vientiane","r":3,"cap":1,"mega":0,"pop":754000,"lon":102.6,"lat":17.967},{"n":"Brazzaville","r":3,"cap":1,"mega":1,"pop":1355000,"lon":15.283,"lat":-4.257},{"n":"Conakry","r":3,"cap":1,"mega":1,"pop":1494000,"lon":-13.682,"lat":9.533},{"n":"Yamoussoukro","r":3,"cap":1,"mega":0,"pop":206499,"lon":-5.276,"lat":6.818},{"n":"Cruzeiro do Sul","r":3,"cap":0,"mega":0,"pop":56862,"lon":-72.67,"lat":-7.63},{"n":"Leticia","r":3,"cap":0,"mega":0,"pop":59575,"lon":-69.955,"lat":-4.201},{"n":"Manaus","r":3,"cap":0,"mega":1,"pop":1753000,"lon":-60.002,"lat":-3.098},{"n":"Caxias","r":3,"cap":0,"mega":0,"pop":134640,"lon":-43.35,"lat":-4.833},{"n":"Santarem","r":3,"cap":0,"mega":0,"pop":230428,"lon":-54.7,"lat":-2.433},{"n":"Maraba","r":3,"cap":0,"mega":0,"pop":166182,"lon":-49.116,"lat":-5.35},{"n":"Vilhena","r":3,"cap":0,"mega":0,"pop":63231,"lon":-60.117,"lat":-12.717},{"n":"Ji-Parana","r":3,"cap":0,"mega":0,"pop":65016,"lon":-61.967,"lat":-10.833},{"n":"Campo Grande","r":3,"cap":0,"mega":1,"pop":778000,"lon":-54.619,"lat":-20.448},{"n":"Florianopolis","r":3,"cap":0,"mega":1,"pop":1023000,"lon":-48.522,"lat":-27.578},{"n":"Feira de Santana","r":3,"cap":0,"mega":0,"pop":481911,"lon":-38.97,"lat":-12.25},{"n":"Winnipeg","r":3,"cap":0,"mega":0,"pop":632063,"lon":-97.166,"lat":49.883},{"n":"Churchill","r":3,"cap":0,"mega":0,"pop":1000,"lon":-94.166,"lat":58.766},{"n":"Regina","r":3,"cap":0,"mega":0,"pop":176183,"lon":-104.617,"lat":50.45},{"n":"Saskatoon","r":3,"cap":0,"mega":0,"pop":198958,"lon":-106.67,"lat":52.17},{"n":"Calgary","r":3,"cap":0,"mega":1,"pop":1110000,"lon":-114.082,"lat":51.085},{"n":"Prince Rupert","r":3,"cap":0,"mega":0,"pop":14708,"lon":-130.33,"lat":54.317},{"n":"Victoria","r":3,"cap":0,"mega":0,"pop":289625,"lon":-123.35,"lat":48.433},{"n":"Arctic Bay","r":3,"cap":0,"mega":0,"pop":604,"lon":-85.167,"lat":73.033},{"n":"Resolute","r":3,"cap":0,"mega":0,"pop":250,"lon":-94.9,"lat":74.683},{"n":"Repulse Bay","r":3,"cap":0,"mega":0,"pop":1000,"lon":-86.283,"lat":66.529},{"n":"Yellowknife","r":3,"cap":0,"mega":0,"pop":19234,"lon":-114.397,"lat":62.442},{"n":"Fort Good Hope","r":3,"cap":0,"mega":0,"pop":597,"lon":-128.633,"lat":66.267},{"n":"Whitehorse","r":3,"cap":0,"mega":0,"pop":23276,"lon":-135.05,"lat":60.717},{"n":"Boa Vista","r":3,"cap":0,"mega":0,"pop":235150,"lon":-60.666,"lat":2.816},{"n":"Macapa","r":3,"cap":0,"mega":0,"pop":499166,"lon":-51.05,"lat":0.033},{"n":"Ottawa","r":3,"cap":1,"mega":1,"pop":1145000,"lon":-75.702,"lat":45.419},{"n":"Fort Severn","r":3,"cap":0,"mega":0,"pop":125,"lon":-87.65,"lat":55.983},{"n":"Thunder Bay","r":3,"cap":0,"mega":0,"pop":99334,"lon":-89.275,"lat":48.446},{"n":"Quebec","r":3,"cap":0,"mega":0,"pop":624177,"lon":-71.246,"lat":46.84},{"n":"Halifax","r":3,"cap":0,"mega":0,"pop":359111,"lon":-63.6,"lat":44.65},{"n":"St. John's","r":3,"cap":0,"mega":0,"pop":131469,"lon":-52.681,"lat":47.585},{"n":"Nain","r":3,"cap":0,"mega":0,"pop":1151,"lon":-61.686,"lat":56.547},{"n":"Charlottetown","r":3,"cap":0,"mega":0,"pop":42402,"lon":-63.131,"lat":46.249},{"n":"Ndele","r":3,"cap":0,"mega":0,"pop":11764,"lon":20.653,"lat":8.409},{"n":"Belgrade","r":3,"cap":1,"mega":1,"pop":1099000,"lon":20.466,"lat":44.821},{"n":"Obo","r":3,"cap":0,"mega":0,"pop":12887,"lon":26.5,"lat":5.4},{"n":"Bandar Seri Begawan","r":3,"cap":1,"mega":0,"pop":296500,"lon":114.933,"lat":4.883},{"n":"Puerto Deseado","r":3,"cap":0,"mega":0,"pop":3305,"lon":-65.9,"lat":-47.75},{"n":"Rio Gallegos","r":3,"cap":0,"mega":0,"pop":85700,"lon":-69.217,"lat":-51.633},{"n":"Comodoro Rivadavia","r":3,"cap":0,"mega":0,"pop":140850,"lon":-67.5,"lat":-45.87},{"n":"Mendoza","r":3,"cap":0,"mega":1,"pop":893000,"lon":-68.819,"lat":-32.881},{"n":"Sucre","r":3,"cap":1,"mega":0,"pop":224838,"lon":-65.26,"lat":-19.041},{"n":"Riberalta","r":3,"cap":0,"mega":0,"pop":74014,"lon":-66.1,"lat":-10.983},{"n":"Bahia Blanca","r":3,"cap":0,"mega":0,"pop":281536,"lon":-62.265,"lat":-38.74},{"n":"Mar del Plata","r":3,"cap":0,"mega":0,"pop":555897,"lon":-57.58,"lat":-38.0},{"n":"Cordoba","r":3,"cap":0,"mega":1,"pop":1452000,"lon":-64.184,"lat":-31.398},{"n":"Posadas","r":3,"cap":0,"mega":0,"pop":357119,"lon":-55.885,"lat":-27.358},{"n":"Belmopan","r":3,"cap":1,"mega":0,"pop":15220,"lon":-88.767,"lat":17.252},{"n":"Bangui","r":3,"cap":1,"mega":0,"pop":831925,"lon":18.558,"lat":4.367},{"n":"Maroua","r":3,"cap":0,"mega":0,"pop":319941,"lon":14.325,"lat":10.596},{"n":"Yaounde","r":3,"cap":1,"mega":1,"pop":1611000,"lon":11.515,"lat":3.869},{"n":"Tirana","r":3,"cap":1,"mega":0,"pop":895350,"lon":19.819,"lat":41.328},{"n":"Yerevan","r":3,"cap":1,"mega":1,"pop":1102000,"lon":44.512,"lat":40.183},{"n":"Baku","r":3,"cap":1,"mega":1,"pop":2122300,"lon":49.86,"lat":40.397},{"n":"Kandahar","r":3,"cap":0,"mega":0,"pop":715542,"lon":65.695,"lat":31.61},{"n":"Phnom Penh","r":3,"cap":1,"mega":1,"pop":1466000,"lon":104.915,"lat":11.552},{"n":"Menongue","r":3,"cap":0,"mega":0,"pop":13030,"lon":17.7,"lat":-14.667},{"n":"Huambo","r":3,"cap":0,"mega":1,"pop":1100000,"lon":15.758,"lat":-12.748},{"n":"La Paz","r":3,"cap":1,"mega":1,"pop":1590000,"lon":-68.152,"lat":-16.496},{"n":"Santa Cruz","r":3,"cap":0,"mega":1,"pop":2102998,"lon":-63.228,"lat":-17.752},{"n":"Oran","r":3,"cap":0,"mega":1,"pop":798000,"lon":-0.622,"lat":35.712},{"n":"Cotonou","r":3,"cap":1,"mega":1,"pop":762000,"lon":2.404,"lat":6.363},{"n":"Tamanrasset","r":3,"cap":0,"mega":0,"pop":76000,"lon":5.523,"lat":22.785},{"n":"Ghardaia","r":3,"cap":0,"mega":0,"pop":125480,"lon":3.67,"lat":32.49},{"n":"Sofia","r":3,"cap":1,"mega":1,"pop":1185000,"lon":23.315,"lat":42.685},{"n":"Minsk","r":3,"cap":1,"mega":1,"pop":1805000,"lon":27.565,"lat":53.902},{"n":"Thimphu","r":3,"cap":1,"mega":0,"pop":98676,"lon":89.639,"lat":27.473},{"n":"Gaborone","r":3,"cap":1,"mega":0,"pop":208411,"lon":25.912,"lat":-24.646},{"n":"Darwin","r":3,"cap":0,"mega":0,"pop":93080,"lon":130.85,"lat":-12.425},{"n":"Alice Springs","r":3,"cap":0,"mega":0,"pop":27710,"lon":133.88,"lat":-23.701},{"n":"Canberra","r":3,"cap":1,"mega":0,"pop":327700,"lon":149.129,"lat":-35.283},{"n":"Newcastle","r":3,"cap":0,"mega":0,"pop":540796,"lon":151.77,"lat":-32.93},{"n":"Adelaide","r":3,"cap":0,"mega":1,"pop":1145000,"lon":138.598,"lat":-34.933},{"n":"Townsville","r":3,"cap":0,"mega":0,"pop":138954,"lon":146.77,"lat":-19.25},{"n":"Brisbane","r":3,"cap":0,"mega":1,"pop":1860000,"lon":153.033,"lat":-27.453},{"n":"Hobart","r":3,"cap":0,"mega":0,"pop":80870,"lon":147.295,"lat":-42.85},{"n":"Ouagadougou","r":3,"cap":1,"mega":1,"pop":1149000,"lon":-1.527,"lat":12.372},{"n":"Sarajevo","r":3,"cap":1,"mega":0,"pop":696731,"lon":18.383,"lat":43.85},{"n":"Naypyidaw","r":3,"cap":1,"mega":1,"pop":930000,"lon":96.117,"lat":19.769},{"n":"San Juan","r":3,"cap":0,"mega":1,"pop":2478905,"lon":-66.13,"lat":18.44},{"n":"Stanley","r":3,"cap":0,"mega":0,"pop":2213,"lon":-57.85,"lat":-51.7},{"n":"Hamilton","r":3,"cap":1,"mega":0,"pop":52320,"lon":-64.784,"lat":32.294},{"n":"Nukualofa","r":3,"cap":1,"mega":0,"pop":42620,"lon":-175.221,"lat":-21.139},{"n":"Hargeysa","r":3,"cap":1,"mega":0,"pop":477876,"lon":44.065,"lat":9.56},{"n":"Victoria","r":3,"cap":1,"mega":0,"pop":33576,"lon":55.45,"lat":-4.617},{"n":"Sao Tome","r":3,"cap":1,"mega":0,"pop":88219,"lon":6.73,"lat":0.337},{"n":"Apia","r":3,"cap":1,"mega":0,"pop":61916,"lon":-171.769,"lat":-13.836},{"n":"Valletta","r":3,"cap":1,"mega":0,"pop":368250,"lon":14.515,"lat":35.9},{"n":"Male","r":3,"cap":1,"mega":0,"pop":112927,"lon":73.509,"lat":4.172},{"n":"Jerusalem","r":3,"cap":1,"mega":0,"pop":1029300,"lon":35.207,"lat":31.778},{"n":"Praia","r":3,"cap":1,"mega":0,"pop":113364,"lon":-23.517,"lat":14.917},{"n":"Nassau","r":3,"cap":1,"mega":0,"pop":227940,"lon":-77.35,"lat":25.083},{"n":"Nicosia","r":3,"cap":1,"mega":0,"pop":224300,"lon":33.367,"lat":35.167},{"n":"Kaohsiung","r":3,"cap":0,"mega":1,"pop":2769072,"lon":120.267,"lat":22.633},{"n":"Wellington","r":3,"cap":1,"mega":0,"pop":393400,"lon":174.777,"lat":-41.292},{"n":"Christchurch","r":3,"cap":0,"mega":0,"pop":363200,"lon":172.63,"lat":-43.535},{"n":"Shenzhen","r":2,"cap":0,"mega":1,"pop":7581000,"lon":114.061,"lat":22.548},{"n":"Zibo","r":2,"cap":0,"mega":1,"pop":3061000,"lon":117.996,"lat":36.821},{"n":"Minneapolis","r":2,"cap":0,"mega":1,"pop":2616000,"lon":-93.254,"lat":44.982},{"n":"Honolulu","r":2,"cap":0,"mega":1,"pop":786000,"lon":-157.858,"lat":21.303},{"n":"Seattle","r":2,"cap":0,"mega":1,"pop":3074000,"lon":-122.315,"lat":47.6},{"n":"Phoenix","r":2,"cap":0,"mega":1,"pop":3551000,"lon":-112.067,"lat":33.448},{"n":"San Diego","r":2,"cap":0,"mega":1,"pop":2916000,"lon":-117.151,"lat":32.719},{"n":"St. Louis","r":2,"cap":0,"mega":1,"pop":2199000,"lon":-90.242,"lat":38.637},{"n":"New Orleans","r":2,"cap":0,"mega":1,"pop":785000,"lon":-90.088,"lat":29.969},{"n":"Dallas","r":2,"cap":0,"mega":1,"pop":4798000,"lon":-96.795,"lat":32.772},{"n":"Maracaibo","r":2,"cap":0,"mega":1,"pop":2072000,"lon":-71.662,"lat":10.732},{"n":"Boston","r":2,"cap":0,"mega":1,"pop":4467000,"lon":-71.072,"lat":42.332},{"n":"Tampa","r":2,"cap":0,"mega":1,"pop":2314000,"lon":-82.461,"lat":27.949},{"n":"Philadelphia","r":2,"cap":0,"mega":1,"pop":5492000,"lon":-75.18,"lat":39.946},{"n":"Detroit","r":2,"cap":0,"mega":1,"pop":4101000,"lon":-83.051,"lat":42.334},{"n":"Anchorage","r":2,"cap":0,"mega":0,"pop":260283,"lon":-149.887,"lat":61.214},{"n":"Hanoi","r":2,"cap":1,"mega":1,"pop":4378000,"lon":105.848,"lat":21.035},{"n":"Ho Chi Minh City","r":2,"cap":0,"mega":1,"pop":5314000,"lon":106.703,"lat":10.762},{"n":"Ankara","r":2,"cap":1,"mega":1,"pop":3716000,"lon":32.862,"lat":39.929},{"n":"Budapest","r":2,"cap":1,"mega":1,"pop":1679000,"lon":19.081,"lat":47.502},{"n":"Sanaa","r":2,"cap":1,"mega":1,"pop":2008000,"lon":44.205,"lat":15.357},{"n":"Barcelona","r":2,"cap":0,"mega":1,"pop":4920000,"lon":2.181,"lat":41.385},{"n":"Bucharest","r":2,"cap":1,"mega":1,"pop":1942000,"lon":26.098,"lat":44.435},{"n":"Aleppo","r":2,"cap":0,"mega":1,"pop":2738000,"lon":37.168,"lat":36.232},{"n":"Damascus","r":2,"cap":1,"mega":1,"pop":2466000,"lon":36.298,"lat":33.502},{"n":"Zurich","r":2,"cap":0,"mega":1,"pop":1108000,"lon":8.548,"lat":47.382},{"n":"Lisbon","r":2,"cap":1,"mega":1,"pop":2812000,"lon":-9.147,"lat":38.725},{"n":"Khartoum","r":2,"cap":1,"mega":1,"pop":4754000,"lon":32.532,"lat":15.59},{"n":"Jeddah","r":2,"cap":0,"mega":1,"pop":3012000,"lon":39.217,"lat":21.519},{"n":"Makkah","r":2,"cap":0,"mega":1,"pop":1385000,"lon":39.818,"lat":21.432},{"n":"Oslo","r":2,"cap":1,"mega":1,"pop":835000,"lon":10.748,"lat":59.919},{"n":"Lahore","r":2,"cap":0,"mega":1,"pop":6577000,"lon":74.348,"lat":31.562},{"n":"Karachi","r":2,"cap":0,"mega":1,"pop":12130000,"lon":66.988,"lat":24.872},{"n":"Durban","r":2,"cap":0,"mega":1,"pop":2729000,"lon":31.011,"lat":-29.861},{"n":"St. Petersburg","r":2,"cap":0,"mega":1,"pop":4553000,"lon":30.314,"lat":59.941},{"n":"Guadalajara","r":2,"cap":0,"mega":1,"pop":4198000,"lon":-103.332,"lat":20.672},{"n":"Puebla","r":2,"cap":0,"mega":1,"pop":2195000,"lon":-98.204,"lat":19.033},{"n":"Kano","r":2,"cap":0,"mega":1,"pop":3140000,"lon":8.518,"lat":12.002},{"n":"Warsaw","r":2,"cap":1,"mega":1,"pop":1707000,"lon":21.005,"lat":52.231},{"n":"Pyongyang","r":2,"cap":1,"mega":1,"pop":3300000,"lon":125.753,"lat":39.021},{"n":"Dar es Salaam","r":2,"cap":1,"mega":1,"pop":2930000,"lon":39.266,"lat":-6.798},{"n":"Medan","r":2,"cap":0,"mega":1,"pop":2115000,"lon":98.648,"lat":3.582},{"n":"Dublin","r":2,"cap":1,"mega":1,"pop":1059000,"lon":-6.257,"lat":53.347},{"n":"Monrovia","r":2,"cap":1,"mega":1,"pop":1041000,"lon":-10.8,"lat":6.315},{"n":"Naples","r":2,"cap":0,"mega":1,"pop":2250000,"lon":14.243,"lat":40.842},{"n":"Milan","r":2,"cap":0,"mega":1,"pop":2945000,"lon":9.203,"lat":45.472},{"n":"Kuala Lumpur","r":2,"cap":1,"mega":1,"pop":1448000,"lon":101.689,"lat":3.14},{"n":"Lanzhou","r":2,"cap":0,"mega":1,"pop":2561000,"lon":103.79,"lat":36.058},{"n":"Nanning","r":2,"cap":0,"mega":1,"pop":2167000,"lon":108.318,"lat":22.822},{"n":"Guiyang","r":2,"cap":0,"mega":1,"pop":3662000,"lon":106.718,"lat":26.582},{"n":"Chongqing","r":2,"cap":0,"mega":1,"pop":6461000,"lon":106.593,"lat":29.567},{"n":"Fuzhou","r":2,"cap":0,"mega":1,"pop":2606000,"lon":119.298,"lat":26.082},{"n":"Guangzhou","r":2,"cap":0,"mega":1,"pop":8829000,"lon":113.262,"lat":23.125},{"n":"Dongguan","r":2,"cap":0,"mega":1,"pop":4528000,"lon":113.75,"lat":23.022},{"n":"Bandung","r":2,"cap":0,"mega":1,"pop":2394000,"lon":107.568,"lat":-6.948},{"n":"Surabaya","r":2,"cap":0,"mega":1,"pop":2845000,"lon":112.749,"lat":-7.247},{"n":"Guayaquil","r":2,"cap":0,"mega":1,"pop":2514000,"lon":-79.922,"lat":-2.218},{"n":"Medellin","r":2,"cap":0,"mega":1,"pop":3297000,"lon":-75.577,"lat":6.277},{"n":"Cali","r":2,"cap":0,"mega":1,"pop":2254000,"lon":-76.502,"lat":3.402},{"n":"Havana","r":2,"cap":1,"mega":1,"pop":2174000,"lon":-82.366,"lat":23.134},{"n":"Alexandria","r":2,"cap":0,"mega":1,"pop":4165000,"lon":29.948,"lat":31.202},{"n":"Frankfurt","r":2,"cap":0,"mega":0,"pop":2895000,"lon":8.675,"lat":50.1},{"n":"Hamburg","r":2,"cap":0,"mega":1,"pop":1757000,"lon":9.998,"lat":53.552},{"n":"Munich","r":2,"cap":0,"mega":1,"pop":1275000,"lon":11.573,"lat":48.132},{"n":"Prague","r":2,"cap":1,"mega":1,"pop":1162000,"lon":14.423,"lat":50.087},{"n":"Kuwait City","r":2,"cap":1,"mega":1,"pop":2063000,"lon":47.976,"lat":29.372},{"n":"Xian","r":2,"cap":0,"mega":1,"pop":4009000,"lon":108.893,"lat":34.277},{"n":"Taiyuan","r":2,"cap":0,"mega":1,"pop":2913000,"lon":112.543,"lat":37.877},{"n":"Wuhan","r":2,"cap":0,"mega":1,"pop":7243000,"lon":114.268,"lat":30.582},{"n":"Changsha","r":2,"cap":0,"mega":1,"pop":2604000,"lon":112.968,"lat":28.202},{"n":"Kunming","r":2,"cap":0,"mega":1,"pop":2931000,"lon":102.697,"lat":25.043},{"n":"Zhengzhou","r":2,"cap":0,"mega":1,"pop":2636000,"lon":113.663,"lat":34.757},{"n":"Shenyeng","r":2,"cap":0,"mega":1,"pop":4787000,"lon":123.448,"lat":41.807},{"n":"Jinan","r":2,"cap":0,"mega":1,"pop":2798000,"lon":116.993,"lat":36.677},{"n":"Tianjin","r":2,"cap":0,"mega":1,"pop":7180000,"lon":117.197,"lat":39.083},{"n":"Nanchang","r":2,"cap":0,"mega":1,"pop":2350000,"lon":115.878,"lat":28.682},{"n":"Nanjing","r":2,"cap":0,"mega":1,"pop":3679000,"lon":118.778,"lat":32.052},{"n":"Hangzhou","r":2,"cap":0,"mega":1,"pop":3007000,"lon":120.168,"lat":30.252},{"n":"Hiroshima","r":2,"cap":0,"mega":1,"pop":2045000,"lon":132.441,"lat":34.39},{"n":"Changchun","r":2,"cap":0,"mega":1,"pop":3183000,"lon":125.338,"lat":43.867},{"n":"Baotou","r":2,"cap":0,"mega":1,"pop":2036000,"lon":109.82,"lat":40.654},{"n":"Harbin","r":2,"cap":0,"mega":1,"pop":3621000,"lon":126.648,"lat":45.752},{"n":"Sapporo","r":2,"cap":0,"mega":1,"pop":2544000,"lon":141.338,"lat":43.077},{"n":"Santo Domingo","r":2,"cap":1,"mega":1,"pop":2154000,"lon":-69.93,"lat":18.471},{"n":"Accra","r":2,"cap":1,"mega":1,"pop":2121000,"lon":-0.219,"lat":5.552},{"n":"Delhi","r":2,"cap":0,"mega":1,"pop":15926000,"lon":77.228,"lat":28.672},{"n":"Hyderabad","r":2,"cap":0,"mega":1,"pop":6376000,"lon":78.478,"lat":17.402},{"n":"Pune","r":2,"cap":0,"mega":1,"pop":4672000,"lon":73.852,"lat":18.516},{"n":"Nagpur","r":2,"cap":0,"mega":1,"pop":2454000,"lon":79.088,"lat":21.172},{"n":"Tripoli","r":2,"cap":1,"mega":1,"pop":2189000,"lon":13.18,"lat":32.892},{"n":"Tel Aviv-Yafo","r":2,"cap":0,"mega":1,"pop":3112000,"lon":34.768,"lat":32.082},{"n":"Helsinki","r":2,"cap":1,"mega":1,"pop":1115000,"lon":24.932,"lat":60.164},{"n":"Mashhad","r":2,"cap":0,"mega":1,"pop":2469000,"lon":59.568,"lat":36.272},{"n":"Jaipur","r":2,"cap":0,"mega":1,"pop":2917000,"lon":75.808,"lat":26.923},{"n":"Kanpur","r":2,"cap":0,"mega":1,"pop":3162000,"lon":80.318,"lat":26.462},{"n":"Patna","r":2,"cap":0,"mega":1,"pop":2158000,"lon":85.128,"lat":25.627},{"n":"Chennai","r":2,"cap":0,"mega":1,"pop":7163000,"lon":80.278,"lat":13.092},{"n":"Ahmedabad","r":2,"cap":0,"mega":1,"pop":5375000,"lon":72.578,"lat":23.032},{"n":"Surat","r":2,"cap":0,"mega":1,"pop":3842000,"lon":72.838,"lat":21.202},{"n":"Kobenhavn","r":2,"cap":1,"mega":1,"pop":1085000,"lon":12.562,"lat":55.681},{"n":"Abidjan","r":2,"cap":1,"mega":1,"pop":3802000,"lon":-4.02,"lat":5.323},{"n":"Belem","r":2,"cap":0,"mega":1,"pop":2167000,"lon":-48.482,"lat":-1.448},{"n":"Brasilia","r":2,"cap":1,"mega":1,"pop":3716996,"lon":-47.918,"lat":-15.781},{"n":"Porto Alegre","r":2,"cap":0,"mega":1,"pop":3917000,"lon":-51.202,"lat":-30.048},{"n":"Curitiba","r":2,"cap":0,"mega":1,"pop":3084000,"lon":-49.322,"lat":-25.418},{"n":"Fortaleza","r":2,"cap":0,"mega":1,"pop":3602319,"lon":-38.582,"lat":-3.748},{"n":"Salvador","r":2,"cap":0,"mega":1,"pop":3484000,"lon":-38.482,"lat":-12.968},{"n":"Edmonton","r":2,"cap":0,"mega":1,"pop":1058000,"lon":-113.502,"lat":53.552},{"n":"Montreal","r":2,"cap":0,"mega":1,"pop":3678000,"lon":-73.585,"lat":45.502},{"n":"Goiania","r":2,"cap":0,"mega":1,"pop":2022000,"lon":-49.302,"lat":-16.718},{"n":"Recife","r":2,"cap":0,"mega":1,"pop":3651000,"lon":-34.909,"lat":-8.061},{"n":"Brussels","r":2,"cap":1,"mega":1,"pop":1743000,"lon":4.331,"lat":50.835},{"n":"Dhaka","r":2,"cap":1,"mega":1,"pop":12797394,"lon":90.407,"lat":23.725},{"n":"Luanda","r":2,"cap":1,"mega":1,"pop":5172900,"lon":13.232,"lat":-8.836},{"n":"Algiers","r":2,"cap":1,"mega":1,"pop":3354000,"lon":3.049,"lat":36.765},{"n":"Chattogram","r":2,"cap":0,"mega":1,"pop":4529000,"lon":91.798,"lat":22.332},{"n":"Perth","r":2,"cap":0,"mega":1,"pop":1532000,"lon":115.838,"lat":-31.953},{"n":"Rangoon","r":2,"cap":0,"mega":1,"pop":4088000,"lon":96.165,"lat":16.785},{"n":"San Francisco","r":1,"cap":0,"mega":1,"pop":3450000,"lon":-122.4,"lat":37.784},{"n":"Denver","r":1,"cap":0,"mega":1,"pop":2313000,"lon":-104.986,"lat":39.741},{"n":"Houston","r":1,"cap":0,"mega":1,"pop":4459000,"lon":-95.348,"lat":29.741},{"n":"Miami","r":1,"cap":0,"mega":1,"pop":5585000,"lon":-80.226,"lat":25.79},{"n":"Atlanta","r":1,"cap":0,"mega":1,"pop":4506000,"lon":-84.368,"lat":33.739},{"n":"Chicago","r":1,"cap":0,"mega":1,"pop":8990000,"lon":-87.635,"lat":41.848},{"n":"Caracas","r":1,"cap":1,"mega":1,"pop":2985000,"lon":-66.919,"lat":10.503},{"n":"Kiev","r":1,"cap":1,"mega":1,"pop":2709000,"lon":30.515,"lat":50.435},{"n":"Dubai","r":1,"cap":0,"mega":1,"pop":1379000,"lon":55.287,"lat":25.215},{"n":"Tashkent","r":1,"cap":1,"mega":1,"pop":2184000,"lon":69.269,"lat":41.304},{"n":"Madrid","r":1,"cap":1,"mega":1,"pop":5567000,"lon":-3.685,"lat":40.402},{"n":"Geneva","r":1,"cap":0,"mega":0,"pop":1240000,"lon":6.14,"lat":46.21},{"n":"Stockholm","r":1,"cap":1,"mega":1,"pop":1264000,"lon":18.066,"lat":59.324},{"n":"Bangkok","r":1,"cap":1,"mega":1,"pop":6704000,"lon":100.515,"lat":13.752},{"n":"Lima","r":1,"cap":1,"mega":1,"pop":8012000,"lon":-77.052,"lat":-12.046},{"n":"Dakar","r":1,"cap":1,"mega":1,"pop":2604000,"lon":-17.475,"lat":14.718},{"n":"Johannesburg","r":1,"cap":0,"mega":1,"pop":3435000,"lon":28.028,"lat":-26.168},{"n":"Amsterdam","r":1,"cap":1,"mega":1,"pop":1031000,"lon":4.915,"lat":52.352},{"n":"Casablanca","r":1,"cap":0,"mega":1,"pop":3181000,"lon":-7.618,"lat":33.602},{"n":"Seoul","r":1,"cap":1,"mega":1,"pop":9796000,"lon":126.998,"lat":37.568},{"n":"Manila","r":1,"cap":1,"mega":1,"pop":11100000,"lon":120.98,"lat":14.606},{"n":"Monterrey","r":1,"cap":0,"mega":1,"pop":3712000,"lon":-100.332,"lat":25.672},{"n":"Berlin","r":1,"cap":1,"mega":1,"pop":3406000,"lon":13.4,"lat":52.524},{"n":"Urumqi","r":1,"cap":0,"mega":1,"pop":3575000,"lon":87.573,"lat":43.807},{"n":"Chengdu","r":1,"cap":0,"mega":1,"pop":4123000,"lon":104.068,"lat":30.672},{"n":"Osaka","r":1,"cap":0,"mega":1,"pop":11294000,"lon":135.504,"lat":34.691},{"n":"Kinshasa","r":1,"cap":1,"mega":1,"pop":7843000,"lon":15.313,"lat":-4.328},{"n":"New Delhi","r":1,"cap":1,"mega":0,"pop":317797,"lon":77.2,"lat":28.6},{"n":"Bengaluru","r":1,"cap":0,"mega":1,"pop":6787000,"lon":77.558,"lat":12.972},{"n":"Athens","r":1,"cap":1,"mega":1,"pop":3242000,"lon":23.731,"lat":37.985},{"n":"Baghdad","r":1,"cap":1,"mega":1,"pop":5054000,"lon":44.392,"lat":33.341},{"n":"Addis Ababa","r":1,"cap":1,"mega":1,"pop":3100000,"lon":38.698,"lat":9.035},{"n":"Tehran","r":1,"cap":1,"mega":1,"pop":7873000,"lon":51.422,"lat":35.674},{"n":"Vancouver","r":1,"cap":0,"mega":1,"pop":2313328,"lon":-123.124,"lat":49.275},{"n":"Toronto","r":1,"cap":0,"mega":1,"pop":5213000,"lon":-79.389,"lat":43.665},{"n":"Buenos Aires","r":1,"cap":1,"mega":1,"pop":12795000,"lon":-58.433,"lat":-34.611},{"n":"Kabul","r":1,"cap":1,"mega":1,"pop":3277000,"lon":69.181,"lat":34.519},{"n":"Vienna","r":1,"cap":1,"mega":1,"pop":2400000,"lon":16.365,"lat":48.202},{"n":"Melbourne","r":1,"cap":0,"mega":1,"pop":4170000,"lon":144.973,"lat":-37.818},{"n":"Taipei","r":1,"cap":1,"mega":1,"pop":6900273,"lon":121.568,"lat":25.036},{"n":"Auckland","r":1,"cap":0,"mega":1,"pop":1377200,"lon":174.763,"lat":-36.848},{"n":"Los Angeles","r":0,"cap":0,"mega":1,"pop":12500000,"lon":-118.232,"lat":34.049},{"n":"Washington, D.C.","r":0,"cap":1,"mega":1,"pop":4338000,"lon":-77.011,"lat":38.901},{"n":"New York","r":0,"cap":0,"mega":1,"pop":19040000,"lon":-73.996,"lat":40.722},{"n":"London","r":0,"cap":1,"mega":1,"pop":8567000,"lon":-0.119,"lat":51.502},{"n":"Istanbul","r":0,"cap":0,"mega":1,"pop":10061000,"lon":28.974,"lat":41.018},{"n":"Riyadh","r":0,"cap":1,"mega":1,"pop":4465000,"lon":46.72,"lat":24.634},{"n":"Cape Town","r":0,"cap":1,"mega":1,"pop":3215000,"lon":18.433,"lat":-33.918},{"n":"Moscow","r":0,"cap":1,"mega":1,"pop":10452000,"lon":37.614,"lat":55.754},{"n":"Mexico City","r":0,"cap":1,"mega":1,"pop":19028000,"lon":-99.133,"lat":19.444},{"n":"Lagos","r":0,"cap":0,"mega":1,"pop":9466000,"lon":3.39,"lat":6.445},{"n":"Rome","r":0,"cap":1,"mega":1,"pop":3339000,"lon":12.481,"lat":41.898},{"n":"Beijing","r":0,"cap":1,"mega":1,"pop":11106000,"lon":116.394,"lat":39.902},{"n":"Nairobi","r":0,"cap":1,"mega":1,"pop":3010000,"lon":36.815,"lat":-1.281},{"n":"Jakarta","r":0,"cap":1,"mega":1,"pop":9125000,"lon":106.827,"lat":-6.172},{"n":"Bogota","r":0,"cap":1,"mega":1,"pop":7772000,"lon":-74.085,"lat":4.598},{"n":"Cairo","r":0,"cap":1,"mega":1,"pop":11893000,"lon":31.248,"lat":30.052},{"n":"Shanghai","r":0,"cap":0,"mega":1,"pop":14987000,"lon":121.435,"lat":31.218},{"n":"Tokyo","r":0,"cap":1,"mega":1,"pop":35676000,"lon":139.749,"lat":35.687},{"n":"Mumbai","r":0,"cap":0,"mega":1,"pop":18978000,"lon":72.876,"lat":19.068},{"n":"Paris","r":0,"cap":1,"mega":1,"pop":9904000,"lon":2.353,"lat":48.858},{"n":"Santiago","r":0,"cap":1,"mega":1,"pop":5720000,"lon":-70.651,"lat":-33.44},{"n":"Kolkata","r":0,"cap":0,"mega":1,"pop":14787000,"lon":88.369,"lat":22.57},{"n":"Rio de Janeiro","r":0,"cap":0,"mega":1,"pop":11748000,"lon":-43.212,"lat":-22.907},{"n":"Sao Paulo","r":0,"cap":0,"mega":1,"pop":18845000,"lon":-46.627,"lat":-23.557},{"n":"Sydney","r":0,"cap":0,"mega":1,"pop":4630000,"lon":151.213,"lat":-33.871},{"n":"Singapore","r":0,"cap":1,"mega":1,"pop":5183700,"lon":103.854,"lat":1.295},{"n":"Hong Kong","r":0,"cap":0,"mega":1,"pop":7206000,"lon":114.183,"lat":22.307}]} \ No newline at end of file diff --git a/bitchat/Resources/Globe/world_land.geojson b/bitchat/Resources/Globe/world_land.geojson new file mode 100644 index 00000000..f842c94d --- /dev/null +++ b/bitchat/Resources/Globe/world_land.geojson @@ -0,0 +1 @@ +{"type":"GeometryCollection","geometries":[{"type":"Polygon","coordinates":[[[-59.57,-80.04],[-59.87,-80.55],[-60.16,-81.0],[-62.26,-80.86],[-64.49,-80.92],[-65.74,-80.59],[-65.74,-80.55],[-66.29,-80.26],[-64.04,-80.29],[-61.88,-80.39],[-61.14,-79.98],[-60.61,-79.63],[-59.57,-80.04]]]},{"type":"Polygon","coordinates":[[[-159.21,-79.5],[-161.13,-79.63],[-162.44,-79.28],[-163.03,-78.93],[-163.07,-78.87],[-163.71,-78.6],[-163.71,-78.6],[-163.11,-78.22],[-161.25,-78.38],[-160.25,-78.69],[-159.48,-79.05],[-159.21,-79.5]]]},{"type":"Polygon","coordinates":[[[-45.15,-78.05],[-43.92,-78.48],[-43.49,-79.09],[-43.37,-79.52],[-43.33,-80.03],[-44.88,-80.34],[-46.51,-80.59],[-48.39,-80.83],[-50.48,-81.03],[-52.85,-80.97],[-54.16,-80.63],[-53.99,-80.22],[-51.85,-79.95],[-50.99,-79.61],[-50.36,-79.18],[-49.91,-78.81],[-49.31,-78.46],[-48.66,-78.05],[-48.66,-78.05],[-48.15,-78.05],[-46.66,-77.83],[-45.15,-78.05]]]},{"type":"Polygon","coordinates":[[[-121.21,-73.5],[-119.92,-73.66],[-118.72,-73.48],[-119.29,-73.83],[-120.23,-74.09],[-121.62,-74.01],[-122.62,-73.66],[-122.62,-73.66],[-122.41,-73.32],[-121.21,-73.5]]]},{"type":"Polygon","coordinates":[[[-125.56,-73.48],[-124.03,-73.87],[-124.62,-73.83],[-125.91,-73.74],[-127.28,-73.46],[-127.28,-73.46],[-126.56,-73.25],[-125.56,-73.48]]]},{"type":"Polygon","coordinates":[[[-98.98,-71.93],[-97.88,-72.07],[-96.79,-71.95],[-96.2,-72.52],[-96.98,-72.44],[-98.2,-72.48],[-99.43,-72.44],[-100.78,-72.5],[-101.8,-72.31],[-102.33,-71.89],[-102.33,-71.89],[-101.7,-71.72],[-100.43,-71.85],[-98.98,-71.93]]]},{"type":"Polygon","coordinates":[[[-68.45,-70.96],[-68.33,-71.41],[-68.51,-71.8],[-68.78,-72.17],[-69.96,-72.31],[-71.08,-72.5],[-72.39,-72.48],[-71.9,-72.09],[-73.07,-72.23],[-74.19,-72.37],[-74.95,-72.07],[-75.01,-71.66],[-73.92,-71.27],[-73.92,-71.27],[-73.23,-71.15],[-72.07,-71.19],[-71.78,-70.68],[-71.72,-70.31],[-71.74,-69.51],[-71.17,-69.04],[-70.25,-68.88],[-69.72,-69.25],[-69.49,-69.62],[-69.06,-70.07],[-68.73,-70.51],[-68.45,-70.96]]]},{"type":"Polygon","coordinates":[[[-58.61,-64.15],[-59.05,-64.37],[-59.79,-64.21],[-60.61,-64.31],[-61.3,-64.54],[-62.02,-64.8],[-62.51,-65.09],[-62.65,-65.48],[-62.59,-65.86],[-62.12,-66.19],[-62.81,-66.43],[-63.75,-66.5],[-64.29,-66.84],[-64.88,-67.15],[-65.51,-67.58],[-65.67,-67.95],[-65.31,-68.37],[-64.78,-68.68],[-63.96,-68.91],[-63.2,-69.23],[-62.79,-69.62],[-62.57,-69.99],[-62.28,-70.38],[-61.81,-70.72],[-61.51,-71.09],[-61.38,-72.01],[-61.08,-72.38],[-61.0,-72.77],[-60.69,-73.17],[-60.83,-73.7],[-61.38,-74.11],[-61.96,-74.44],[-63.3,-74.58],[-63.75,-74.93],[-64.35,-75.26],[-65.86,-75.64],[-67.19,-75.79],[-68.45,-76.01],[-69.8,-76.22],[-70.6,-76.63],[-72.21,-76.67],[-73.97,-76.63],[-75.56,-76.71],[-77.24,-76.71],[-76.93,-77.1],[-75.4,-77.28],[-74.28,-77.56],[-73.66,-77.91],[-74.77,-78.22],[-76.5,-78.12],[-77.93,-78.38],[-77.98,-78.79],[-78.02,-79.18],[-76.85,-79.51],[-76.63,-79.89],[-75.36,-80.26],[-73.24,-80.42],[-71.44,-80.69],[-70.01,-81.0],[-68.19,-81.32],[-65.7,-81.47],[-63.26,-81.75],[-61.55,-82.04],[-59.69,-82.38],[-58.71,-82.85],[-58.22,-83.22],[-57.01,-82.87],[-55.36,-82.57],[-53.62,-82.26],[-51.54,-82.0],[-49.76,-81.73],[-47.27,-81.71],[-44.83,-81.85],[-42.81,-82.08],[-42.16,-81.65],[-40.77,-81.36],[-38.24,-81.34],[-36.27,-81.12],[-34.39,-80.91],[-32.31,-80.77],[-30.1,-80.59],[-28.55,-80.34],[-29.25,-79.99],[-29.69,-79.63],[-29.69,-79.26],[-31.62,-79.3],[-33.68,-79.46],[-35.64,-79.46],[-35.91,-79.08],[-35.78,-78.34],[-35.33,-78.12],[-33.9,-77.89],[-32.21,-77.65],[-31.0,-77.36],[-29.78,-77.07],[-28.88,-76.67],[-27.51,-76.5],[-26.16,-76.36],[-25.47,-76.28],[-23.93,-76.24],[-22.46,-76.11],[-21.22,-75.91],[-20.01,-75.67],[-18.91,-75.44],[-17.52,-75.13],[-16.64,-74.79],[-15.7,-74.5],[-15.41,-74.11],[-16.47,-73.87],[-16.11,-73.46],[-15.45,-73.15],[-14.41,-72.95],[-13.31,-72.72],[-12.29,-72.4],[-11.51,-72.01],[-11.02,-71.54],[-10.3,-71.27],[-9.1,-71.32],[-8.61,-71.66],[-7.42,-71.7],[-7.38,-71.32],[-6.87,-70.93],[-5.79,-71.03],[-5.54,-71.4],[-4.34,-71.46],[-3.05,-71.29],[-1.8,-71.17],[-0.66,-71.23],[-0.23,-71.64],[0.87,-71.3],[1.89,-71.13],[3.02,-70.99],[4.14,-70.85],[5.16,-70.62],[6.27,-70.46],[7.14,-70.25],[7.74,-69.89],[8.49,-70.15],[9.53,-70.01],[10.25,-70.48],[10.82,-70.83],[11.95,-70.64],[12.4,-70.25],[13.42,-69.97],[14.73,-70.03],[15.13,-70.4],[15.95,-70.03],[17.03,-69.91],[18.2,-69.87],[19.26,-69.89],[20.38,-70.01],[21.45,-70.07],[21.92,-70.4],[22.57,-70.7],[23.67,-70.52],[24.84,-70.48],[25.98,-70.48],[27.09,-70.46],[28.09,-70.32],[29.15,-70.21],[30.03,-69.93],[30.97,-69.76],[31.99,-69.66],[32.75,-69.38],[33.3,-68.84],[33.87,-68.5],[34.91,-68.66],[35.3,-69.01],[36.16,-69.25],[37.2,-69.17],[37.91,-69.52],[38.65,-69.78],[39.67,-69.54],[40.02,-69.11],[40.92,-68.93],[41.96,-68.6],[42.94,-68.46],[44.11,-68.27],[44.9,-68.05],[45.72,-67.82],[46.5,-67.6],[47.44,-67.72],[48.34,-67.37],[48.99,-67.09],[49.93,-67.11],[50.75,-66.88],[50.95,-66.52],[51.79,-66.25],[52.61,-66.05],[53.61,-65.9],[54.53,-65.82],[55.41,-65.88],[56.36,-65.97],[57.16,-66.25],[57.26,-66.68],[58.14,-67.01],[58.74,-67.29],[59.94,-67.41],[60.61,-67.68],[61.43,-67.95],[62.39,-68.01],[63.19,-67.82],[64.05,-67.41],[64.99,-67.62],[65.97,-67.74],[66.91,-67.86],[67.89,-67.93],[68.89,-67.93],[69.71,-68.97],[69.67,-69.23],[69.56,-69.68],[68.6,-69.93],[67.81,-70.31],[67.95,-70.7],[69.07,-70.68],[68.93,-71.07],[68.42,-71.44],[67.95,-71.85],[68.71,-72.17],[69.87,-72.26],[71.02,-72.09],[71.57,-71.7],[71.91,-71.32],[72.45,-71.01],[73.08,-70.72],[73.34,-70.36],[73.86,-69.87],[74.49,-69.78],[75.63,-69.74],[76.63,-69.62],[77.64,-69.46],[78.13,-69.07],[78.43,-68.7],[79.11,-68.33],[80.09,-68.07],[80.94,-67.88],[81.48,-67.54],[82.05,-67.37],[82.78,-67.21],[83.78,-67.31],[84.68,-67.21],[85.66,-67.09],[86.75,-67.15],[87.48,-66.88],[87.99,-66.21],[88.36,-66.48],[88.83,-66.95],[89.67,-67.15],[90.63,-67.23],[91.59,-67.11],[92.61,-67.19],[93.55,-67.21],[94.18,-67.11],[95.02,-67.17],[95.78,-67.39],[96.68,-67.25],[97.76,-67.25],[98.68,-67.11],[99.72,-67.25],[100.38,-66.92],[100.89,-66.58],[101.58,-66.31],[102.83,-65.56],[103.48,-65.7],[104.24,-65.97],[104.91,-66.33],[106.18,-66.93],[107.16,-66.95],[108.08,-66.95],[109.16,-66.84],[110.24,-66.7],[111.06,-66.43],[111.74,-66.13],[112.86,-66.09],[113.6,-65.88],[114.39,-66.07],[114.9,-66.39],[115.6,-66.7],[116.7,-66.66],[117.38,-66.92],[118.58,-67.17],[119.83,-67.27],[120.87,-67.19],[121.65,-66.88],[122.32,-66.56],[123.22,-66.48],[124.12,-66.62],[125.16,-66.72],[126.1,-66.56],[127.0,-66.56],[127.88,-66.66],[128.8,-66.76],[129.7,-66.58],[130.78,-66.43],[131.8,-66.39],[132.94,-66.39],[133.86,-66.29],[134.76,-66.21],[135.03,-65.72],[135.07,-65.31],[135.7,-65.58],[135.87,-66.03],[136.21,-66.45],[136.62,-66.78],[137.46,-66.95],[138.6,-66.9],[139.91,-66.88],[140.81,-66.82],[142.12,-66.82],[143.06,-66.8],[144.37,-66.84],[145.49,-66.92],[146.2,-67.23],[146.0,-67.6],[146.65,-67.9],[147.72,-68.13],[148.84,-68.39],[150.13,-68.56],[151.48,-68.72],[152.5,-68.87],[153.64,-68.89],[154.28,-68.56],[155.17,-68.84],[155.93,-69.15],[156.81,-69.38],[158.03,-69.48],[159.18,-69.6],[159.67,-69.99],[160.81,-70.23],[161.57,-70.58],[162.69,-70.74],[163.84,-70.72],[164.92,-70.78],[166.11,-70.76],[167.31,-70.83],[168.43,-70.97],[169.46,-71.21],[170.5,-71.4],[171.21,-71.7],[171.09,-72.09],[170.56,-72.44],[170.11,-72.89],[169.76,-73.24],[169.29,-73.66],[167.98,-73.81],[167.39,-74.17],[166.09,-74.38],[165.64,-74.77],[164.96,-75.15],[164.23,-75.46],[163.82,-75.87],[163.57,-76.24],[163.47,-76.69],[163.49,-77.07],[164.06,-77.46],[164.27,-77.83],[164.74,-78.18],[166.6,-78.32],[167.0,-78.75],[165.19,-78.91],[163.67,-79.12],[161.77,-79.16],[160.92,-79.73],[160.75,-80.2],[160.32,-80.57],[159.79,-80.95],[161.12,-81.28],[161.63,-81.69],[162.49,-82.06],[163.71,-82.4],[165.1,-82.71],[166.6,-83.02],[168.9,-83.34],[169.4,-83.83],[172.28,-84.04],[172.48,-84.12],[173.22,-84.41],[175.99,-84.16],[178.28,-84.47],[180,-84.71],[180,-90],[-180,-90],[-180,-84.71],[-179.94,-84.72],[-179.06,-84.14],[-177.26,-84.45],[-177.14,-84.42],[-176.86,-84.33],[-176.52,-84.23],[-176.23,-84.14],[-176.08,-84.1],[-175.93,-84.1],[-175.83,-84.12],[-174.38,-84.53],[-173.12,-84.12],[-172.89,-84.06],[-169.95,-83.88],[-169.0,-84.12],[-168.53,-84.24],[-167.02,-84.57],[-164.18,-84.83],[-161.93,-85.14],[-158.07,-85.37],[-155.19,-85.1],[-150.94,-85.3],[-148.53,-85.61],[-145.89,-85.32],[-143.11,-85.04],[-142.89,-84.57],[-146.83,-84.53],[-150.06,-84.3],[-150.9,-83.9],[-153.59,-83.69],[-153.41,-83.24],[-153.04,-82.83],[-152.67,-82.45],[-152.86,-82.04],[-154.53,-81.77],[-155.29,-81.42],[-156.84,-81.1],[-154.41,-81.16],[-152.1,-81.0],[-150.65,-81.34],[-148.87,-81.04],[-147.22,-80.67],[-146.42,-80.34],[-146.77,-79.93],[-148.06,-79.65],[-149.53,-79.36],[-151.59,-79.3],[-153.39,-79.16],[-155.33,-79.06],[-155.98,-78.69],[-157.27,-78.38],[-158.05,-78.03],[-158.37,-76.89],[-157.88,-76.99],[-156.97,-77.3],[-155.33,-77.2],[-153.74,-77.07],[-152.92,-77.5],[-151.33,-77.4],[-150.0,-77.18],[-148.75,-76.91],[-147.61,-76.58],[-146.1,-76.48],[-146.14,-76.11],[-146.5,-75.73],[-146.2,-75.38],[-144.91,-75.2],[-144.32,-75.54],[-142.79,-75.34],[-141.64,-75.09],[-140.21,-75.07],[-138.86,-74.97],[-137.51,-74.73],[-136.43,-74.52],[-135.21,-74.3],[-134.43,-74.36],[-133.75,-74.44],[-132.26,-74.3],[-130.93,-74.48],[-129.55,-74.46],[-128.24,-74.32],[-126.89,-74.42],[-125.4,-74.52],[-124.01,-74.48],[-122.56,-74.5],[-121.07,-74.52],[-119.7,-74.48],[-118.68,-74.19],[-117.47,-74.03],[-116.22,-74.24],[-115.02,-74.07],[-113.94,-73.71],[-113.3,-74.03],[-112.95,-74.38],[-112.3,-74.71],[-111.26,-74.42],[-110.07,-74.79],[-108.71,-74.91],[-107.56,-75.18],[-106.15,-75.13],[-104.88,-74.95],[-103.37,-74.99],[-102.02,-75.13],[-100.65,-75.3],[-100.12,-74.87],[-100.76,-74.54],[-101.25,-74.19],[-102.55,-74.11],[-103.11,-73.73],[-103.33,-73.36],[-103.68,-72.62],[-102.92,-72.75],[-101.61,-72.81],[-100.31,-72.75],[-99.14,-72.91],[-98.12,-73.21],[-97.69,-73.56],[-96.34,-73.62],[-95.04,-73.48],[-93.67,-73.28],[-92.44,-73.17],[-91.42,-73.4],[-90.09,-73.32],[-89.23,-72.56],[-88.42,-73.01],[-87.27,-73.19],[-86.01,-73.09],[-85.19,-73.48],[-83.88,-73.52],[-82.67,-73.64],[-81.47,-73.85],[-80.69,-73.48],[-80.3,-73.13],[-79.3,-73.52],[-77.93,-73.42],[-76.91,-73.64],[-76.22,-73.97],[-74.89,-73.87],[-73.85,-73.66],[-72.83,-73.4],[-71.62,-73.26],[-70.21,-73.15],[-68.94,-73.01],[-67.96,-72.79],[-67.37,-72.48],[-67.13,-72.05],[-67.25,-71.64],[-67.56,-71.25],[-67.92,-70.85],[-68.23,-70.46],[-68.49,-70.11],[-68.54,-69.72],[-68.45,-69.33],[-67.98,-68.95],[-67.58,-68.54],[-67.43,-68.15],[-67.62,-67.72],[-67.74,-67.33],[-67.25,-66.88],[-66.7,-66.58],[-66.06,-66.21],[-65.37,-65.9],[-64.57,-65.6],[-64.18,-65.17],[-63.63,-64.9],[-63.0,-64.64],[-62.04,-64.58],[-61.41,-64.27],[-60.71,-64.07],[-59.89,-63.96],[-59.16,-63.7],[-58.59,-63.39],[-57.81,-63.27],[-57.22,-63.53],[-57.6,-63.86],[-58.61,-64.15]]]},{"type":"Polygon","coordinates":[[[-67.75,-53.85],[-66.45,-54.45],[-65.05,-54.7],[-65.5,-55.2],[-66.45,-55.25],[-66.96,-54.9],[-67.29,-55.3],[-68.15,-55.61],[-69.23,-55.5],[-69.96,-55.2],[-71.01,-55.05],[-72.26,-54.5],[-73.29,-53.96],[-74.66,-52.84],[-73.84,-53.05],[-72.43,-53.72],[-71.11,-54.07],[-70.59,-53.62],[-70.27,-52.93],[-69.35,-52.52],[-68.63,-52.64],[-68.63,-52.64],[-68.25,-53.1],[-67.75,-53.85]]]},{"type":"Polygon","coordinates":[[[-58.55,-51.1],[-57.75,-51.55],[-58.05,-51.9],[-59.4,-52.2],[-59.85,-51.85],[-60.7,-52.3],[-61.2,-51.85],[-60,-51.25],[-59.15,-51.5],[-58.55,-51.1]]]},{"type":"Polygon","coordinates":[[[70.28,-49.71],[68.75,-49.77],[68.72,-49.24],[68.87,-48.83],[68.94,-48.62],[69.58,-48.94],[70.53,-49.06],[70.56,-49.26],[70.28,-49.71]]]},{"type":"Polygon","coordinates":[[[145.4,-40.79],[146.36,-41.14],[146.91,-41.0],[147.69,-40.81],[148.29,-40.88],[148.36,-42.06],[148.02,-42.41],[147.91,-43.21],[147.56,-42.94],[146.87,-43.63],[146.66,-43.58],[146.05,-43.55],[145.43,-42.69],[145.3,-42.03],[144.72,-41.16],[144.74,-40.7],[145.4,-40.79]]]},{"type":"Polygon","coordinates":[[[173.02,-40.92],[173.25,-41.33],[173.96,-40.93],[174.25,-41.35],[174.25,-41.77],[173.88,-42.23],[173.22,-42.97],[172.71,-43.37],[173.08,-43.85],[172.31,-43.87],[171.45,-44.24],[171.19,-44.9],[170.62,-45.91],[169.83,-46.36],[169.33,-46.64],[168.41,-46.62],[167.76,-46.29],[166.68,-46.22],[166.51,-45.85],[167.05,-45.11],[168.3,-44.12],[168.95,-43.94],[169.67,-43.56],[170.52,-43.03],[171.13,-42.51],[171.57,-41.77],[171.95,-41.51],[172.1,-40.96],[172.8,-40.49],[173.02,-40.92]]]},{"type":"Polygon","coordinates":[[[174.61,-36.16],[175.34,-37.21],[175.36,-36.53],[175.81,-36.8],[175.96,-37.56],[176.76,-37.88],[177.44,-37.96],[178.01,-37.58],[178.52,-37.7],[178.27,-38.58],[177.97,-39.17],[177.21,-39.15],[176.94,-39.45],[177.03,-39.88],[176.89,-40.07],[176.51,-40.6],[176.01,-41.29],[175.24,-41.69],[175.07,-41.43],[174.65,-41.28],[175.23,-40.46],[174.9,-39.91],[173.82,-39.51],[173.85,-39.15],[174.57,-38.8],[174.74,-38.03],[174.7,-37.38],[174.29,-36.71],[174.32,-36.53],[173.84,-36.12],[173.05,-35.24],[172.64,-34.53],[173.01,-34.45],[173.55,-35.01],[174.33,-35.27],[174.61,-36.16]]]},{"type":"Polygon","coordinates":[[[167.12,-22.16],[166.74,-22.4],[166.19,-22.13],[165.47,-21.68],[164.83,-21.15],[164.17,-20.44],[164.03,-20.11],[164.46,-20.12],[165.02,-20.46],[165.46,-20.8],[165.78,-21.08],[166.6,-21.7],[167.12,-22.16]]]},{"type":"Polygon","coordinates":[[[178.37,-17.34],[178.72,-17.63],[178.55,-18.15],[177.93,-18.29],[177.38,-18.16],[177.29,-17.72],[177.67,-17.38],[178.13,-17.5],[178.37,-17.34]]]},{"type":"Polygon","coordinates":[[[179.36,-16.8],[178.73,-17.01],[178.6,-16.64],[179.1,-16.43],[179.41,-16.38],[180,-16.07],[180,-16.56],[179.36,-16.8]]]},{"type":"Polygon","coordinates":[[[-179.92,-16.5],[-180,-16.56],[-180,-16.07],[-179.79,-16.02],[-179.92,-16.5]]]},{"type":"Polygon","coordinates":[[[167.84,-16.47],[167.52,-16.6],[167.18,-16.16],[167.22,-15.89],[167.84,-16.47]]]},{"type":"Polygon","coordinates":[[[167.11,-14.93],[167.27,-15.74],[167.0,-15.61],[166.79,-15.67],[166.65,-15.39],[166.63,-14.63],[167.11,-14.93]]]},{"type":"Polygon","coordinates":[[[50.06,-13.56],[50.22,-14.76],[50.48,-15.23],[50.38,-15.71],[50.2,-16.0],[49.86,-15.41],[49.67,-15.71],[49.86,-16.45],[49.77,-16.88],[49.5,-17.11],[49.44,-17.95],[49.04,-19.12],[48.55,-20.5],[47.93,-22.39],[47.55,-23.78],[47.1,-24.94],[46.28,-25.18],[45.41,-25.6],[44.83,-25.35],[44.04,-24.99],[43.76,-24.46],[43.7,-23.57],[43.35,-22.78],[43.25,-22.06],[43.43,-21.34],[43.89,-21.16],[43.9,-20.83],[44.37,-20.07],[44.46,-19.44],[44.23,-18.96],[44.04,-18.33],[43.96,-17.41],[44.31,-16.85],[44.45,-16.22],[44.94,-16.18],[45.5,-15.97],[45.87,-15.79],[46.31,-15.78],[46.88,-15.21],[47.71,-14.59],[48.01,-14.09],[47.87,-13.66],[48.29,-13.78],[48.85,-13.09],[48.86,-12.49],[49.19,-12.04],[49.54,-12.47],[49.81,-12.9],[50.06,-13.56]]]},{"type":"Polygon","coordinates":[[[143.56,-13.76],[143.92,-14.55],[144.56,-14.17],[144.89,-14.59],[145.37,-14.98],[145.27,-15.43],[145.49,-16.29],[145.64,-16.78],[145.89,-16.91],[146.16,-17.76],[146.06,-18.28],[146.39,-18.96],[147.47,-19.48],[148.18,-19.96],[148.85,-20.39],[148.72,-20.63],[149.29,-21.26],[149.68,-22.34],[150.08,-22.12],[150.48,-22.56],[150.73,-22.4],[150.9,-23.46],[151.61,-24.08],[152.07,-24.46],[152.86,-25.27],[153.14,-26.07],[153.16,-26.64],[153.09,-27.26],[153.57,-28.11],[153.51,-29.0],[153.34,-29.46],[153.07,-30.35],[153.09,-30.92],[152.89,-31.64],[152.45,-32.55],[151.71,-33.04],[151.34,-33.82],[151.01,-34.31],[150.71,-35.17],[150.33,-35.67],[150.08,-36.42],[149.95,-37.11],[150.0,-37.43],[149.42,-37.77],[148.3,-37.81],[147.38,-38.22],[146.92,-38.61],[146.32,-39.04],[145.49,-38.59],[144.88,-38.42],[145.03,-37.9],[144.49,-38.09],[143.61,-38.81],[142.75,-38.54],[142.18,-38.38],[141.61,-38.31],[140.64,-38.02],[139.99,-37.4],[139.81,-36.64],[139.57,-36.14],[139.08,-35.73],[138.12,-35.61],[138.45,-35.13],[138.21,-34.38],[137.72,-35.08],[136.83,-35.26],[137.35,-34.71],[137.5,-34.13],[137.89,-33.64],[137.81,-32.9],[137.0,-33.75],[136.37,-34.09],[135.99,-34.89],[135.21,-34.48],[135.24,-33.95],[134.61,-33.22],[134.09,-32.85],[134.27,-32.62],[132.99,-32.01],[132.29,-31.98],[131.33,-31.5],[129.54,-31.59],[128.24,-31.95],[127.1,-32.28],[126.15,-32.22],[125.09,-32.73],[124.22,-32.96],[124.03,-33.48],[123.66,-33.89],[122.81,-33.91],[122.18,-34.0],[121.3,-33.82],[120.58,-33.93],[119.89,-33.98],[119.3,-34.51],[119.01,-34.46],[118.51,-34.75],[118.02,-35.06],[117.3,-35.03],[116.63,-35.03],[115.56,-34.39],[115.03,-34.2],[115.05,-33.62],[115.55,-33.49],[115.71,-33.26],[115.68,-32.9],[115.8,-32.21],[115.69,-31.61],[115.16,-30.6],[115.0,-30.03],[115.04,-29.46],[114.64,-28.81],[114.62,-28.52],[114.17,-28.12],[114.05,-27.33],[113.48,-26.54],[113.34,-26.12],[113.78,-26.55],[113.44,-25.62],[113.94,-25.91],[114.23,-26.3],[114.22,-25.79],[113.72,-25.0],[113.63,-24.68],[113.39,-24.38],[113.5,-23.81],[113.71,-23.56],[113.84,-23.06],[113.74,-22.48],[114.15,-21.76],[114.23,-22.52],[114.65,-21.83],[115.46,-21.5],[115.95,-21.07],[116.71,-20.7],[117.17,-20.62],[117.44,-20.75],[118.23,-20.37],[118.84,-20.26],[118.99,-20.04],[119.25,-19.95],[119.81,-19.98],[120.86,-19.68],[121.4,-19.24],[121.66,-18.71],[122.24,-18.2],[122.29,-17.8],[122.31,-17.25],[123.01,-16.41],[123.43,-17.27],[123.86,-17.07],[123.5,-16.6],[123.82,-16.11],[124.26,-16.33],[124.38,-15.57],[124.93,-15.08],[125.17,-14.68],[125.67,-14.51],[125.69,-14.23],[126.13,-14.35],[126.14,-14.1],[126.58,-13.95],[127.07,-13.82],[127.8,-14.28],[128.36,-14.87],[128.99,-14.88],[129.62,-14.97],[129.41,-14.42],[129.89,-13.62],[130.34,-13.36],[130.18,-13.11],[130.62,-12.54],[131.22,-12.18],[131.74,-12.3],[132.58,-12.11],[132.56,-11.6],[131.82,-11.27],[132.36,-11.13],[133.02,-11.38],[133.55,-11.79],[134.39,-12.04],[134.68,-11.94],[135.3,-12.25],[135.88,-11.96],[136.26,-12.05],[136.49,-11.86],[136.95,-12.35],[136.69,-12.89],[136.31,-13.29],[135.96,-13.32],[136.08,-13.72],[135.78,-14.22],[135.43,-14.72],[135.5,-15.0],[136.3,-15.55],[137.07,-15.87],[137.58,-16.22],[138.3,-16.81],[138.59,-16.81],[139.11,-17.06],[139.26,-17.37],[140.22,-17.71],[140.88,-17.37],[141.07,-16.83],[141.27,-16.39],[141.4,-15.84],[141.7,-15.04],[141.56,-14.56],[141.64,-14.27],[141.52,-13.7],[141.65,-12.94],[141.84,-12.74],[141.69,-12.41],[141.93,-11.88],[142.12,-11.33],[142.14,-11.04],[142.52,-10.67],[142.8,-11.16],[142.87,-11.78],[143.12,-11.91],[143.16,-12.33],[143.52,-12.83],[143.6,-13.4],[143.56,-13.76]]]},{"type":"Polygon","coordinates":[[[162.12,-10.48],[162.4,-10.83],[161.7,-10.82],[161.32,-10.2],[161.92,-10.45],[162.12,-10.48]]]},{"type":"Polygon","coordinates":[[[120.72,-10.24],[120.3,-10.26],[118.97,-9.56],[119.9,-9.36],[120.43,-9.67],[120.78,-9.97],[120.72,-10.24]]]},{"type":"Polygon","coordinates":[[[160.85,-9.87],[160.46,-9.9],[159.85,-9.79],[159.64,-9.64],[159.7,-9.24],[160.36,-9.4],[160.69,-9.61],[160.85,-9.87]]]},{"type":"Polygon","coordinates":[[[161.68,-9.6],[161.53,-9.78],[160.79,-8.92],[160.58,-8.32],[160.92,-8.32],[161.28,-9.12],[161.68,-9.6]]]},{"type":"Polygon","coordinates":[[[124.44,-10.14],[123.58,-10.36],[123.46,-10.24],[123.55,-9.9],[123.98,-9.29],[124.97,-8.89],[125.09,-8.66],[125.95,-8.43],[126.64,-8.4],[126.96,-8.27],[127.34,-8.4],[126.97,-8.67],[125.93,-9.11],[125.09,-9.39],[124.44,-10.14]]]},{"type":"Polygon","coordinates":[[[117.9,-8.1],[118.26,-8.36],[118.88,-8.28],[119.13,-8.71],[117.97,-8.91],[117.28,-9.04],[116.74,-9.03],[117.08,-8.46],[117.63,-8.45],[117.9,-8.1]]]},{"type":"Polygon","coordinates":[[[122.9,-8.09],[122.76,-8.65],[121.25,-8.93],[119.92,-8.81],[119.92,-8.44],[120.72,-8.24],[121.34,-8.54],[122.01,-8.46],[122.9,-8.09]]]},{"type":"Polygon","coordinates":[[[159.88,-8.34],[159.92,-8.54],[159.13,-8.11],[158.59,-7.75],[158.21,-7.42],[158.36,-7.32],[158.82,-7.56],[159.64,-8.02],[159.88,-8.34]]]},{"type":"Polygon","coordinates":[[[157.54,-7.35],[157.34,-7.4],[156.9,-7.18],[156.49,-6.77],[156.54,-6.6],[157.14,-7.02],[157.54,-7.35]]]},{"type":"Polygon","coordinates":[[[108.62,-6.78],[110.54,-6.88],[110.76,-6.47],[112.61,-6.95],[112.98,-7.59],[114.48,-7.78],[115.71,-8.37],[114.56,-8.75],[113.46,-8.35],[112.56,-8.38],[111.52,-8.3],[110.59,-8.12],[109.43,-7.74],[108.69,-7.64],[108.28,-7.77],[106.45,-7.35],[106.28,-6.92],[105.37,-6.85],[106.05,-5.9],[107.27,-5.95],[108.07,-6.35],[108.49,-6.42],[108.62,-6.78]]]},{"type":"Polygon","coordinates":[[[134.72,-6.21],[134.21,-6.9],[134.11,-6.14],[134.29,-5.78],[134.5,-5.45],[134.73,-5.74],[134.72,-6.21]]]},{"type":"Polygon","coordinates":[[[155.88,-6.82],[155.6,-6.92],[155.17,-6.54],[154.73,-5.9],[154.51,-5.14],[154.65,-5.04],[154.76,-5.34],[155.06,-5.57],[155.55,-6.2],[156.02,-6.54],[155.88,-6.82]]]},{"type":"Polygon","coordinates":[[[151.98,-5.48],[151.46,-5.56],[151.3,-5.84],[150.75,-6.08],[150.24,-6.32],[149.71,-6.32],[148.89,-6.03],[148.32,-5.75],[148.4,-5.44],[149.3,-5.58],[149.85,-5.51],[150.0,-5.03],[150.14,-5.0],[150.24,-5.53],[150.81,-5.46],[151.09,-5.11],[151.65,-4.76],[151.54,-4.17],[152.14,-4.15],[152.34,-4.31],[152.32,-4.87],[151.98,-5.48]]]},{"type":"Polygon","coordinates":[[[127.25,-3.46],[126.87,-3.79],[126.18,-3.61],[125.99,-3.18],[127.0,-3.13],[127.25,-3.46]]]},{"type":"Polygon","coordinates":[[[130.47,-3.09],[130.83,-3.86],[129.99,-3.45],[129.16,-3.36],[128.59,-3.43],[127.9,-3.39],[128.14,-2.84],[129.37,-2.8],[130.47,-3.09]]]},{"type":"Polygon","coordinates":[[[153.14,-4.5],[152.83,-4.77],[152.64,-4.18],[152.41,-3.79],[151.95,-3.46],[151.38,-3.04],[150.66,-2.74],[150.94,-2.5],[151.48,-2.78],[151.82,-3.0],[152.24,-3.24],[152.64,-3.66],[153.02,-3.98],[153.14,-4.5]]]},{"type":"Polygon","coordinates":[[[134.14,-1.15],[134.42,-2.77],[135.46,-3.37],[136.29,-2.31],[137.44,-1.7],[138.33,-1.7],[139.18,-2.05],[139.93,-2.41],[141.0,-2.6],[142.74,-3.29],[144.58,-3.86],[145.27,-4.37],[145.83,-4.88],[145.98,-5.47],[147.65,-6.08],[147.89,-6.61],[146.97,-6.72],[147.19,-7.39],[148.08,-8.04],[148.73,-9.1],[149.31,-9.07],[149.27,-9.51],[150.04,-9.68],[149.74,-9.87],[150.8,-10.29],[150.69,-10.58],[150.03,-10.65],[149.78,-10.39],[148.92,-10.28],[147.91,-10.13],[147.14,-9.49],[146.57,-8.94],[146.05,-8.07],[144.74,-7.63],[143.9,-7.92],[143.29,-8.25],[143.41,-8.98],[142.63,-9.33],[142.07,-9.16],[141.03,-9.12],[140.14,-8.3],[139.13,-8.1],[138.88,-8.38],[137.61,-8.41],[138.04,-7.6],[138.67,-7.32],[138.41,-6.23],[137.93,-5.39],[135.99,-4.55],[135.16,-4.46],[133.66,-3.54],[133.37,-4.02],[132.98,-4.11],[132.76,-3.75],[132.75,-3.31],[131.99,-2.82],[133.07,-2.46],[133.78,-2.48],[133.7,-2.21],[132.23,-2.21],[131.84,-1.62],[130.94,-1.43],[130.52,-0.94],[131.87,-0.7],[132.38,-0.37],[133.99,-0.78],[134.14,-1.15]]]},{"type":"Polygon","coordinates":[[[125.24,1.42],[124.44,0.43],[123.69,0.24],[122.72,0.43],[121.06,0.38],[120.18,0.24],[120.04,-0.52],[120.94,-1.41],[121.48,-0.96],[123.34,-0.62],[123.26,-1.08],[122.82,-0.93],[122.39,-1.52],[121.51,-1.9],[122.45,-3.19],[122.27,-3.53],[123.17,-4.68],[123.16,-5.34],[122.63,-5.63],[122.24,-5.28],[122.72,-4.46],[121.74,-4.85],[121.49,-4.57],[121.62,-4.19],[120.9,-3.6],[120.97,-2.63],[120.31,-2.93],[120.39,-4.1],[120.43,-5.53],[119.8,-5.67],[119.37,-5.38],[119.65,-4.46],[119.5,-3.49],[119.08,-3.49],[118.77,-2.8],[119.18,-2.15],[119.32,-1.35],[119.83,0.15],[120.04,0.57],[120.89,1.31],[121.67,1.01],[122.93,0.88],[124.08,0.92],[125.07,1.64],[125.24,1.42]]]},{"type":"Polygon","coordinates":[[[128.69,1.13],[128.64,0.26],[128.12,0.36],[127.97,-0.25],[128.38,-0.78],[128.1,-0.9],[127.7,-0.27],[127.4,1.01],[127.6,1.81],[127.93,2.17],[128.0,1.63],[128.59,1.54],[128.69,1.13]]]},{"type":"Polygon","coordinates":[[[105.82,-5.85],[104.71,-5.87],[103.87,-5.04],[102.58,-4.22],[102.16,-3.61],[101.4,-2.8],[100.9,-2.05],[100.14,-0.65],[99.26,0.18],[98.97,1.04],[98.6,1.82],[97.7,2.45],[97.18,3.31],[96.42,3.87],[95.38,4.97],[95.29,5.48],[95.94,5.44],[97.48,5.25],[98.37,4.27],[99.14,3.59],[99.69,3.17],[100.64,2.1],[101.66,2.08],[102.5,1.4],[103.08,0.56],[103.84,0.1],[103.44,-0.71],[104.01,-1.06],[104.37,-1.08],[104.54,-1.78],[104.89,-2.34],[105.62,-2.43],[106.11,-3.06],[105.86,-4.31],[105.82,-5.85]]]},{"type":"Polygon","coordinates":[[[117.88,1.83],[119.0,0.9],[117.81,0.78],[117.48,0.1],[117.52,-0.8],[116.56,-1.49],[116.53,-2.48],[116.15,-4.01],[116.0,-3.66],[114.86,-4.11],[114.47,-3.5],[113.76,-3.44],[113.26,-3.12],[112.07,-3.48],[111.7,-2.99],[111.05,-3.05],[110.22,-2.93],[110.07,-1.59],[109.57,-1.31],[109.09,-0.46],[108.95,0.42],[109.07,1.34],[109.66,2.01],[110.4,1.66],[111.17,1.85],[111.37,2.7],[111.8,2.89],[113.0,3.1],[113.71,3.89],[114.2,4.53],[114.6,4.9],[115.45,5.45],[116.22,6.14],[116.73,6.92],[117.13,6.93],[117.64,6.42],[117.69,5.99],[118.35,5.71],[119.18,5.41],[119.11,5.02],[118.44,4.97],[118.62,4.48],[117.88,4.14],[117.31,3.23],[118.05,2.29],[117.88,1.83]]]},{"type":"Polygon","coordinates":[[[126.38,8.41],[126.48,7.75],[126.54,7.19],[126.2,6.27],[125.83,7.29],[125.36,6.79],[125.68,6.05],[125.4,5.58],[124.22,6.16],[123.94,6.89],[124.24,7.36],[123.61,7.83],[123.3,7.42],[122.83,7.46],[122.09,6.9],[121.92,7.19],[122.31,8.03],[122.94,8.32],[123.49,8.69],[123.84,8.24],[124.6,8.51],[124.76,8.96],[125.47,8.99],[125.41,9.76],[126.22,9.29],[126.31,8.78],[126.38,8.41]]]},{"type":"Polygon","coordinates":[[[81.22,6.2],[80.35,5.97],[79.87,6.76],[79.7,8.2],[80.15,9.82],[80.84,9.27],[81.3,8.56],[81.79,7.52],[81.64,6.48],[81.22,6.2]]]},{"type":"Polygon","coordinates":[[[-60.94,10.11],[-61.77,10],[-61.95,10.09],[-61.66,10.37],[-61.68,10.76],[-61.1,10.89],[-60.9,10.86],[-60.94,10.11]]]},{"type":"Polygon","coordinates":[[[123.98,10.28],[123.62,9.95],[123.31,9.32],[123.0,9.02],[122.38,9.71],[122.59,9.98],[122.84,10.26],[122.95,10.88],[123.5,10.94],[123.34,10.27],[124.08,11.23],[123.98,10.28]]]},{"type":"Polygon","coordinates":[[[118.5,9.32],[117.17,8.37],[117.66,9.07],[118.39,9.68],[118.99,10.38],[119.51,11.37],[119.69,10.55],[119.03,10.0],[118.5,9.32]]]},{"type":"Polygon","coordinates":[[[121.88,11.89],[122.48,11.58],[123.12,11.58],[123.1,11.17],[122.64,10.74],[122.0,10.44],[121.97,10.91],[122.04,11.42],[121.88,11.89]]]},{"type":"Polygon","coordinates":[[[125.5,12.16],[125.78,11.05],[125.01,11.31],[125.03,10.98],[125.28,10.36],[124.8,10.13],[124.76,10.84],[124.46,10.89],[124.3,11.5],[124.89,11.42],[124.88,11.79],[124.27,12.56],[125.23,12.54],[125.5,12.16]]]},{"type":"Polygon","coordinates":[[[121.53,13.07],[121.26,12.21],[120.83,12.7],[120.32,13.47],[121.18,13.43],[121.53,13.07]]]},{"type":"Polygon","coordinates":[[[121.32,18.5],[121.94,18.22],[122.25,18.48],[122.34,18.22],[122.17,17.81],[122.52,17.09],[122.25,16.26],[121.66,15.93],[121.51,15.12],[121.73,14.33],[122.26,14.22],[122.7,14.34],[123.95,13.78],[123.86,13.24],[124.18,13.0],[124.08,12.54],[123.3,13.03],[122.93,13.55],[122.67,13.19],[122.03,13.78],[121.13,13.64],[120.63,13.86],[120.68,14.27],[120.99,14.53],[120.69,14.76],[120.56,14.4],[120.07,14.97],[119.92,15.41],[119.88,16.36],[120.29,16.03],[120.39,17.6],[120.72,18.51],[121.32,18.5]]]},{"type":"Polygon","coordinates":[[[-65.59,18.23],[-65.85,17.98],[-66.6,17.98],[-67.18,17.95],[-67.24,18.37],[-67.1,18.52],[-66.28,18.51],[-65.77,18.43],[-65.59,18.23]]]},{"type":"Polygon","coordinates":[[[-76.9,17.87],[-77.21,17.7],[-77.77,17.86],[-78.34,18.23],[-78.22,18.45],[-77.8,18.52],[-77.57,18.49],[-76.9,18.4],[-76.37,18.16],[-76.2,17.89],[-76.9,17.87]]]},{"type":"Polygon","coordinates":[[[-72.58,19.87],[-71.71,19.71],[-71.59,19.88],[-70.81,19.88],[-70.21,19.62],[-69.95,19.65],[-69.77,19.29],[-69.22,19.31],[-69.25,19.02],[-68.81,18.98],[-68.32,18.61],[-68.69,18.21],[-69.16,18.42],[-69.62,18.38],[-69.95,18.43],[-70.13,18.25],[-70.52,18.18],[-70.67,18.43],[-71.0,18.28],[-71.4,17.6],[-71.66,17.76],[-71.71,18.04],[-72.37,18.21],[-72.84,18.15],[-73.45,18.22],[-73.92,18.03],[-74.46,18.34],[-74.37,18.66],[-73.45,18.53],[-72.69,18.45],[-72.33,18.67],[-72.79,19.1],[-72.78,19.48],[-73.42,19.64],[-73.19,19.92],[-72.58,19.87]]]},{"type":"Polygon","coordinates":[[[110.34,18.68],[109.48,18.2],[108.66,18.51],[108.63,19.37],[109.12,19.82],[110.21,20.1],[110.79,20.08],[111.01,19.7],[110.57,19.26],[110.34,18.68]]]},{"type":"Polygon","coordinates":[[[-155.54,19.08],[-155.69,18.92],[-155.94,19.06],[-155.91,19.34],[-156.07,19.7],[-156.02,19.81],[-155.85,19.98],[-155.92,20.17],[-155.86,20.27],[-155.79,20.25],[-155.4,20.08],[-155.22,19.99],[-155.06,19.86],[-154.81,19.51],[-154.83,19.45],[-155.22,19.24],[-155.54,19.08]]]},{"type":"Polygon","coordinates":[[[-156.08,20.64],[-156.41,20.57],[-156.59,20.78],[-156.7,20.86],[-156.71,20.93],[-156.61,21.01],[-156.26,20.92],[-156.0,20.76],[-156.08,20.64]]]},{"type":"Polygon","coordinates":[[[-156.76,21.18],[-156.79,21.07],[-157.33,21.1],[-157.25,21.22],[-156.76,21.18]]]},{"type":"Polygon","coordinates":[[[-157.65,21.32],[-157.71,21.26],[-157.78,21.28],[-158.13,21.31],[-158.25,21.54],[-158.29,21.58],[-158.03,21.72],[-157.94,21.65],[-157.65,21.32]]]},{"type":"Polygon","coordinates":[[[-159.35,21.98],[-159.46,21.88],[-159.8,22.07],[-159.75,22.14],[-159.6,22.24],[-159.37,22.21],[-159.35,21.98]]]},{"type":"Polygon","coordinates":[[[-79.68,22.77],[-79.28,22.4],[-78.35,22.51],[-77.99,22.28],[-77.15,21.66],[-76.52,21.21],[-76.19,21.22],[-75.6,21.02],[-75.67,20.74],[-74.93,20.69],[-74.18,20.28],[-74.3,20.05],[-74.96,19.92],[-75.63,19.87],[-76.32,19.95],[-77.76,19.86],[-77.09,20.41],[-77.49,20.67],[-78.14,20.74],[-78.48,21.03],[-78.72,21.6],[-79.28,21.56],[-80.22,21.83],[-80.52,22.04],[-81.82,22.19],[-82.17,22.39],[-81.8,22.64],[-82.78,22.69],[-83.49,22.17],[-83.91,22.15],[-84.05,21.91],[-84.55,21.8],[-84.97,21.9],[-84.45,22.2],[-84.23,22.57],[-83.78,22.79],[-83.27,22.98],[-82.51,23.08],[-82.27,23.19],[-81.4,23.12],[-80.62,23.11],[-79.68,22.77]]]},{"type":"Polygon","coordinates":[[[-77.53,23.76],[-77.78,23.71],[-78.03,24.29],[-78.41,24.58],[-78.19,25.21],[-77.89,25.17],[-77.54,24.34],[-77.53,23.76]]]},{"type":"Polygon","coordinates":[[[121.18,22.79],[120.75,21.97],[120.22,22.81],[120.11,23.56],[120.69,24.54],[121.5,25.3],[121.95,25.0],[121.78,24.39],[121.18,22.79]]]},{"type":"Polygon","coordinates":[[[-77.82,26.58],[-78.91,26.42],[-78.98,26.79],[-78.51,26.87],[-77.85,26.84],[-77.82,26.58]]]},{"type":"Polygon","coordinates":[[[-77,26.59],[-77.17,25.88],[-77.36,26.01],[-77.34,26.53],[-77.79,26.93],[-77.79,27.04],[-77,26.59]]]},{"type":"Polygon","coordinates":[[[134.64,34.15],[134.77,33.81],[134.2,33.2],[133.79,33.52],[133.28,33.29],[133.01,32.7],[132.36,32.99],[132.37,33.46],[132.92,34.06],[133.49,33.94],[133.9,34.36],[134.64,34.15]]]},{"type":"Polygon","coordinates":[[[34.58,35.67],[33.9,35.25],[33.97,35.06],[34.0,34.98],[32.98,34.57],[32.49,34.7],[32.26,35.1],[32.73,35.14],[32.8,35.15],[32.95,35.39],[33.67,35.37],[34.58,35.67]]]},{"type":"Polygon","coordinates":[[[23.7,35.71],[24.25,35.37],[25.03,35.42],[25.77,35.35],[25.75,35.18],[26.29,35.3],[26.16,35.0],[24.72,34.92],[24.74,35.08],[23.51,35.28],[23.7,35.71]]]},{"type":"Polygon","coordinates":[[[15.52,38.23],[15.16,37.44],[15.31,37.13],[15.1,36.62],[14.34,37.0],[13.83,37.1],[12.43,37.61],[12.57,38.13],[13.74,38.03],[14.76,38.14],[15.52,38.23]]]},{"type":"Polygon","coordinates":[[[9.21,41.21],[9.81,40.5],[9.67,39.18],[9.21,39.24],[8.81,38.91],[8.43,39.17],[8.39,40.38],[8.16,40.95],[8.71,40.9],[9.21,41.21]]]},{"type":"Polygon","coordinates":[[[140.98,37.14],[140.6,36.34],[140.77,35.84],[140.25,35.14],[138.98,34.67],[137.22,34.61],[135.79,33.46],[135.12,33.85],[135.08,34.6],[133.34,34.38],[132.16,33.9],[130.99,33.89],[132.0,33.15],[131.33,31.45],[130.69,31.03],[130.2,31.42],[130.45,32.32],[129.81,32.61],[129.41,33.3],[130.35,33.6],[130.88,34.23],[131.88,34.75],[132.62,35.43],[134.61,35.73],[135.68,35.53],[136.72,37.3],[137.39,36.83],[138.86,37.83],[139.43,38.22],[140.05,39.44],[139.88,40.56],[140.31,41.2],[141.37,41.38],[141.91,39.99],[141.88,39.18],[140.96,38.17],[140.98,37.14]]]},{"type":"Polygon","coordinates":[[[9.56,42.15],[9.23,41.38],[8.78,41.58],[8.54,42.26],[8.75,42.63],[9.39,43.01],[9.56,42.15]]]},{"type":"Polygon","coordinates":[[[143.91,44.17],[144.61,43.96],[145.32,44.38],[145.54,43.26],[144.06,42.99],[143.18,42.0],[141.61,42.68],[141.07,41.58],[139.96,41.57],[139.82,42.56],[140.31,43.33],[141.38,43.39],[141.67,44.77],[141.97,45.55],[143.14,44.51],[143.91,44.17]]]},{"type":"Polygon","coordinates":[[[-63.66,46.55],[-62.94,46.42],[-62.01,46.44],[-62.5,46.03],[-62.87,45.97],[-64.14,46.39],[-64.39,46.73],[-64.01,47.04],[-63.66,46.55]]]},{"type":"Polygon","coordinates":[[[-61.81,49.11],[-62.29,49.09],[-63.59,49.4],[-64.52,49.87],[-64.17,49.96],[-62.86,49.71],[-61.84,49.29],[-61.81,49.11]]]},{"type":"Polygon","coordinates":[[[-123.51,48.51],[-124.01,48.37],[-125.66,48.83],[-125.95,49.18],[-126.85,49.53],[-127.03,49.81],[-128.06,49.99],[-128.44,50.54],[-128.36,50.77],[-127.31,50.55],[-126.7,50.4],[-125.76,50.3],[-125.42,49.95],[-124.92,49.48],[-123.92,49.06],[-123.51,48.51]]]},{"type":"Polygon","coordinates":[[[-56.13,50.69],[-56.8,49.81],[-56.14,50.15],[-55.47,49.94],[-55.82,49.59],[-54.94,49.31],[-54.47,49.56],[-53.48,49.25],[-53.79,48.52],[-53.09,48.69],[-52.96,48.16],[-52.65,47.54],[-53.07,46.66],[-53.52,46.62],[-54.18,46.81],[-53.96,47.63],[-54.24,47.75],[-55.4,46.88],[-56.0,46.92],[-55.29,47.39],[-56.25,47.63],[-57.33,47.57],[-59.27,47.6],[-59.42,47.9],[-58.8,48.25],[-59.23,48.52],[-58.39,49.13],[-57.36,50.72],[-56.74,51.29],[-55.87,51.63],[-55.41,51.59],[-55.6,51.32],[-56.13,50.69]]]},{"type":"Polygon","coordinates":[[[-132.71,54.04],[-132.71,54.04],[-132.71,54.04],[-132.71,54.04],[-131.75,54.12],[-132.05,52.98],[-131.18,52.18],[-131.58,52.18],[-132.18,52.64],[-132.55,53.1],[-133.05,53.41],[-133.24,53.85],[-133.18,54.17],[-132.71,54.04]]]},{"type":"Polygon","coordinates":[[[143.65,50.75],[144.65,48.98],[143.17,49.31],[142.56,47.86],[143.53,46.84],[143.51,46.14],[142.75,46.74],[142.09,45.97],[141.91,46.81],[142.02,47.78],[141.9,48.86],[142.14,49.62],[142.18,50.95],[141.59,51.94],[141.68,53.3],[142.61,53.76],[142.21,54.23],[142.65,54.37],[142.91,53.7],[143.26,52.74],[143.24,51.76],[143.65,50.75]]]},{"type":"Polygon","coordinates":[[[-6.79,52.26],[-8.56,51.67],[-9.98,51.82],[-9.17,52.86],[-9.69,53.88],[-8.33,54.66],[-7.57,55.13],[-6.73,55.17],[-5.66,54.55],[-6.2,53.87],[-6.03,53.15],[-6.79,52.26]]]},{"type":"Polygon","coordinates":[[[12.69,55.61],[12.09,54.8],[11.04,55.36],[10.9,55.78],[12.37,56.11],[12.69,55.61]]]},{"type":"Polygon","coordinates":[[[-153.01,57.12],[-154.01,56.73],[-154.52,56.99],[-154.67,57.46],[-153.76,57.82],[-153.23,57.97],[-152.56,57.9],[-152.14,57.59],[-153.01,57.12]]]},{"type":"Polygon","coordinates":[[[-3.01,58.63],[-4.07,57.55],[-3.06,57.69],[-1.96,57.68],[-2.22,56.87],[-3.12,55.97],[-2.09,55.91],[-1.11,54.62],[-0.43,54.46],[0.18,53.33],[0.47,52.93],[1.68,52.74],[1.56,52.1],[1.05,51.81],[1.45,51.29],[0.55,50.77],[-0.79,50.77],[-2.49,50.5],[-2.96,50.7],[-3.62,50.23],[-4.54,50.34],[-5.25,49.96],[-5.78,50.16],[-4.31,51.21],[-3.41,51.43],[-4.98,51.59],[-5.27,51.99],[-4.22,52.3],[-4.77,52.84],[-4.58,53.5],[-3.09,53.4],[-2.95,53.98],[-3.63,54.62],[-4.84,54.79],[-5.08,55.06],[-4.72,55.51],[-5.05,55.78],[-5.59,55.31],[-5.64,56.28],[-6.15,56.79],[-5.79,57.82],[-5.01,58.63],[-4.21,58.55],[-3.01,58.63]]]},{"type":"Polygon","coordinates":[[[-165.58,59.91],[-166.19,59.75],[-166.85,59.94],[-167.46,60.21],[-166.47,60.38],[-165.67,60.29],[-165.58,59.91]]]},{"type":"Polygon","coordinates":[[[-79.27,62.16],[-79.66,61.63],[-80.1,61.72],[-80.36,62.02],[-80.32,62.09],[-79.93,62.39],[-79.52,62.36],[-79.27,62.16]]]},{"type":"Polygon","coordinates":[[[-81.9,62.71],[-83.07,62.16],[-83.77,62.18],[-83.99,62.45],[-83.25,62.91],[-81.88,62.9],[-81.9,62.71]]]},{"type":"Polygon","coordinates":[[[-171.73,63.78],[-171.11,63.59],[-170.49,63.69],[-169.68,63.43],[-168.69,63.3],[-168.77,63.19],[-169.53,62.98],[-170.29,63.19],[-170.67,63.38],[-171.55,63.32],[-171.79,63.41],[-171.73,63.78]]]},{"type":"Polygon","coordinates":[[[-85.16,65.66],[-84.98,65.22],[-84.46,65.37],[-83.88,65.11],[-82.79,64.77],[-81.64,64.46],[-81.55,63.98],[-80.82,64.06],[-80.1,63.73],[-80.99,63.41],[-82.55,63.65],[-83.11,64.1],[-84.1,63.57],[-85.52,63.05],[-85.87,63.64],[-87.22,63.54],[-86.35,64.04],[-86.22,64.82],[-85.88,65.74],[-85.16,65.66]]]},{"type":"Polygon","coordinates":[[[-14.51,66.46],[-14.74,65.81],[-13.61,65.13],[-14.91,64.36],[-17.79,63.68],[-18.66,63.5],[-19.97,63.64],[-22.76,63.96],[-21.78,64.4],[-23.96,64.89],[-22.18,65.08],[-22.23,65.38],[-24.33,65.61],[-23.65,66.26],[-22.13,66.41],[-20.58,65.73],[-19.06,66.28],[-17.8,65.99],[-16.17,66.53],[-14.51,66.46]]]},{"type":"Polygon","coordinates":[[[-75.87,67.15],[-76.99,67.1],[-77.24,67.59],[-76.81,68.15],[-75.9,68.29],[-75.11,68.01],[-75.1,67.58],[-75.22,67.44],[-75.87,67.15]]]},{"type":"Polygon","coordinates":[[[-175.01,66.58],[-174.34,66.34],[-174.57,67.06],[-171.86,66.91],[-169.9,65.98],[-170.89,65.54],[-172.53,65.44],[-172.56,64.46],[-172.96,64.25],[-173.89,64.28],[-174.65,64.63],[-175.98,64.92],[-176.21,65.36],[-177.22,65.52],[-178.36,65.39],[-178.9,65.74],[-178.69,66.11],[-179.88,65.87],[-179.43,65.4],[-180,64.98],[-180,68.96],[-177.55,68.2],[-174.93,67.21],[-175.01,66.58]]]},{"type":"Polygon","coordinates":[[[-95.65,69.11],[-96.27,68.76],[-97.62,69.06],[-98.43,68.95],[-99.8,69.4],[-98.92,69.71],[-98.22,70.14],[-97.16,69.86],[-96.56,69.68],[-96.26,69.49],[-95.65,69.11]]]},{"type":"Polygon","coordinates":[[[180,70.83],[178.9,70.78],[178.73,71.1],[180,71.52],[180,70.83]]]},{"type":"Polygon","coordinates":[[[-178.69,70.89],[-180,70.83],[-180,71.52],[-179.87,71.56],[-179.02,71.56],[-177.58,71.27],[-177.66,71.13],[-178.69,70.89]]]},{"type":"Polygon","coordinates":[[[-90.55,69.5],[-90.55,68.48],[-89.22,69.26],[-88.02,68.62],[-88.32,67.87],[-87.35,67.2],[-86.31,67.92],[-85.58,68.78],[-85.52,69.88],[-84.1,69.81],[-82.62,69.66],[-81.28,69.16],[-81.22,68.67],[-81.96,68.13],[-81.26,67.6],[-81.39,67.11],[-83.34,66.41],[-84.74,66.26],[-85.77,66.56],[-86.07,66.06],[-87.03,65.21],[-87.32,64.78],[-88.48,64.1],[-89.91,64.03],[-90.7,63.61],[-90.77,62.96],[-91.93,62.84],[-93.16,62.02],[-94.24,60.9],[-94.63,60.11],[-94.68,58.95],[-93.22,58.78],[-92.76,57.85],[-92.3,57.09],[-90.9,57.28],[-89.04,56.85],[-88.04,56.47],[-87.32,56.0],[-86.07,55.72],[-85.01,55.3],[-83.36,55.24],[-82.27,55.15],[-82.44,54.28],[-82.12,53.28],[-81.4,52.16],[-79.91,51.21],[-79.14,51.53],[-78.6,52.56],[-79.12,54.14],[-79.83,54.67],[-78.23,55.14],[-77.1,55.84],[-76.54,56.53],[-76.62,57.2],[-77.3,58.05],[-78.52,58.8],[-77.34,59.85],[-77.77,60.76],[-78.11,62.32],[-77.41,62.55],[-75.7,62.28],[-74.67,62.18],[-73.84,62.44],[-72.91,62.11],[-71.68,61.53],[-71.37,61.14],[-69.59,61.06],[-69.62,60.22],[-69.29,58.96],[-68.37,58.8],[-67.65,58.21],[-66.2,58.77],[-65.25,59.87],[-64.58,60.34],[-63.8,59.44],[-62.5,58.17],[-61.4,56.97],[-61.8,56.34],[-60.47,55.78],[-59.57,55.2],[-57.98,54.95],[-57.33,54.63],[-56.94,53.78],[-56.16,53.65],[-55.76,53.27],[-55.68,52.15],[-56.41,51.77],[-57.13,51.42],[-58.77,51.06],[-60.03,50.24],[-61.72,50.08],[-63.86,50.29],[-65.36,50.3],[-66.4,50.23],[-67.24,49.51],[-68.51,49.07],[-69.95,47.74],[-71.1,46.82],[-70.26,46.99],[-68.65,48.3],[-66.55,49.13],[-65.06,49.23],[-64.17,48.74],[-65.12,48.07],[-64.8,46.99],[-64.47,46.24],[-63.17,45.74],[-61.52,45.88],[-60.52,47.01],[-60.45,46.28],[-59.8,45.92],[-61.04,45.27],[-63.25,44.67],[-64.25,44.27],[-65.36,43.55],[-66.12,43.62],[-66.16,44.47],[-64.43,45.29],[-66.03,45.26],[-67.14,45.14],[-66.96,44.81],[-68.03,44.33],[-69.06,43.98],[-70.12,43.68],[-70.69,43.03],[-70.81,42.87],[-70.83,42.34],[-70.49,41.81],[-70.08,41.78],[-70.18,42.15],[-69.88,41.92],[-69.97,41.64],[-70.64,41.48],[-71.12,41.49],[-71.86,41.32],[-72.29,41.27],[-72.88,41.22],[-73.71,40.93],[-72.24,41.12],[-71.95,40.93],[-73.34,40.63],[-73.98,40.63],[-73.95,40.75],[-74.26,40.47],[-73.96,40.43],[-74.18,39.71],[-74.91,38.94],[-74.98,39.2],[-75.2,39.25],[-75.53,39.5],[-75.32,38.96],[-75.08,38.78],[-75.06,38.4],[-75.38,38.02],[-75.94,37.22],[-76.03,37.26],[-75.72,37.94],[-76.23,38.32],[-76.35,39.15],[-76.54,38.72],[-76.33,38.08],[-76.96,38.23],[-76.3,37.92],[-76.26,36.97],[-75.97,36.9],[-75.87,36.55],[-75.73,35.55],[-76.36,34.81],[-77.4,34.51],[-78.05,33.93],[-78.55,33.86],[-79.06,33.49],[-79.2,33.16],[-80.3,32.51],[-80.86,32.03],[-81.34,31.44],[-81.49,30.73],[-81.31,30.04],[-80.98,29.18],[-80.54,28.47],[-80.53,28.04],[-80.06,26.88],[-80.09,26.21],[-80.13,25.82],[-80.38,25.21],[-80.68,25.08],[-81.17,25.2],[-81.33,25.64],[-81.71,25.87],[-82.24,26.73],[-82.71,27.5],[-82.86,27.89],[-82.65,28.55],[-82.93,29.1],[-83.71,29.94],[-84.1,30.09],[-85.11,29.64],[-85.29,29.69],[-85.77,30.15],[-86.4,30.4],[-87.53,30.27],[-88.42,30.38],[-89.18,30.32],[-89.6,30.18],[-89.41,29.89],[-89.43,29.49],[-89.22,29.29],[-89.41,29.16],[-89.78,29.31],[-90.15,29.12],[-90.88,29.15],[-91.63,29.68],[-92.5,29.55],[-93.23,29.78],[-93.85,29.71],[-94.69,29.48],[-95.6,28.74],[-96.59,28.31],[-97.14,27.83],[-97.37,27.38],[-97.38,26.69],[-97.33,26.21],[-97.14,25.87],[-97.14,25.87],[-97.14,25.87],[-97.53,24.99],[-97.7,24.27],[-97.78,22.93],[-97.87,22.44],[-97.7,21.9],[-97.39,21.41],[-97.19,20.64],[-96.53,19.89],[-96.29,19.32],[-95.9,18.83],[-94.84,18.56],[-94.43,18.14],[-93.55,18.42],[-92.79,18.52],[-92.04,18.7],[-91.41,18.88],[-90.77,19.28],[-90.53,19.87],[-90.45,20.71],[-90.28,21.0],[-89.6,21.26],[-88.54,21.49],[-87.66,21.46],[-87.05,21.54],[-86.81,21.33],[-86.85,20.85],[-87.38,20.26],[-87.62,19.65],[-87.44,19.47],[-87.59,19.04],[-87.84,18.26],[-88.09,18.52],[-88.3,18.5],[-88.3,18.35],[-88.11,18.35],[-88.12,18.08],[-88.29,17.64],[-88.2,17.49],[-88.3,17.13],[-88.24,17.04],[-88.36,16.53],[-88.55,16.27],[-88.73,16.23],[-88.93,15.89],[-88.6,15.71],[-88.52,15.86],[-88.22,15.73],[-88.12,15.69],[-87.9,15.86],[-87.62,15.88],[-87.52,15.8],[-87.37,15.85],[-86.9,15.76],[-86.44,15.78],[-86.12,15.89],[-86.0,16.01],[-85.68,15.95],[-85.44,15.89],[-85.18,15.91],[-84.98,16.0],[-84.53,15.86],[-84.37,15.84],[-84.06,15.65],[-83.77,15.42],[-83.41,15.27],[-83.15,15.0],[-83.23,14.9],[-83.28,14.68],[-83.18,14.31],[-83.41,13.97],[-83.52,13.57],[-83.55,13.13],[-83.5,12.87],[-83.47,12.42],[-83.63,12.32],[-83.72,11.89],[-83.65,11.63],[-83.86,11.37],[-83.81,11.1],[-83.66,10.94],[-83.4,10.4],[-83.02,9.99],[-82.55,9.57],[-82.19,9.21],[-82.21,9.0],[-81.81,8.95],[-81.71,9.03],[-81.44,8.79],[-80.95,8.86],[-80.52,9.11],[-79.91,9.31],[-79.57,9.61],[-79.02,9.55],[-79.06,9.45],[-78.5,9.42],[-78.06,9.25],[-77.73,8.95],[-77.35,8.67],[-76.84,8.64],[-76.09,9.34],[-75.67,9.44],[-75.66,9.77],[-75.48,10.62],[-74.91,11.08],[-74.28,11.1],[-74.2,11.31],[-73.41,11.23],[-72.63,11.73],[-72.24,11.96],[-71.75,12.44],[-71.4,12.38],[-71.14,12.11],[-71.33,11.78],[-71.36,11.54],[-71.95,11.42],[-71.62,10.97],[-71.63,10.45],[-72.07,9.87],[-71.7,9.07],[-71.26,9.14],[-71.04,9.86],[-71.35,10.21],[-71.4,10.97],[-70.16,11.38],[-70.29,11.85],[-69.94,12.16],[-69.58,11.46],[-68.88,11.44],[-68.23,10.89],[-68.19,10.55],[-67.3,10.55],[-66.23,10.65],[-65.66,10.2],[-64.89,10.08],[-64.33,10.39],[-64.32,10.64],[-63.08,10.7],[-61.88,10.72],[-62.73,10.42],[-62.39,9.95],[-61.59,9.87],[-60.83,9.38],[-60.67,8.58],[-60.15,8.6],[-59.76,8.37],[-59.1,8.0],[-58.48,7.35],[-58.45,6.83],[-58.08,6.81],[-57.54,6.32],[-57.15,5.97],[-55.95,5.77],[-55.84,5.95],[-55.03,6.03],[-53.96,5.76],[-53.62,5.65],[-52.88,5.41],[-51.82,4.57],[-51.66,4.16],[-51.32,4.2],[-51.07,3.65],[-50.51,1.9],[-49.97,1.74],[-49.95,1.05],[-50.7,0.22],[-50.39,-0.08],[-48.62,-0.24],[-48.58,-1.24],[-47.82,-0.58],[-46.57,-0.94],[-44.91,-1.55],[-44.42,-2.14],[-44.58,-2.69],[-43.42,-2.38],[-41.47,-2.91],[-39.98,-2.87],[-38.5,-3.7],[-37.22,-4.82],[-36.45,-5.11],[-35.6,-5.15],[-35.24,-5.46],[-34.9,-6.74],[-34.73,-7.34],[-35.13,-9.0],[-35.64,-9.65],[-37.05,-11.04],[-37.68,-12.17],[-38.42,-13.04],[-38.67,-13.06],[-38.95,-13.79],[-38.88,-15.67],[-39.16,-17.21],[-39.27,-17.87],[-39.58,-18.26],[-39.76,-19.6],[-40.77,-20.9],[-40.94,-21.94],[-41.75,-22.37],[-41.99,-22.97],[-43.07,-22.97],[-44.65,-23.35],[-45.35,-23.8],[-46.47,-24.09],[-47.65,-24.89],[-48.5,-25.88],[-48.64,-26.62],[-48.47,-27.18],[-48.66,-28.19],[-48.89,-28.67],[-49.59,-29.22],[-50.7,-30.98],[-51.58,-31.78],[-52.26,-32.25],[-52.71,-33.2],[-53.37,-33.77],[-53.81,-34.4],[-54.94,-34.95],[-55.67,-34.75],[-56.22,-34.86],[-57.14,-34.43],[-57.82,-34.46],[-58.43,-33.91],[-58.5,-34.43],[-57.23,-35.29],[-57.36,-35.98],[-56.74,-36.41],[-56.79,-36.9],[-57.75,-38.18],[-59.23,-38.72],[-61.24,-38.93],[-62.34,-38.83],[-62.13,-39.42],[-62.33,-40.17],[-62.15,-40.68],[-62.75,-41.03],[-63.77,-41.17],[-64.73,-40.8],[-65.12,-41.06],[-64.98,-42.06],[-64.3,-42.36],[-63.76,-42.04],[-63.46,-42.56],[-64.38,-42.87],[-65.18,-43.5],[-65.33,-44.5],[-65.57,-45.04],[-66.51,-45.04],[-67.29,-45.55],[-67.58,-46.3],[-66.6,-47.03],[-65.64,-47.24],[-65.99,-48.13],[-67.17,-48.7],[-67.82,-49.87],[-68.73,-50.26],[-69.14,-50.73],[-68.82,-51.77],[-68.15,-52.35],[-68.57,-52.3],[-69.46,-52.29],[-69.94,-52.54],[-70.85,-52.9],[-71.01,-53.83],[-71.43,-53.86],[-72.56,-53.53],[-73.7,-52.84],[-74.95,-52.26],[-75.26,-51.63],[-74.98,-51.04],[-75.48,-50.38],[-75.61,-48.67],[-75.18,-47.71],[-74.13,-46.94],[-75.64,-46.65],[-74.69,-45.76],[-74.35,-44.1],[-73.24,-44.45],[-72.72,-42.38],[-73.39,-42.12],[-73.7,-43.37],[-74.33,-43.22],[-74.02,-41.79],[-73.68,-39.94],[-73.22,-39.26],[-73.51,-38.28],[-73.59,-37.16],[-73.17,-37.12],[-72.55,-35.51],[-71.86,-33.91],[-71.44,-32.42],[-71.67,-30.92],[-71.37,-30.1],[-71.49,-28.86],[-70.91,-27.64],[-70.72,-25.71],[-70.4,-23.63],[-70.09,-21.39],[-70.16,-19.76],[-70.37,-18.35],[-71.38,-17.77],[-71.46,-17.36],[-73.44,-16.36],[-75.24,-15.27],[-76.01,-14.65],[-76.42,-13.82],[-76.26,-13.53],[-77.11,-12.22],[-78.09,-10.38],[-79.04,-8.39],[-79.45,-7.93],[-79.76,-7.19],[-80.54,-6.54],[-81.25,-6.14],[-80.93,-5.69],[-81.41,-4.74],[-81.1,-4.04],[-80.3,-3.4],[-79.77,-2.66],[-79.99,-2.22],[-80.37,-2.69],[-80.97,-2.25],[-80.76,-1.97],[-80.93,-1.06],[-80.58,-0.91],[-80.4,-0.28],[-80.02,0.36],[-80.09,0.77],[-79.54,0.98],[-78.86,1.38],[-78.99,1.69],[-78.62,1.77],[-78.66,2.27],[-78.43,2.63],[-77.93,2.7],[-77.51,3.33],[-77.13,3.85],[-77.5,4.09],[-77.31,4.67],[-77.53,5.58],[-77.32,5.85],[-77.48,6.69],[-77.88,7.22],[-78.21,7.51],[-78.43,8.05],[-78.18,8.32],[-78.44,8.39],[-78.62,8.72],[-79.12,9.0],[-79.56,8.93],[-79.76,8.58],[-80.16,8.33],[-80.38,8.3],[-80.48,8.09],[-80.0,7.55],[-80.28,7.42],[-80.42,7.27],[-80.89,7.22],[-81.06,7.82],[-81.19,7.65],[-81.52,7.71],[-81.72,8.11],[-82.13,8.18],[-82.39,8.29],[-82.82,8.29],[-82.85,8.07],[-82.97,8.23],[-83.51,8.45],[-83.71,8.66],[-83.6,8.83],[-83.63,9.05],[-83.91,9.29],[-84.3,9.49],[-84.65,9.62],[-84.71,9.91],[-84.98,10.09],[-84.91,9.8],[-85.11,9.56],[-85.34,9.83],[-85.66,9.93],[-85.8,10.13],[-85.79,10.44],[-85.66,10.75],[-85.94,10.9],[-85.71,11.09],[-86.06,11.4],[-86.53,11.81],[-86.75,12.14],[-87.17,12.46],[-87.67,12.91],[-87.56,13.06],[-87.39,12.91],[-87.32,12.98],[-87.49,13.3],[-87.79,13.38],[-87.9,13.15],[-88.48,13.16],[-88.84,13.26],[-89.26,13.46],[-89.81,13.52],[-90.1,13.74],[-90.61,13.91],[-91.23,13.93],[-91.69,14.13],[-92.23,14.54],[-93.36,15.62],[-93.88,15.94],[-94.69,16.2],[-95.25,16.13],[-96.05,15.75],[-96.56,15.65],[-97.26,15.92],[-98.01,16.11],[-98.95,16.57],[-99.7,16.71],[-100.83,17.17],[-101.67,17.65],[-101.92,17.92],[-102.48,17.98],[-103.5,18.29],[-103.92,18.75],[-104.99,19.32],[-105.49,19.95],[-105.73,20.43],[-105.4,20.53],[-105.5,20.82],[-105.27,21.08],[-105.27,21.42],[-105.6,21.87],[-105.69,22.27],[-106.03,22.77],[-106.91,23.77],[-107.92,24.55],[-108.4,25.17],[-109.26,25.58],[-109.44,25.82],[-109.29,26.44],[-109.8,26.68],[-110.39,27.16],[-110.64,27.86],[-111.18,27.94],[-111.76,28.47],[-112.23,28.95],[-112.27,29.27],[-112.81,30.02],[-113.16,30.79],[-113.15,31.17],[-113.87,31.57],[-114.21,31.52],[-114.78,31.8],[-114.94,31.39],[-114.77,30.91],[-114.67,30.16],[-114.33,29.75],[-113.59,29.06],[-113.42,28.83],[-113.27,28.75],[-113.14,28.41],[-112.96,28.43],[-112.76,27.78],[-112.46,27.53],[-112.24,27.17],[-111.62,26.66],[-111.28,25.73],[-110.99,25.29],[-110.71,24.83],[-110.66,24.3],[-110.17,24.27],[-109.77,23.81],[-109.41,23.36],[-109.43,23.19],[-109.85,22.82],[-110.03,22.82],[-110.29,23.43],[-110.95,24.0],[-111.67,24.48],[-112.18,24.74],[-112.15,25.47],[-112.3,26.01],[-112.78,26.32],[-113.46,26.77],[-113.6,26.64],[-113.85,26.9],[-114.47,27.14],[-115.06,27.72],[-114.98,27.8],[-114.57,27.74],[-114.2,28.12],[-114.16,28.57],[-114.93,29.28],[-115.52,29.56],[-115.89,30.18],[-116.26,30.84],[-116.72,31.64],[-117.13,32.54],[-117.3,33.05],[-117.94,33.62],[-118.41,33.74],[-118.52,34.03],[-119.08,34.08],[-119.44,34.35],[-120.37,34.45],[-120.62,34.61],[-120.74,35.16],[-121.71,36.16],[-122.55,37.55],[-122.51,37.78],[-122.95,38.11],[-123.73,38.95],[-123.87,39.77],[-124.4,40.31],[-124.18,41.14],[-124.21,42.0],[-124.53,42.77],[-124.14,43.71],[-123.9,45.52],[-124.08,46.86],[-124.4,47.72],[-124.69,48.18],[-124.57,48.38],[-123.12,48.04],[-122.59,47.1],[-122.34,47.36],[-122.5,48.18],[-122.84,49.0],[-122.97,49.0],[-124.91,49.98],[-125.62,50.42],[-127.44,50.83],[-127.99,51.72],[-127.85,52.33],[-129.13,52.76],[-129.31,53.56],[-130.51,54.29],[-130.54,54.8],[-131.09,55.18],[-131.97,55.5],[-132.25,56.37],[-133.54,57.18],[-134.08,58.12],[-135.04,58.19],[-136.63,58.21],[-137.8,58.5],[-139.87,59.54],[-140.83,59.73],[-142.57,60.08],[-143.96,60.0],[-145.93,60.46],[-147.11,60.88],[-148.22,60.67],[-148.02,59.98],[-148.57,59.91],[-149.73,59.71],[-150.61,59.37],[-151.72,59.16],[-151.86,59.75],[-151.41,60.73],[-150.35,61.03],[-150.62,61.28],[-151.9,60.73],[-152.58,60.06],[-154.02,59.35],[-153.29,58.86],[-154.23,58.15],[-155.31,57.73],[-156.31,57.42],[-156.56,56.98],[-158.12,56.46],[-158.43,55.99],[-159.6,55.57],[-160.29,55.64],[-161.22,55.36],[-162.24,55.02],[-163.07,54.69],[-164.79,54.4],[-164.94,54.57],[-163.85,55.04],[-162.87,55.35],[-161.8,55.9],[-160.56,56.01],[-160.07,56.42],[-158.68,57.02],[-158.46,57.22],[-157.72,57.57],[-157.55,58.33],[-157.04,58.92],[-158.19,58.62],[-158.52,58.79],[-159.06,58.42],[-159.71,58.93],[-159.98,58.57],[-160.36,59.07],[-161.35,58.67],[-161.97,58.67],[-162.05,59.27],[-161.87,59.63],[-162.52,59.99],[-163.82,59.8],[-164.66,60.27],[-165.35,60.51],[-165.35,61.07],[-166.12,61.5],[-165.73,62.08],[-164.92,62.63],[-164.56,63.15],[-163.75,63.22],[-163.07,63.06],[-162.26,63.54],[-161.53,63.46],[-160.77,63.77],[-160.96,64.22],[-161.52,64.4],[-160.78,64.79],[-161.39,64.78],[-162.45,64.56],[-162.76,64.34],[-163.55,64.56],[-164.96,64.45],[-166.43,64.69],[-166.84,65.09],[-168.11,65.67],[-166.71,66.09],[-164.47,66.58],[-163.65,66.58],[-163.79,66.08],[-161.68,66.12],[-162.49,66.74],[-163.72,67.12],[-164.43,67.62],[-165.39,68.04],[-166.76,68.36],[-166.2,68.88],[-164.43,68.92],[-163.17,69.37],[-162.93,69.86],[-161.91,70.33],[-160.93,70.45],[-159.04,70.89],[-158.12,70.82],[-156.58,71.36],[-155.07,71.15],[-154.34,70.7],[-153.9,70.89],[-152.21,70.83],[-152.27,70.6],[-150.74,70.43],[-149.72,70.53],[-147.61,70.21],[-145.69,70.12],[-144.92,69.99],[-143.59,70.15],[-142.07,69.85],[-140.99,69.71],[-139.12,69.47],[-137.55,68.99],[-136.5,68.9],[-135.63,69.32],[-134.41,69.63],[-132.93,69.51],[-131.43,69.94],[-129.79,70.19],[-129.11,69.78],[-128.36,70.01],[-128.14,70.48],[-127.45,70.38],[-125.76,69.48],[-124.42,70.16],[-124.29,69.4],[-123.06,69.56],[-122.68,69.86],[-121.47,69.8],[-119.94,69.38],[-117.6,69.01],[-116.23,68.84],[-115.25,68.91],[-113.9,68.4],[-115.3,67.9],[-113.5,67.69],[-110.8,67.81],[-109.95,67.98],[-108.88,67.38],[-107.79,67.89],[-108.81,68.31],[-108.17,68.65],[-106.95,68.7],[-106.15,68.8],[-105.34,68.56],[-104.34,68.02],[-103.22,68.1],[-101.45,67.65],[-99.9,67.81],[-98.44,67.78],[-98.56,68.4],[-97.67,68.58],[-96.12,68.24],[-96.13,67.29],[-95.49,68.09],[-94.68,68.06],[-94.23,69.07],[-95.3,69.69],[-96.47,70.09],[-96.39,71.19],[-95.21,71.92],[-93.89,71.76],[-92.88,71.32],[-91.52,70.19],[-92.41,69.7],[-90.55,69.5]]]},{"type":"Polygon","coordinates":[[[-114.17,73.12],[-114.67,72.65],[-112.44,72.96],[-111.05,72.45],[-109.92,72.96],[-109.01,72.63],[-108.19,71.65],[-107.69,72.07],[-108.4,73.09],[-107.52,73.24],[-106.52,73.08],[-105.4,72.67],[-104.77,71.7],[-104.46,70.99],[-102.79,70.5],[-100.98,70.02],[-101.09,69.58],[-102.73,69.5],[-102.09,69.12],[-102.43,68.75],[-104.24,68.91],[-105.96,69.18],[-107.12,69.12],[-109,68.78],[-111.97,68.6],[-113.31,68.54],[-113.85,69.01],[-115.22,69.28],[-116.11,69.17],[-117.34,69.96],[-116.67,70.07],[-115.13,70.24],[-113.72,70.19],[-112.42,70.37],[-114.35,70.6],[-116.49,70.52],[-117.9,70.54],[-118.43,70.91],[-116.11,71.31],[-117.66,71.3],[-119.4,71.56],[-118.56,72.31],[-117.87,72.71],[-115.19,73.31],[-114.17,73.12]]]},{"type":"Polygon","coordinates":[[[-104.5,73.42],[-105.38,72.76],[-106.94,73.46],[-106.6,73.6],[-105.26,73.64],[-104.5,73.42]]]},{"type":"Polygon","coordinates":[[[-76.34,73.1],[-76.25,72.83],[-77.31,72.86],[-78.39,72.88],[-79.49,72.74],[-79.78,72.8],[-80.88,73.33],[-80.83,73.69],[-80.35,73.76],[-78.06,73.65],[-76.34,73.1]]]},{"type":"Polygon","coordinates":[[[-86.56,73.16],[-85.77,72.53],[-84.85,73.34],[-82.32,73.75],[-80.6,72.72],[-80.75,72.06],[-78.77,72.35],[-77.82,72.75],[-75.61,72.24],[-74.23,71.77],[-74.1,71.33],[-72.24,71.56],[-71.2,70.92],[-68.79,70.53],[-67.91,70.12],[-66.97,69.19],[-68.81,68.72],[-66.45,68.07],[-64.86,67.85],[-63.42,66.93],[-61.85,66.86],[-62.16,66.16],[-63.92,65.0],[-65.15,65.43],[-66.72,66.39],[-68.02,66.26],[-68.14,65.69],[-67.09,65.11],[-65.73,64.65],[-65.32,64.38],[-64.67,63.39],[-65.01,62.67],[-66.28,62.95],[-68.78,63.75],[-67.37,62.88],[-66.33,62.28],[-66.17,61.93],[-68.88,62.33],[-71.02,62.91],[-72.24,63.4],[-71.89,63.68],[-73.38,64.19],[-74.83,64.68],[-74.82,64.39],[-77.71,64.23],[-78.56,64.57],[-77.9,65.31],[-76.02,65.33],[-73.96,65.45],[-74.29,65.81],[-73.94,66.31],[-72.65,67.28],[-72.93,67.73],[-73.31,68.07],[-74.84,68.55],[-76.87,68.89],[-76.23,69.15],[-77.29,69.77],[-78.17,69.83],[-78.96,70.17],[-79.49,69.87],[-81.31,69.74],[-84.94,69.97],[-87.06,70.26],[-88.68,70.41],[-89.51,70.76],[-88.47,71.22],[-89.89,71.22],[-90.21,72.24],[-89.44,73.13],[-88.41,73.54],[-85.83,73.8],[-86.56,73.16]]]},{"type":"Polygon","coordinates":[[[-100.36,73.84],[-99.16,73.63],[-97.38,73.76],[-97.12,73.47],[-98.05,72.99],[-96.54,72.56],[-96.72,71.66],[-98.36,71.27],[-99.32,71.36],[-100.01,71.74],[-102.5,72.51],[-102.48,72.83],[-100.44,72.71],[-101.54,73.36],[-100.36,73.84]]]},{"type":"Polygon","coordinates":[[[143.6,73.21],[142.09,73.21],[140.04,73.32],[139.86,73.37],[140.81,73.77],[142.06,73.86],[143.48,73.48],[143.6,73.21]]]},{"type":"Polygon","coordinates":[[[-93.2,72.77],[-94.27,72.02],[-95.41,72.06],[-96.03,72.94],[-96.02,73.44],[-95.5,73.86],[-94.5,74.13],[-92.42,74.1],[-90.51,73.86],[-92.0,72.97],[-93.2,72.77]]]},{"type":"Polygon","coordinates":[[[-120.46,71.4],[-123.09,70.9],[-123.62,71.34],[-125.93,71.87],[-125.59,72.19],[-124.81,73.02],[-123.94,73.68],[-124.92,74.29],[-121.54,74.45],[-120.11,74.24],[-117.56,74.19],[-116.58,73.9],[-115.51,73.48],[-116.77,73.22],[-119.22,72.52],[-120.46,71.82],[-120.46,71.4]]]},{"type":"Polygon","coordinates":[[[150.73,75.08],[149.58,74.69],[147.98,74.78],[146.12,75.17],[146.36,75.5],[148.22,75.35],[150.73,75.08]]]},{"type":"Polygon","coordinates":[[[-93.61,74.98],[-94.16,74.59],[-95.61,74.67],[-96.82,74.93],[-96.29,75.38],[-94.85,75.65],[-93.98,75.3],[-93.61,74.98]]]},{"type":"Polygon","coordinates":[[[145.09,75.56],[144.3,74.82],[140.61,74.85],[138.96,74.61],[136.97,75.26],[137.51,75.95],[138.83,76.14],[141.47,76.09],[145.09,75.56]]]},{"type":"Polygon","coordinates":[[[-98.5,76.72],[-97.74,76.26],[-97.7,75.74],[-98.16,75],[-99.81,74.9],[-100.88,75.06],[-100.86,75.64],[-102.5,75.56],[-102.57,76.34],[-101.49,76.31],[-99.98,76.65],[-98.58,76.59],[-98.5,76.72]]]},{"type":"Polygon","coordinates":[[[-108.21,76.2],[-107.82,75.85],[-106.93,76.01],[-105.88,75.97],[-105.7,75.48],[-106.31,75.01],[-109.7,74.85],[-112.22,74.42],[-113.74,74.39],[-113.87,74.72],[-111.79,75.16],[-116.31,75.04],[-117.71,75.22],[-116.35,76.2],[-115.4,76.48],[-112.59,76.14],[-110.81,75.55],[-109.07,75.47],[-110.5,76.43],[-109.58,76.79],[-108.55,76.68],[-108.21,76.2]]]},{"type":"Polygon","coordinates":[[[57.54,70.72],[56.94,70.63],[53.68,70.76],[53.41,71.21],[51.6,71.47],[51.46,72.01],[52.48,72.23],[52.44,72.77],[54.43,73.63],[53.51,73.75],[55.9,74.63],[55.63,75.08],[57.87,75.61],[61.17,76.25],[64.5,76.44],[66.21,76.81],[68.16,76.94],[68.85,76.54],[68.18,76.23],[64.64,75.74],[61.58,75.26],[58.48,74.31],[56.99,73.33],[55.42,72.37],[55.62,71.54],[57.54,70.72]]]},{"type":"Polygon","coordinates":[[[-94.68,77.1],[-93.57,76.78],[-91.61,76.78],[-90.74,76.45],[-90.97,76.07],[-89.82,75.85],[-89.19,75.61],[-87.84,75.57],[-86.38,75.48],[-84.79,75.7],[-82.75,75.78],[-81.13,75.71],[-80.06,75.34],[-79.83,74.92],[-80.46,74.66],[-81.95,74.44],[-83.23,74.56],[-86.1,74.41],[-88.15,74.39],[-89.76,74.52],[-92.42,74.84],[-92.77,75.39],[-92.89,75.88],[-93.89,76.32],[-95.96,76.44],[-97.12,76.75],[-96.75,77.16],[-94.68,77.1]]]},{"type":"Polygon","coordinates":[[[-116.2,77.65],[-116.34,76.88],[-117.11,76.53],[-118.04,76.48],[-119.9,76.05],[-121.5,75.9],[-122.85,76.12],[-122.85,76.12],[-121.16,76.86],[-119.1,77.51],[-117.57,77.5],[-116.2,77.65]]]},{"type":"Polygon","coordinates":[[[106.97,76.97],[107.24,76.48],[108.15,76.72],[111.08,76.71],[113.33,76.22],[114.13,75.85],[113.89,75.33],[112.78,75.03],[110.15,74.48],[109.4,74.18],[110.64,74.04],[112.12,73.79],[113.02,73.98],[113.53,73.34],[113.97,73.59],[115.57,73.75],[118.78,73.59],[119.02,73.12],[123.2,72.97],[123.26,73.74],[125.38,73.56],[126.98,73.57],[128.59,73.04],[129.05,72.4],[128.46,71.98],[129.72,71.19],[131.29,70.79],[132.25,71.84],[133.86,71.39],[135.56,71.66],[137.5,71.35],[138.23,71.63],[139.87,71.49],[139.15,72.42],[140.47,72.85],[149.5,72.2],[150.35,71.61],[152.97,70.84],[157.01,71.03],[159.0,70.87],[159.83,70.45],[159.71,69.72],[160.94,69.44],[162.28,69.64],[164.05,69.67],[165.94,69.47],[167.84,69.58],[169.58,68.69],[170.82,69.01],[170.01,69.65],[170.45,70.1],[173.64,69.82],[175.72,69.88],[178.6,69.4],[180,68.96],[180,64.98],[179.99,64.97],[178.71,64.53],[177.41,64.61],[178.31,64.08],[178.91,63.25],[179.37,62.98],[179.49,62.57],[179.23,62.3],[177.36,62.52],[174.57,61.77],[173.68,61.65],[172.15,60.95],[170.7,60.34],[170.33,59.88],[168.9,60.57],[166.3,59.79],[165.84,60.16],[164.88,59.73],[163.54,59.87],[163.22,59.21],[162.02,58.24],[162.05,57.84],[163.19,57.62],[163.06,56.16],[162.13,56.12],[161.7,55.29],[162.12,54.86],[160.37,54.34],[160.02,53.2],[158.53,52.96],[158.23,51.94],[156.79,51.01],[156.42,51.7],[155.99,53.16],[155.43,55.38],[155.91,56.77],[156.76,57.36],[156.81,57.83],[158.36,58.06],[160.15,59.31],[161.87,60.34],[163.67,61.14],[164.47,62.55],[163.26,62.47],[162.66,61.64],[160.12,60.54],[159.3,61.77],[156.72,61.43],[154.22,59.76],[155.04,59.15],[152.81,58.88],[151.27,58.78],[151.34,59.5],[149.78,59.66],[148.54,59.16],[145.49,59.34],[142.2,59.04],[138.96,57.09],[135.13,54.73],[136.7,54.6],[137.19,53.98],[138.16,53.76],[138.8,54.25],[139.9,54.19],[141.35,53.09],[141.38,52.24],[140.6,51.24],[140.51,50.05],[140.06,48.45],[138.55,47.0],[138.22,46.31],[136.86,45.14],[135.52,43.99],[134.87,43.4],[133.54,42.81],[132.91,42.8],[132.28,43.28],[130.94,42.55],[130.78,42.22],[130.4,42.28],[129.97,41.94],[129.67,41.6],[129.71,40.88],[129.19,40.66],[129.01,40.49],[128.63,40.19],[127.97,40.03],[127.53,39.76],[127.5,39.32],[127.39,39.21],[127.78,39.05],[128.35,38.61],[129.21,37.43],[129.46,36.78],[129.47,35.63],[129.09,35.08],[128.19,34.89],[127.39,34.48],[126.49,34.39],[126.37,34.93],[126.56,35.68],[126.12,36.73],[126.86,36.89],[126.17,37.75],[125.69,37.94],[125.57,37.75],[125.28,37.67],[125.24,37.86],[124.98,37.95],[124.71,38.11],[124.99,38.55],[125.22,38.67],[125.13,38.85],[125.39,39.39],[125.32,39.55],[124.74,39.66],[124.27,39.93],[122.87,39.64],[122.13,39.17],[121.05,38.9],[121.59,39.36],[121.38,39.75],[122.17,40.42],[121.64,40.95],[120.77,40.59],[119.64,39.9],[119.02,39.25],[118.04,39.2],[117.53,38.74],[118.06,38.06],[118.88,37.9],[118.91,37.45],[119.7,37.16],[120.82,37.87],[121.71,37.48],[122.36,37.45],[122.52,36.93],[121.1,36.65],[120.64,36.11],[119.66,35.61],[119.15,34.91],[120.23,34.36],[120.62,33.38],[121.23,32.46],[121.91,31.69],[121.89,30.95],[121.26,30.68],[121.5,30.14],[122.09,29.83],[121.94,29.02],[121.68,28.23],[121.13,28.14],[120.4,27.05],[119.59,25.74],[118.66,24.55],[117.28,23.62],[115.89,22.78],[114.76,22.67],[114.15,22.22],[113.81,22.55],[113.24,22.05],[111.84,21.55],[110.79,21.4],[110.44,20.34],[109.89,20.28],[109.63,21.01],[109.86,21.4],[108.52,21.72],[108.05,21.55],[106.72,20.7],[105.88,19.75],[105.66,19.06],[106.43,18.0],[107.36,16.7],[108.27,16.08],[108.88,15.28],[109.34,13.43],[109.2,11.67],[108.37,11.01],[107.22,10.36],[106.41,9.53],[105.16,8.6],[104.8,9.24],[105.08,9.92],[104.33,10.49],[103.5,10.63],[103.09,11.15],[102.59,12.19],[101.69,12.65],[100.83,12.63],[100.98,13.41],[100.1,13.41],[100.02,12.31],[99.48,10.85],[99.15,9.96],[99.22,9.24],[99.87,9.21],[100.28,8.3],[100.46,7.43],[101.02,6.86],[101.62,6.74],[102.14,6.22],[102.37,6.13],[102.96,5.52],[103.38,4.86],[103.44,4.18],[103.33,3.73],[103.43,3.38],[103.5,2.79],[103.85,2.52],[104.25,1.63],[104.23,1.29],[103.52,1.23],[102.57,1.97],[101.39,2.76],[101.27,3.27],[100.7,3.94],[100.56,4.77],[100.2,5.31],[100.31,6.04],[100.09,6.46],[99.69,6.85],[99.52,7.34],[98.99,7.91],[98.5,8.38],[98.34,7.79],[98.15,8.35],[98.26,8.97],[98.55,9.93],[98.46,10.68],[98.76,11.44],[98.43,12.03],[98.51,13.12],[98.1,13.64],[97.78,14.84],[97.6,16.1],[97.16,16.93],[96.51,16.43],[95.37,15.71],[94.81,15.8],[94.19,16.04],[94.53,17.28],[94.32,18.21],[93.54,19.37],[93.66,19.73],[93.08,19.86],[92.37,20.67],[92.08,21.19],[92.03,21.7],[91.83,22.18],[91.42,22.77],[90.5,22.81],[90.59,22.39],[90.27,21.84],[89.85,22.04],[89.7,21.86],[89.42,21.97],[89.03,22.06],[88.89,21.69],[88.21,21.7],[86.98,21.5],[87.03,20.74],[86.5,20.15],[85.06,19.48],[83.94,18.3],[83.19,17.67],[82.19,17.02],[82.19,16.56],[81.69,16.31],[80.79,15.95],[80.32,15.9],[80.03,15.14],[80.23,13.84],[80.29,13.01],[79.86,12.06],[79.86,10.36],[79.34,10.31],[78.89,9.55],[79.19,9.22],[78.28,8.93],[77.94,8.25],[77.54,7.97],[76.59,8.9],[76.13,10.3],[75.75,11.31],[75.4,11.78],[74.86,12.74],[74.62,13.99],[74.44,14.62],[73.53,15.99],[73.12,17.93],[72.82,19.21],[72.82,20.42],[72.63,21.36],[71.18,20.76],[70.47,20.88],[69.16,22.09],[69.64,22.45],[69.35,22.84],[68.18,23.69],[67.44,23.94],[67.15,24.66],[66.37,25.43],[64.53,25.24],[62.91,25.22],[61.5,25.08],[59.62,25.38],[58.53,25.61],[57.4,25.74],[56.97,26.97],[56.49,27.14],[55.72,26.96],[54.72,26.48],[53.49,26.81],[52.48,27.58],[51.52,27.87],[50.85,28.81],[50.12,30.15],[49.58,29.99],[48.94,30.32],[48.57,29.93],[47.97,29.98],[48.18,29.53],[48.09,29.31],[48.42,28.55],[48.81,27.69],[49.3,27.46],[49.47,27.11],[50.15,26.69],[50.21,26.28],[50.11,25.94],[50.24,25.61],[50.53,25.33],[50.66,25.0],[50.81,24.75],[50.74,25.48],[51.01,26.01],[51.29,26.11],[51.59,25.8],[51.61,25.22],[51.39,24.63],[51.58,24.25],[51.76,24.29],[51.79,24.02],[52.58,24.18],[53.4,24.15],[54.01,24.12],[54.69,24.8],[55.44,25.44],[56.07,26.06],[56.36,26.4],[56.49,26.31],[56.39,25.9],[56.26,25.71],[56.4,24.92],[56.85,24.24],[57.4,23.88],[58.14,23.75],[58.73,23.57],[59.18,22.99],[59.45,22.66],[59.81,22.53],[59.81,22.31],[59.44,21.71],[59.28,21.43],[58.86,21.11],[58.49,20.43],[58.03,20.48],[57.83,20.24],[57.67,19.74],[57.79,19.07],[57.69,18.94],[57.23,18.95],[56.61,18.57],[56.51,18.09],[56.28,17.88],[55.66,17.88],[55.27,17.63],[55.27,17.23],[54.79,16.95],[54.24,17.05],[53.57,16.71],[53.11,16.65],[52.39,16.38],[52.19,15.94],[52.17,15.6],[51.17,15.18],[49.57,14.71],[48.68,14.0],[48.24,13.95],[47.94,14.01],[47.35,13.59],[46.72,13.4],[45.88,13.35],[45.63,13.29],[45.41,13.03],[45.14,12.95],[44.99,12.7],[44.49,12.72],[44.18,12.59],[43.48,12.64],[43.22,13.22],[43.25,13.77],[43.09,14.06],[42.89,14.8],[42.6,15.21],[42.81,15.26],[42.7,15.72],[42.82,15.91],[42.78,16.35],[42.65,16.77],[42.35,17.08],[42.27,17.47],[41.75,17.83],[41.22,18.67],[40.94,19.49],[40.25,20.17],[39.8,20.34],[39.14,21.29],[39.02,21.99],[39.07,22.58],[38.49,23.69],[38.02,24.08],[37.48,24.29],[37.15,24.86],[37.21,25.08],[36.93,25.6],[36.64,25.83],[36.25,26.57],[35.64,27.38],[35.13,28.06],[34.63,28.06],[34.79,28.61],[34.83,28.96],[34.96,29.36],[34.92,29.5],[34.64,29.1],[34.43,28.34],[34.15,27.82],[33.92,27.65],[33.59,27.97],[33.14,28.42],[32.42,29.85],[32.32,29.76],[32.73,28.71],[33.35,27.7],[34.1,26.14],[34.47,25.6],[34.8,25.03],[35.69,23.93],[35.49,23.75],[35.53,23.1],[36.69,22.2],[36.87,22.0],[37.19,21.02],[36.97,20.84],[37.11,19.81],[37.48,18.61],[37.86,18.37],[38.41,18.0],[38.99,16.84],[39.27,15.92],[39.81,15.44],[41.18,14.49],[41.73,13.92],[42.28,13.34],[42.59,13.0],[43.08,12.7],[43.32,12.39],[43.29,11.97],[42.72,11.74],[43.15,11.46],[43.47,11.28],[43.67,10.86],[44.12,10.45],[44.61,10.44],[45.56,10.7],[46.65,10.82],[47.53,11.13],[48.02,11.19],[48.38,11.38],[48.95,11.41],[49.27,11.43],[49.73,11.58],[50.26,11.68],[50.73,12.02],[51.11,12.02],[51.13,11.75],[51.04,11.17],[51.05,10.64],[50.83,10.28],[50.55,9.2],[50.07,8.08],[49.45,6.8],[48.59,5.34],[47.74,4.22],[46.56,2.86],[45.56,2.05],[44.07,1.05],[43.14,0.29],[42.04,-0.92],[41.81,-1.45],[41.59,-1.68],[40.88,-2.08],[40.64,-2.5],[40.26,-2.57],[40.12,-3.28],[39.8,-3.68],[39.6,-4.35],[39.2,-4.68],[38.74,-5.91],[38.8,-6.48],[39.44,-6.84],[39.47,-7.1],[39.19,-7.7],[39.25,-8.01],[39.19,-8.49],[39.54,-9.11],[39.95,-10.1],[40.32,-10.32],[40.48,-10.77],[40.44,-11.76],[40.56,-12.64],[40.6,-14.2],[40.78,-14.69],[40.48,-15.41],[40.09,-16.1],[39.45,-16.72],[38.54,-17.1],[37.41,-17.59],[36.28,-18.66],[35.9,-18.84],[35.2,-19.55],[34.79,-19.78],[34.7,-20.5],[35.18,-21.25],[35.37,-21.84],[35.39,-22.14],[35.56,-22.09],[35.53,-23.07],[35.37,-23.54],[35.61,-23.71],[35.46,-24.12],[35.04,-24.48],[34.22,-24.82],[33.01,-25.36],[32.57,-25.73],[32.66,-26.15],[32.92,-26.22],[32.83,-26.74],[32.58,-27.47],[32.46,-28.3],[32.2,-28.75],[31.52,-29.26],[31.33,-29.4],[30.9,-29.91],[30.62,-30.42],[30.06,-31.14],[28.93,-32.17],[28.22,-32.77],[27.46,-33.23],[26.42,-33.61],[25.91,-33.67],[25.78,-33.94],[25.17,-33.8],[24.68,-33.99],[23.59,-33.79],[22.99,-33.92],[22.57,-33.86],[21.54,-34.26],[20.69,-34.42],[20.07,-34.8],[19.62,-34.82],[19.19,-34.46],[18.86,-34.44],[18.42,-34.0],[18.38,-34.14],[18.24,-33.87],[18.25,-33.28],[17.93,-32.61],[18.25,-32.43],[18.22,-31.66],[17.57,-30.73],[17.06,-29.88],[17.06,-29.88],[16.35,-28.58],[15.6,-27.82],[15.21,-27.09],[14.99,-26.12],[14.74,-25.39],[14.41,-23.85],[14.39,-22.66],[14.26,-22.11],[13.87,-21.7],[13.35,-20.87],[12.83,-19.67],[12.61,-19.05],[11.79,-18.07],[11.73,-17.3],[11.64,-16.67],[11.78,-15.79],[12.12,-14.88],[12.18,-14.45],[12.5,-13.55],[12.74,-13.14],[13.31,-12.48],[13.63,-12.04],[13.74,-11.3],[13.69,-10.73],[13.39,-10.37],[13.12,-9.77],[12.88,-9.17],[12.93,-8.96],[13.24,-8.56],[12.93,-7.6],[12.73,-6.93],[12.23,-6.29],[12.32,-6.1],[12.18,-5.79],[11.92,-5.04],[11.09,-3.98],[10.07,-2.97],[9.41,-2.14],[8.8,-1.11],[8.83,-0.78],[9.05,-0.46],[9.29,0.27],[9.49,1.01],[9.31,1.16],[9.65,2.28],[9.8,3.07],[9.4,3.73],[8.95,3.9],[8.74,4.35],[8.49,4.5],[8.5,4.77],[7.46,4.41],[7.08,4.46],[6.7,4.24],[5.9,4.26],[5.36,4.89],[5.03,5.61],[4.33,6.27],[3.57,6.26],[2.69,6.26],[1.87,6.14],[1.06,5.93],[-0.51,5.34],[-1.06,5.0],[-1.96,4.71],[-2.86,4.99],[-3.31,4.98],[-4.01,5.18],[-4.65,5.17],[-5.83,4.99],[-6.53,4.71],[-7.52,4.34],[-7.71,4.36],[-7.97,4.36],[-9.0,4.83],[-9.91,5.59],[-10.77,6.14],[-11.44,6.79],[-11.71,6.86],[-12.43,7.26],[-12.95,7.8],[-13.12,8.16],[-13.25,8.9],[-13.69,9.49],[-14.07,9.89],[-14.33,10.02],[-14.58,10.21],[-14.69,10.66],[-14.84,10.88],[-15.13,11.04],[-15.66,11.46],[-16.09,11.52],[-16.31,11.81],[-16.31,11.96],[-16.61,12.17],[-16.68,12.38],[-16.84,13.15],[-16.71,13.6],[-17.13,14.37],[-17.62,14.73],[-17.19,14.92],[-16.7,15.62],[-16.46,16.14],[-16.55,16.67],[-16.27,17.17],[-16.15,18.11],[-16.26,19.1],[-16.38,19.59],[-16.28,20.09],[-16.54,20.57],[-17.06,21.0],[-17.02,21.42],[-16.97,21.89],[-16.59,22.16],[-16.26,22.68],[-16.33,23.02],[-15.98,23.72],[-15.43,24.36],[-15.09,24.52],[-14.82,25.1],[-14.8,25.64],[-14.44,26.25],[-13.77,26.62],[-13.14,27.64],[-12.62,28.04],[-11.69,28.15],[-10.9,28.83],[-10.4,29.1],[-9.56,29.93],[-9.81,31.18],[-9.43,32.04],[-9.3,32.56],[-8.66,33.24],[-7.65,33.7],[-6.91,34.11],[-6.24,35.15],[-5.93,35.76],[-5.19,35.76],[-4.59,35.33],[-3.64,35.4],[-2.6,35.18],[-2.17,35.17],[-1.21,35.71],[-0.13,35.89],[0.5,36.3],[1.47,36.61],[3.16,36.78],[4.82,36.87],[5.32,36.72],[6.26,37.11],[7.33,37.12],[7.74,36.89],[8.42,36.95],[9.51,37.35],[10.21,37.23],[10.18,36.72],[11.03,37.09],[11.1,36.9],[10.6,36.41],[10.59,35.95],[10.94,35.7],[10.81,34.83],[10.15,34.33],[10.34,33.79],[10.86,33.77],[11.11,33.29],[11.49,33.14],[12.66,32.79],[13.08,32.88],[13.92,32.71],[15.25,32.27],[15.71,31.38],[16.61,31.18],[18.02,30.76],[19.09,30.27],[19.57,30.53],[20.05,30.99],[19.82,31.75],[20.13,32.24],[20.85,32.71],[21.54,32.84],[22.9,32.64],[23.24,32.19],[23.61,32.19],[23.93,32.02],[24.92,31.9],[25.16,31.57],[26.5,31.59],[27.46,31.32],[28.45,31.03],[28.91,30.87],[29.68,31.19],[30.1,31.47],[30.98,31.56],[31.69,31.43],[31.96,30.93],[32.19,31.26],[32.99,31.02],[33.77,30.97],[34.27,31.22],[34.56,31.55],[34.49,31.61],[34.75,32.07],[34.96,32.83],[35.1,33.08],[35.13,33.09],[35.48,33.91],[35.98,34.61],[36.0,34.64],[35.91,35.41],[36.15,35.82],[35.78,36.28],[36.16,36.65],[35.55,36.57],[34.71,36.8],[34.03,36.22],[32.51,36.11],[31.7,36.64],[30.62,36.68],[30.39,36.26],[29.7,36.14],[28.73,36.68],[27.64,36.66],[27.05,37.65],[26.32,38.21],[26.8,38.99],[26.17,39.46],[27.28,40.42],[28.82,40.46],[29.24,41.22],[31.15,41.09],[32.35,41.74],[33.51,42.02],[35.17,42.04],[36.91,41.34],[38.35,40.95],[39.51,41.1],[40.37,41.01],[41.55,41.54],[41.7,41.96],[41.45,42.65],[40.88,43.01],[40.32,43.13],[39.96,43.44],[38.68,44.28],[37.54,44.66],[36.68,45.24],[37.4,45.4],[38.23,46.24],[37.67,46.64],[39.15,47.04],[39.12,47.26],[38.22,47.1],[37.43,47.02],[36.76,46.7],[35.82,46.65],[34.96,46.27],[35.02,45.65],[35.51,45.41],[36.53,45.47],[36.33,45.11],[35.24,44.94],[33.88,44.36],[33.33,44.56],[33.55,45.03],[32.45,45.33],[32.63,45.52],[33.59,45.85],[33.3,46.08],[31.74,46.33],[31.68,46.71],[30.75,46.58],[30.38,46.03],[29.6,45.29],[29.63,45.04],[29.14,44.82],[28.84,44.91],[28.56,43.71],[28.04,43.29],[27.67,42.58],[28.0,42.01],[28.12,41.62],[28.99,41.3],[28.81,41.05],[27.62,41.0],[27.19,40.69],[26.36,40.15],[26.04,40.62],[26.06,40.82],[25.45,40.85],[24.93,40.95],[23.71,40.69],[24.41,40.13],[23.9,39.96],[23.34,39.96],[22.81,40.48],[22.63,40.26],[22.85,39.66],[23.35,39.19],[22.97,38.97],[23.53,38.51],[24.03,38.22],[24.04,37.66],[23.12,37.92],[23.41,37.41],[22.78,37.31],[23.15,36.42],[22.49,36.41],[21.67,36.85],[21.3,37.65],[21.12,38.31],[20.73,38.77],[20.22,39.34],[20.15,39.63],[19.98,39.7],[19.96,39.92],[19.41,40.25],[19.32,40.73],[19.4,41.41],[19.54,41.72],[19.37,41.88],[19.16,41.96],[18.88,42.28],[18.45,42.48],[17.51,42.85],[16.93,43.21],[16.02,43.51],[15.17,44.24],[15.38,44.32],[14.92,44.74],[14.9,45.08],[14.26,45.23],[13.95,44.8],[13.66,45.14],[13.68,45.48],[13.72,45.5],[13.94,45.59],[13.14,45.74],[12.33,45.38],[12.38,44.89],[12.26,44.6],[12.59,44.09],[13.53,43.59],[14.03,42.76],[15.14,41.96],[15.93,41.96],[16.17,41.74],[15.89,41.54],[16.79,41.18],[17.52,40.88],[18.38,40.36],[18.48,40.17],[18.29,39.81],[17.74,40.28],[16.87,40.44],[16.45,39.8],[17.17,39.42],[17.05,38.9],[16.64,38.84],[16.1,37.99],[15.68,37.91],[15.69,38.21],[15.89,38.75],[16.11,38.96],[15.72,39.54],[15.41,40.05],[15.0,40.17],[14.7,40.6],[14.06,40.79],[13.63,41.19],[12.89,41.25],[12.11,41.7],[11.19,42.36],[10.51,42.93],[10.2,43.92],[9.7,44.04],[8.89,44.37],[8.43,44.23],[7.85,43.77],[7.44,43.69],[6.53,43.13],[4.56,43.4],[3.1,43.08],[2.99,42.47],[3.04,41.89],[2.09,41.23],[0.81,41.01],[0.72,40.68],[0.11,40.12],[-0.28,39.31],[0.11,38.74],[-0.47,38.29],[-0.68,37.64],[-1.44,37.44],[-2.15,36.67],[-3.42,36.66],[-4.37,36.68],[-5.0,36.32],[-5.38,35.95],[-5.87,36.03],[-6.24,36.37],[-6.52,36.94],[-7.45,37.1],[-7.86,36.84],[-8.38,36.98],[-8.9,36.87],[-8.75,37.65],[-8.84,38.27],[-9.29,38.36],[-9.53,38.74],[-9.45,39.39],[-9.05,39.76],[-8.98,40.16],[-8.77,40.76],[-8.79,41.18],[-8.99,41.54],[-9.03,41.88],[-8.98,42.59],[-9.39,43.03],[-7.98,43.75],[-6.75,43.57],[-5.41,43.57],[-4.35,43.4],[-3.52,43.46],[-1.9,43.42],[-1.38,44.02],[-1.19,46.01],[-2.23,47.06],[-2.96,47.57],[-4.49,47.96],[-4.59,48.68],[-3.3,48.9],[-1.62,48.64],[-1.93,49.78],[-0.99,49.35],[1.34,50.13],[1.64,50.95],[2.51,51.15],[3.32,51.35],[3.83,51.62],[4.71,53.09],[6.07,53.51],[6.91,53.48],[7.1,53.69],[7.94,53.75],[8.12,53.53],[8.8,54.02],[8.57,54.4],[8.53,54.96],[8.12,55.52],[8.09,56.54],[8.26,56.81],[8.54,57.11],[9.42,57.17],[9.78,57.45],[10.58,57.73],[10.55,57.22],[10.25,56.89],[10.37,56.61],[10.91,56.46],[10.67,56.08],[10.37,56.19],[9.65,55.47],[9.92,54.98],[9.94,54.6],[10.95,54.36],[10.94,54.01],[11.96,54.2],[12.52,54.47],[13.65,54.08],[14.12,53.76],[14.8,54.05],[16.36,54.51],[17.62,54.85],[18.62,54.68],[18.7,54.44],[19.66,54.43],[19.89,54.87],[21.27,55.19],[21.06,56.03],[21.09,56.78],[21.58,57.41],[22.52,57.75],[23.32,57.01],[24.12,57.03],[24.31,57.79],[24.43,58.38],[24.06,58.26],[23.43,58.61],[23.34,59.19],[24.6,59.47],[25.86,59.61],[26.95,59.45],[27.98,59.48],[29.12,60.03],[28.07,60.5],[26.26,60.42],[24.5,60.06],[22.87,59.85],[22.29,60.39],[21.32,60.72],[21.54,61.71],[21.06,62.61],[21.54,63.19],[22.44,63.82],[24.73,64.9],[25.4,65.11],[25.29,65.53],[23.9,66.01],[22.18,65.72],[21.21,65.03],[21.37,64.41],[19.78,63.61],[17.85,62.75],[17.12,61.34],[17.83,60.64],[18.79,60.08],[17.87,58.95],[16.83,58.72],[16.45,57.04],[15.88,56.1],[14.67,56.2],[14.1,55.41],[12.94,55.36],[12.63,56.31],[11.79,57.44],[11.03,58.86],[10.36,59.47],[8.38,58.31],[7.05,58.08],[5.67,58.59],[5.31,59.66],[4.99,61.97],[5.91,62.61],[8.55,63.45],[10.53,64.49],[12.36,65.88],[14.76,67.81],[16.44,68.56],[19.18,69.82],[21.38,70.26],[23.02,70.2],[24.55,71.03],[26.37,70.99],[28.17,71.19],[31.29,70.45],[30.01,70.19],[31.1,69.56],[32.13,69.91],[33.78,69.3],[36.51,69.06],[40.29,67.93],[41.06,67.46],[41.13,66.79],[40.02,66.27],[38.38,66.0],[33.92,66.76],[33.18,66.63],[34.81,65.9],[34.94,64.41],[36.23,64.11],[37.01,63.85],[37.14,64.33],[36.52,64.78],[37.18,65.14],[39.59,64.52],[40.44,64.76],[39.76,65.5],[42.09,66.48],[43.02,66.42],[43.95,66.07],[44.53,66.76],[43.7,67.35],[44.19,67.95],[43.45,68.57],[46.25,68.25],[46.82,67.69],[45.56,67.57],[45.56,67.01],[46.35,66.67],[47.89,66.88],[48.14,67.52],[50.23,68.0],[53.72,68.86],[54.47,68.81],[53.49,68.2],[54.73,68.1],[55.44,68.44],[57.32,68.47],[58.8,68.88],[59.94,68.28],[61.08,68.94],[60.03,69.52],[60.55,69.85],[63.5,69.55],[64.89,69.23],[68.51,68.09],[69.18,68.62],[68.16,69.14],[68.14,69.36],[66.93,69.45],[67.26,69.93],[66.72,70.71],[66.69,71.03],[68.54,71.93],[69.2,72.84],[69.94,73.04],[72.59,72.78],[72.8,72.22],[71.85,71.41],[72.47,71.09],[72.79,70.39],[72.56,69.02],[73.67,68.41],[73.24,67.74],[71.28,66.32],[72.42,66.17],[72.82,66.53],[73.92,66.79],[74.19,67.28],[75.05,67.76],[74.47,68.33],[74.94,68.99],[73.84,69.07],[73.6,69.63],[74.4,70.63],[73.1,71.45],[74.89,72.12],[74.66,72.83],[75.16,72.86],[75.68,72.3],[75.29,71.34],[76.36,71.15],[75.9,71.87],[77.58,72.27],[79.65,72.32],[81.5,71.75],[80.61,72.58],[80.51,73.65],[82.25,73.85],[84.66,73.81],[86.82,73.94],[86.01,74.46],[87.17,75.12],[88.32,75.14],[90.26,75.64],[92.9,75.77],[93.23,76.05],[95.86,76.14],[96.68,75.92],[98.92,76.45],[100.76,76.43],[101.04,76.86],[101.99,77.29],[104.35,77.7],[106.07,77.37],[104.71,77.13],[106.97,76.97]],[[49.11,41.28],[49.62,40.57],[50.08,40.53],[50.39,40.26],[49.57,40.18],[49.4,39.4],[49.22,39.05],[48.86,38.82],[48.88,38.32],[49.2,37.58],[50.15,37.37],[50.84,36.87],[52.26,36.7],[53.83,36.97],[53.92,37.2],[53.74,37.91],[53.88,38.95],[53.1,39.29],[53.36,39.98],[52.69,40.03],[52.92,40.88],[53.86,40.63],[54.74,40.95],[54.01,41.55],[53.72,42.12],[52.92,41.87],[52.81,41.14],[52.5,41.78],[52.45,42.03],[52.69,42.44],[52.5,42.79],[51.34,43.13],[50.89,44.03],[50.34,44.28],[50.31,44.61],[51.28,44.51],[51.32,45.25],[52.17,45.41],[53.04,45.26],[53.22,46.23],[53.04,46.85],[52.04,46.8],[51.19,47.05],[50.03,46.61],[49.1,46.4],[48.65,45.81],[47.68,45.64],[46.68,44.61],[47.59,43.66],[47.49,42.99],[48.58,41.81],[49.11,41.28]]]},{"type":"Polygon","coordinates":[[[-93.84,77.52],[-94.3,77.49],[-96.17,77.56],[-96.44,77.83],[-94.42,77.82],[-93.72,77.63],[-93.84,77.52]]]},{"type":"Polygon","coordinates":[[[-110.19,77.7],[-112.05,77.41],[-113.53,77.73],[-112.72,78.05],[-111.26,78.15],[-109.85,78.0],[-110.19,77.7]]]},{"type":"Polygon","coordinates":[[[24.72,77.85],[22.49,77.44],[20.73,77.68],[21.42,77.94],[20.81,78.25],[22.88,78.45],[23.28,78.08],[24.72,77.85]]]},{"type":"Polygon","coordinates":[[[-109.66,78.6],[-110.88,78.41],[-112.54,78.41],[-112.53,78.55],[-111.5,78.85],[-110.96,78.8],[-109.66,78.6]]]},{"type":"Polygon","coordinates":[[[-95.83,78.06],[-97.31,77.85],[-98.12,78.08],[-98.55,78.46],[-98.63,78.87],[-97.34,78.83],[-96.75,78.77],[-95.56,78.42],[-95.83,78.06]]]},{"type":"Polygon","coordinates":[[[-100.06,78.32],[-99.67,77.91],[-101.3,78.02],[-102.95,78.34],[-105.18,78.38],[-104.21,78.68],[-105.42,78.92],[-105.49,79.3],[-103.53,79.17],[-100.83,78.8],[-100.06,78.32]]]},{"type":"Polygon","coordinates":[[[105.08,78.31],[99.44,77.92],[101.26,79.23],[102.09,79.35],[102.84,79.28],[105.37,78.71],[105.08,78.31]]]},{"type":"Polygon","coordinates":[[[18.25,79.7],[21.54,78.96],[19.03,78.56],[18.47,77.83],[17.59,77.64],[17.12,76.81],[15.91,76.77],[13.76,77.38],[14.67,77.74],[13.17,78.02],[11.22,78.87],[10.44,79.65],[13.17,80.01],[13.72,79.66],[15.14,79.67],[15.52,80.02],[16.99,80.05],[18.25,79.7]]]},{"type":"Polygon","coordinates":[[[25.45,80.41],[27.41,80.06],[25.92,79.52],[23.02,79.4],[20.08,79.57],[19.9,79.84],[18.46,79.86],[17.37,80.32],[20.46,80.6],[21.91,80.36],[22.92,80.66],[25.45,80.41]]]},{"type":"Polygon","coordinates":[[[51.14,80.55],[49.79,80.42],[48.89,80.34],[48.75,80.18],[47.59,80.01],[46.5,80.25],[47.07,80.56],[44.85,80.59],[46.8,80.77],[48.32,80.78],[48.52,80.51],[49.1,80.75],[50.04,80.92],[51.52,80.7],[51.14,80.55]]]},{"type":"Polygon","coordinates":[[[99.94,78.88],[97.76,78.76],[94.97,79.04],[93.31,79.43],[92.55,80.14],[91.18,80.34],[93.78,81.02],[95.94,81.25],[97.88,80.75],[100.19,79.78],[99.94,78.88]]]},{"type":"Polygon","coordinates":[[[-87.02,79.66],[-85.81,79.34],[-87.19,79.04],[-89.04,78.29],[-90.8,78.22],[-92.88,78.34],[-93.95,78.75],[-93.94,79.11],[-93.15,79.38],[-94.97,79.37],[-96.08,79.71],[-96.71,80.16],[-96.02,80.6],[-95.32,80.91],[-94.3,80.98],[-94.74,81.21],[-92.41,81.26],[-91.13,80.72],[-89.45,80.51],[-87.81,80.32],[-87.02,79.66]]]},{"type":"Polygon","coordinates":[[[-68.5,83.11],[-65.83,83.03],[-63.68,82.9],[-61.85,82.63],[-61.89,82.36],[-64.33,81.93],[-66.75,81.73],[-67.66,81.5],[-65.48,81.51],[-67.84,80.9],[-69.47,80.62],[-71.18,79.8],[-73.24,79.63],[-73.88,79.43],[-76.91,79.32],[-75.53,79.2],[-76.22,79.02],[-75.39,78.53],[-76.34,78.18],[-77.89,77.9],[-78.36,77.51],[-79.76,77.21],[-79.62,76.98],[-77.91,77.02],[-77.89,76.78],[-80.56,76.18],[-83.17,76.45],[-86.11,76.3],[-87.6,76.42],[-89.49,76.47],[-89.62,76.95],[-87.77,77.18],[-88.26,77.9],[-87.65,77.97],[-84.98,77.54],[-86.34,78.18],[-87.96,78.37],[-87.15,78.76],[-85.38,79.0],[-85.09,79.35],[-86.51,79.74],[-86.93,80.25],[-84.2,80.21],[-83.41,80.1],[-81.85,80.46],[-84.1,80.58],[-87.6,80.52],[-89.37,80.86],[-90.2,81.26],[-91.37,81.55],[-91.59,81.89],[-90.1,82.08],[-88.93,82.12],[-86.97,82.28],[-85.5,82.65],[-84.26,82.6],[-83.18,82.32],[-82.42,82.86],[-81.1,83.02],[-79.31,83.13],[-76.25,83.17],[-75.72,83.06],[-72.83,83.23],[-70.67,83.17],[-68.5,83.11]]]},{"type":"Polygon","coordinates":[[[-27.1,83.52],[-20.85,82.73],[-22.69,82.34],[-26.52,82.3],[-31.9,82.2],[-31.4,82.02],[-27.86,82.13],[-24.84,81.79],[-22.9,82.09],[-22.07,81.73],[-23.17,81.15],[-20.62,81.52],[-15.77,81.91],[-12.77,81.72],[-12.21,81.29],[-16.29,80.58],[-16.85,80.35],[-20.05,80.18],[-17.73,80.13],[-18.9,79.4],[-19.7,78.75],[-19.67,77.64],[-18.47,76.99],[-20.04,76.94],[-21.68,76.63],[-19.83,76.1],[-19.6,75.25],[-20.67,75.16],[-19.37,74.3],[-21.59,74.22],[-20.43,73.82],[-20.76,73.46],[-22.17,73.31],[-23.57,73.31],[-22.31,72.63],[-22.3,72.18],[-24.28,72.6],[-24.79,72.33],[-23.44,72.08],[-22.13,71.47],[-21.75,70.66],[-23.54,70.47],[-24.31,70.86],[-25.54,71.43],[-25.2,70.75],[-26.36,70.23],[-23.73,70.18],[-22.35,70.13],[-25.03,69.26],[-27.75,68.47],[-30.67,68.13],[-31.78,68.12],[-32.81,67.74],[-34.2,66.68],[-36.35,65.98],[-37.04,65.94],[-38.38,65.69],[-39.81,65.46],[-40.67,64.84],[-40.68,64.14],[-41.19,63.48],[-42.82,62.68],[-42.42,61.9],[-42.87,61.07],[-43.38,60.1],[-44.79,60.04],[-46.26,60.85],[-48.26,60.86],[-49.23,61.41],[-49.9,62.38],[-51.63,63.63],[-52.14,64.28],[-52.28,65.18],[-53.66,66.1],[-53.3,66.84],[-53.97,67.19],[-52.98,68.36],[-51.48,68.73],[-51.08,69.15],[-50.87,69.93],[-52.01,69.57],[-52.56,69.43],[-53.46,69.28],[-54.68,69.61],[-54.75,70.29],[-54.36,70.82],[-53.43,70.84],[-51.39,70.57],[-53.11,71.2],[-54.0,71.55],[-55,71.41],[-55.83,71.65],[-54.72,72.59],[-55.33,72.96],[-56.12,73.65],[-57.32,74.71],[-58.6,75.1],[-58.59,75.52],[-61.27,76.1],[-63.39,76.18],[-66.06,76.13],[-68.5,76.06],[-69.66,76.38],[-71.4,77.01],[-68.78,77.32],[-66.76,77.38],[-71.04,77.64],[-73.3,78.04],[-73.16,78.43],[-69.37,78.91],[-65.71,79.39],[-65.32,79.76],[-68.02,80.12],[-67.15,80.52],[-63.69,81.21],[-62.23,81.32],[-62.65,81.77],[-60.28,82.03],[-57.21,82.19],[-54.13,82.2],[-53.04,81.89],[-50.39,82.44],[-48.0,82.06],[-46.6,81.99],[-44.52,81.66],[-46.9,82.2],[-46.76,82.63],[-43.41,83.23],[-39.9,83.18],[-38.62,83.55],[-35.09,83.65],[-27.1,83.52]]]}]} \ No newline at end of file diff --git a/bitchat/Services/AutocompleteService.swift b/bitchat/Services/AutocompleteService.swift index 3e739e74..dd588d24 100644 --- a/bitchat/Services/AutocompleteService.swift +++ b/bitchat/Services/AutocompleteService.swift @@ -12,6 +12,15 @@ import Foundation final class AutocompleteService { private typealias Patterns = MessageFormattingEngine.Patterns + /// Whether the text before the cursor ends in an `@` mention token: the + /// only case `getSuggestions` can return anything for, whatever the peers. + /// Lets callers skip assembling the peer list after every keystroke. + static func hasMentionToken(in text: String, cursorPosition: Int) -> Bool { + let textToPosition = String(text.prefix(cursorPosition)) + let range = NSRange(location: 0, length: (textToPosition as NSString).length) + return Patterns.mentionAutocomplete.firstMatch(in: textToPosition, options: [], range: range) != nil + } + /// Get autocomplete suggestions for current text func getSuggestions(for text: String, peers: [String], cursorPosition: Int) -> (suggestions: [String], range: NSRange?) { let textToPosition = String(text.prefix(cursorPosition)) diff --git a/bitchat/Services/BLE/BLEService.swift b/bitchat/Services/BLE/BLEService.swift index edd630e9..a07e5d31 100644 --- a/bitchat/Services/BLE/BLEService.swift +++ b/bitchat/Services/BLE/BLEService.swift @@ -2488,7 +2488,7 @@ final class BLEService: NSObject { } // Signature verification and registry lookups run on messageQueue // like the live receive path. - self.messageQueue.async { + self.messageQueue.async { [self] in guard self.isCurrentPanicLifecycleGeneration(generation) else { return } diff --git a/bitchat/Services/CommandProcessor.swift b/bitchat/Services/CommandProcessor.swift index c37aa3dc..7b8d1bf2 100644 --- a/bitchat/Services/CommandProcessor.swift +++ b/bitchat/Services/CommandProcessor.swift @@ -48,6 +48,9 @@ protocol CommandContextProvider: AnyObject { func getPeerIDForNickname(_ nickname: String) -> PeerID? func getVisibleGeoParticipants() -> [CommandGeoParticipant] func nostrPubkeyForDisplayName(_ displayName: String) -> String? + /// A /block or /unblock by name changed which geohash participants are + /// hidden; the roster re-filters instead of waiting for its timer. + func geohashBlockListDidChange() // MARK: - Chat Actions func startPrivateChat(with peerID: PeerID) @@ -368,6 +371,7 @@ final class CommandProcessor { return .success(message: String(format: String(localized: "command.block.already", defaultValue: "%@ is already blocked", comment: "Reply when /block targets an already-blocked nickname"), locale: .current, nickname)) } identityManager.setNostrBlocked(pub, isBlocked: true) + contextProvider?.geohashBlockListDidChange() return .success(message: String(format: String(localized: "command.block.done_geo", defaultValue: "blocked %@ in geohash chats", comment: "Confirmation after blocking a geohash participant"), locale: .current, nickname)) } @@ -396,6 +400,7 @@ final class CommandProcessor { return .success(message: String(format: String(localized: "command.unblock.not_blocked", defaultValue: "%@ is not blocked", comment: "Reply when /unblock targets a nickname that isn't blocked"), locale: .current, nickname)) } identityManager.setNostrBlocked(pub, isBlocked: false) + contextProvider?.geohashBlockListDidChange() return .success(message: String(format: String(localized: "command.unblock.done_geo", defaultValue: "unblocked %@ in geohash chats", comment: "Confirmation after unblocking a geohash participant"), locale: .current, nickname)) } return .error(message: String(format: String(localized: "command.unblock.failed", defaultValue: "cannot unblock %@: not found", comment: "Error when /unblock can't resolve the target"), locale: .current, nickname)) diff --git a/bitchat/Services/ConversationNotificationMuteStore.swift b/bitchat/Services/ConversationNotificationMuteStore.swift index 39c116ca..633b6f0e 100644 --- a/bitchat/Services/ConversationNotificationMuteStore.swift +++ b/bitchat/Services/ConversationNotificationMuteStore.swift @@ -6,6 +6,7 @@ // For more information, see // +import BitFoundation import Foundation /// Persistent mute preferences for individual conversations (#1594). diff --git a/bitchat/Services/GeohashParticipantTracker.swift b/bitchat/Services/GeohashParticipantTracker.swift index be1ea35e..f5f7e39e 100644 --- a/bitchat/Services/GeohashParticipantTracker.swift +++ b/bitchat/Services/GeohashParticipantTracker.swift @@ -43,6 +43,12 @@ final class GeohashParticipantTracker: ObservableObject { /// Currently visible people for the active geohash @Published private(set) var visiblePeople: [GeoPerson] = [] + /// Bumps whenever the set of ids in `visiblePeople` changes, so derived + /// per-roster state (the sender color palette) is rebuilt only when + /// membership changes — not on every activity timestamp update. + private(set) var visibleMembershipRevision: UInt64 = 0 + private var visibleMemberIDs: Set = [] + /// The currently active geohash (if any) private var activeGeohash: String? @@ -65,40 +71,67 @@ final class GeohashParticipantTracker: ObservableObject { func setActiveGeohash(_ geohash: String?) { activeGeohash = geohash if geohash == nil { - visiblePeople = [] + publishVisiblePeople([]) } else { refresh() } } - /// Record activity from a participant in the current active geohash - func recordParticipant(pubkeyHex: String) { - guard let gh = activeGeohash else { return } - recordParticipant(pubkeyHex: pubkeyHex, geohash: gh) + /// Record activity from a participant in the current active geohash. + /// Returns `false`, recording nothing, when no geohash is active. + @discardableResult + func recordParticipant(pubkeyHex: String, seenAt: Date = Date()) -> Bool { + guard let gh = activeGeohash else { return false } + return recordParticipant(pubkeyHex: pubkeyHex, geohash: gh, seenAt: seenAt) } - /// Record activity from a participant in a specific geohash - func recordParticipant(pubkeyHex: String, geohash: String) { - let key = pubkeyHex.lowercased() - var map = participants[geohash] ?? [:] - map[key] = Date() - participants[geohash] = map - - // Always notify observers that state has changed so counts in UI update - objectWillChange.send() + /// Record activity from a participant in a specific geohash. + /// + /// `seenAt` is when the activity happened, clamped to now: arrival time + /// for live events, the event's own timestamp for history relays replay + /// on subscribe. Replayed history older than the activity window must + /// not make its authors count as present. Returns whether the activity + /// counted, i.e. fell inside the window. + /// + /// Runs for every inbound geohash event, so the common case — someone + /// already present sending a heartbeat or message — only moves their + /// timestamp. The roster is republished only when someone becomes + /// visible; departures are picked up by the refresh timer. + @discardableResult + func recordParticipant(pubkeyHex: String, geohash: String, seenAt: Date = Date()) -> Bool { + let now = Date() + let cutoff = now.addingTimeInterval(activityCutoff) + let stamp = min(seenAt, now) + guard stamp >= cutoff else { return false } - // Only refresh visible list if this geohash is currently active + let key = pubkeyHex.lowercased() + let previous = participants[geohash]?[key] + if let previous, previous >= stamp { return true } + participants[geohash, default: [:]][key] = stamp + + let wasActive = previous.map { $0 >= cutoff } ?? false + guard !wasActive else { return true } + // Someone newly counts as present here: participant counts for + // this geohash changed (sampled channels included). + objectWillChange.send() if activeGeohash == geohash { refresh() } + return true + } + + /// A participant's display name may have changed (a nickname was learned + /// or edited). Republishes the roster if they're currently visible. + func noteDisplayNameChanged(pubkeyHex: String) { + guard visibleMemberIDs.contains(pubkeyHex.lowercased()) else { return } + refresh() } /// Remove a participant from all geohashes (used when blocking) func removeParticipant(pubkeyHex: String) { let key = pubkeyHex.lowercased() - for (gh, var map) in participants { - map.removeValue(forKey: key) - participants[gh] = map + for geohash in participants.keys { + participants[geohash]?.removeValue(forKey: key) } refresh() } @@ -107,7 +140,22 @@ final class GeohashParticipantTracker: ObservableObject { func participantCount(for geohash: String) -> Int { let cutoff = Date().addingTimeInterval(activityCutoff) let map = participants[geohash] ?? [:] - return map.values.filter { $0 >= cutoff }.count + return map.values.reduce(0) { $1 >= cutoff ? $0 + 1 : $0 } + } + + /// Drops entries that aged out of the activity window, in every geohash + /// (sampled ones included) so a long session doesn't keep every pubkey + /// it ever saw. + func pruneExpired(now: Date = Date()) { + let cutoff = now.addingTimeInterval(activityCutoff) + for (geohash, map) in participants { + let active = map.filter { $0.value >= cutoff } + if active.isEmpty { + participants.removeValue(forKey: geohash) + } else if active.count != map.count { + participants[geohash] = active + } + } } /// Get the visible people list for the active geohash (read-only query) @@ -125,16 +173,35 @@ final class GeohashParticipantTracker: ObservableObject { .sorted { $0.lastSeen > $1.lastSeen } } - /// Refresh the visible people list + /// Refresh the visible people list. Publishes only when what the roster + /// shows changed — who is present or how they're named — so subscribers + /// (the people sheet, the bootstrapper's prune) don't rebuild on + /// activity that only moved timestamps. func refresh() { - visiblePeople = getVisiblePeople() + let people = getVisiblePeople() + guard Self.rosterKey(people) != Self.rosterKey(visiblePeople) else { return } + publishVisiblePeople(people) } - /// Start the periodic refresh timer + private static func rosterKey(_ people: [GeoPerson]) -> [String: String] { + Dictionary(people.map { ($0.id, $0.displayName) }, uniquingKeysWith: { first, _ in first }) + } + + private func publishVisiblePeople(_ people: [GeoPerson]) { + let ids = Set(people.map(\.id)) + if ids != visibleMemberIDs { + visibleMemberIDs = ids + visibleMembershipRevision &+= 1 + } + visiblePeople = people + } + + /// Start the periodic refresh timer: expires people who went quiet. func startRefreshTimer(interval: TimeInterval = 30.0) { stopRefreshTimer() refreshTimer = Timer.scheduledTimer(withTimeInterval: interval, repeats: true) { [weak self] _ in Task { @MainActor in + self?.pruneExpired() self?.refresh() } } @@ -149,14 +216,14 @@ final class GeohashParticipantTracker: ObservableObject { /// Clear all participant data func clear() { participants.removeAll() - visiblePeople = [] + publishVisiblePeople([]) } /// Clear participant data for a specific geohash func clear(geohash: String) { participants.removeValue(forKey: geohash) if activeGeohash == geohash { - visiblePeople = [] + publishVisiblePeople([]) } } } diff --git a/bitchat/Services/NostrTransport.swift b/bitchat/Services/NostrTransport.swift index 8c62d711..10f51219 100644 --- a/bitchat/Services/NostrTransport.swift +++ b/bitchat/Services/NostrTransport.swift @@ -184,7 +184,7 @@ final class NostrTransport: Transport, @unchecked Sendable { } private func refreshReachablePeers() { - Task { @MainActor in + Task { @MainActor [self] in let favorites = dependencies.loadFavorites() let reachable = favorites.values .filter { $0.peerNostrPublicKey != nil } diff --git a/bitchat/Services/PrivateChatManager.swift b/bitchat/Services/PrivateChatManager.swift index dcf4631b..fb18e513 100644 --- a/bitchat/Services/PrivateChatManager.swift +++ b/bitchat/Services/PrivateChatManager.swift @@ -142,12 +142,20 @@ final class PrivateChatManager: ObservableObject { // 2. Consolidate from temporary Nostr peer IDs (nostr_* prefixed) let normalizedNickname = peerNickname.lowercased() + let myPeerID = meshService.myPeerID var tempPeerIDsToConsolidate: [PeerID] = [] for (storedPeerID, messages) in privateChats { if storedPeerID.isGeoDM && storedPeerID != peerID { + // Only the peer's own rows say who a thread is with. Mine + // carry my plain nickname (sendGeohashDM), so next to a mesh + // peer who shares it they would match as well: my thread with + // a geohash stranger would fold into the namesake's chat, a + // reply typed there would reach the namesake, and the + // stranger's next reply would open a fresh thread. + let containsMyRows = messages.contains { $0.senderPeerID == myPeerID } let nicknamesMatch = messages.allSatisfy { $0.sender.lowercased() == normalizedNickname } - if nicknamesMatch && !messages.isEmpty { + if !containsMyRows && nicknamesMatch && !messages.isEmpty { tempPeerIDsToConsolidate.append(storedPeerID) } } @@ -173,7 +181,11 @@ final class PrivateChatManager: ObservableObject { originalSender: message.originalSender, isPrivate: message.isPrivate, recipientNickname: message.recipientNickname, - senderPeerID: peerID, + // Defense in depth: threads holding my rows are + // skipped above, so every row here is the peer's and + // moves to `peerID`. Were one of mine to get through, + // it would keep my ID, as in the stable-key branch. + senderPeerID: message.senderPeerID == meshService.myPeerID ? meshService.myPeerID : peerID, mentions: message.mentions, deliveryStatus: message.deliveryStatus ) @@ -198,11 +210,15 @@ final class PrivateChatManager: ObservableObject { return hasUnreadMessages } - /// Syncs the read receipt tracking between manager and view model for sent messages + /// Syncs the read receipt tracking between manager and view model for sent + /// messages. "Sent" means carrying my peer ID, never merely my nickname: + /// a namesake's delivered message still gets its READ receipt, and my + /// messages from before a rename still count as mine. @MainActor - func syncReadReceiptsForSentMessages(peerID: PeerID, nickname: String, externalReceipts: inout Set) { + func syncReadReceiptsForSentMessages(peerID: PeerID, externalReceipts: inout Set) { + guard let myPeerID = meshService?.myPeerID else { return } for message in messages(for: peerID) { - if message.sender == nickname { + if message.isOwn(myPeerID: myPeerID, myGeoChatPeerID: nil) { switch message.deliveryStatus { case .read, .delivered: externalReceipts.insert(message.id) diff --git a/bitchat/Utils/GeohashCoverage.swift b/bitchat/Utils/GeohashCoverage.swift new file mode 100644 index 00000000..6d85101d --- /dev/null +++ b/bitchat/Utils/GeohashCoverage.swift @@ -0,0 +1,67 @@ +// +// GeohashCoverage.swift +// bitchat +// +// This is free and unencumbered software released into the public domain. +// For more information, see +// + +import Foundation + +/// Human-readable size of a geohash cell, shared by the location channels sheet and +/// the globe picker. +enum GeohashCoverage { + /// Approximate max cell dimension at the equator, e.g. "~4.9 km" or "~3.0 mi". + static func string(forPrecision len: Int, locale: Locale = .current) -> String { + // Values sourced from common geohash dimension tables. + let maxMeters: Double = { + switch len { + case 2: return 1_250_000 + case 3: return 156_000 + case 4: return 39_100 + case 5: return 4_890 + case 6: return 1_220 + case 7: return 153 + case 8: return 38.2 + case 9: return 4.77 + case 10: return 1.19 + default: + if len <= 1 { return 5_000_000 } + // For >10, scale down conservatively by ~1/4 each char + let over = len - 10 + return 1.19 * pow(0.25, Double(over)) + } + }() + + if usesMetric(locale) { + return "~\(formatDistance(maxMeters / 1000.0)) km" + } else { + return "~\(formatDistance(maxMeters / 1609.344)) mi" + } + } + + /// Channel level a geohash of this length belongs to. + static func level(forLength length: Int) -> GeohashChannelLevel { + switch length { + case ...2: return .region + case 3...4: return .province + case 5: return .city + case 6: return .neighborhood + case 7: return .block + default: return .building + } + } + + static func usesMetric(_ locale: Locale = .current) -> Bool { + if #available(iOS 16.0, macOS 13.0, *) { + return locale.measurementSystem == .metric + } else { + return locale.usesMetricSystem + } + } + + private static func formatDistance(_ value: Double) -> String { + if value >= 100 { return String(format: "%.0f", value.rounded()) } + return String(format: "%.1f", value) + } +} diff --git a/bitchat/Utils/Theme.swift b/bitchat/Utils/Theme.swift index ec0283e0..41628630 100644 --- a/bitchat/Utils/Theme.swift +++ b/bitchat/Utils/Theme.swift @@ -197,7 +197,13 @@ struct ThemedRootBackground: View { } .ignoresSafeArea() } else { + // Full-bleed like the gradient above. Passed to .background(_:) + // as a view, a backdrop stops at the safe area (a bare Color + // passed as a ShapeStyle would not). In a sheet, the sheet's own + // background (#1C1C1E in dark mode) then shows through the + // home-indicator inset and under the navigation bar. palette.background + .ignoresSafeArea() } } } diff --git a/bitchat/ViewModels/ChatComposerCoordinator.swift b/bitchat/ViewModels/ChatComposerCoordinator.swift index d0d347f2..84a7cf3d 100644 --- a/bitchat/ViewModels/ChatComposerCoordinator.swift +++ b/bitchat/ViewModels/ChatComposerCoordinator.swift @@ -82,6 +82,14 @@ final class ChatComposerCoordinator { } func updateAutocomplete(for text: String, cursorPosition: Int) { + // The query can only suggest for an @-token ending at the cursor, so + // skip assembling the candidates (a pass over every mesh peer or + // geohash participant) after each typing pause in plain text. + guard AutocompleteService.hasMentionToken(in: text, cursorPosition: cursorPosition) else { + setAutocompleteState(suggestions: [], range: nil) + return + } + let peerCandidates = autocompleteCandidates() let (suggestions, range) = context.autocompleteQuery( for: text, @@ -89,17 +97,7 @@ final class ChatComposerCoordinator { cursorPosition: cursorPosition ) - if !suggestions.isEmpty { - context.autocompleteSuggestions = suggestions - context.autocompleteRange = range - context.showAutocomplete = true - context.selectedAutocompleteIndex = 0 - } else { - context.autocompleteSuggestions = [] - context.autocompleteRange = nil - context.showAutocomplete = false - context.selectedAutocompleteIndex = 0 - } + setAutocompleteState(suggestions: suggestions, range: suggestions.isEmpty ? nil : range) } func completeNickname(_ nickname: String, in text: inout String) -> Int { @@ -143,6 +141,25 @@ final class ChatComposerCoordinator { } private extension ChatComposerCoordinator { + /// Shows `suggestions` (hidden when empty) with the highlight reset to the + /// first one. Writes only the properties that change: each write + /// republishes the composer state, which re-renders every message row. + func setAutocompleteState(suggestions: [String], range: NSRange?) { + let isShown = !suggestions.isEmpty + if context.autocompleteSuggestions != suggestions { + context.autocompleteSuggestions = suggestions + } + if context.autocompleteRange != range { + context.autocompleteRange = range + } + if context.showAutocomplete != isShown { + context.showAutocomplete = isShown + } + if context.selectedAutocompleteIndex != 0 { + context.selectedAutocompleteIndex = 0 + } + } + func autocompleteCandidates() -> [String] { switch context.activeChannel { case .mesh: diff --git a/bitchat/ViewModels/ChatMessageFormatter.swift b/bitchat/ViewModels/ChatMessageFormatter.swift index 1a00315b..8a5310c1 100644 --- a/bitchat/ViewModels/ChatMessageFormatter.swift +++ b/bitchat/ViewModels/ChatMessageFormatter.swift @@ -9,6 +9,20 @@ final class ChatMessageFormatter { private unowned let viewModel: ChatViewModel private let meshPalette = MinimalDistancePalette(config: .mesh) private let nostrPalette = MinimalDistancePalette(config: .nostr) + /// What the Nostr palette was last built from. Colors are looked up once + /// per people-sheet row and per formatted geochat message, so the palette + /// is rebuilt only when the roster's membership (or our own excluded + /// key) changes rather than recomputing the roster on every lookup. + private var nostrPaletteKey: NostrPaletteKey? + + private struct NostrPaletteKey: Equatable { + // periphery:ignore - read only via the synthesized Equatable + // conformance (the rebuild check), which the indexer cannot + // attribute. + let membershipRevision: UInt64 + // periphery:ignore - see `membershipRevision`. + let excludedHex: String? + } init(viewModel: ChatViewModel) { self.viewModel = viewModel @@ -348,6 +362,10 @@ final class ChatMessageFormatter { return result } + /// Prefix of the header's formatted-text cache variants. No full-text + /// variant starts with it, so the two caches can't collide. + static let headerCacheNamespace = "hdr:" + func formatMessageHeader(_ message: BitchatMessage, colorScheme: ColorScheme, theme: AppTheme = .matrix) -> AttributedString { let design = theme.bodyFontDesign let isSelf: Bool = { @@ -364,14 +382,23 @@ final class ChatMessageFormatter { }() let isDark = colorScheme == .dark - let baseColor: Color = isSelf ? .orange : peerColor(for: message, isDark: isDark) let isVerifiedSender = !isSelf && isVerifiedSender(of: message) + // Same key ingredients as the full-text cache, in a namespace of its + // own so a header and a full text never answer each other's lookups. + let cacheVariant = Self.headerCacheNamespace + theme.formatCacheVariant + (isVerifiedSender ? "-vf" : "") + if let cachedHeader = message.getCachedFormattedText(isDark: isDark, isSelf: isSelf, variant: cacheVariant) { + return cachedHeader + } + + let baseColor: Color = isSelf ? .orange : peerColor(for: message, isDark: isDark) if message.sender == "system" { var style = AttributeContainer() style.foregroundColor = baseColor style.font = .bitchatSystem(size: 14, weight: .medium, design: design) - return AttributedString(message.sender).mergingAttributes(style) + let header = AttributedString(message.sender).mergingAttributes(style) + message.setCachedFormattedText(header, isDark: isDark, isSelf: isSelf, variant: cacheVariant) + return header } var result = AttributedString() @@ -395,6 +422,7 @@ final class ChatMessageFormatter { appendVerifiedSeal(to: &result, baseColor: baseColor, design: design) } result.append(AttributedString("> ").mergingAttributes(senderStyle)) + message.setCachedFormattedText(result, isDark: isDark, isSelf: isSelf, variant: cacheVariant) return result } @@ -511,20 +539,31 @@ private extension ChatMessageFormatter { return .orange } - nostrPalette.ensurePalette(for: currentNostrPaletteSeeds(excluding: myHex)) + ensureNostrPalette(excluding: myHex) if let color = nostrPalette.color(for: pubkeyHexLowercased, isDark: isDark) { return color } return Color(peerSeed: "nostr:" + pubkeyHexLowercased, isDark: isDark) } - func currentNostrPaletteSeeds(excluding myHex: String?) -> [String: String] { + /// Seeds the palette from the tracker's published roster, and only when + /// its membership changed. Rebuilding it from a fresh roster scan per + /// lookup made every people-sheet render O(N²) in the participant count. + func ensureNostrPalette(excluding myHex: String?) { + let tracker = viewModel.participantTracker + let key = NostrPaletteKey( + membershipRevision: tracker.visibleMembershipRevision, + excludedHex: myHex + ) + guard key != nostrPaletteKey else { return } + nostrPaletteKey = key + var seeds: [String: String] = [:] let excluded = myHex ?? "" - for person in viewModel.visibleGeohashPeople() where person.id != excluded { + for person in tracker.visiblePeople where person.id != excluded { seeds[person.id] = "nostr:" + person.id } - return seeds + nostrPalette.ensurePalette(for: seeds) } func currentGeohashIdentityHex() -> String? { diff --git a/bitchat/ViewModels/ChatPrivateConversationCoordinator.swift b/bitchat/ViewModels/ChatPrivateConversationCoordinator.swift index a22f93f8..49585ea3 100644 --- a/bitchat/ViewModels/ChatPrivateConversationCoordinator.swift +++ b/bitchat/ViewModels/ChatPrivateConversationCoordinator.swift @@ -870,6 +870,7 @@ final class ChatPrivateConversationCoordinator { var oldPeerIDsToRemove: [PeerID] = [] var didMigrate = false let cutoffTime = Date().addingTimeInterval(-TransportConfig.uiMigrationCutoffSeconds) + let myPeerID = context.myPeerID for (oldPeerID, messages) in context.privateChats where oldPeerID != peerID { let oldFingerprint = context.storedFingerprint(for: oldPeerID) @@ -895,9 +896,20 @@ final class ChatPrivateConversationCoordinator { category: .session ) } else if currentFingerprint == nil || oldFingerprint == nil { + // Which rows are mine goes by sender ID: after a rename my + // older rows carry my previous name, and a stranger who + // takes that name must not read as their author. My + // geo-DM rows name me, not the peer, as their recipient + // (sendGeohashDM), so they say nothing about who a geo-DM + // thread is with: there only the peer's rows count. + // Otherwise a namesake (or someone who took my old name) + // would take the thread, and my next reply, along. + let isGeoDMThread = oldPeerID.isGeoDM let isRelevantChat = recentMessages.contains { msg in - (msg.sender == senderNickname && msg.sender != context.nickname) - || (msg.sender == context.nickname && msg.recipientNickname == senderNickname) + if msg.isOwn(myPeerID: myPeerID, myGeoChatPeerID: nil) { + return !isGeoDMThread && msg.recipientNickname == senderNickname + } + return msg.sender == senderNickname } if isRelevantChat { diff --git a/bitchat/ViewModels/ChatPublicConversationCoordinator.swift b/bitchat/ViewModels/ChatPublicConversationCoordinator.swift index d69e9880..ef9eb989 100644 --- a/bitchat/ViewModels/ChatPublicConversationCoordinator.swift +++ b/bitchat/ViewModels/ChatPublicConversationCoordinator.swift @@ -24,10 +24,6 @@ protocol ChatPublicConversationContext: AnyObject { var currentGeohash: String? { get } var nickname: String { get } var myPeerID: PeerID { get } - /// Publishes the public-timeline batching state (UI animation suppression). - /// (Single mutation path for the owner's `isBatchingPublic`; this - /// coordinator never reads it.) - func setPublicBatching(_ isBatching: Bool) /// Signals that message state changed so observers refresh (e.g. `objectWillChange.send()`). func notifyUIChanged() @@ -249,14 +245,17 @@ final class ChatPublicConversationCoordinator: PublicMessagePipelineDelegate { ) } + /// Runs once per participant on every roster rebuild, so keep it to one + /// lowercase copy: `publicKeyHex` is already lowercase. func displayNameForNostrPubkey(_ pubkeyHex: String) -> String { let suffix = String(pubkeyHex.suffix(4)) + let key = pubkeyHex.lowercased() if let geohash = context.currentGeohash, let myGeoIdentity = try? context.deriveNostrIdentity(forGeohash: geohash), - myGeoIdentity.publicKeyHex.lowercased() == pubkeyHex.lowercased() { + myGeoIdentity.publicKeyHex == key { return context.nickname + "#" + suffix } - if let nick = context.geoNicknames[pubkeyHex.lowercased()], !nick.isEmpty { + if let nick = context.geoNicknames[key], !nick.isEmpty { return nick + "#" + suffix } return "anon#\(suffix)" @@ -522,7 +521,7 @@ final class ChatPublicConversationCoordinator: PublicMessagePipelineDelegate { } let isMentioned = message.mentions?.contains { myTokens.contains($0.normalizedNickname) } ?? false - if isMentioned && message.sender != context.nickname { + if isMentioned && !isOwnMessage(message) { SecureLogger.info("🔔 Mention from \(message.sender)", category: .session) context.notifyMention(from: message.sender, message: message.content) } @@ -547,7 +546,7 @@ final class ChatPublicConversationCoordinator: PublicMessagePipelineDelegate { let isHugForMe = message.content.contains("🫂") && hugsMe let isSlapForMe = message.content.contains("🐟") && slapsMe - if isHugForMe && message.sender != context.nickname { + if isHugForMe && !isOwnMessage(message) { let impactFeedback = UIImpactFeedbackGenerator(style: .medium) impactFeedback.prepare() @@ -558,7 +557,7 @@ final class ChatPublicConversationCoordinator: PublicMessagePipelineDelegate { impactFeedback.impactOccurred() } } - } else if isSlapForMe && message.sender != context.nickname { + } else if isSlapForMe && !isOwnMessage(message) { let impactFeedback = UIImpactFeedbackGenerator(style: .heavy) impactFeedback.prepare() impactFeedback.impactOccurred() @@ -585,10 +584,6 @@ final class ChatPublicConversationCoordinator: PublicMessagePipelineDelegate { func pipelinePrewarmMessage(_: PublicMessagePipeline, message: BitchatMessage) { context.prewarmMessageFormatting(message) } - - func pipelineSetBatchingState(_: PublicMessagePipeline, isBatching: Bool) { - context.setPublicBatching(isBatching) - } } private extension ChatPublicConversationCoordinator { @@ -606,4 +601,15 @@ private extension ChatPublicConversationCoordinator { } return "name:" + message.sender.lowercased() } + + /// Whether I wrote an inbound message (a gossip replay of my mesh text, or + /// a relay echo of my geochat text), by its sender ID rather than its + /// display name, so a namesake's mention or hug still reaches me. + func isOwnMessage(_ message: BitchatMessage) -> Bool { + message.isOwn( + myPeerID: context.myPeerID, + // The ID my own public rows carry in the active channel. + myGeoChatPeerID: currentPublicSender().peerID + ) + } } diff --git a/bitchat/ViewModels/ChatViewModel.swift b/bitchat/ViewModels/ChatViewModel.swift index c99a2c6a..82e71553 100644 --- a/bitchat/ViewModels/ChatViewModel.swift +++ b/bitchat/ViewModels/ChatViewModel.swift @@ -442,8 +442,6 @@ final class ChatViewModel: ObservableObject, BitchatDelegate, SynchronousMessage // MARK: - Public message batching (UI perf) let publicMessagePipeline: PublicMessagePipeline - // Single-writer: mutate only via `setPublicBatching(_:)` below. - @Published private(set) var isBatchingPublic: Bool = false // Backing store for `sentReadReceipts` persistence. `.standard` in // production; injectable so tests can use a scratch suite that does not @@ -554,7 +552,6 @@ final class ChatViewModel: ObservableObject, BitchatDelegate, SynchronousMessage func syncReadReceiptsForSentMessages(for peerID: PeerID) { privateChatManager.syncReadReceiptsForSentMessages( peerID: peerID, - nickname: nickname, externalReceipts: &sentReadReceipts ) } @@ -568,12 +565,6 @@ final class ChatViewModel: ObservableObject, BitchatDelegate, SynchronousMessage return oldCount - sentReadReceipts.count } - /// Publishes the public-timeline batching state (UI animation suppression). - @MainActor - func setPublicBatching(_ isBatching: Bool) { - isBatchingPublic = isBatching - } - @MainActor func setGeoChatSubscriptionID(_ id: String?) { geoSubscriptionID = id @@ -1355,6 +1346,19 @@ final class ChatViewModel: ObservableObject, BitchatDelegate, SynchronousMessage return false } + /// This device's identity in `geohash`'s location channel, through the + /// `cachedGeohashIdentity` slot the message formatter shares (cleared on + /// panic), so per-row callers pay no derivation. + @MainActor + func geohashIdentity(for geohash: String) -> NostrIdentity? { + if let cached = cachedGeohashIdentity, cached.geohash == geohash { + return cached.identity + } + guard let identity = try? idBridge.deriveIdentity(forGeohash: geohash) else { return nil } + cachedGeohashIdentity = (geohash, identity) + return identity + } + // MARK: - Public helpers /// Return the current, pruned, sorted people list for the active geohash without mutating state. @@ -1609,8 +1613,11 @@ final class ChatViewModel: ObservableObject, BitchatDelegate, SynchronousMessage // Wipe persisted location state (selected channel, teleport set, // bookmarks). For an activist-safety wipe, where the user has been is - // exactly the data an adversary inspecting the device wants. - LocationStateManager.shared.panicWipe() + // exactly the data an adversary inspecting the device wants. The app + // runs on `LocationChannelManager.shared` (AppRuntime injects it), so + // this wipes the process-wide state there; a test's own manager keeps + // the wipe from resetting the channel under every other test. + locationManager.panicWipe() // Reset nickname to anonymous nickname = "anon\(Int.random(in: 1000...9999))" @@ -1686,6 +1693,8 @@ final class ChatViewModel: ObservableObject, BitchatDelegate, SynchronousMessage _ = clearGeoSamplingSubs() cachedGeohashIdentity = nil nostrKeyMapping.removeAll() + // Every pubkey seen in any geohash this session, with when. + participantTracker.clear() // Clear read receipt tracking sentReadReceipts.removeAll() diff --git a/bitchat/ViewModels/ChatViewModelBootstrapper.swift b/bitchat/ViewModels/ChatViewModelBootstrapper.swift index 3ccb7d12..14de9c9b 100644 --- a/bitchat/ViewModels/ChatViewModelBootstrapper.swift +++ b/bitchat/ViewModels/ChatViewModelBootstrapper.swift @@ -157,13 +157,19 @@ private extension ChatViewModelBootstrapper { } .store(in: &viewModel.cancellables) + // Teleport markers describe people present now, so they follow the + // roster (pruned against it as it is when this runs, not the + // delivered snapshot). Nicknames don't: they name the authors of + // messages on screen, including replayed history from people no + // longer present, so they stay for the channel (cleared on switch, + // bounded by the store's capacity). viewModel.participantTracker.$visiblePeople .receive(on: DispatchQueue.main) - .sink { [weak viewModel] people in - Task { @MainActor [weak viewModel] in - let visible = Set(people.map { $0.id }) - viewModel?.locationPresenceStore.retainTeleportedGeo(keeping: visible) - viewModel?.locationPresenceStore.retainGeoNicknames(keeping: visible) + .sink { [weak viewModel] _ in + MainActor.assumeIsolated { + guard let viewModel else { return } + let visible = Set(viewModel.participantTracker.visiblePeople.map(\.id)) + viewModel.locationPresenceStore.retainTeleportedGeo(keeping: visible) } } .store(in: &viewModel.cancellables) diff --git a/bitchat/ViewModels/Extensions/ChatViewModel+Nostr.swift b/bitchat/ViewModels/Extensions/ChatViewModel+Nostr.swift index 8205e13b..7b5a3562 100644 --- a/bitchat/ViewModels/Extensions/ChatViewModel+Nostr.swift +++ b/bitchat/ViewModels/Extensions/ChatViewModel+Nostr.swift @@ -80,6 +80,11 @@ extension ChatViewModel { nostrCoordinator.nostrPubkeyForDisplayName(name) } + @MainActor + func geohashBlockListDidChange() { + participantTracker.refresh() + } + @MainActor func startGeohashDM(withPubkeyHex hex: String) { nostrCoordinator.startGeohashDM(withPubkeyHex: hex) diff --git a/bitchat/ViewModels/GeoPresenceTracker.swift b/bitchat/ViewModels/GeoPresenceTracker.swift index c2f89b79..bbcf0969 100644 --- a/bitchat/ViewModels/GeoPresenceTracker.swift +++ b/bitchat/ViewModels/GeoPresenceTracker.swift @@ -19,7 +19,7 @@ protocol GeoPresenceContext: AnyObject { func isNostrBlocked(pubkeyHexLowercased: String) -> Bool func parseMentions(from content: String) -> [String] - func recordGeoParticipant(pubkeyHex: String, geohash: String) + func recordGeoParticipant(pubkeyHex: String, geohash: String, seenAt: Date) func geoParticipantCount(for geohash: String) -> Int func markGeoTeleported(_ pubkeyHexLowercased: String) @@ -43,8 +43,8 @@ extension ChatViewModel: GeoPresenceContext { locationPresenceStore.teleportedGeo.count } - func recordGeoParticipant(pubkeyHex: String, geohash: String) { - participantTracker.recordParticipant(pubkeyHex: pubkeyHex, geohash: geohash) + func recordGeoParticipant(pubkeyHex: String, geohash: String, seenAt: Date) { + participantTracker.recordParticipant(pubkeyHex: pubkeyHex, geohash: geohash, seenAt: seenAt) } func geoParticipantCount(for geohash: String) -> Int { @@ -107,8 +107,21 @@ final class GeoPresenceTracker { // actor) by NostrRelayManager before delivery. guard shouldProcessGeoSamplingEvent(event.id) else { return } - let existingCount = context.geoParticipantCount(for: gh) - context.recordGeoParticipant(pubkeyHex: event.pubkey, geohash: gh) + // The open channel is usually one of the sampled cells, and its own + // subscription already records its senders; recording this copy too + // ran the participant bookkeeping twice for every event there. + let isOpenChannel: Bool = { + if case .location(let channel) = context.activeChannel { + return channel.geohash == gh + } + return false + }() + let existingCount = isOpenChannel ? nil : context.geoParticipantCount(for: gh) + if !isOpenChannel { + // Arrival time: sampling replays at most a few minutes of history, + // and live senders with skewed clocks must still count. + context.recordGeoParticipant(pubkeyHex: event.pubkey, geohash: gh, seenAt: Date()) + } guard let content = event.content.trimmedOrNilIfEmpty else { return } if context.isNostrBlocked(pubkeyHexLowercased: event.pubkey.lowercased()) { return } diff --git a/bitchat/ViewModels/GeohashSubscriptionManager.swift b/bitchat/ViewModels/GeohashSubscriptionManager.swift index ce4c9448..930cc549 100644 --- a/bitchat/ViewModels/GeohashSubscriptionManager.swift +++ b/bitchat/ViewModels/GeohashSubscriptionManager.swift @@ -47,7 +47,8 @@ protocol GeohashSubscriptionContext: AnyObject { func startGeoParticipantRefreshTimer() func stopGeoParticipantRefreshTimer() func setActiveParticipantGeohash(_ geohash: String?) - func recordGeoParticipant(pubkeyHex: String) + @discardableResult + func recordGeoParticipant(pubkeyHex: String, seenAt: Date) -> Bool func markGeoTeleported(_ pubkeyHexLowercased: String) func clearGeoTeleported(_ pubkeyHexLowercased: String) func clearTeleportedGeo() @@ -118,6 +119,12 @@ final class GeohashSubscriptionManager { /// Geohashes already told "sent via mesh gateway" this session, so the /// notice appears once per channel instead of once per message. private var gatewayNoticeGeohashes = Set() + /// The geochat subscription whose stored history relays may still be + /// replaying; cleared when its EOSE callback runs. Best effort: the relay + /// manager also runs that callback on its fallback timeout (e.g. while + /// Tor is still bootstrapping), and history arriving after it counts as + /// live activity. See `NostrInboundPipeline`'s `isHistoryReplay`. + private var replayingGeoSubscriptionID: String? init(context: any GeohashSubscriptionContext, inbound: NostrInboundPipeline, presence: GeoPresenceTracker) { self.context = context @@ -145,14 +152,20 @@ final class GeohashSubscriptionManager { toGeohash: channel.geohash, count: TransportConfig.nostrGeoRelayCount ) - NostrRelayManager.shared.subscribe(filter: filter, id: subID, relayUrls: subRelays) { [weak self] event in + replayingGeoSubscriptionID = subID + NostrRelayManager.shared.subscribe(filter: filter, id: subID, relayUrls: subRelays, handler: { [weak self] event in Task { @MainActor [weak self] in - self?.inbound.subscribeNostrEvent(event) + guard let self else { return } + self.inbound.subscribeNostrEvent(event, isHistoryReplay: self.replayingGeoSubscriptionID == subID) // Gateway downlink: rebroadcast relay events for the viewed // channel onto the mesh (no-op unless gateway mode is on). GatewayService.shared.rebroadcastRelayEvent(event, geohash: channel.geohash) } - } + }, onEOSE: { [weak self] in + Task { @MainActor [weak self] in + self?.endHistoryReplay(for: subID) + } + }) if let dmSub = context.geoDmSubscriptionID { NostrRelayManager.shared.unsubscribe(id: dmSub) @@ -219,7 +232,7 @@ final class GeohashSubscriptionManager { context.setActiveParticipantGeohash(channel.geohash) if let identity = try? context.deriveNostrIdentity(forGeohash: channel.geohash) { - context.recordGeoParticipant(pubkeyHex: identity.publicKeyHex) + context.recordGeoParticipant(pubkeyHex: identity.publicKeyHex, seenAt: Date()) let key = identity.publicKeyHex.lowercased() if context.isTeleported && context.isGeohashOutsideRegionalChannels(channel.geohash) { context.markGeoTeleported(key) @@ -238,14 +251,20 @@ final class GeohashSubscriptionManager { let ts = Date().addingTimeInterval(-TransportConfig.nostrGeohashInitialLookbackSeconds) let filter = NostrFilter.geohashEphemeral(channel.geohash, since: ts, limit: TransportConfig.nostrGeohashInitialLimit) let subRelays = GeoRelayDirectory.shared.closestRelays(toGeohash: channel.geohash, count: 5) - NostrRelayManager.shared.subscribe(filter: filter, id: subID, relayUrls: subRelays) { [weak self] event in + replayingGeoSubscriptionID = subID + NostrRelayManager.shared.subscribe(filter: filter, id: subID, relayUrls: subRelays, handler: { [weak self] event in Task { @MainActor [weak self] in - self?.inbound.handleNostrEvent(event) + guard let self else { return } + self.inbound.handleNostrEvent(event, isHistoryReplay: self.replayingGeoSubscriptionID == subID) // Gateway downlink: rebroadcast relay events for the viewed // channel onto the mesh (no-op unless gateway mode is on). GatewayService.shared.rebroadcastRelayEvent(event, geohash: channel.geohash) } - } + }, onEOSE: { [weak self] in + Task { @MainActor [weak self] in + self?.endHistoryReplay(for: subID) + } + }) subscribeToGeoChat(channel) } @@ -306,7 +325,7 @@ final class GeohashSubscriptionManager { ) } - context.recordGeoParticipant(pubkeyHex: identity.publicKeyHex) + context.recordGeoParticipant(pubkeyHex: identity.publicKeyHex, seenAt: Date()) context.registerNostrKeyMapping(identity.publicKeyHex, for: PeerID(nostr: identity.publicKeyHex)) SecureLogger.debug( "GeoTeleport: sent geo message pub=\(identity.publicKeyHex.prefix(8))… teleported=\(geoContext.teleported)", @@ -325,6 +344,12 @@ final class GeohashSubscriptionManager { context.recordProcessedNostrEvent(event.id) } + @MainActor + private func endHistoryReplay(for subscriptionID: String) { + guard replayingGeoSubscriptionID == subscriptionID else { return } + replayingGeoSubscriptionID = nil + } + @MainActor func beginGeohashSampling(for geohashes: [String]) { guard let context else { return } diff --git a/bitchat/ViewModels/NostrInboundPipeline.swift b/bitchat/ViewModels/NostrInboundPipeline.swift index a6592802..535f1ae5 100644 --- a/bitchat/ViewModels/NostrInboundPipeline.swift +++ b/bitchat/ViewModels/NostrInboundPipeline.swift @@ -29,7 +29,10 @@ protocol NostrInboundPipelineContext: AnyObject { func setGeoNickname(_ nickname: String, forPubkey pubkeyHex: String) /// Records the Nostr pubkey behind a (possibly virtual) peer ID. func registerNostrKeyMapping(_ pubkey: String, for peerID: PeerID) - func recordGeoParticipant(pubkeyHex: String) + /// `seenAt` is the event's own timestamp, so replayed history doesn't + /// count its authors as present. Returns whether the activity counted. + @discardableResult + func recordGeoParticipant(pubkeyHex: String, seenAt: Date) -> Bool // MARK: Inbound public messages /// `powBits` is the validated NIP-13 difficulty of the source event @@ -70,11 +73,14 @@ extension ChatViewModel: NostrInboundPipelineContext { } func setGeoNickname(_ nickname: String, forPubkey pubkeyHex: String) { - locationPresenceStore.setNickname(nickname, for: pubkeyHex) + if locationPresenceStore.setNickname(nickname, for: pubkeyHex) { + participantTracker.noteDisplayNameChanged(pubkeyHex: pubkeyHex) + } } - func recordGeoParticipant(pubkeyHex: String) { - participantTracker.recordParticipant(pubkeyHex: pubkeyHex) + @discardableResult + func recordGeoParticipant(pubkeyHex: String, seenAt: Date) -> Bool { + participantTracker.recordParticipant(pubkeyHex: pubkeyHex, seenAt: seenAt) } } @@ -115,8 +121,12 @@ final class NostrInboundPipeline { self.presence = presence } + /// `isHistoryReplay` marks events relays return from storage before EOSE. + /// Those count as activity at the time they happened, so an hour of + /// replayed history doesn't make its authors look present; live events + /// count when they arrive, which keeps senders with skewed clocks visible. @MainActor - func subscribeNostrEvent(_ event: NostrEvent) { + func subscribeNostrEvent(_ event: NostrEvent, isHistoryReplay: Bool = false) { guard let context else { return } // Cheap rejects (kind, dedup lookup) — duplicates dominate real // traffic. The signature was already verified (exactly once, off the @@ -146,13 +156,21 @@ final class NostrInboundPipeline { context.registerNostrKeyMapping(event.pubkey, for: PeerID(nostr_: event.pubkey)) context.registerNostrKeyMapping(event.pubkey, for: PeerID(nostr: event.pubkey)) - context.recordGeoParticipant(pubkeyHex: event.pubkey) + let countsAsPresence = context.recordGeoParticipant( + pubkeyHex: event.pubkey, + seenAt: isHistoryReplay ? Date(timeIntervalSince1970: TimeInterval(event.created_at)) : Date() + ) if event.kind == NostrProtocol.EventKind.geohashPresence.rawValue { return } - if GeoPresenceTracker.hasTeleportTag(event) { + // Teleport markers describe people present now and are pruned only + // when the roster changes, so a tag on history too old to count must + // not mark its absent author: the marker could still be there when + // they came back. A teleported sender tags every message, so their + // recent ones still mark them. + if countsAsPresence, GeoPresenceTracker.hasTeleportTag(event) { let key = event.pubkey.lowercased() let isSelf: Bool = { if let gh = context.currentGeohash, @@ -193,8 +211,9 @@ final class NostrInboundPipeline { } } + /// See `subscribeNostrEvent(_:isHistoryReplay:)` for `isHistoryReplay`. @MainActor - func handleNostrEvent(_ event: NostrEvent) { + func handleNostrEvent(_ event: NostrEvent, isHistoryReplay: Bool = false) { guard let context else { return } // Cheap rejects (kind, dedup lookup) — the signature was already // verified (exactly once, off the main actor) by NostrRelayManager. @@ -231,25 +250,27 @@ final class NostrInboundPipeline { return false }() - if hasTeleportTag, !isSelf { - presence.scheduleMarkPeerTeleported(event.pubkey.lowercased(), logged: true) - } - - context.recordGeoParticipant(pubkeyHex: event.pubkey) - - if isSelf { - let eventTime = Date(timeIntervalSince1970: TimeInterval(event.created_at)) - if Date().timeIntervalSince(eventTime) < 15 { - return - } + let eventTime = Date(timeIntervalSince1970: TimeInterval(event.created_at)) + let seenAt = isHistoryReplay ? eventTime : Date() + if isSelf, Date().timeIntervalSince(eventTime) < 15 { + context.recordGeoParticipant(pubkeyHex: event.pubkey, seenAt: seenAt) + return } + // Learn the nickname before recording the sender, so a newcomer + // enters the roster under their name rather than anon#xxxx. if let nickTag = event.tags.first(where: { $0.first == "n" }), nickTag.count >= 2 { context.setGeoNickname(nickTag[1].trimmed, forPubkey: event.pubkey) } context.registerNostrKeyMapping(event.pubkey, for: PeerID(nostr_: event.pubkey)) context.registerNostrKeyMapping(event.pubkey, for: PeerID(nostr: event.pubkey)) + let countsAsPresence = context.recordGeoParticipant(pubkeyHex: event.pubkey, seenAt: seenAt) + + // Only activity that counts marks teleport; see subscribeNostrEvent. + if hasTeleportTag, !isSelf, countsAsPresence { + presence.scheduleMarkPeerTeleported(event.pubkey.lowercased(), logged: true) + } if event.kind == NostrProtocol.EventKind.geohashPresence.rawValue { return diff --git a/bitchat/ViewModels/PublicMessagePipeline.swift b/bitchat/ViewModels/PublicMessagePipeline.swift index 9d30f83e..92dd0412 100644 --- a/bitchat/ViewModels/PublicMessagePipeline.swift +++ b/bitchat/ViewModels/PublicMessagePipeline.swift @@ -22,7 +22,6 @@ protocol PublicMessagePipelineDelegate: AnyObject { @discardableResult func pipeline(_: PublicMessagePipeline, commit message: BitchatMessage, to conversationID: ConversationID) -> Bool func pipelinePrewarmMessage(_: PublicMessagePipeline, message: BitchatMessage) - func pipelineSetBatchingState(_: PublicMessagePipeline, isBatching: Bool) } @MainActor @@ -100,8 +99,6 @@ private extension PublicMessagePipeline { return } - delegate.pipelineSetBatchingState(self, isBatching: true) - // Content-window dedup against recorded keys and within the batch; // ID dedup happens in the store at commit time. var pending: [(message: BitchatMessage, conversationID: ConversationID, contentKey: String)] = [] @@ -122,10 +119,7 @@ private extension PublicMessagePipeline { } buffer.removeAll(keepingCapacity: true) - guard !pending.isEmpty else { - delegate.pipelineSetBatchingState(self, isBatching: false) - return - } + guard !pending.isEmpty else { return } pending.sort { $0.message.timestamp < $1.message.timestamp } @@ -140,8 +134,6 @@ private extension PublicMessagePipeline { delegate.pipelinePrewarmMessage(self, message: item.message) } - delegate.pipelineSetBatchingState(self, isBatching: false) - if !buffer.isEmpty { scheduleFlush() } diff --git a/bitchat/Views/Components/MeshEmptyStateView.swift b/bitchat/Views/Components/MeshEmptyStateView.swift index b225927d..4b4fe26d 100644 --- a/bitchat/Views/Components/MeshEmptyStateView.swift +++ b/bitchat/Views/Components/MeshEmptyStateView.swift @@ -9,6 +9,7 @@ // This is free and unencumbered software released into the public domain. // +import Combine import SwiftUI struct MeshEmptyStateView: View { diff --git a/bitchat/Views/Components/TextMessageView.swift b/bitchat/Views/Components/TextMessageView.swift index ed376acf..c7f3ee36 100644 --- a/bitchat/Views/Components/TextMessageView.swift +++ b/bitchat/Views/Components/TextMessageView.swift @@ -34,14 +34,12 @@ struct TextMessageView: View { var body: some View { VStack(alignment: .leading, spacing: 0) { - // Precompute heavy token scans once per row - let cashuLinks = message.content.extractCashuLinks() - let lightningLinks = message.content.extractLightningLinks() + // Heavy token scans run once per message, not once per render + let scan = message.contentScan // Baseline alignment keeps the lock and delivery glyphs on the // first text line; a fixed top padding left the lock's solid body // hanging below the line's visual center. HStack(alignment: .firstTextBaseline, spacing: 0) { - let isLong = message.content.isLongForDisplay() let isExpanded = expandedMessageIDs.contains(message.id) if message.isPrivate { Image(systemName: "lock.fill") @@ -70,7 +68,7 @@ struct TextMessageView: View { } Text(conversationUIModel.formatMessage(message, colorScheme: colorScheme, theme: theme)) .fixedSize(horizontal: false, vertical: true) - .lineLimit(isLong && !isExpanded ? TransportConfig.uiLongMessageLineLimit : nil) + .lineLimit(scan.isLongForDisplay && !isExpanded ? TransportConfig.uiLongMessageLineLimit : nil) .frame(maxWidth: .infinity, alignment: .leading) // Delivery status indicator for private messages. Tappable: @@ -112,7 +110,7 @@ struct TextMessageView: View { } // Expand/Collapse for very long messages - if message.content.isLongForDisplay() { + if scan.isLongForDisplay { let isExpanded = expandedMessageIDs.contains(message.id) let labelKey = isExpanded ? LocalizedStringKey("content.message.show_less") : LocalizedStringKey("content.message.show_more") Button(labelKey) { @@ -125,12 +123,12 @@ struct TextMessageView: View { } // Render payment chips (Lightning / Cashu) with rounded background - if !lightningLinks.isEmpty || !cashuLinks.isEmpty { + if !scan.lightningLinks.isEmpty || !scan.cashuLinks.isEmpty { HStack(spacing: 8) { - ForEach(lightningLinks, id: \.self) { link in + ForEach(scan.lightningLinks, id: \.self) { link in PaymentChipView(paymentType: .lightning(link)) } - ForEach(cashuLinks, id: \.self) { link in + ForEach(scan.cashuLinks, id: \.self) { link in PaymentChipView(paymentType: .cashu(link)) } } diff --git a/bitchat/Views/ContentHeaderView.swift b/bitchat/Views/ContentHeaderView.swift index 39b11ada..56b711ce 100644 --- a/bitchat/Views/ContentHeaderView.swift +++ b/bitchat/Views/ContentHeaderView.swift @@ -291,7 +291,10 @@ struct ContentHeaderView: View { HStack(spacing: 4) { Image(systemName: "person.2.fill") .font(.system(size: headerPeerIconSize, weight: .regular)) - Text("\(headerOtherPeersCount)") + // Format style, not Text("\(count)"): same locale digits + // and grouping, and no letterless key for Xcode's + // localization export to add back to the catalog. + Text(headerOtherPeersCount, format: .number) .font(.system(size: headerPeerCountFontSize, weight: .regular, design: theme.bodyFontDesign)) .accessibilityHidden(true) } diff --git a/bitchat/Views/ContentSheetViews.swift b/bitchat/Views/ContentSheetViews.swift index 555ffdc6..2383210b 100644 --- a/bitchat/Views/ContentSheetViews.swift +++ b/bitchat/Views/ContentSheetViews.swift @@ -380,6 +380,9 @@ private struct ContentPeopleListView: View { showSidebar = true } ) + // Skip re-rendering the roster when this view + // refreshes for models the list doesn't read. + .equatable() // Direct conversations survive channel switches; the // geoDM someone opened from another cell must stay // reachable here too. @@ -443,7 +446,11 @@ private struct ContentPeopleListView: View { // the ScrollView centers it — headers and empty states // floated mid-screen on iPhone. .frame(maxWidth: .infinity, alignment: .leading) - .id(peerListModel.renderID) + // Keyed by channel only. Rows are keyed by person, so roster + // updates diff in place; a key derived from the rows rebuilds + // the whole list on every heartbeat and resets its stable + // ordering. + .id(ConversationID(channelID: locationChannelsModel.selectedChannel)) } } .sheet(isPresented: $showVerifySheet) { diff --git a/bitchat/Views/ContentView.swift b/bitchat/Views/ContentView.swift index 7c07d546..9b09c73d 100644 --- a/bitchat/Views/ContentView.swift +++ b/bitchat/Views/ContentView.swift @@ -228,7 +228,7 @@ struct ContentView: View { var body: some View { mainContent - .onAppear { + .onAppear { [conversationUIModel, voiceRecordingVM] in conversationUIModel.setCurrentColorScheme(colorScheme) conversationUIModel.setCurrentTheme(appTheme) voiceRecordingVM.sessionProvider = { [weak conversationUIModel] in diff --git a/bitchat/Views/GeohashPeopleList.swift b/bitchat/Views/GeohashPeopleList.swift index 9613f227..bfcc5b60 100644 --- a/bitchat/Views/GeohashPeopleList.swift +++ b/bitchat/Views/GeohashPeopleList.swift @@ -1,12 +1,21 @@ import SwiftUI -struct GeohashPeopleList: View { +struct GeohashPeopleList: View, Equatable { @EnvironmentObject private var peerListModel: PeerListModel @ThemedPalette private var palette let onTapPerson: () -> Void @Environment(\.colorScheme) var colorScheme @State private var orderedIDs: [String] = [] + /// The only input is the tap action, which always reveals the DM pane + /// and can't be compared. Treating it as equal lets SwiftUI skip this + /// list when the presenting view re-renders for models the list doesn't + /// read (message batches, chrome, verification); roster changes still + /// arrive through the observed PeerListModel. + nonisolated static func == (lhs: GeohashPeopleList, rhs: GeohashPeopleList) -> Bool { + true + } + private enum Strings { static let noneNearby: LocalizedStringKey = "geohash_people.none_nearby" static let youSuffix: LocalizedStringKey = "geohash_people.you_suffix" @@ -34,21 +43,17 @@ struct GeohashPeopleList: View { } else { let people = peerListModel.geohashPeople let currentIDs = people.map(\.id) + let personByID = Dictionary(people.map { ($0.id, $0) }, uniquingKeysWith: { first, _ in first }) + let displayed = PeopleListOrdering.stableOrder(previous: orderedIDs, current: currentIDs) + .compactMap { personByID[$0] } + // People physically here first, then those who teleported in. + let rows = displayed.filter { !$0.isTeleported } + displayed.filter(\.isTeleported) + let firstID = rows.first?.id - let displayIDs = orderedIDs.filter { currentIDs.contains($0) } + currentIDs.filter { !orderedIDs.contains($0) } - let nonTele = displayIDs.filter { id in - !(people.first(where: { $0.id == id })?.isTeleported ?? false) - } - let tele = displayIDs.filter { id in - people.first(where: { $0.id == id })?.isTeleported ?? false - } - let finalOrder: [String] = nonTele + tele - let firstID = finalOrder.first - let personByID = Dictionary(uniqueKeysWithValues: people.map { ($0.id, $0) }) - - VStack(alignment: .leading, spacing: 0) { - ForEach(finalOrder.filter { personByID[$0] != nil }, id: \.self) { pid in - let person = personByID[pid]! + // Lazy: a busy room has hundreds of rows, each with a context + // menu and accessibility actions; only the visible ones are built. + LazyVStack(alignment: .leading, spacing: 0) { + ForEach(rows) { person in HStack(spacing: 4) { let icon = person.isTeleported ? "face.dashed" : "mappin.and.ellipse" let assignedColor = peerListModel.colorForGeohashPerson(id: person.id, isDark: colorScheme == .dark) @@ -144,12 +149,17 @@ struct GeohashPeopleList: View { } // Seed and update order outside result builder .onAppear { - orderedIDs = currentIDs + // The roster republishes only when membership or names + // change, so its recency order can be stale. Rebuild once so + // the sheet opens with the most recently active people first. + peerListModel.refreshNow() + orderedIDs = PeopleListOrdering.stableOrder( + previous: [], + current: peerListModel.geohashPeople.map(\.id) + ) } .onChange(of: currentIDs) { ids in - var newOrder = orderedIDs - newOrder.removeAll { !ids.contains($0) } - for id in ids where !newOrder.contains(id) { newOrder.append(id) } + let newOrder = PeopleListOrdering.stableOrder(previous: orderedIDs, current: ids) if newOrder != orderedIDs { orderedIDs = newOrder } } } diff --git a/bitchat/Views/Globe/GeohashPickerView.swift b/bitchat/Views/Globe/GeohashPickerView.swift new file mode 100644 index 00000000..9ac39f62 --- /dev/null +++ b/bitchat/Views/Globe/GeohashPickerView.swift @@ -0,0 +1,250 @@ +// +// GeohashPickerView.swift +// bitchat +// +// This is free and unencumbered software released into the public domain. +// For more information, see +// + +import SwiftUI + +/// Full-screen 3D globe for choosing a geohash channel to teleport to. The cell under +/// the crosshair is the selection; zooming changes precision, and the +/- buttons step +/// precision while framing the cell. +struct GeohashPickerView: View { + let onSelect: (String) -> Void + let onCancel: () -> Void + + @StateObject private var state: GlobeState + @State private var world: GlobeWorldData? + @Environment(\.colorScheme) private var colorScheme + @ThemedPalette private var palette + + private enum Strings { + static let instruction = String(localized: "geohash_picker.instruction", defaultValue: "drag to spin · pinch to zoom · tap to focus", comment: "Hint at the top of the globe geohash picker explaining its gestures") + static let noSelection = String(localized: "geohash_picker.no_selection", defaultValue: "select location", comment: "Shown in the globe geohash picker before a geohash is under the crosshair") + static let select = String(localized: "geohash_picker.select", defaultValue: "select", comment: "Button in the globe geohash picker that teleports to the geohash under the crosshair") + static let selectHint = String(localized: "geohash_picker.accessibility.select", defaultValue: "select geohash", comment: "Accessibility label for the globe picker's select button") + static let decreasePrecision = String(localized: "geohash_picker.accessibility.decrease_precision", defaultValue: "decrease precision", comment: "Accessibility label for the globe picker button that zooms out to a larger geohash cell") + static let increasePrecision = String(localized: "geohash_picker.accessibility.increase_precision", defaultValue: "increase precision", comment: "Accessibility label for the globe picker button that zooms in to a smaller geohash cell") + } + + /// - Parameters: + /// - initialGeohash: cell to fly to; when empty, the coarsest of + /// `nearbyGeohashes` is used, else a wide view of the world. + init( + initialGeohash: String?, + nearbyGeohashes: [String] = [], + onSelect: @escaping (String) -> Void, + onCancel: @escaping () -> Void + ) { + self.onSelect = onSelect + self.onCancel = onCancel + let target = Self.initialTarget(initialGeohash: initialGeohash, nearbyGeohashes: nearbyGeohashes) + _state = StateObject(wrappedValue: GlobeState( + targetLat: target.lat, + targetLon: target.lon, + initialPrecision: target.precision, + startZoomedOut: true + )) + } + + /// Where the intro flies to: the given geohash, else the coarsest nearby channel, + /// else a wide view at precision 2. + static func initialTarget(initialGeohash: String?, nearbyGeohashes: [String]) -> (lat: Double, lon: Double, precision: Int) { + let initial = (initialGeohash ?? "").trimmingCharacters(in: .whitespacesAndNewlines).lowercased() + let focus = Geohash.isValidGeohash(initial) + ? initial + : nearbyGeohashes.filter(Geohash.isValidGeohash).min { $0.count < $1.count } + guard let focus else { return (20, 0, 2) } + let center = Geohash.decodeCenter(focus) + return (center.lat, center.lon, min(max(focus.count, 1), GlobeMath.maxPrecision)) + } + + var body: some View { + ZStack { + palette.background + .ignoresSafeArea() + + if let world { + GlobeView(state: state, colors: globeColors, world: world) + .ignoresSafeArea() + } + + VStack(spacing: 0) { + topBar + Spacer(minLength: 0) + bottomControls + } + .padding(.horizontal, 16) + .padding(.top, 20) + .padding(.bottom, 20) + } + #if os(macOS) + .frame(minWidth: 560, minHeight: 640) + #endif + .task { + guard world == nil else { return } + world = await Task.detached(priority: .userInitiated) { GlobeWorldData.bundled }.value + } + } + + // MARK: - Chrome + + private var topBar: some View { + HStack(spacing: 10) { + Text(Strings.instruction) + .bitchatFont(size: 12) + .foregroundColor(palette.primary) + .multilineTextAlignment(.center) + .fixedSize(horizontal: false, vertical: true) + .padding(.horizontal, 14) + .padding(.vertical, 10) + .frame(maxWidth: .infinity) + .geohashPickerPanel() + + SheetCloseButton(action: onCancel) + .foregroundColor(palette.primary) + .frame(width: 40, height: 40) + .geohashPickerPanel(cornerRadius: 20) + } + } + + private var bottomControls: some View { + VStack(spacing: 10) { + VStack(spacing: 2) { + Text(verbatim: hasSelection ? "#\(state.selectedGeohash)" : Strings.noSelection) + .bitchatFont(size: 14, weight: .medium) + .foregroundColor(palette.primary) + if hasSelection { + Text(verbatim: "\(GeohashCoverage.level(forLength: state.precision).displayName) • \(GeohashCoverage.string(forPrecision: state.precision))") + .bitchatFont(size: 10) + .foregroundColor(palette.secondary) + } + } + .padding(.horizontal, 16) + .padding(.vertical, 8) + .geohashPickerPanel() + .accessibilityElement(children: .combine) + + HStack(spacing: 10) { + precisionButton(systemImage: "minus", label: Strings.decreasePrecision) { + state.animatePrecision(state.precision - 1) + } + precisionButton(systemImage: "plus", label: Strings.increasePrecision) { + state.animatePrecision(state.precision + 1) + } + Button { + guard hasSelection else { return } + onSelect(state.selectedGeohash) + } label: { + HStack(spacing: 6) { + Image(systemName: "checkmark") + .font(.bitchatSystem(size: 14, weight: .semibold)) + Text(verbatim: Strings.select) + .bitchatFont(size: 12) + } + .foregroundColor(palette.primary) + .pickerCapsule(fill: palette.accentBlue.opacity(0.12)) + } + .buttonStyle(.plain) + .disabled(!hasSelection) + .opacity(hasSelection ? 1 : 0.38) + .accessibilityLabel(Strings.selectHint) + } + } + } + + private func precisionButton(systemImage: String, label: String, action: @escaping () -> Void) -> some View { + Button(action: action) { + Image(systemName: systemImage) + .font(.bitchatSystem(size: 16, weight: .semibold)) + .foregroundColor(palette.locationAccent) + .pickerCapsule(fill: palette.locationAccent.opacity(0.12)) + } + .buttonStyle(.plain) + .accessibilityLabel(label) + } + + private var hasSelection: Bool { !state.selectedGeohash.isEmpty } + + // MARK: - Globe palette + + /// Fixed land/ocean tones shared with the Android picker; the accent follows the + /// theme's location color. + private var globeColors: GlobeColors { + let accent = palette.locationAccent + if colorScheme == .dark { + let onSurface = Color(red: 0.961, green: 0.961, blue: 0.961) + let onSurfaceVariant = Color(red: 0.604, green: 0.651, blue: 0.604) + return GlobeColors( + accent: accent, + land: Color(red: 0.086, green: 0.141, blue: 0.106), + coastline: accent.opacity(0.45), + border: onSurfaceVariant.opacity(0.5), + oceanCenter: Color(red: 0.039, green: 0.078, blue: 0.063), + oceanEdge: Color(red: 0.008, green: 0.024, blue: 0.016), + atmosphere: accent, + graticule: onSurface.opacity(0.055), + grid: onSurfaceVariant.opacity(0.6), + label: onSurfaceVariant, + labelHalo: palette.background, + star: onSurface + ) + } else { + let onSurface = Color(red: 0.075, green: 0.102, blue: 0.075) + let onSurfaceVariant = Color(red: 0.298, green: 0.341, blue: 0.298) + return GlobeColors( + accent: accent, + land: Color(red: 0.737, green: 0.824, blue: 0.753), + coastline: accent.opacity(0.5), + border: onSurfaceVariant.opacity(0.6), + oceanCenter: Color(red: 0.918, green: 0.949, blue: 0.925), + oceanEdge: Color(red: 0.831, green: 0.886, blue: 0.843), + atmosphere: accent, + graticule: onSurface.opacity(0.08), + grid: onSurfaceVariant.opacity(0.7), + label: onSurfaceVariant, + labelHalo: palette.background, + star: onSurfaceVariant + ) + } + } +} + +// MARK: - Styling + +private struct GeohashPickerPanel: ViewModifier { + @Environment(\.appTheme) private var theme + @ThemedPalette private var palette + let cornerRadius: CGFloat + + @ViewBuilder + func body(content: Content) -> some View { + if theme.usesGlassChrome { + content.themedOverlayPanel() + } else { + let shape = RoundedRectangle(cornerRadius: cornerRadius, style: .continuous) + content + .background(shape.fill(palette.background.opacity(0.85))) + .overlay(shape.stroke(palette.divider, lineWidth: 1)) + .shadow(color: .black.opacity(0.25), radius: 6, x: 0, y: 2) + } + } +} + +private extension View { + /// Floating translucent surface for the picker's hint, readout and close button. + func geohashPickerPanel(cornerRadius: CGFloat = 12) -> some View { + modifier(GeohashPickerPanel(cornerRadius: cornerRadius)) + } + + /// Pill button body sized like a standard 40pt-tall button. + func pickerCapsule(fill: Color) -> some View { + self + .padding(.horizontal, 24) + .frame(minHeight: 40) + .background(Capsule().fill(fill)) + .contentShape(Capsule()) + } +} diff --git a/bitchat/Views/Globe/GlobeGeometry.swift b/bitchat/Views/Globe/GlobeGeometry.swift new file mode 100644 index 00000000..d62cc0b2 --- /dev/null +++ b/bitchat/Views/Globe/GlobeGeometry.swift @@ -0,0 +1,285 @@ +// +// GlobeGeometry.swift +// bitchat +// +// This is free and unencumbered software released into the public domain. +// For more information, see +// + +import CoreGraphics +import Foundation + +/// Polygon/polyline helpers that turn projected geometry into drawable screen paths: +/// splitting at the limb, closing fills along the horizon, and clipping to the viewport. +enum GlobeGeometry { + /// A projected point in disc units (radius 1, screen y down). + struct DiscPoint: Equatable { + let x: Double + let y: Double + let front: Bool + } + + /// Core Graphics loses precision with path coordinates far outside the view, which + /// happens at high globe zoom. All geometry is clipped to an expanded viewport rect + /// in screen space before it becomes a path. + struct ClipRect { + let left: Double + let top: Double + let right: Double + let bottom: Double + + init(size: CGSize) { + left = -Double(size.width) + top = -Double(size.height) + right = Double(size.width) * 2 + bottom = Double(size.height) * 2 + } + + init(left: Double, top: Double, right: Double, bottom: Double) { + self.left = left + self.top = top + self.right = right + self.bottom = bottom + } + } + + private static func limbPoint(behind: DiscPoint, front: DiscPoint) -> CGPoint { + var lo = 0.0 + var hi = 1.0 + for _ in 0..<14 { + let t = (lo + hi) / 2 + let x = behind.x + (front.x - behind.x) * t + let y = behind.y + (front.y - behind.y) * t + if x * x + y * y < 1 { lo = t } else { hi = t } + } + let t = (lo + hi) / 2 + return CGPoint(x: behind.x + (front.x - behind.x) * t, y: behind.y + (front.y - behind.y) * t) + } + + /// Splits a projected polygon into front-facing runs (disc units). Runs that touch the + /// limb are padded with the horizon intersection point so they can be closed along the + /// horizon. Pass `closed = false` for open polylines (border lines). + static func frontRuns(_ pts: [DiscPoint], closed: Bool = true) -> [[CGPoint]] { + guard let first = pts.first, let last = pts.last else { return [] } + var runs: [[CGPoint]] = [] + var run: [CGPoint] = [] + var prev: DiscPoint? = closed ? last : nil + for cur in pts { + if cur.front { + if run.isEmpty, let p = prev, !p.front { run.append(limbPoint(behind: p, front: cur)) } + // Antimeridian wrap: consecutive front points can jump across the whole + // disc when a polygon crosses ±180° — break the run instead of drawing + // a chord through the view. + if let tail = run.last { + let dx = cur.x - Double(tail.x) + let dy = cur.y - Double(tail.y) + if dx * dx + dy * dy > 1.2 { + runs.append(run) + run = [] + } + } + run.append(CGPoint(x: cur.x, y: cur.y)) + } else if !run.isEmpty, let p = prev { + run.append(limbPoint(behind: p, front: cur)) + runs.append(run) + run = [] + } + prev = cur + } + if !run.isEmpty { + if closed, !runs.isEmpty, first.front, last.front { + runs[0] = run + runs[0] + } else { + // A fully front-facing ring has no limb transition to terminate its run. + // Close it explicitly; cell boundary sampling intentionally omits the + // duplicated final corner. + if closed, runs.isEmpty, first.front, last.front, let head = run.first { + run.append(head) + } + runs.append(run) + } + } + return runs + } + + /// Builds a fill polygon (screen units) for a projected ring by clamping back-facing + /// points onto the limb and inserting horizon arc steps between consecutive limb + /// points, so the result approximates (polygon ∩ visible disc) without + /// self-intersecting chords. + static func fillPolygon(_ pts: [DiscPoint], cx: Double, cy: Double, r: Double) -> [CGPoint] { + var out: [CGPoint] = [] + out.reserveCapacity(pts.count + 128) + var prevLimbAngle: Double? + var firstLimbAngle: Double? + + func addArc(from: Double, to: Double) { + var d = to - from + while d > .pi { d -= 2 * .pi } + while d < -.pi { d += 2 * .pi } + let steps = min(max(Int(abs(d) / 0.04), 1), 64) + for s in 1.. 1e-6 ? p.x / len : 0 + let ly = len > 1e-6 ? p.y / len : -1 + let angle = atan2(ly, lx) + if let prev = prevLimbAngle { addArc(from: prev, to: angle) } + if firstLimbAngle == nil { firstLimbAngle = angle } + out.append(CGPoint(x: cx + lx * r, y: cy + ly * r)) + prevLimbAngle = angle + } + } + // Wrap-around arc if the ring ends and starts on the limb. + if let lastAngle = prevLimbAngle, let firstAngle = firstLimbAngle, let head = pts.first, !head.front { + addArc(from: lastAngle, to: firstAngle) + } + return out + } + + /// Sutherland–Hodgman clip of a polygon to the rect. + static func clipPolygon(_ pts: [CGPoint], to rect: ClipRect) -> [CGPoint] { + func clipEdge( + _ input: [CGPoint], + inside: (CGPoint) -> Bool, + intersect: (CGPoint, CGPoint) -> CGPoint + ) -> [CGPoint] { + guard var s = input.last else { return input } + var result: [CGPoint] = [] + result.reserveCapacity(input.count + 4) + for e in input { + let eIn = inside(e) + if eIn { + if !inside(s) { result.append(intersect(s, e)) } + result.append(e) + } else if inside(s) { + result.append(intersect(s, e)) + } + s = e + } + return result + } + let left = CGFloat(rect.left), right = CGFloat(rect.right) + let top = CGFloat(rect.top), bottom = CGFloat(rect.bottom) + var out = pts + out = clipEdge(out, inside: { $0.x >= left }) { a, b in + CGPoint(x: left, y: a.y + (left - a.x) / (b.x - a.x) * (b.y - a.y)) + } + out = clipEdge(out, inside: { $0.x <= right }) { a, b in + CGPoint(x: right, y: a.y + (right - a.x) / (b.x - a.x) * (b.y - a.y)) + } + out = clipEdge(out, inside: { $0.y >= top }) { a, b in + CGPoint(x: a.x + (top - a.y) / (b.y - a.y) * (b.x - a.x), y: top) + } + out = clipEdge(out, inside: { $0.y <= bottom }) { a, b in + CGPoint(x: a.x + (bottom - a.y) / (b.y - a.y) * (b.x - a.x), y: bottom) + } + return out + } + + /// Liang–Barsky clip of a segment to the rect; returns the clipped endpoints or nil. + static func clipSegment(_ a: CGPoint, _ b: CGPoint, to rect: ClipRect) -> (CGPoint, CGPoint)? { + let x0 = Double(a.x), y0 = Double(a.y) + let dx = Double(b.x) - x0 + let dy = Double(b.y) - y0 + var u1 = 0.0 + var u2 = 1.0 + func test(_ p: Double, _ q: Double) -> Bool { + if p == 0 { return q >= 0 } + let r = q / p + if p < 0 { + if r > u2 { return false } + if r > u1 { u1 = r } + } else { + if r < u1 { return false } + if r < u2 { u2 = r } + } + return true + } + guard test(-dx, x0 - rect.left), + test(dx, rect.right - x0), + test(-dy, y0 - rect.top), + test(dy, rect.bottom - y0) else { return nil } + return ( + CGPoint(x: x0 + u1 * dx, y: y0 + u1 * dy), + CGPoint(x: x0 + u2 * dx, y: y0 + u2 * dy) + ) + } + + /// Orthographic projection can choose the wrong side of the horizon closure for very + /// large rings. A single center-point check is ambiguous for a large polygon and + /// caused an occasional whole-disc fill, so compare several visible points with the + /// original geographic ring and invert only when the opposite fill wins clearly. + static func projectedFillNeedsInversion( + polygon: [CGPoint], + ring: GlobeRing, + cx: Double, + cy: Double, + r: Double, + centerLat: Double, + centerLon: Double + ) -> Bool { + let samples: [(Double, Double)] = [ + (0, 0), (-0.5, 0), (0.5, 0), (0, -0.5), (0, 0.5), + (-0.35, -0.35), (0.35, -0.35), (-0.35, 0.35), (0.35, 0.35) + ] + var normalErrors = 0 + var invertedErrors = 0 + for (nx, ny) in samples { + guard let location = GlobeMath.unproject(x: nx, y: ny, centerLat: centerLat, centerLon: centerLon) else { continue } + let geographicInside = ringContains(ring, lat: location.lat, lon: location.lon) + let projectedInside = polygonContains(polygon, x: cx + nx * r, y: cy + ny * r) + if projectedInside != geographicInside { normalErrors += 1 } + if !projectedInside != geographicInside { invertedErrors += 1 } + } + return invertedErrors < normalErrors + } + + /// Even-odd point-in-polygon test in screen space. + static func polygonContains(_ polygon: [CGPoint], x: Double, y: Double) -> Bool { + guard polygon.count >= 3, var previous = polygon.last else { return false } + var inside = false + for current in polygon { + let cy = Double(current.y), py = Double(previous.y) + if (cy > y) != (py > y) { + let intersectionX = (Double(previous.x) - Double(current.x)) * (y - cy) / (py - cy) + Double(current.x) + if x < intersectionX { inside.toggle() } + } + previous = current + } + return inside + } + + /// Point-in-ring test in geographic space: counts the ring edges that cross the + /// probe's meridian north of it. Each edge is followed the short way around, so a + /// ring that wraps the antimeridian (Eurasia at Chukotka) has no false crossing at + /// the ±180° seam. Comparing raw relative longitudes there misjudged whole oceans + /// as inside Eurasia, which flipped its fill over the Pacific and Atlantic. + static func ringContains(_ ring: GlobeRing, lat: Double, lon: Double) -> Bool { + guard ring.count >= 3 else { return false } + var inside = false + var previousIndex = ring.count - 1 + for index in 0.. 0) != (end > 0) { + let t = start / (start - end) + if startLat + (endLat - startLat) * t > lat { inside.toggle() } + } + previousIndex = index + } + return inside + } +} diff --git a/bitchat/Views/Globe/GlobeMath.swift b/bitchat/Views/Globe/GlobeMath.swift new file mode 100644 index 00000000..a04708e0 --- /dev/null +++ b/bitchat/Views/Globe/GlobeMath.swift @@ -0,0 +1,149 @@ +// +// GlobeMath.swift +// bitchat +// +// This is free and unencumbered software released into the public domain. +// For more information, see +// + +import Foundation + +/// Orthographic globe projection and geohash zoom math for the 3D globe picker. +/// +/// The globe is rendered as a disc of radius R centered on screen. Points are +/// projected with an orthographic projection around a view center lat/lon. +enum GlobeMath { + static let minZoom: Double = 1 + static let maxZoom: Double = 120_000 + static let maxPrecision = 12 + + struct Projection: Equatable { + /// Disc coordinates in units of globe radius, screen y down. + let x: Double + let y: Double + /// Cosine of the angular distance from the view center; negative on the far side. + let cosC: Double + } + + /// Per-point sin/cos of latitude and longitude. Preparing these once removes + /// nearly all trigonometry from animated frames. + struct Terms: Sendable { + let sinLat: Double + let cosLat: Double + let sinLon: Double + let cosLon: Double + + init(lat: Double, lon: Double) { + let latRadians = lat * .pi / 180 + let lonRadians = lon * .pi / 180 + sinLat = sin(latRadians) + cosLat = cos(latRadians) + sinLon = sin(lonRadians) + cosLon = cos(lonRadians) + } + } + + /// Frame-local projector for prepared static geometry: center terms are calculated once. + struct PreparedProjector { + private let sinCenterLat: Double + private let cosCenterLat: Double + private let sinCenterLon: Double + private let cosCenterLon: Double + + init(centerLat: Double, centerLon: Double) { + let latRadians = centerLat * .pi / 180 + let lonRadians = centerLon * .pi / 180 + sinCenterLat = sin(latRadians) + cosCenterLat = cos(latRadians) + sinCenterLon = sin(lonRadians) + cosCenterLon = cos(lonRadians) + } + + func project(_ terms: Terms) -> Projection { + let sinDeltaLon = terms.sinLon * cosCenterLon - terms.cosLon * sinCenterLon + let cosDeltaLon = terms.cosLon * cosCenterLon + terms.sinLon * sinCenterLon + return Projection( + x: terms.cosLat * sinDeltaLon, + y: -(cosCenterLat * terms.sinLat - sinCenterLat * terms.cosLat * cosDeltaLon), + cosC: sinCenterLat * terms.sinLat + cosCenterLat * terms.cosLat * cosDeltaLon + ) + } + } + + /// Projects (lat, lon) onto the view disc of a globe centered at (centerLat, centerLon). + /// `cosC` is negative when the point is on the far side of the sphere. + static func projectRaw(lat: Double, lon: Double, centerLat: Double, centerLon: Double) -> Projection { + let phi = lat * .pi / 180 + let phi0 = centerLat * .pi / 180 + let dLambda = normalizeLon(lon - centerLon) * .pi / 180 + let cosC = sin(phi0) * sin(phi) + cos(phi0) * cos(phi) * cos(dLambda) + let x = cos(phi) * sin(dLambda) + let y = -(cos(phi0) * sin(phi) - sin(phi0) * cos(phi) * cos(dLambda)) + return Projection(x: x, y: y, cosC: cosC) + } + + /// Like `projectRaw` but nil when the point is behind the limb. + static func project(lat: Double, lon: Double, centerLat: Double, centerLon: Double) -> Projection? { + let p = projectRaw(lat: lat, lon: lon, centerLat: centerLat, centerLon: centerLon) + return p.cosC >= 0 ? p : nil + } + + /// Inverse projection: disc coordinates (units of radius, screen y down) back to lat/lon. + /// Returns nil if the point lies outside the disc. + static func unproject(x: Double, y: Double, centerLat: Double, centerLon: Double) -> (lat: Double, lon: Double)? { + let rho = (x * x + y * y).squareRoot() + if rho > 1 { return nil } + let c = asin(min(1, max(-1, rho))) + let phi0 = centerLat * .pi / 180 + let sinC = sin(c) + let cosC = cos(c) + let lat: Double + let lonOffset: Double + if rho < 1e-9 { + lat = centerLat + lonOffset = 0 + } else { + lat = asin(cosC * sin(phi0) + (-y) * sinC * cos(phi0) / rho) * 180 / .pi + lonOffset = atan2(x * sinC, rho * cos(phi0) * cosC - (-y) * sin(phi0) * sinC) * 180 / .pi + } + return (lat, normalizeLon(centerLon + lonOffset)) + } + + static func normalizeLon(_ lon: Double) -> Double { + var x = lon.truncatingRemainder(dividingBy: 360) + if x > 180 { x -= 360 } + if x < -180 { x += 360 } + return x + } + + /// Longitude span of a geohash cell in degrees. + static func cellSpanLon(precision: Int) -> Double { + 360 / pow(2, (5 * Double(precision) / 2).rounded(.up)) + } + + /// Latitude span of a geohash cell in degrees. + static func cellSpanLat(precision: Int) -> Double { + 180 / pow(2, (5 * Double(precision) / 2).rounded(.down)) + } + + /// Picks the geohash precision whose cells render at a comfortable on-screen size + /// for the current zoom: the largest precision whose cell is at least ~22% of the + /// screen's smallest dimension. + static func autoPrecision(globeRadius: Double, screenMin: Double) -> Int { + let target = screenMin * 0.22 + var best = 1 + for p in 1...maxPrecision { + let span = cellSpanLat(precision: p) * .pi / 180 * globeRadius + if span >= target { best = p } else { break } + } + return min(max(best, 1), maxPrecision) + } + + /// Zoom factor (globe radius multiplier over the fit-to-screen base radius) that frames + /// a cell of the given precision nicely: the cell spans ~1/3 of the screen. + static func zoomForPrecision(_ precision: Int, baseRadius: Double, screenMin: Double) -> Double { + let spanRadians = cellSpanLat(precision: precision) * .pi / 180 + let targetRadius = (screenMin / 3) / spanRadians + return min(max(targetRadius / baseRadius, minZoom), maxZoom) + } +} diff --git a/bitchat/Views/Globe/GlobeState.swift b/bitchat/Views/Globe/GlobeState.swift new file mode 100644 index 00000000..235d2106 --- /dev/null +++ b/bitchat/Views/Globe/GlobeState.swift @@ -0,0 +1,552 @@ +// +// GlobeState.swift +// bitchat +// +// This is free and unencumbered software released into the public domain. +// For more information, see +// + +import Combine +import Foundation +import QuartzCore +#if os(iOS) +import UIKit +#endif + +/// How much of the globe a moving frame draws. Detail drops while the globe moves +/// on slow devices and is fully restored once interaction settles. The geohash grid +/// (selected cell and its neighbors) and the city dots are not part of this: both +/// are cheap next to the land geometry, and making them vanish while dragging and +/// pop back on release read as a rendering bug. +enum GlobeMotionDetail: Equatable, Comparable { + case full + case balanced + case fast + + struct Frame: Equatable { + let graticuleStepDegrees: Double + let landPointStride: Int + let showBorders: Bool + let showCityLabels: Bool + } + + var frame: Frame { + switch self { + case .full: + return Frame(graticuleStepDegrees: 4, landPointStride: 1, showBorders: true, + showCityLabels: true) + case .balanced: + return Frame(graticuleStepDegrees: 8, landPointStride: 2, showBorders: true, + showCityLabels: false) + case .fast: + return Frame(graticuleStepDegrees: 10, landPointStride: 2, showBorders: false, + showCityLabels: false) + } + } + + /// Ordered from least to most detailed. + static func < (lhs: GlobeMotionDetail, rhs: GlobeMotionDetail) -> Bool { + lhs.rank < rhs.rank + } + + private var rank: Int { + switch self { + case .fast: return 0 + case .balanced: return 1 + case .full: return 2 + } + } + + var moreDetailed: GlobeMotionDetail { + switch self { + case .fast: return .balanced + case .balanced, .full: return .full + } + } + + /// The level measured frame cadence calls for. Hysteresis alone cannot stop + /// oscillation (shedding detail is what makes frames fast again), so `GlobeState` + /// only ever applies downgrades while the globe is moving. + func next(averageFrameMillis: Double) -> GlobeMotionDetail { + guard averageFrameMillis.isFinite else { return .fast } + switch self { + case .full: + if averageFrameMillis > 34 { return .fast } + if averageFrameMillis > 22 { return .balanced } + return .full + case .balanced: + if averageFrameMillis > 29 { return .fast } + if averageFrameMillis < 18.5 { return .full } + return .balanced + case .fast: + return averageFrameMillis < 22 ? .balanced : .fast + } + } +} + +/// Picks the detail level for moving frames. A motion session spans everything from +/// touch-down through any fling or animation until the globe is at rest. +/// +/// Within a session detail only ever steps down: shedding layers is what makes +/// frames fast again, so letting measured cadence step back up made neighbor cells, +/// labels and the grid flash on and off while dragging. Between sessions, a smooth +/// one lets the next start a level higher, until any session has had to shed detail. +struct GlobeMotionGovernor { + static let frameSampleCount = 8 + static let smoothFrameMillis = 18.5 + static let maxSampledFrameMillis = 50.0 + + private(set) var detail: GlobeMotionDetail = .full + private(set) var isSessionActive = false + private var startDetail: GlobeMotionDetail = .balanced + private var ceilingFound = false + private var sessionDegraded = false + private var windowMillis = 0.0 + private var windowCount = 0 + private var sessionMillis = 0.0 + private var sessionCount = 0 + + mutating func beginSession() { + guard !isSessionActive else { return } + isSessionActive = true + sessionDegraded = false + windowMillis = 0 + windowCount = 0 + sessionMillis = 0 + sessionCount = 0 + detail = startDetail + } + + mutating func recordFrame(millis: Double) { + guard isSessionActive else { return } + let frameMillis = min(max(millis, 1), Self.maxSampledFrameMillis) + windowMillis += frameMillis + windowCount += 1 + sessionMillis += frameMillis + sessionCount += 1 + guard windowCount >= Self.frameSampleCount else { return } + let wanted = detail.next(averageFrameMillis: windowMillis / Double(windowCount)) + if wanted < detail { + detail = wanted + sessionDegraded = true + } + windowMillis = 0 + windowCount = 0 + } + + /// Back to full detail at rest; remembers where the next session should start. + mutating func endSession() { + guard isSessionActive else { return } + isSessionActive = false + if sessionDegraded { + ceilingFound = true + startDetail = detail + } else if !ceilingFound, + sessionCount >= Self.frameSampleCount, + sessionMillis / Double(sessionCount) < Self.smoothFrameMillis { + startDetail = detail.moreDetailed + } + detail = .full + } +} + +/// Hoisted state for the interactive 3D globe: view center, zoom, geohash precision +/// and the current selection. All mutation funnels through this class so rendering, +/// gestures and buttons stay in sync. +@MainActor +final class GlobeState: ObservableObject { + @Published private(set) var centerLat: Double + @Published private(set) var centerLon: Double + @Published private(set) var zoom: Double + @Published private(set) var precision: Int + @Published private(set) var selectedGeohash = "" + @Published private(set) var isInteracting = false + @Published private(set) var isAnimating = false + /// Detail level for moving frames; `.full` whenever the globe is at rest. + @Published private(set) var motionDetail: GlobeMotionDetail = .full + + private(set) var baseRadius: Double = 0 + private(set) var screenMin: Double = 0 + + /// Pending cinematic intro target; consumed once the viewport is known. + private var introTarget: (lat: Double, lon: Double, precision: Int)? + + private var motion: Motion? + private var lastTick: CFTimeInterval? + private var governor = GlobeMotionGovernor() + private lazy var clock = GlobeFrameClock { [weak self] timestamp in + self?.tick(timestamp) + } + + private enum Motion { + case tween(Tween) + case fling(vx: Double, vy: Double) + } + + private struct Tween { + let startLat: Double + let startLon: Double + let endLat: Double + let dLon: Double + let startZoom: Double + let endZoom: Double + let targetPrecision: Int? + let duration: CFTimeInterval + var startTime: CFTimeInterval? + } + + private enum Constants { + // Dragging stops close to the projection limit so polar geohash cells remain + // selectable; clamping tighter would make syncSelection() encode the wrong cell. + // Animations may go past it to reach a target (see clampedLat). + static let maxDragLat = 89.0 + static let minFlingPerSecond = 35.0 + static let maxFlingPerSecond = 1_200.0 + static let maxFrameDelta = 1.0 / 30 + static let maxFlingRadiusFractionPerFrame = 0.12 + static let flingFrictionPerSecond = 4.2 + } + + /// - Parameter startZoomedOut: begin from a far, offset view and fly into the + /// target once the viewport is laid out. + init(targetLat: Double, targetLon: Double, initialPrecision: Int, startZoomedOut: Bool) { + let precision = min(max(initialPrecision, 1), GlobeMath.maxPrecision) + centerLat = startZoomedOut ? targetLat * 0.4 : targetLat + centerLon = startZoomedOut ? GlobeMath.normalizeLon(targetLon - 70) : targetLon + zoom = GlobeMath.minZoom + self.precision = precision + if startZoomedOut { + introTarget = (targetLat, targetLon, precision) + } + } + + var globeRadius: Double { baseRadius * zoom } + + var isInMotion: Bool { isInteracting || isAnimating } + + /// Detail the next frame should draw. + var frameDetail: GlobeMotionDetail.Frame { + (isInMotion ? motionDetail : .full).frame + } + + func setViewport(baseRadius: Double, screenMin: Double, animateIntro: Bool = true) { + guard baseRadius > 0, screenMin > 0 else { return } + let firstLayout = self.baseRadius <= 0 + self.baseRadius = baseRadius + self.screenMin = screenMin + if firstLayout, let target = introTarget { + introTarget = nil + let targetZoom = GlobeMath.zoomForPrecision(target.precision, baseRadius: baseRadius, screenMin: screenMin) + if animateIntro { + // Cinematic intro: spin and zoom from the far view into the target location. + animateTo(lat: target.lat, lon: target.lon, zoom: targetZoom, precision: target.precision, duration: 1.4) + } else { + centerLat = target.lat + centerLon = target.lon + zoom = targetZoom + precision = target.precision + } + } + syncSelection() + } + + // MARK: - Gestures + + func beginInteraction() { + // Mark the touch first so catching a fling continues the same motion session. + isInteracting = true + motionStateChanged() + cancelAnimations() + } + + /// Ends a touch; a release velocity (points/second) carries on as an inertial spin + /// within the same motion session. + func endInteraction(flingVelocityX vx: Double = 0, flingVelocityY vy: Double = 0) { + fling(vx: vx, vy: vy) + isInteracting = false + motionStateChanged() + } + + /// Direct rotation from drag gestures. Deltas are in screen points. + func rotateBy(dx: Double, dy: Double) { + let r = globeRadius + guard r > 0 else { return } + let degPerPoint = 180 / (Double.pi * r) + centerLon = GlobeMath.normalizeLon(centerLon - dx * degPerPoint) + // A view already past the drag limit (a polar target) may move toward the + // equator but not further out, and never snaps back to the limit. + centerLat = clampedLat(centerLat + dy * degPerPoint, reaching: centerLat) + syncSelection() + } + + /// Continuous zoom from pinch gestures; precision follows automatically. + func zoomBy(_ factor: Double) { + guard factor != 1, factor.isFinite, factor > 0 else { return } + zoom = min(max(zoom * factor, GlobeMath.minZoom), GlobeMath.maxZoom) + syncPrecisionFromZoom() + syncSelection() + } + + /// Inertial spin after a fling. Velocities are in points/second. + func fling(vx: Double, vy: Double) { + var initialVx = min(max(vx, -Constants.maxFlingPerSecond), Constants.maxFlingPerSecond) + var initialVy = min(max(vy, -Constants.maxFlingPerSecond), Constants.maxFlingPerSecond) + if abs(initialVx) < Constants.minFlingPerSecond { initialVx = 0 } + if abs(initialVy) < Constants.minFlingPerSecond { initialVy = 0 } + guard initialVx != 0 || initialVy != 0 else { return } + start(.fling(vx: initialVx, vy: initialVy)) + } + + /// Single tap focuses the tapped point; double tap also zooms in. + func focus(lat: Double, lon: Double, zoomIn: Bool) { + if zoomIn { + animateTo(lat: lat, lon: lon, zoom: min(zoom * 1.9, GlobeMath.maxZoom), duration: 0.5) + } else { + animateTo(lat: lat, lon: lon, duration: 0.45) + } + } + + // MARK: - Animations + + /// Animate the view to a lat/lon, optionally to a zoom and precision. + func animateTo(lat: Double, lon: Double, zoom targetZoom: Double? = nil, precision targetPrecision: Int? = nil, duration: CFTimeInterval = 0.55) { + let endZoom = min(max(targetZoom ?? zoom, GlobeMath.minZoom), GlobeMath.maxZoom) + start(.tween(Tween( + startLat: centerLat, + startLon: centerLon, + endLat: lat, + dLon: GlobeMath.normalizeLon(lon - centerLon), + startZoom: zoom, + endZoom: endZoom, + targetPrecision: targetPrecision, + duration: duration + ))) + } + + /// Button-driven precision change: adjusts precision and animates zoom to frame it. + func animatePrecision(_ newPrecision: Int) { + let p = min(max(newPrecision, 1), GlobeMath.maxPrecision) + guard p != precision, baseRadius > 0 else { return } + let targetZoom = GlobeMath.zoomForPrecision(p, baseRadius: baseRadius, screenMin: screenMin) + animateTo(lat: centerLat, lon: centerLon, zoom: targetZoom, precision: p, duration: 0.45) + } + + func cancelAnimations() { + motion = nil + if isAnimating { + isAnimating = false + motionStateChanged() + } + } + + private func start(_ newMotion: Motion) { + motion = newMotion + if !isAnimating { + isAnimating = true + motionStateChanged() + } + clock.start() + } + + private func finishMotion() { + motion = nil + isAnimating = false + motionStateChanged() + } + + // MARK: - Frame loop + + /// One display frame. Internal so tests can drive animations deterministically. + func tick(_ timestamp: CFTimeInterval) { + let previous = lastTick + lastTick = timestamp + let dt = previous.map { min(max(timestamp - $0, 0), Constants.maxFrameDelta) } ?? 0 + + switch motion { + case .tween(var tween): + let startTime = tween.startTime ?? timestamp + tween.startTime = startTime + let progress = min(max((timestamp - startTime) / tween.duration, 0), 1) + applyTween(tween, t: GlobeEasing.fastOutSlowIn(progress)) + if progress >= 1 { + finishMotion() + } else { + motion = .tween(tween) + } + case .fling(var vx, var vy): + let maxStep = globeRadius * Constants.maxFlingRadiusFractionPerFrame + rotateBy( + dx: min(max(vx * dt, -maxStep), maxStep), + dy: min(max(vy * dt, -maxStep), maxStep) + ) + let decay = exp(-Constants.flingFrictionPerSecond * dt) + vx *= decay + vy *= decay + if abs(vx) >= Constants.minFlingPerSecond || abs(vy) >= Constants.minFlingPerSecond { + motion = .fling(vx: vx, vy: vy) + } else { + finishMotion() + } + case nil: + break + } + + if isInMotion, let previous { + governor.recordFrame(millis: (timestamp - previous) * 1000) + publishMotionDetail() + } + + if motion == nil && !isInteracting { + clock.stop() + lastTick = nil + } + } + + private func applyTween(_ tween: Tween, t: Double) { + // The target itself is always reachable: a polar cell's center can lie past + // the drag limit, and clamping it would end the animation on another cell. + centerLat = clampedLat(tween.startLat + (tween.endLat - tween.startLat) * t, reaching: tween.endLat) + centerLon = GlobeMath.normalizeLon(tween.startLon + tween.dLon * t) + // Exponential interpolation feels natural for zoom. + zoom = tween.startZoom * pow(tween.endZoom / tween.startZoom, t) + if let target = tween.targetPrecision { + precision = min(max(target, 1), GlobeMath.maxPrecision) + } else { + syncPrecisionFromZoom() + } + syncSelection() + } + + /// Starts a motion session when the globe begins moving and ends it once both the + /// touch and any animation are done (see `GlobeMotionGovernor`). + private func motionStateChanged() { + if isInMotion { + guard !governor.isSessionActive else { return } + governor.beginSession() + lastTick = nil + clock.start() + } else { + governor.endSession() + } + publishMotionDetail() + } + + private func publishMotionDetail() { + if motionDetail != governor.detail { motionDetail = governor.detail } + } + + /// Clamps to the drag limit, widened (up to that pole) on `reach`'s side only. + private func clampedLat(_ lat: Double, reaching reach: Double) -> Double { + let lower = max(min(-Constants.maxDragLat, reach), -90) + let upper = min(max(Constants.maxDragLat, reach), 90) + return min(max(lat, lower), upper) + } + + private func syncPrecisionFromZoom() { + guard baseRadius > 0 else { return } + let p = GlobeMath.autoPrecision(globeRadius: globeRadius, screenMin: screenMin) + if p != precision { precision = p } + } + + private func syncSelection() { + guard baseRadius > 0 else { return } + let gh = Geohash.encode(latitude: centerLat, longitude: centerLon, precision: precision) + if gh != selectedGeohash { selectedGeohash = gh } + } +} + +/// Material's FastOutSlowIn curve, cubic-bezier(0.4, 0.0, 0.2, 1.0), which the +/// Android globe animates with. +enum GlobeEasing { + static func fastOutSlowIn(_ t: Double) -> Double { + cubicBezier(t, x1: 0.4, y1: 0, x2: 0.2, y2: 1) + } + + static func cubicBezier(_ t: Double, x1: Double, y1: Double, x2: Double, y2: Double) -> Double { + guard t > 0 else { return 0 } + guard t < 1 else { return 1 } + func sample(_ s: Double, _ a1: Double, _ a2: Double) -> Double { + let inv = 1 - s + return 3 * inv * inv * s * a1 + 3 * inv * s * s * a2 + s * s * s + } + // Solve x(s) = t by bisection; x is monotonic for these control points. + var lo = 0.0 + var hi = 1.0 + var s = t + for _ in 0..<24 { + let x = sample(s, x1, x2) + if abs(x - t) < 1e-6 { break } + if x < t { lo = s } else { hi = s } + s = (lo + hi) / 2 + } + return sample(s, y1, y2) + } +} + +/// Per-display-frame callback driving globe animations: CADisplayLink on iOS, +/// a common-mode timer on macOS. +@MainActor +final class GlobeFrameClock { + private let onFrame: (CFTimeInterval) -> Void + #if os(iOS) + private var displayLink: CADisplayLink? + private var proxy: Proxy? + + private final class Proxy: NSObject { + weak var clock: GlobeFrameClock? + + @objc func step(_ link: CADisplayLink) { + MainActor.assumeIsolated { + clock?.onFrame(link.timestamp) + } + } + } + #else + private var timer: Timer? + #endif + + init(onFrame: @escaping (CFTimeInterval) -> Void) { + self.onFrame = onFrame + } + + func start() { + #if os(iOS) + guard displayLink == nil else { return } + let proxy = Proxy() + proxy.clock = self + let link = CADisplayLink(target: proxy, selector: #selector(Proxy.step(_:))) + link.preferredFrameRateRange = CAFrameRateRange(minimum: 30, maximum: 120, preferred: 120) + link.add(to: .main, forMode: .common) + self.proxy = proxy + displayLink = link + #else + guard timer == nil else { return } + let timer = Timer(timeInterval: 1.0 / 60, repeats: true) { [weak self] _ in + MainActor.assumeIsolated { + self?.onFrame(CACurrentMediaTime()) + } + } + RunLoop.main.add(timer, forMode: .common) + self.timer = timer + #endif + } + + func stop() { + #if os(iOS) + displayLink?.invalidate() + displayLink = nil + proxy = nil + #else + timer?.invalidate() + timer = nil + #endif + } + + deinit { + #if os(iOS) + displayLink?.invalidate() + #else + timer?.invalidate() + #endif + } +} diff --git a/bitchat/Views/Globe/GlobeView.swift b/bitchat/Views/Globe/GlobeView.swift new file mode 100644 index 00000000..a18bbbc0 --- /dev/null +++ b/bitchat/Views/Globe/GlobeView.swift @@ -0,0 +1,831 @@ +// +// GlobeView.swift +// bitchat +// +// This is free and unencumbered software released into the public domain. +// For more information, see +// + +import SwiftUI +#if os(iOS) +import UIKit +#else +import AppKit +#endif + +/// Color palette for the globe, derived from the app theme by the caller. +struct GlobeColors: Equatable { + let accent: Color + let land: Color + let coastline: Color + let border: Color + let oceanCenter: Color + let oceanEdge: Color + let atmosphere: Color + let graticule: Color + let grid: Color + let label: Color + let labelHalo: Color + let star: Color +} + +/// Interactive orthographic globe: drag to spin (with inertia), pinch to zoom, tap to +/// focus, double tap to zoom in. The selected geohash is always the cell under the +/// crosshair at the screen center. +struct GlobeView: View { + @ObservedObject var state: GlobeState + let colors: GlobeColors + let world: GlobeWorldData + + @Environment(\.displayScale) private var displayScale + @Environment(\.appTheme) private var theme + @Environment(\.accessibilityReduceMotion) private var reduceMotion + + #if os(iOS) + @State private var selectionFeedback = UISelectionFeedbackGenerator() + #endif + + var body: some View { + GeometryReader { proxy in + ZStack { + // Static background lives in its own layer and is not redrawn by globe movement. + GlobeStarfield(color: colors.star) + .equatable() + + let renderer = GlobeRenderer( + centerLat: state.centerLat, + centerLon: state.centerLon, + radius: state.globeRadius, + zoom: state.zoom, + selectedGeohash: state.selectedGeohash, + detail: state.frameDetail, + colors: colors, + world: world, + pixel: 1 / max(displayScale, 1), + fontDesign: theme.bodyFontDesign + ) + Canvas(rendersAsynchronously: false) { context, size in + renderer.draw(in: &context, size: size) + } + + GlobeTouchLayer(state: state) + + // Isolated so its pulse does not redraw the globe geometry. + GlobeCrosshair(color: colors.accent, isInMotion: state.isInMotion) + .allowsHitTesting(false) + } + .onAppear { updateViewport(proxy.size) } + .onChange(of: proxy.size) { updateViewport($0) } + } + .onChange(of: state.selectedGeohash) { [previous = state.selectedGeohash] _ in + guard !previous.isEmpty else { return } + #if os(iOS) + selectionFeedback.selectionChanged() + #endif + } + .accessibilityElement() + .accessibilityLabel(Text(verbatim: state.selectedGeohash.isEmpty ? "" : "#\(state.selectedGeohash)")) + .accessibilityAdjustableAction { direction in + switch direction { + case .increment: state.animatePrecision(state.precision + 1) + case .decrement: state.animatePrecision(state.precision - 1) + @unknown default: break + } + } + } + + private func updateViewport(_ size: CGSize) { + let minDim = Double(min(size.width, size.height)) + state.setViewport(baseRadius: minDim * 0.44, screenMin: minDim, animateIntro: !reduceMotion) + } +} + +// MARK: - Background and crosshair + +private struct GlobeStarfield: View, Equatable { + let color: Color + + private struct Star { + let x: Double + let y: Double + let radius: Double + let alpha: Double + } + + private static let stars: [Star] = { + var rng = SeededGenerator(seed: 42) + return (0..<160).map { _ in + Star( + x: rng.nextUnit(), + y: rng.nextUnit(), + radius: 0.6 + rng.nextUnit() * 1.5, + alpha: 0.15 + rng.nextUnit() * 0.55 + ) + } + }() + + var body: some View { + Canvas { context, size in + for star in Self.stars { + let center = CGPoint(x: star.x * size.width, y: star.y * size.height) + let rect = CGRect(x: center.x - star.radius, y: center.y - star.radius, width: star.radius * 2, height: star.radius * 2) + context.fill(Path(ellipseIn: rect), with: .color(color.opacity(star.alpha))) + } + } + .allowsHitTesting(false) + } + + /// Deterministic SplitMix64 so the sky is the same every time the picker opens. + private struct SeededGenerator { + var state: UInt64 + + init(seed: UInt64) { state = seed } + + mutating func nextUnit() -> Double { + state &+= 0x9E37_79B9_7F4A_7C15 + var z = state + z = (z ^ (z >> 30)) &* 0xBF58_476D_1CE4_E5B9 + z = (z ^ (z >> 27)) &* 0x94D0_49BB_1331_11EB + z ^= z >> 31 + return Double(z >> 11) / Double(1 << 53) + } + } +} + +private struct GlobeCrosshair: View { + let color: Color + let isInMotion: Bool + + var body: some View { + TimelineView(.animation(minimumInterval: nil, paused: isInMotion)) { timeline in + Canvas { context, size in + let alpha = isInMotion ? 0.9 : Self.pulse(at: timeline.date) + let shading = GraphicsContext.Shading.color(color.opacity(alpha)) + let cx = size.width / 2 + let cy = size.height / 2 + let gap: CGFloat = 5 + let len: CGFloat = 9 + var path = Path() + path.move(to: CGPoint(x: cx - gap - len, y: cy)) + path.addLine(to: CGPoint(x: cx - gap, y: cy)) + path.move(to: CGPoint(x: cx + gap, y: cy)) + path.addLine(to: CGPoint(x: cx + gap + len, y: cy)) + path.move(to: CGPoint(x: cx, y: cy - gap - len)) + path.addLine(to: CGPoint(x: cx, y: cy - gap)) + path.move(to: CGPoint(x: cx, y: cy + gap)) + path.addLine(to: CGPoint(x: cx, y: cy + gap + len)) + context.stroke(path, with: shading, lineWidth: 1.6) + context.fill(Path(ellipseIn: CGRect(x: cx - 1.8, y: cy - 1.8, width: 3.6, height: 3.6)), with: shading) + } + } + } + + /// 0.45 → 1 → 0.45 over 2.2s, eased like the Android picker's reversing tween. + private static func pulse(at date: Date) -> Double { + let period = 1.1 + let phase = date.timeIntervalSinceReferenceDate.truncatingRemainder(dividingBy: period * 2) / period + let t = phase <= 1 ? phase : 2 - phase + return 0.45 + 0.55 * GlobeEasing.fastOutSlowIn(t) + } +} + +// MARK: - Renderer + +/// Draws one globe frame. Built fresh per frame from a snapshot of `GlobeState`. +private struct GlobeRenderer { + let centerLat: Double + let centerLon: Double + let radius: Double + let zoom: Double + let selectedGeohash: String + let detail: GlobeMotionDetail.Frame + let colors: GlobeColors + let world: GlobeWorldData + /// One device pixel in points; hairline widths are specified in pixels. + let pixel: Double + let fontDesign: Font.Design + + private typealias DiscPoint = GlobeGeometry.DiscPoint + + func draw(in context: inout GraphicsContext, size: CGSize) { + guard radius > 0, size.width > 0, size.height > 0 else { return } + let cx = Double(size.width) / 2 + let cy = Double(size.height) / 2 + let r = radius + let center = CGPoint(x: cx, y: cy) + let projector = GlobeMath.PreparedProjector(centerLat: centerLat, centerLon: centerLon) + let clip = GlobeGeometry.ClipRect(size: size) + let screenRect = CGRect(origin: .zero, size: size) + // Once the disc covers the screen, the sphere-wide gradients are constant across + // it (and their huge coordinates would only cost precision), so draw flat fills. + let coverRadius = (cx * cx + cy * cy).squareRoot() + 2 + let discCoversScreen = r > coverRadius + let gradientsMatter = r < Double(min(size.width, size.height)) * 10 + + func disc(_ discRadius: Double) -> Path { + if discRadius > coverRadius { return Path(screenRect) } + return Path(ellipseIn: CGRect(x: cx - discRadius, y: cy - discRadius, width: discRadius * 2, height: discRadius * 2)) + } + + // Atmosphere glow + if !discCoversScreen { + context.fill(disc(r * 1.22), with: .radialGradient( + Gradient(stops: [ + .init(color: colors.atmosphere.opacity(0.30), location: 0), + .init(color: colors.atmosphere.opacity(0.12), location: 0.75), + .init(color: colors.atmosphere.opacity(0), location: 1) + ]), + center: center, + startRadius: 0, + endRadius: r * 1.22 + )) + } + + // Ocean sphere + if gradientsMatter { + context.fill(disc(r), with: .radialGradient( + Gradient(stops: [ + .init(color: colors.oceanCenter, location: 0), + .init(color: colors.oceanCenter, location: 0.7), + .init(color: colors.oceanEdge, location: 1) + ]), + center: CGPoint(x: cx - r * 0.32, y: cy - r * 0.38), + startRadius: 0, + endRadius: r * 1.5 + )) + } else { + context.fill(Path(screenRect), with: .color(colors.oceanCenter)) + } + + drawGraticule(in: &context, cx: cx, cy: cy, r: r, clip: clip) + + // Fill every landmass first. Coastlines are drawn in a separate final pass so a + // large continent fill can never cover an island outline drawn earlier. + var coastlines = Path() + for ring in world.land { + drawLand(ring, in: &context, projector: projector, cx: cx, cy: cy, r: r, clip: clip, coastlines: &coastlines) + } + context.stroke(coastlines, with: .color(colors.coastline), lineWidth: 1.4 * pixel) + + // Country borders are restored when interaction settles. + if detail.showBorders { + var borders = Path() + for line in world.borders { + let pts = line.terms.map { terms -> (DiscPoint, Bool) in + let p = projector.project(terms) + return (DiscPoint(x: p.x, y: p.y, front: p.cosC > 0.005), p.cosC >= 0) + } + guard pts.contains(where: { $0.1 }) else { continue } + appendRuns(GlobeGeometry.frontRuns(pts.map(\.0), closed: false), to: &borders, cx: cx, cy: cy, r: r, clip: clip) + } + context.stroke(borders, with: .color(colors.border), lineWidth: 1.2 * pixel) + } + + // Sphere shading: dark limb + night side for 3D depth + if gradientsMatter { + context.fill(disc(r + 1), with: .radialGradient( + Gradient(stops: [ + .init(color: .black.opacity(0), location: 0), + .init(color: .black.opacity(0), location: 0.62), + .init(color: .black.opacity(0.34), location: 0.88), + .init(color: .black.opacity(0.72), location: 1) + ]), + center: CGPoint(x: cx - r * 0.25, y: cy - r * 0.3), + startRadius: 0, + endRadius: r * 1.35 + )) + context.fill(disc(r + 1), with: .linearGradient( + Gradient(stops: [ + .init(color: .black.opacity(0), location: 0), + .init(color: .black.opacity(0), location: 0.55), + .init(color: .black.opacity(0.42), location: 1) + ]), + startPoint: CGPoint(x: cx - r * 0.7, y: cy - r * 0.7), + endPoint: CGPoint(x: cx + r * 0.75, y: cy + r * 0.8) + )) + } + + // Dots follow the zoom at every detail level; only their labels wait for rest. + drawCities(in: &context, projector: projector, cx: cx, cy: cy, r: r, size: size) + + // The grid is drawn at every detail level, including while dragging. + if !selectedGeohash.isEmpty { + let cells = visibleCells + drawGeohashGrid(cells, in: &context, cx: cx, cy: cy, r: r, clip: clip) + drawGeohashLabels(cells, in: &context, cx: cx, cy: cy, r: r) + } + } + + private var visibleCells: [String] { + var cells = [selectedGeohash] + for neighbor in Geohash.neighbors(of: selectedGeohash) where !cells.contains(neighbor) { + cells.append(neighbor) + } + return cells + } + + private func screen(_ p: CGPoint, cx: Double, cy: Double, r: Double) -> CGPoint { + CGPoint(x: cx + Double(p.x) * r, y: cy + Double(p.y) * r) + } + + private func appendRuns(_ runs: [[CGPoint]], to path: inout Path, cx: Double, cy: Double, r: Double, clip: GlobeGeometry.ClipRect) { + for run in runs where run.count >= 2 { + for k in 1.. 0.02 { + if let pp = prev, let segment = GlobeGeometry.clipSegment( + CGPoint(x: cx + pp.x * r, y: cy + pp.y * r), + CGPoint(x: cx + p.x * r, y: cy + p.y * r), + to: clip + ) { + path.move(to: segment.0) + path.addLine(to: segment.1) + } + prev = p + } else { + prev = nil + } + } + } + // Latitude lines + for lat in stride(from: -75.0, through: 75.0, by: 15) { + trace(stride(from: -180.0, through: 180.0, by: step).map { (lat, $0) }) + } + // Longitude lines + for lon in stride(from: -180.0, to: 180.0, by: 15) { + trace(stride(from: -90.0, through: 90.0, by: step).map { ($0, lon) }) + } + context.stroke(path, with: .color(colors.graticule), lineWidth: pixel) + } + + private func drawLand( + _ ring: GlobeRing, + in context: inout GraphicsContext, + projector: GlobeMath.PreparedProjector, + cx: Double, cy: Double, r: Double, + clip: GlobeGeometry.ClipRect, + coastlines: inout Path + ) { + let pointStride = ring.count >= 64 ? detail.landPointStride : 1 + let n = (ring.count - 1) / pointStride + 1 + guard n >= 3 else { return } + + var anyFront = false + var anyBack = false + var pts: [DiscPoint] = [] + pts.reserveCapacity(n) + for i in 0..= 0 { anyFront = true } else { anyBack = true } + pts.append(DiscPoint(x: p.x, y: p.y, front: p.cosC > 0.005)) + } + guard anyFront else { return } + + appendRuns(GlobeGeometry.frontRuns(pts), to: &coastlines, cx: cx, cy: cy, r: r, clip: clip) + let polygon = GlobeGeometry.fillPolygon(pts, cx: cx, cy: cy, r: r) + let invert = anyBack && GlobeGeometry.projectedFillNeedsInversion( + polygon: polygon, ring: ring, cx: cx, cy: cy, r: r, centerLat: centerLat, centerLon: centerLon + ) + fill(pts, polygon: polygon, color: colors.land, in: &context, cx: cx, cy: cy, r: r, clip: clip, invert: invert) + } + + private func fill( + _ pts: [DiscPoint], + polygon: [CGPoint]? = nil, + color: Color, + in context: inout GraphicsContext, + cx: Double, cy: Double, r: Double, + clip: GlobeGeometry.ClipRect, + invert: Bool = false + ) { + guard pts.contains(where: \.front) else { return } + let poly = polygon ?? GlobeGeometry.fillPolygon(pts, cx: cx, cy: cy, r: r) + guard poly.count >= 3 else { return } + let clipped = GlobeGeometry.clipPolygon(poly, to: clip) + guard clipped.count >= 3 else { return } + var path = Path() + if invert { + // Even-odd filling with the globe disc flips the one ring whose horizon + // closure the projection put on the wrong side. + let clipBounds = CGRect(x: clip.left, y: clip.top, width: clip.right - clip.left, height: clip.bottom - clip.top) + let discRect = CGRect(x: cx - r, y: cy - r, width: r * 2, height: r * 2) + if discRect.contains(clipBounds) { + path.addRect(clipBounds) + } else { + path.addEllipse(in: discRect) + } + } + path.addLines(clipped) + path.closeSubpath() + context.fill(path, with: .color(color), style: FillStyle(eoFill: invert)) + } + + private func drawCities( + in context: inout GraphicsContext, + projector: GlobeMath.PreparedProjector, + cx: Double, cy: Double, r: Double, + size: CGSize + ) { + let maxRank: Int + if zoom < 2 { + maxRank = 1 + } else if zoom < 8 { + maxRank = 3 + } else if zoom < 40 { + maxRank = 4 + } else { + maxRank = 10 + } + let width = Double(size.width) + let height = Double(size.height) + for city in world.cities where city.rank <= maxRank { + let p = projector.project(city.terms) + guard p.cosC >= 0.03 else { continue } + let sx = cx + p.x * r + let sy = cy + p.y * r + guard sx >= -50, sx <= width + 50, sy >= -50, sy <= height + 50 else { continue } + + let alpha = min(max(p.cosC, 0.25), 1) + let important = city.capital || city.megacity + let dotRadius = important ? 2.6 : 1.8 + let dotColor = city.capital ? colors.accent.opacity(alpha) : colors.label.opacity(alpha * 0.85) + context.fill( + Path(ellipseIn: CGRect(x: sx - dotRadius, y: sy - dotRadius, width: dotRadius * 2, height: dotRadius * 2)), + with: .color(dotColor) + ) + + if detail.showCityLabels && (zoom >= 6 || (important && zoom >= 2.5)) { + drawLabel( + city.name, + at: CGPoint(x: sx + dotRadius + 3, y: sy), + anchor: .leading, + size: 10, + weight: .medium, + color: colors.label.opacity(200 / 255 * alpha), + halo: colors.labelHalo.opacity(140 / 255 * alpha), + in: &context + ) + } + } + } + + private func drawGeohashGrid(_ cells: [String], in context: inout GraphicsContext, cx: Double, cy: Double, r: Double, clip: GlobeGeometry.ClipRect) { + for cell in cells { + let isSelected = cell == selectedGeohash + let b = Geohash.decodeBounds(cell) + let spanLat = b.latMax - b.latMin + let spanLon = b.lonMax - b.lonMin + let steps = min(max(Int((spanLat / 1.5).rounded(.up)), 4), 48) + + // Sample the cell boundary: N edge l->r, E edge t->b, S edge r->l, W edge b->t + var pts: [DiscPoint] = [] + pts.reserveCapacity(steps * 4 + 4) + func add(_ lat: Double, _ rawLon: Double) { + // Keep the boundary continuous across the antimeridian relative to the view. + var lon = rawLon + while lon - centerLon > 180 { lon -= 360 } + while lon - centerLon < -180 { lon += 360 } + let p = GlobeMath.projectRaw(lat: lat, lon: lon, centerLat: centerLat, centerLon: centerLon) + pts.append(DiscPoint(x: p.x, y: p.y, front: p.cosC >= 0.005)) + } + for s in 0...steps { add(b.latMax, b.lonMin + spanLon * Double(s) / Double(steps)) } + for s in 1...steps { add(b.latMax - spanLat * Double(s) / Double(steps), b.lonMax) } + for s in 1...steps { add(b.latMin, b.lonMax - spanLon * Double(s) / Double(steps)) } + for s in 1..= 0.08 else { continue } + drawLabel( + cell, + at: CGPoint(x: cx + p.x * r, y: cy + p.y * r), + anchor: .center, + size: isSelected ? 12.5 : 10, + weight: isSelected ? .semibold : .medium, + color: isSelected ? colors.accent : colors.label.opacity(160 / 255 * min(max(p.cosC, 0.4), 1)), + halo: colors.labelHalo.opacity(isSelected ? 200 / 255 : 120 / 255), + in: &context + ) + } + } + + /// Text with a thin halo in the background color so labels stay legible over land, + /// grid lines and the limb shading. + private func drawLabel( + _ string: String, + at point: CGPoint, + anchor: UnitPoint, + size: CGFloat, + weight: Font.Weight, + color: Color, + halo: Color, + in context: inout GraphicsContext + ) { + var resolved = context.resolve( + Text(verbatim: string).font(.system(size: size, weight: weight, design: fontDesign)) + ) + resolved.shading = .color(halo) + let w = size * 0.09 + for (dx, dy) in [(-w, 0), (w, 0), (0, -w), (0, w), (-w, -w), (w, -w), (-w, w), (w, w)] { + context.draw(resolved, at: CGPoint(x: point.x + dx, y: point.y + dy), anchor: anchor) + } + resolved.shading = .color(color) + context.draw(resolved, at: point, anchor: anchor) + } +} + +// MARK: - Touch handling + +/// Gesture surface over the globe. A single raw-touch handler (rather than stacked +/// recognizers) mirrors the Android picker: centroid pan rotates, pinch zooms in the +/// same gesture, a quick tap focuses immediately and a second tap zooms in. +#if os(iOS) +private struct GlobeTouchLayer: UIViewRepresentable { + let state: GlobeState + + func makeUIView(context: Context) -> GlobeTouchSurface { + let view = GlobeTouchSurface() + view.state = state + return view + } + + func updateUIView(_ view: GlobeTouchSurface, context: Context) { + view.state = state + } +} + +private final class GlobeTouchSurface: UIView { + weak var state: GlobeState? + + private static let touchSlop: CGFloat = 8 + private var touches: Set = [] + private var downTime: TimeInterval = 0 + private var downPosition: CGPoint = .zero + private var moved: CGVector = .zero + private var dragStarted = false + private var hadMultipleTouches = false + private var lastCentroid: CGPoint? + private var lastSpan: CGFloat? + private var samples: [(time: TimeInterval, position: CGPoint)] = [] + private var lastTapTime: TimeInterval = 0 + private var lastTapPosition: CGPoint = .zero + + override init(frame: CGRect) { + super.init(frame: frame) + isMultipleTouchEnabled = true + backgroundColor = .clear + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + override func touchesBegan(_ began: Set, with event: UIEvent?) { + if touches.isEmpty, let first = began.first { + state?.beginInteraction() + downTime = first.timestamp + downPosition = first.location(in: self) + moved = .zero + dragStarted = false + hadMultipleTouches = false + samples = [(first.timestamp, downPosition)] + } + touches.formUnion(began) + if touches.count > 1 { + hadMultipleTouches = true + samples.removeAll() + } + resetBaseline() + } + + override func touchesMoved(_ movedTouches: Set, with event: UIEvent?) { + guard let state, let previousCentroid = lastCentroid else { return } + let centroid = currentCentroid() + let pan = CGVector(dx: centroid.x - previousCentroid.x, dy: centroid.y - previousCentroid.y) + if pan != .zero { + moved.dx += pan.dx + moved.dy += pan.dy + if !dragStarted && hypot(moved.dx, moved.dy) >= Self.touchSlop { + dragStarted = true + } + if dragStarted { state.rotateBy(dx: Double(pan.dx), dy: Double(pan.dy)) } + } + if touches.count > 1, let previousSpan = lastSpan, previousSpan > 0 { + let span = currentSpan(around: centroid) + if span > 0 { state.zoomBy(Double(span / previousSpan)) } + lastSpan = span + } + lastCentroid = centroid + if !hadMultipleTouches, touches.count == 1, let touch = touches.first { + samples.append((touch.timestamp, touch.location(in: self))) + if samples.count > 20 { samples.removeFirst(samples.count - 20) } + } + } + + override func touchesEnded(_ ended: Set, with event: UIEvent?) { + if !hadMultipleTouches, touches.count == 1, let touch = ended.first { + samples.append((touch.timestamp, touch.location(in: self))) + } + finish(ended, upTime: ended.first?.timestamp ?? downTime, cancelled: false) + } + + override func touchesCancelled(_ cancelled: Set, with event: UIEvent?) { + finish(cancelled, upTime: cancelled.first?.timestamp ?? downTime, cancelled: true) + } + + private func finish(_ lifted: Set, upTime: TimeInterval, cancelled: Bool) { + touches.subtract(lifted) + guard touches.isEmpty else { + resetBaseline() + return + } + lastCentroid = nil + lastSpan = nil + guard let state else { return } + guard !cancelled else { + state.endInteraction() + return + } + + let isTap = !hadMultipleTouches + && !dragStarted + && upTime - downTime < 0.4 + && hypot(moved.dx, moved.dy) < Self.touchSlop + let r = state.globeRadius + let tapLocation = r > 0 ? GlobeMath.unproject( + x: Double((downPosition.x - bounds.midX) / r), + y: Double((downPosition.y - bounds.midY) / r), + centerLat: state.centerLat, + centerLon: state.centerLon + ) : nil + if isTap, let location = tapLocation { + let isDouble = upTime - lastTapTime < 0.35 + && hypot(downPosition.x - lastTapPosition.x, downPosition.y - lastTapPosition.y) < Self.touchSlop * 4 + lastTapTime = upTime + lastTapPosition = downPosition + state.focus(lat: location.lat, lon: location.lon, zoomIn: isDouble) + state.endInteraction() + } else if dragStarted && !hadMultipleTouches { + let velocity = releaseVelocity(at: upTime) + state.endInteraction(flingVelocityX: Double(velocity.dx), flingVelocityY: Double(velocity.dy)) + } else { + state.endInteraction() + } + } + + /// Average velocity over the last 100ms of movement; zero when the finger rested + /// before lifting. + private func releaseVelocity(at upTime: TimeInterval) -> CGVector { + guard let last = samples.last, upTime - last.time < 0.04 else { return .zero } + let window = samples.filter { last.time - $0.time <= 0.1 } + guard let first = window.first, last.time - first.time > 0.005 else { return .zero } + let dt = CGFloat(last.time - first.time) + return CGVector(dx: (last.position.x - first.position.x) / dt, dy: (last.position.y - first.position.y) / dt) + } + + private func resetBaseline() { + let centroid = currentCentroid() + lastCentroid = centroid + lastSpan = touches.count > 1 ? currentSpan(around: centroid) : nil + } + + private func currentCentroid() -> CGPoint { + guard !touches.isEmpty else { return .zero } + var x: CGFloat = 0 + var y: CGFloat = 0 + for touch in touches { + let p = touch.location(in: self) + x += p.x + y += p.y + } + return CGPoint(x: x / CGFloat(touches.count), y: y / CGFloat(touches.count)) + } + + private func currentSpan(around centroid: CGPoint) -> CGFloat { + guard !touches.isEmpty else { return 0 } + let total = touches.reduce(CGFloat(0)) { sum, touch in + let p = touch.location(in: self) + return sum + hypot(p.x - centroid.x, p.y - centroid.y) + } + return total / CGFloat(touches.count) + } +} +#else +private struct GlobeTouchLayer: NSViewRepresentable { + let state: GlobeState + + func makeNSView(context: Context) -> GlobeTouchSurface { + let view = GlobeTouchSurface() + view.state = state + return view + } + + func updateNSView(_ view: GlobeTouchSurface, context: Context) { + view.state = state + } +} + +/// macOS: click-drag spins, trackpad pinch or scroll zooms, click focuses, +/// double click zooms in. +private final class GlobeTouchSurface: NSView { + weak var state: GlobeState? + + private var lastDrag: CGPoint? + private var dragDistance: CGFloat = 0 + private var samples: [(time: TimeInterval, position: CGPoint)] = [] + + override var isFlipped: Bool { true } + override var acceptsFirstResponder: Bool { true } + + override func mouseDown(with event: NSEvent) { + state?.beginInteraction() + let p = convert(event.locationInWindow, from: nil) + lastDrag = p + dragDistance = 0 + samples = [(event.timestamp, p)] + } + + override func mouseDragged(with event: NSEvent) { + let p = convert(event.locationInWindow, from: nil) + if let last = lastDrag { + dragDistance += hypot(p.x - last.x, p.y - last.y) + state?.rotateBy(dx: Double(p.x - last.x), dy: Double(p.y - last.y)) + } + lastDrag = p + samples.append((event.timestamp, p)) + if samples.count > 20 { samples.removeFirst(samples.count - 20) } + } + + override func mouseUp(with event: NSEvent) { + guard let state else { return } + lastDrag = nil + let p = convert(event.locationInWindow, from: nil) + let r = state.globeRadius + if dragDistance < 4 { + if r > 0, let location = GlobeMath.unproject( + x: Double((p.x - bounds.midX) / r), + y: Double((p.y - bounds.midY) / r), + centerLat: state.centerLat, + centerLon: state.centerLon + ) { + state.focus(lat: location.lat, lon: location.lon, zoomIn: event.clickCount >= 2) + } + state.endInteraction() + } else if let last = samples.last, event.timestamp - last.time < 0.04, + let first = samples.first(where: { last.time - $0.time <= 0.1 }), + last.time - first.time > 0.005 { + let dt = CGFloat(last.time - first.time) + state.endInteraction( + flingVelocityX: Double((last.position.x - first.position.x) / dt), + flingVelocityY: Double((last.position.y - first.position.y) / dt) + ) + } else { + state.endInteraction() + } + } + + override func magnify(with event: NSEvent) { + state?.cancelAnimations() + state?.zoomBy(Double(1 + event.magnification)) + } + + override func scrollWheel(with event: NSEvent) { + state?.cancelAnimations() + state?.zoomBy(Double(exp(event.scrollingDeltaY * (event.hasPreciseScrollingDeltas ? 0.01 : 0.1)))) + } +} +#endif diff --git a/bitchat/Views/Globe/GlobeWorldData.swift b/bitchat/Views/Globe/GlobeWorldData.swift new file mode 100644 index 00000000..3fca931f --- /dev/null +++ b/bitchat/Views/Globe/GlobeWorldData.swift @@ -0,0 +1,139 @@ +// +// GlobeWorldData.swift +// bitchat +// +// This is free and unencumbered software released into the public domain. +// For more information, see +// + +import Foundation + +/// A polygon ring or polyline on the globe, with projection terms prepared once. +struct GlobeRing: Sendable { + let lats: [Double] + let lons: [Double] + let terms: [GlobeMath.Terms] + + var count: Int { lats.count } + + init(lats: [Double], lons: [Double]) { + self.lats = lats + self.lons = lons + self.terms = zip(lats, lons).map { GlobeMath.Terms(lat: $0, lon: $1) } + } +} + +struct GlobeCity: Sendable { + let name: String + let rank: Int + let capital: Bool + let megacity: Bool + /// The position, kept only as the projection terms the renderer reads. + let terms: GlobeMath.Terms + + init(name: String, lat: Double, lon: Double, rank: Int, capital: Bool, megacity: Bool) { + self.name = name + self.rank = rank + self.capital = capital + self.megacity = megacity + self.terms = GlobeMath.Terms(lat: lat, lon: lon) + } +} + +/// The bundled Natural Earth geometry (public domain) the globe draws: 110m land +/// polygons, admin-0 boundary lines and 50m populated places. The files are the +/// same ones the Android picker ships. +struct GlobeWorldData: Sendable { + let land: [GlobeRing] + let borders: [GlobeRing] + let cities: [GlobeCity] + + /// Parsed on first access; callers load it off the main thread. + static let bundled = GlobeWorldData(bundle: .main) + + init(land: [GlobeRing], borders: [GlobeRing], cities: [GlobeCity]) { + self.land = land + self.borders = borders + self.cities = cities + } + + private init(bundle: Bundle) { + func data(_ name: String) -> Data? { + bundle.url(forResource: name, withExtension: "geojson").flatMap { try? Data(contentsOf: $0) } + } + self.init( + land: data("world_land").map(Self.parseLand) ?? [], + borders: data("world_borders").map(Self.parseBorders) ?? [], + cities: data("world_cities").map(Self.parseCities) ?? [] + ) + } + + /// Polygon and MultiPolygon geometries; every ring (outer and holes) becomes one entry. + static func parseLand(_ data: Data) -> [GlobeRing] { + var rings: [GlobeRing] = [] + for geometry in geometries(data) { + switch geometry["type"] as? String { + case "Polygon": + appendRings(geometry["coordinates"], minimumPoints: 3, to: &rings) + case "MultiPolygon": + for polygon in geometry["coordinates"] as? [Any] ?? [] { + appendRings(polygon, minimumPoints: 3, to: &rings) + } + default: + continue + } + } + return rings + } + + /// LineString and MultiLineString geometries. + static func parseBorders(_ data: Data) -> [GlobeRing] { + var lines: [GlobeRing] = [] + for geometry in geometries(data) { + switch geometry["type"] as? String { + case "LineString": + appendRings([geometry["coordinates"] as Any], minimumPoints: 2, to: &lines) + case "MultiLineString": + appendRings(geometry["coordinates"], minimumPoints: 2, to: &lines) + default: + continue + } + } + return lines + } + + /// `{"cities": [{"n": name, "r": rank, "cap": 0|1, "mega": 0|1, "lat": .., "lon": ..}]}` + static func parseCities(_ data: Data) -> [GlobeCity] { + guard let root = try? JSONSerialization.jsonObject(with: data) as? [String: Any], + let entries = root["cities"] as? [[String: Any]] else { return [] } + return entries.compactMap { entry in + guard let name = entry["n"] as? String, + let lat = (entry["lat"] as? NSNumber)?.doubleValue, + let lon = (entry["lon"] as? NSNumber)?.doubleValue, + let rank = (entry["r"] as? NSNumber)?.intValue else { return nil } + return GlobeCity( + name: name, + lat: lat, + lon: lon, + rank: rank, + capital: (entry["cap"] as? NSNumber)?.intValue == 1, + megacity: (entry["mega"] as? NSNumber)?.intValue == 1 + ) + } + } + + private static func geometries(_ data: Data) -> [[String: Any]] { + guard let root = try? JSONSerialization.jsonObject(with: data) as? [String: Any] else { return [] } + return root["geometries"] as? [[String: Any]] ?? [] + } + + /// GeoJSON positions are [lon, lat]. + private static func appendRings(_ ringsJSON: Any?, minimumPoints: Int, to out: inout [GlobeRing]) { + for ring in ringsJSON as? [Any] ?? [] { + guard let points = ring as? [[NSNumber]], points.count >= minimumPoints else { continue } + let valid = points.filter { $0.count >= 2 } + guard valid.count >= minimumPoints else { continue } + out.append(GlobeRing(lats: valid.map { $0[1].doubleValue }, lons: valid.map { $0[0].doubleValue })) + } + } +} diff --git a/bitchat/Views/GroupChatList.swift b/bitchat/Views/GroupChatList.swift index 4dff5c1d..564d656c 100644 --- a/bitchat/Views/GroupChatList.swift +++ b/bitchat/Views/GroupChatList.swift @@ -30,7 +30,7 @@ struct GroupChatList: View { ForEach(groups) { group in HStack(spacing: 4) { - Text("#\(group.name)") + hashtagText(for: group) .bitchatFont(size: 14) .foregroundColor(palette.primary) .lineLimit(1) @@ -69,6 +69,19 @@ struct GroupChatList: View { } } + /// "#name", not localized: there is nothing to translate, and a + /// letterless "#%@" catalog key breaks string catalog symbol generation + /// (SwiftPM's default build system). It renders as the localized lookup + /// did: the name is isolated (the lookup isolates names containing + /// right-to-left text; isolating every name renders the same), so the + /// "#" stays on the same side of RTL names, and the text is tagged with + /// the app language, as text from a localization table is. + private func hashtagText(for group: GroupChatRow) -> Text { + var hashtag = AttributedString("#\u{2068}\(group.name)\u{2069}") + hashtag.languageIdentifier = Bundle.main.preferredLocalizations.first ?? "en" + return Text(hashtag) + } + private func accessibilityDescription(for group: GroupChatRow) -> String { var parts: [String] = [ group.name, diff --git a/bitchat/Views/LocationChannelsSheet.swift b/bitchat/Views/LocationChannelsSheet.swift index dcc2bc84..c7fdef39 100644 --- a/bitchat/Views/LocationChannelsSheet.swift +++ b/bitchat/Views/LocationChannelsSheet.swift @@ -16,6 +16,9 @@ struct LocationChannelsSheet: View { @State private var pendingShareGeohash: String? @State private var showSharePrecisionWarning = false @State private var activeSharePayload: ChannelSharePayload? + @State private var showGlobePicker = false + /// Geohash chosen on the globe; applied once the picker has dismissed. + @State private var pickedGeohash: String? private enum Strings { static let title: LocalizedStringKey = "location_channels.title" @@ -55,6 +58,7 @@ struct LocationChannelsSheet: View { static let sharePrecisionTitle = String(localized: "channel.share.precision_warning.title", defaultValue: "share a precise location channel?", comment: "Title of the confirmation before sharing a neighborhood-or-finer geohash invite") static let sharePrecisionMessage = String(localized: "channel.share.precision_warning.message", defaultValue: "this channel covers a small area. an invite sent over sms or imessage is visible to the carrier and both handsets — it discloses interest in that place, not only that someone uses bitchat.", comment: "Body of the confirmation before sharing a fine-precision geohash invite") static let shareAnyway = String(localized: "channel.share.precision_warning.confirm", defaultValue: "share anyway", comment: "Confirms sharing a fine-precision location channel after the OpSec warning") + static let openMap = String(localized: "location_channels.accessibility.open_map", defaultValue: "open map", comment: "Accessibility label for the button that opens the globe geohash picker") static func meshTitle(_ count: Int) -> String { let label = String(localized: "location_channels.mesh_label", comment: "Label for the mesh channel row") @@ -220,6 +224,47 @@ struct LocationChannelsSheet: View { .sheet(item: $activeSharePayload) { payload in ShareActivityView(text: payload.text) } + #if os(iOS) + .fullScreenCover(isPresented: $showGlobePicker, onDismiss: applyPickedGeohash) { + globePicker + } + #else + .sheet(isPresented: $showGlobePicker, onDismiss: applyPickedGeohash) { + globePicker + } + #endif + } + + /// Opens on the typed geohash, else the current location channel; the picker + /// itself falls back to the coarsest nearby channel. + private var globePicker: some View { + let typed = customGeohash.trimmed.lowercased().replacingOccurrences(of: "#", with: "") + let initial: String + if !typed.isEmpty { + initial = typed + } else if case .location(let channel) = locationChannelsModel.selectedChannel { + initial = channel.geohash + } else { + initial = "" + } + return GeohashPickerView( + initialGeohash: initial, + nearbyGeohashes: locationChannelsModel.availableChannels.map(\.geohash), + onSelect: { geohash in + pickedGeohash = geohash + showGlobePicker = false + }, + onCancel: { showGlobePicker = false } + ) + } + + private func applyPickedGeohash() { + guard let geohash = pickedGeohash else { return } + pickedGeohash = nil + guard validateGeohash(geohash) else { return } + customError = nil + locationChannelsModel.teleport(to: geohash) + isPresented = false } private func requestShare(forGeohash geohash: String) { @@ -239,7 +284,17 @@ struct LocationChannelsSheet: View { SheetCloseButton { isPresented = false } } + /// Participant counts mean "active in the last five minutes": they change + /// as people arrive and as quiet ones age out, neither of which publishes + /// anything this sheet observes, so re-read them every few seconds while + /// the sheet is open. private var channelList: some View { + TimelineView(.periodic(from: .now, by: 5)) { _ in + channelListContent + } + } + + private var channelListContent: some View { ScrollView { LazyVStack(spacing: 0) { channelRow(title: Strings.meshTitle(peerListModel.reachableMeshPeerCount), subtitlePrefix: Strings.subtitlePrefix(geohash: "bluetooth", coverage: bluetoothRangeString()), isSelected: isMeshSelected, titleColor: standardBlue, titleBold: peerListModel.reachableMeshPeerCount > 0) { @@ -374,6 +429,15 @@ struct LocationChannelsSheet: View { .lowercased() .replacingOccurrences(of: "#", with: "") let isValid = validateGeohash(normalized) + Button(action: { showGlobePicker = true }) { + Image(systemName: "map") + .font(.bitchatSystem(size: 16)) + .foregroundColor(palette.secondary) + .frame(width: 36, height: 36) + .contentShape(Rectangle()) + } + .buttonStyle(.plain) + .accessibilityLabel(Strings.openMap) Button(action: { let gh = normalized guard isValid else { customError = Strings.invalidGeohash; return } @@ -617,59 +681,12 @@ extension LocationChannelsSheet { // MARK: - Coverage helpers extension LocationChannelsSheet { private func coverageString(forPrecision len: Int) -> String { - // Approximate max cell dimension at equator for a given geohash length. - // Values sourced from common geohash dimension tables. - let maxMeters: Double = { - switch len { - case 2: return 1_250_000 - case 3: return 156_000 - case 4: return 39_100 - case 5: return 4_890 - case 6: return 1_220 - case 7: return 153 - case 8: return 38.2 - case 9: return 4.77 - case 10: return 1.19 - default: - if len <= 1 { return 5_000_000 } - // For >10, scale down conservatively by ~1/4 each char - let over = len - 10 - return 1.19 * pow(0.25, Double(over)) - } - }() - - let usesMetric: Bool = { - if #available(iOS 16.0, macOS 13.0, *) { - return Locale.current.measurementSystem == .metric - } else { - return Locale.current.usesMetricSystem - } - }() - if usesMetric { - let km = maxMeters / 1000.0 - return "~\(formatDistance(km)) km" - } else { - let miles = maxMeters / 1609.344 - return "~\(formatDistance(miles)) mi" - } - } - - private func formatDistance(_ value: Double) -> String { - if value >= 100 { return String(format: "%.0f", value.rounded()) } - if value >= 10 { return String(format: "%.1f", value) } - return String(format: "%.1f", value) + GeohashCoverage.string(forPrecision: len) } private func bluetoothRangeString() -> String { - let usesMetric: Bool = { - if #available(iOS 16.0, macOS 13.0, *) { - return Locale.current.measurementSystem == .metric - } else { - return Locale.current.usesMetricSystem - } - }() // Approximate Bluetooth LE range for typical mobile devices; environment dependent - return usesMetric ? "~10–50 m" : "~30–160 ft" + GeohashCoverage.usesMetric() ? "~10–50 m" : "~30–160 ft" } private func locationName(for level: GeohashChannelLevel) -> String? { diff --git a/bitchat/Views/MeshPeerList.swift b/bitchat/Views/MeshPeerList.swift index a0f147eb..95ec0339 100644 --- a/bitchat/Views/MeshPeerList.swift +++ b/bitchat/Views/MeshPeerList.swift @@ -39,10 +39,9 @@ struct MeshPeerList: View { var body: some View { let currentIDs = peerListModel.meshRows.map(\.id) - let displayIDs = orderedIDs.filter { currentIDs.contains($0) } + currentIDs.filter { !orderedIDs.contains($0) } - let peers: [MeshPeerRow] = displayIDs.compactMap { id in - peerListModel.meshRows.first(where: { $0.id == id }) - } + let rowByID = Dictionary(peerListModel.meshRows.map { ($0.id, $0) }, uniquingKeysWith: { first, _ in first }) + let peers: [MeshPeerRow] = PeopleListOrdering.stableOrder(previous: orderedIDs, current: currentIDs) + .compactMap { rowByID[$0] } if peerListModel.meshRows.isEmpty { // Match the section's row rhythm (same size, indent, and vertical @@ -55,8 +54,7 @@ struct MeshPeerList: View { .padding(.vertical, 4) } else { VStack(alignment: .leading, spacing: 0) { - ForEach(0.. TimelineReaction { + // No mark here: the list arrives from another timeline (a channel or + // DM switch), whatever the old timeline's row callbacks did to + // isAtBottom on the way out. + guard let mark else { return .land } + // Emptied (e.g. /clear): nothing to scroll to. + guard !messages.isEmpty else { return .hold } + // A new message of mine takes the reader to it from anywhere. New + // means appended since the mark (the newest message is then the last + // one counted): an older message of mine that a removal left newest + // (a retracted bridge alias, a dropped empty voice burst) is not. + if newestIsOwn && appendedCount > 0 { + return .follow + } + if !isAtBottom { + return .keepPosition + } + // At the bottom, follow any change that can move the rendered rows: a + // late message landing among the visible rows pushes the newest one + // off screen. Only provably unchanged rows skip the scroll, which + // would be a no-op, and a no-op scrollTo stays queued until the next + // layout pass: the reader's next drag, which it snaps back down. + let isWindowUnchanged = isRenderedWindowUnchanged( + since: mark, + appendedCount: appendedCount, + windowCount: windowCount, + in: messages + ) + return isWindowUnchanged ? .hold : .follow + } + + /// Whether the window rendered at the bottom (the last `windowCount` + /// messages) holds exactly the rows it held at `mark`: nothing appended, + /// the same message count, a full window starting at the same message. + /// True for a late message landing above the window at the store cap + /// (it evicts the oldest message, also above the window). + static func isRenderedWindowUnchanged( + since mark: TimelineMark, + appendedCount: Int, + windowCount: Int, + in messages: [BitchatMessage] + ) -> Bool { + appendedCount == 0 + && mark.count == messages.count + && mark.windowCount == windowCount + && messages.count >= windowCount + && mark.windowFirstMessageID == messages.suffix(windowCount).first?.id + } + + /// Whether a row ID (`"|"`) belongs to the timeline + /// of `contextKey`. Row callbacks lag a switch, so the list checks them + /// against the context it has landed in. + static func isRow(_ rowID: String, inContext contextKey: String) -> Bool { + rowID.hasPrefix(contextKey + "|") + } + + /// Whether the retry of a scroll to the bottom has anything to do: not + /// once the newest row is the one confirmed on screen, where the + /// scrollTo would be a no-op that stays queued until the reader's next + /// drag. + static func needsScroll(toNewestRowID newestRowID: String?, bottomRowID: String?) -> Bool { + guard let newestRowID else { return false } + return newestRowID != bottomRowID + } + + /// Messages the unseen counters may book as "new": rows that render as + /// human messages. System lines render as narration and whitespace-only + /// content never renders at all, so neither belongs in the pill count. + static func isUnseenEligible(_ message: BitchatMessage) -> Bool { + message.sender != "system" && !message.content.trimmed.isEmpty + } + + /// Messages after `mark`'s newest one. Located by ID, not by count: at + /// the store cap every append evicts the oldest message, so the count + /// stops moving. If that message is gone (evicted by a burst larger than + /// the cap, or removed), everything newer than its timestamp counts. + static func appended(since mark: TimelineMark, in messages: [BitchatMessage]) -> Appended { + let start: Int + if let newestID = mark.newestMessageID, let newestTimestamp = mark.newestTimestamp { + if let index = messages.lastIndex(where: { $0.id == newestID }) { + start = index + 1 + } else { + // The timeline is timestamp-ordered. + start = (messages.lastIndex(where: { $0.timestamp <= newestTimestamp }) ?? -1) + 1 + } + } else { + start = 0 + } + + var appended = Appended() + for message in messages[start...] { + appended.total += 1 + if isUnseenEligible(message) { + appended.unseen += 1 + } + } + return appended + } + + /// Window size that keeps a scrolled-up reader's rows in place. The + /// window is a suffix of the timeline, so every message landing below its + /// first row (appended, or a late one inserted mid-timeline) would push + /// that row out of the top and shift everything on screen up a row. + /// While `mark` still describes the window, its first message stays + /// first; otherwise the window grows by `appendedCount`. Never shrinks, + /// never grows past the timeline. + static func windowCountKeepingFirstRow( + current: Int, + mark: TimelineMark?, + appendedCount: Int, + in messages: [BitchatMessage] + ) -> Int { + let needed: Int + if let mark, + mark.windowCount == current, + let firstID = mark.windowFirstMessageID, + let index = messages.lastIndex(where: { $0.id == firstID }) { + needed = messages.count - index + } else { + needed = current + appendedCount + } + return max(current, min(messages.count, needed)) + } + + /// Whether the window's first row coming on screen may grow the window. + /// Not while an earlier expansion's position restore is still queued: the + /// rows it inserted put a new first row on screen at once, and expanding + /// again cascades straight to the oldest message. And not before the list + /// has settled at the bottom of this context: the initial scroll down to + /// the newest row starts with the top rows on screen. + static func canExpandWindow( + isRestoringExpansion: Bool, + bottomSettledContextKey: String?, + contextKey: String + ) -> Bool { + !isRestoringExpansion && bottomSettledContextKey == contextKey + } + + /// Whether a throttled follow-scroll should still run when its timer + /// fires. The timer is held back while a drag is tracking, so by then the + /// reader may have scrolled away from the bottom or switched timelines. + static func shouldRunDeferredFollowScroll( + isAtBottom: Bool, + scheduledContextKey: String, + currentContextKey: String + ) -> Bool { + isAtBottom && scheduledContextKey == currentContextKey + } +} + +extension MessageListScrollPolicy.TimelineMark { + /// Marks `messages` as seen, with the window taken at `windowCount`. + init(contextKey: String, messages: [BitchatMessage], windowCount: Int) { + self.init( + contextKey: contextKey, + newestMessageID: messages.last?.id, + newestTimestamp: messages.last?.timestamp, + windowFirstMessageID: messages.suffix(windowCount).first?.id, + windowCount: windowCount, + count: messages.count + ) + } + + /// The same mark with the window re-taken at `windowCount` (after the + /// window was resized without anything new being seen). + func withWindowCount(_ windowCount: Int, in messages: [BitchatMessage]) -> Self { + Self( + contextKey: contextKey, + newestMessageID: newestMessageID, + newestTimestamp: newestTimestamp, + windowFirstMessageID: messages.suffix(windowCount).first?.id, + windowCount: windowCount, + count: count + ) + } +} diff --git a/bitchat/Views/MessageListView.swift b/bitchat/Views/MessageListView.swift index 1894a347..58722957 100644 --- a/bitchat/Views/MessageListView.swift +++ b/bitchat/Views/MessageListView.swift @@ -14,6 +14,34 @@ private struct MessageDisplayItem: Identifiable { let message: BitchatMessage } +/// What the list's change detection keys on. The count alone stops moving +/// once the store's cap evicts the oldest message on every append, so the IDs +/// at both ends ride along, and the context key makes a switch to another +/// timeline one change even between two empty ones. The DM peer rides along +/// because the deprecated `onChange(of:perform:)` runs the closure from the +/// previous render, whose `privatePeer` is still the old one right after a +/// DM switch. +private struct TimelineSignature: Equatable { + let privatePeer: PeerID? + let contextKey: String + // periphery:ignore - read only via the synthesized Equatable + // conformance (onChange's comparison), which the indexer cannot + // attribute. + let count: Int + // periphery:ignore - see `count`. + let firstMessageID: String? + // periphery:ignore - see `count`. + let lastMessageID: String? + + init(privatePeer: PeerID?, contextKey: String, messages: [BitchatMessage]) { + self.privatePeer = privatePeer + self.contextKey = contextKey + count = messages.count + firstMessageID = messages.first?.id + lastMessageID = messages.last?.id + } +} + struct MessageListView: View { @EnvironmentObject private var publicChatModel: PublicChatModel @EnvironmentObject private var privateInboxModel: PrivateInboxModel @@ -43,11 +71,24 @@ struct MessageListView: View { @State private var lastScrollTime: Date = .distantPast @State private var scrollThrottleTimer: Timer? @State private var unseenCount = 0 - @State private var lastSeenMessageCount = 0 - /// Context key the unseen counters were baselined against. Channel - /// switches swap the timeline wholesale, so a count delta is only a - /// "new messages" signal while the context is unchanged. - @State private var unseenBaselineKey = "" + /// The timeline as of the last change this list observed: its newest + /// message (the next change counts what landed after it) and the + /// window's first row (kept in place while the reader is scrolled up). + /// Marks are per context: channel switches swap the timeline wholesale, + /// so a difference only means "new messages" within one context. Its + /// context is the one the list has landed in; row callbacks from any + /// other timeline are ignored. + @State private var timelineMark: MessageListScrollPolicy.TimelineMark? + /// Row whose appearance last put the list at the bottom, cleared when it + /// leaves the screen. Its leaving means the reader scrolled up, even while + /// a newer row that landed below it has not appeared yet. + @State private var bottomRowID: String? + /// Set while an expansion's position-restoring scroll is still queued. + @State private var isRestoringExpansion = false + /// Context whose newest row has appeared since the list appeared or + /// landed in it, i.e. whose scroll to the bottom has landed. Window + /// expansion waits for it. + @State private var bottomSettledContextKey: String? /// Whether this instance holds the nearby-notes counter active (mesh /// public timeline only); balanced against activate/deactivate. @State private var holdsNotesCounter = false @@ -55,28 +96,31 @@ struct MessageListView: View { @ThemedPalette private var palette var body: some View { - let currentWindowCount: Int = { - if let peer = privatePeer { - return windowCountPrivate[peer] ?? TransportConfig.uiWindowInitialCountPrivate - } - return windowCountPublic - }() + let currentWindowCount = windowCount(for: privatePeer) let messages = conversationMessages(for: privatePeer) - let windowedMessages = Array(messages.suffix(currentWindowCount)) - - let contextKey: String = { - if let peer = privatePeer { - "dm:\(peer)" - } else { - locationChannelsModel.selectedChannel.contextKey - } - }() + let contextKey = timelineContextKey(for: privatePeer) + // While the reader is scrolled up, messages landing below the + // window's first row widen the window in this same render instead of + // pushing that row out of the top, which would shift what they are + // reading (onTimelineChange then records the wider window). + let renderedWindowCount = isAtBottom + ? currentWindowCount + : MessageListScrollPolicy.windowCountKeepingFirstRow( + current: currentWindowCount, + mark: contextMark(for: contextKey), + appendedCount: 0, + in: messages + ) + let windowedMessages = Array(messages.suffix(renderedWindowCount)) let messageItems: [MessageDisplayItem] = windowedMessages.compactMap { message in guard !message.content.trimmed.isEmpty else { return nil } return MessageDisplayItem(id: "\(contextKey)|\(message.id)", message: message) } + // Top edge of the rendered window (whitespace-only messages get no + // row, so they could never report reaching it). + let firstRowID = messageItems.first?.id VStack(spacing: 0) { // Notes pinned to this place stay visible while chatting — a @@ -97,11 +141,25 @@ struct MessageListView: View { let message = item.message messageRow(for: message) .onAppear { - if message.id == windowedMessages.last?.id { + // Callbacks lag a timeline switch: the new + // rows appear before the old ones disappear, + // each with its own render's view of which row + // was last. Only rows of the timeline the list + // has landed in may move its state, checked + // against live state rather than the render's. + guard isLandedRow(item.id) else { return } + if item.id == newestRowID(for: privatePeer) { isAtBottom = true unseenCount = 0 + if bottomRowID != item.id { + bottomRowID = item.id + } + if bottomSettledContextKey != contextKey { + bottomSettledContextKey = contextKey + } + returnWindowToInitialSize(for: privatePeer, contextKey: contextKey, messages: messages) } - if message.id == windowedMessages.first?.id, + if item.id == firstRowID, messages.count > windowedMessages.count { expandWindow( ifNeededFor: message, @@ -112,8 +170,16 @@ struct MessageListView: View { } } .onDisappear { - if message.id == windowedMessages.last?.id { + // A row of the landed timeline shares this + // closure's peer, so newestRowID is live here. + guard isLandedRow(item.id) else { return } + if item.id == newestRowID(for: privatePeer) || item.id == bottomRowID { isAtBottom = false + bottomRowID = nil + // Leaving the bottom drops a follow-scroll + // still waiting on the throttle: it would + // yank the reader back down. + cancelFollowScroll() } } .contentShape(Rectangle()) @@ -170,7 +236,6 @@ struct MessageListView: View { .background(message.isArchivedEcho ? palette.secondary.opacity(0.08) : Color.clear) } } - .transaction { tx in if conversationUIModel.isBatchingPublic { tx.disablesAnimations = true } } .padding(.vertical, 2) // Only carried history on screen: the ambient layer (radar, @@ -203,19 +268,18 @@ struct MessageListView: View { Button("common.cancel", role: .cancel) {} } .onAppear { - scrollToBottom(on: proxy) + // Runs before the rows' onAppear: lands the list (and sets the + // mark the row callbacks are checked against) before any row + // reports in. Expansion waits until the scroll below has + // brought the newest row on screen. + bottomSettledContextKey = nil + scrollToBottom(on: proxy, privatePeer: privatePeer) } - .onChange(of: privatePeer) { _ in - scrollToBottom(on: proxy) - } - .onChange(of: publicChatModel.messages.count) { _ in - onMessagesChange(proxy: proxy) - } - .onChange(of: privateMessageCount(for: privatePeer)) { _ in - onPrivateChatsChange(proxy: proxy) - } - .onChange(of: locationChannelsModel.selectedChannel) { newChannel in - onSelectedChannelChange(newChannel, proxy: proxy) + // The one change handler: a channel or DM switch changes the + // signature too, so landing in the new timeline happens here, + // ahead of that update's row callbacks. + .onChange(of: TimelineSignature(privatePeer: privatePeer, contextKey: contextKey, messages: messages)) { signature in + onTimelineChange(signature, proxy: proxy) } .confirmationDialog( selectedMessageSender.map { "@\($0)" } ?? String(localized: "content.actions.title", comment: "Fallback title for the message action sheet"), @@ -271,7 +335,7 @@ struct MessageListView: View { } } .onDisappear { - scrollThrottleTimer?.invalidate() + cancelFollowScroll() } } } @@ -306,11 +370,61 @@ private extension MessageListView { } } - var currentContextKey: String { + /// Context key of the timeline shown for `privatePeer` (the DM, or the + /// public channel); also the prefix of its row IDs. The public key comes + /// from the channel PublicChatModel publishes together with its messages: + /// the selected channel switches one render or more before the timeline + /// does, and keying the old messages with the new channel re-keys (and + /// re-appears) every row. + func timelineContextKey(for privatePeer: PeerID?) -> String { if let peer = privatePeer { return "dm:\(peer)" } - return locationChannelsModel.selectedChannel.contextKey + return publicChatModel.activeChannel.contextKey + } + + func windowCount(for privatePeer: PeerID?) -> Int { + if let peer = privatePeer { + return windowCountPrivate[peer] ?? TransportConfig.uiWindowInitialCountPrivate + } + return windowCountPublic + } + + func setWindowCount(_ count: Int, for privatePeer: PeerID?) { + if let peer = privatePeer { + windowCountPrivate[peer] = count + } else { + windowCountPublic = count + } + } + + /// Returns the window to its initial size once the reader is back at the + /// bottom (the newest row has appeared): whatever it grew by while they + /// were scrolled up, or expanded into history, need not stay rendered, + /// and dropping rows above the bottom moves nothing on screen. Never in + /// the same update as a scroll: rows changing above the viewport make + /// SwiftUI hold its position, and a pending scrollTo never lands. + func returnWindowToInitialSize(for privatePeer: PeerID?, contextKey: String, messages: [BitchatMessage]) { + let initialCount = privatePeer == nil + ? TransportConfig.uiWindowInitialCountPublic + : TransportConfig.uiWindowInitialCountPrivate + guard windowCount(for: privatePeer) > initialCount else { return } + setWindowCount(initialCount, for: privatePeer) + timelineMark = contextMark(for: contextKey)?.withWindowCount(initialCount, in: messages) + } + + /// The timeline mark, if it was taken in `contextKey`. + func contextMark(for contextKey: String) -> MessageListScrollPolicy.TimelineMark? { + guard let timelineMark, timelineMark.contextKey == contextKey else { return nil } + return timelineMark + } + + /// Whether a row belongs to the timeline the list has landed in (the + /// mark's context: the change handler lands a switch before the rows of + /// that update report in). + func isLandedRow(_ rowID: String) -> Bool { + guard let landedContextKey = timelineMark?.contextKey else { return false } + return MessageListScrollPolicy.isRow(rowID, inContext: landedContextKey) } /// Tappable strip above the mesh timeline while notes are pinned at this @@ -412,30 +526,6 @@ private extension MessageListView { .fixedSize(horizontal: false, vertical: true) } - /// Messages the unseen counters may book as "new": rows that render as - /// human messages. System lines render as narration and whitespace-only - /// content never renders at all, so neither belongs in the pill count. - func unseenEligibleCount(in messages: [BitchatMessage]) -> Int { - messages.filter { $0.sender != "system" && !$0.content.trimmed.isEmpty }.count - } - - /// Updates the unseen-count baseline for the current context and returns - /// how many messages were appended since the last observation. A context - /// change (timeline swapped wholesale) re-baselines and reports zero, so - /// cross-channel count differences are never booked as "new" messages. - func rebaselinedAppendedCount(newCount: Int) -> Int { - let key = currentContextKey - if unseenBaselineKey != key { - unseenBaselineKey = key - unseenCount = 0 - lastSeenMessageCount = newCount - return 0 - } - let appended = max(0, newCount - lastSeenMessageCount) - lastSeenMessageCount = newCount - return appended - } - /// A failed private text message of our own can be resent through the /// normal send path (the context menu removes the failed original and /// re-submits its content). @@ -467,7 +557,7 @@ private extension MessageListView { /// message via the existing scrollToBottom helper. func jumpToLatestPill(proxy: ScrollViewProxy) -> some View { Button { - scrollToBottom(on: proxy) + scrollToBottom(on: proxy, privatePeer: privatePeer) } label: { HStack(spacing: 4) { Image(systemName: "arrow.down") @@ -533,32 +623,28 @@ private extension MessageListView { allMessages: [BitchatMessage], privatePeer: PeerID?, proxy: ScrollViewProxy) { - let step = TransportConfig.uiWindowStepCount - let contextKey: String = { - if let peer = privatePeer { - "dm:\(peer)" - } else { - locationChannelsModel.selectedChannel.contextKey - } - }() - let preserveID = "\(contextKey)|\(message.id)" + let contextKey = timelineContextKey(for: privatePeer) + guard MessageListScrollPolicy.canExpandWindow( + isRestoringExpansion: isRestoringExpansion, + bottomSettledContextKey: bottomSettledContextKey, + contextKey: contextKey + ) else { return } - if let peer = privatePeer { - let current = windowCountPrivate[peer] ?? TransportConfig.uiWindowInitialCountPrivate - let newCount = min(allMessages.count, current + step) - guard newCount != current else { return } - windowCountPrivate[peer] = newCount - DispatchQueue.main.async { - proxy.scrollTo(preserveID, anchor: .top) - } - } else { - let current = windowCountPublic - let newCount = min(allMessages.count, current + step) - guard newCount != current else { return } - windowCountPublic = newCount - DispatchQueue.main.async { - proxy.scrollTo(preserveID, anchor: .top) - } + let current = windowCount(for: privatePeer) + let newCount = min(allMessages.count, current + TransportConfig.uiWindowStepCount) + guard newCount != current else { return } + setWindowCount(newCount, for: privatePeer) + // The window's first row moved up with it: re-take the mark's window + // so a scrolled-up reader keeps holding the new first row. + timelineMark = contextMark(for: contextKey)?.withWindowCount(newCount, in: allMessages) + + // Until the restore below lands, the rows just inserted above leave a + // new first row on screen; it must not expand the window again. + let preserveID = "\(contextKey)|\(message.id)" + isRestoringExpansion = true + DispatchQueue.main.async { + proxy.scrollTo(preserveID, anchor: .top) + isRestoringExpansion = false } } @@ -593,155 +679,161 @@ private extension MessageListView { } } - func scrollToBottom(on proxy: ScrollViewProxy) { + func scrollToBottom(on proxy: ScrollViewProxy, privatePeer: PeerID?) { + // A follow-scroll still pending (possibly for a timeline being left) + // has nothing left to do. + cancelFollowScroll() isAtBottom = true unseenCount = 0 - lastSeenMessageCount = unseenEligibleCount(in: conversationMessages(for: privatePeer)) - unseenBaselineKey = currentContextKey - if let targetPeerID { - proxy.scrollTo(targetPeerID, anchor: .bottom) + timelineMark = MessageListScrollPolicy.TimelineMark( + contextKey: timelineContextKey(for: privatePeer), + messages: conversationMessages(for: privatePeer), + windowCount: windowCount(for: privatePeer) + ) + if let target = newestRowID(for: privatePeer) { + proxy.scrollTo(target, anchor: .bottom) } DispatchQueue.main.asyncAfter(deadline: .now() + 0.05) { - if let secondTarget = self.targetPeerID { + // Retry only a scroll that has not landed. Once the newest row is + // on screen the retry would be a no-op, and a no-op scrollTo stays + // queued until the next layout pass: the reader's next drag. + if let secondTarget = self.newestRowID(for: privatePeer), + MessageListScrollPolicy.needsScroll(toNewestRowID: secondTarget, bottomRowID: bottomRowID) { proxy.scrollTo(secondTarget, anchor: .bottom) } } } - var targetPeerID: String? { - if let peer = privatePeer, - let last = privateInboxModel.messages(for: peer).last?.id { - return "dm:\(peer)|\(last)" - } - if let last = publicChatModel.messages.last?.id { - return "\(locationChannelsModel.selectedChannel.contextKey)|\(last)" - } - return nil + /// Lands the list at the newest message of a timeline it was not showing + /// (a channel or DM switch): nothing about the old timeline's bottom + /// carries over. + func land(on proxy: ScrollViewProxy, privatePeer: PeerID?) { + bottomRowID = nil + bottomSettledContextKey = nil + scrollToBottom(on: proxy, privatePeer: privatePeer) } - func onMessagesChange(proxy: ScrollViewProxy) { - guard privatePeer == nil else { return } - let messages = publicChatModel.messages - let appendedCount = rebaselinedAppendedCount(newCount: unseenEligibleCount(in: messages)) - guard let lastMsg = messages.last else { - // Timeline emptied (e.g. /clear): nothing below to jump to. - unseenCount = 0 + /// Row ID of the newest message that has a row (whitespace-only + /// messages render none). + func newestRowID(for privatePeer: PeerID?) -> String? { + guard let newest = conversationMessages(for: privatePeer).last(where: { !$0.content.trimmed.isEmpty }) else { + return nil + } + return "\(timelineContextKey(for: privatePeer))|\(newest.id)" + } + + /// Handles any change to the shown timeline: an append, a late message + /// inserted mid-timeline, an eviction at the cap, a removal, or a + /// different timeline altogether (a channel or DM switch). + func onTimelineChange(_ signature: TimelineSignature, proxy: ScrollViewProxy) { + // The deprecated onChange runs the previous render's closure, so the + // timeline comes from the new value rather than `self.privatePeer`. + let privatePeer = signature.privatePeer + let contextKey = signature.contextKey + let messages = conversationMessages(for: privatePeer) + + // No mark in this context means the timeline was swapped wholesale: + // nothing is booked as "new", the list lands instead. + let mark = contextMark(for: contextKey) + let appended = mark.map { MessageListScrollPolicy.appended(since: $0, in: messages) } + ?? MessageListScrollPolicy.Appended() + let currentWindowCount = windowCount(for: privatePeer) + let reaction = MessageListScrollPolicy.reaction( + mark: mark, + messages: messages, + newestIsOwn: messages.last.map { conversationUIModel.isSentByCurrentUser($0) } ?? false, + appendedCount: appended.total, + windowCount: currentWindowCount, + isAtBottom: isAtBottom + ) + + if reaction == .land { + land(on: proxy, privatePeer: privatePeer) return } - // If the newest message is from me, always scroll to bottom - let isFromSelf = conversationUIModel.isSentByCurrentUser(lastMsg) - if !isFromSelf && !isAtBottom { // Only autoscroll when user is at/near bottom - unseenCount += appendedCount - return - } else { // Ensure we consider ourselves at bottom for subsequent messages + // Record the window this render kept: for a scrolled-up reader, + // widened over what landed below its first row instead of dropping + // that row (grown by the appended count if the mark lost track of + // it). A follow keeps it too: rows changing above the viewport in the + // same update as the scroll make SwiftUI hold its position instead. + let keptWindowCount = isAtBottom + ? currentWindowCount + : MessageListScrollPolicy.windowCountKeepingFirstRow( + current: currentWindowCount, + mark: mark, + appendedCount: appended.total, + in: messages + ) + if keptWindowCount != currentWindowCount { + setWindowCount(keptWindowCount, for: privatePeer) + } + timelineMark = MessageListScrollPolicy.TimelineMark(contextKey: contextKey, messages: messages, windowCount: keptWindowCount) + + switch reaction { + case .keepPosition: + unseenCount += appended.unseen + case .follow: + // Ensure we consider ourselves at bottom for subsequent messages isAtBottom = true unseenCount = 0 - } - - func scrollIfNeeded(date: Date) { - lastScrollTime = date - let contextKey = locationChannelsModel.selectedChannel.contextKey - if let target = messages.last.map({ "\(contextKey)|\($0.id)" }) { - proxy.scrollTo(target, anchor: .bottom) + followToBottom(privatePeer: privatePeer, proxy: proxy) + case .hold: + if messages.isEmpty { + // Timeline emptied (e.g. /clear): nothing below to jump to. + unseenCount = 0 } + case .land: + break } + } - // Throttle scroll animations to prevent excessive UI updates + /// Scrolls to the newest row, at most once per throttle interval. A + /// throttled scroll decides when its timer fires: the timer is held back + /// while a drag is tracking, so by then the reader may have scrolled + /// away or switched timelines, and newer rows may have landed. + func followToBottom(privatePeer: PeerID?, proxy: ScrollViewProxy) { let now = Date() if now.timeIntervalSince(lastScrollTime) > TransportConfig.uiScrollThrottleSeconds { // Immediate scroll if enough time has passed - scrollIfNeeded(date: now) - } else { - // Schedule a delayed scroll - scrollThrottleTimer?.invalidate() - scrollThrottleTimer = Timer.scheduledTimer(withTimeInterval: TransportConfig.uiScrollThrottleSeconds, repeats: false) { _ in - Task { @MainActor in - scrollIfNeeded(date: Date()) - } + scrollToNewestRow(privatePeer: privatePeer, proxy: proxy, at: now) + return + } + // Schedule a delayed scroll + let scheduledContextKey = timelineContextKey(for: privatePeer) + scrollThrottleTimer?.invalidate() + scrollThrottleTimer = Timer.scheduledTimer(withTimeInterval: TransportConfig.uiScrollThrottleSeconds, repeats: false) { _ in + Task { @MainActor in + guard MessageListScrollPolicy.shouldRunDeferredFollowScroll( + isAtBottom: isAtBottom, + scheduledContextKey: scheduledContextKey, + currentContextKey: timelineContextKey(for: privatePeer) + ) else { return } + scrollToNewestRow(privatePeer: privatePeer, proxy: proxy, at: Date()) } } } - func onPrivateChatsChange(proxy: ScrollViewProxy) { - guard let peerID = privatePeer else { return } - let messages = privateInboxModel.messages(for: peerID) - let appendedCount = rebaselinedAppendedCount(newCount: unseenEligibleCount(in: messages)) - guard let lastMsg = messages.last else { - // Timeline emptied (e.g. /clear): nothing below to jump to. - unseenCount = 0 - return - } - - // If the newest private message is from me, always scroll - let isFromSelf = conversationUIModel.isSentByCurrentUser(lastMsg) - if !isFromSelf && !isAtBottom { // Only autoscroll when user is at/near bottom - unseenCount += appendedCount - return - } else { - isAtBottom = true - unseenCount = 0 - } - - func scrollIfNeeded(date: Date) { - lastScrollTime = date - let contextKey = "dm:\(peerID)" - if let target = messages.last.map({ "\(contextKey)|\($0.id)" }) { - proxy.scrollTo(target, anchor: .bottom) - } - } - - // Same throttling for private chats - let now = Date() - if now.timeIntervalSince(lastScrollTime) > TransportConfig.uiScrollThrottleSeconds { - scrollIfNeeded(date: now) - } else { - scrollThrottleTimer?.invalidate() - scrollThrottleTimer = Timer.scheduledTimer(withTimeInterval: TransportConfig.uiScrollThrottleSeconds, repeats: false) { _ in - Task { @MainActor in - scrollIfNeeded(date: Date()) - } - } - } - } - - func onSelectedChannelChange(_ channel: ChannelID, proxy: ScrollViewProxy) { - // When switching to a new geohash channel, scroll to the bottom - guard privatePeer == nil else { return } - // Invalidate the unseen baseline: the timeline is about to swap (or - // already has — the ordering of this onChange vs the count onChange - // is not guaranteed), so the next count observation re-baselines - // instead of booking the cross-channel difference as "new". - unseenCount = 0 - unseenBaselineKey = "" - // Entering any public channel shows its latest messages: a channel - // switch swaps the timeline wholesale, so the prior scroll offset is - // meaningless. Landing at the bottom keeps isAtBottom honest (no - // stale jump-to-latest pill) and matches standard chat behavior. - isAtBottom = true - windowCountPublic = TransportConfig.uiWindowInitialCountPublic - let contextKey: String - switch channel { - case .mesh: - contextKey = "mesh" - case .location(let ch): - contextKey = "geo:\(ch.geohash)" - } - if let target = publicChatModel.messages.last?.id.map({ "\(contextKey)|\($0)" }) { + func scrollToNewestRow(privatePeer: PeerID?, proxy: ScrollViewProxy, at date: Date) { + lastScrollTime = date + if let target = newestRowID(for: privatePeer) { proxy.scrollTo(target, anchor: .bottom) } } + /// Drops a follow-scroll still waiting on the throttle. + func cancelFollowScroll() { + guard let timer = scrollThrottleTimer else { return } + timer.invalidate() + scrollThrottleTimer = nil + } + func conversationMessages(for privatePeer: PeerID?) -> [BitchatMessage] { if let privatePeer { return privateInboxModel.messages(for: privatePeer) } return publicChatModel.messages } - - func privateMessageCount(for privatePeer: PeerID?) -> Int { - conversationMessages(for: privatePeer).count - } } private extension ChannelID { diff --git a/bitchat/Views/MessageTextHelpers.swift b/bitchat/Views/MessageTextHelpers.swift index fd438f10..f487d5ca 100644 --- a/bitchat/Views/MessageTextHelpers.swift +++ b/bitchat/Views/MessageTextHelpers.swift @@ -3,8 +3,27 @@ // Shared text parsing helpers for message rendering. // +import BitFoundation import Foundation +extension BitchatMessage { + /// The row's payment chips and collapse decision, scanned on first use + /// and cached on the message: a row re-renders far more often than its + /// immutable `content` could change. + var contentScan: ContentScan { + if let cached = getCachedContentScan() { + return cached + } + let scan = ContentScan( + cashuLinks: content.extractCashuLinks(), + lightningLinks: content.extractLightningLinks(), + isLongForDisplay: content.isLongForDisplay() + ) + setCachedContentScan(scan) + return scan + } +} + extension String { // Detect if there is an extremely long token (no whitespace/newlines) that could break layout func hasVeryLongToken(threshold: Int) -> Bool { diff --git a/bitchat/Views/PeopleListOrdering.swift b/bitchat/Views/PeopleListOrdering.swift new file mode 100644 index 00000000..b4190248 --- /dev/null +++ b/bitchat/Views/PeopleListOrdering.swift @@ -0,0 +1,32 @@ +// +// PeopleListOrdering.swift +// bitchat +// +// This is free and unencumbered software released into the public domain. +// For more information, see +// + +/// Row ordering for the people sheet's rosters. +/// +/// Rows stay where they are while the sheet is open: ids already on screen +/// keep their relative order (minus anyone who left) and newcomers append in +/// the producer's order. Without this, recency-sorted rosters reshuffle on +/// every heartbeat and rows move out from under a tap. +enum PeopleListOrdering { + /// Linear in the roster size; duplicate ids in `current` collapse to + /// their first occurrence so `ForEach` identities stay unique. + static func stableOrder(previous: [String], current: [String]) -> [String] { + let currentIDs = Set(current) + var ordered: [String] = [] + ordered.reserveCapacity(current.count) + var placed = Set() + placed.reserveCapacity(current.count) + for id in previous where currentIDs.contains(id) && placed.insert(id).inserted { + ordered.append(id) + } + for id in current where placed.insert(id).inserted { + ordered.append(id) + } + return ordered + } +} diff --git a/bitchatTests/AppArchitectureTests.swift b/bitchatTests/AppArchitectureTests.swift index 747e737b..ef5dfb92 100644 --- a/bitchatTests/AppArchitectureTests.swift +++ b/bitchatTests/AppArchitectureTests.swift @@ -182,9 +182,6 @@ struct AppArchitectureTests { #expect(store.geoNicknames == ["bbbbbb": "bob", "cccccc": "carol"]) - store.retainGeoNicknames(keeping: Set(["CCCCCC"])) - #expect(store.geoNicknames == ["cccccc": "carol"]) - store.setCurrentGeohash("u4pruz") #expect(store.geoNicknames.isEmpty) } @@ -714,6 +711,44 @@ struct AppArchitectureTests { #expect(transport.sentMessages.last?.content == "hello mesh") } + @Test("ConversationUIModel republishes only changed composer state") + @MainActor + func conversationUIModelSkipsUnchangedComposerState() async { + let viewModel = makeArchitectureViewModel() + let locationChannelsModel = LocationChannelsModel(manager: makeArchitectureLocationManager()) + let privateConversationModel = PrivateConversationModel( + chatViewModel: viewModel, + conversations: viewModel.conversations, + locationChannelsModel: locationChannelsModel + ) + let uiModel = ConversationUIModel( + chatViewModel: viewModel, + privateConversationModel: privateConversationModel, + conversations: viewModel.conversations + ) + + // Bindings deliver on the main queue in FIFO order: once this change + // lands, every initial value delivered before it has landed too. + viewModel.selectedAutocompleteIndex = 1 + await waitUntil { uiModel.selectedAutocompleteIndex == 1 } + + var publishCount = 0 + let cancellable = uiModel.objectWillChange.sink { publishCount += 1 } + defer { cancellable.cancel() } + + // Re-sent equal values (what every typing pause used to produce) ... + viewModel.showAutocomplete = viewModel.showAutocomplete + viewModel.autocompleteSuggestions = viewModel.autocompleteSuggestions + viewModel.selectedAutocompleteIndex = 1 + viewModel.activePublicVoiceTalker = viewModel.activePublicVoiceTalker + // ... are dropped: only the real change queued behind them publishes. + viewModel.selectedAutocompleteIndex = 2 + await waitUntil { uiModel.selectedAutocompleteIndex == 2 } + + #expect(uiModel.selectedAutocompleteIndex == 2) + #expect(publishCount == 1) + } + @Test("VerificationModel bridges selected conversation and fingerprint actions") @MainActor func verificationModelBridgesSelectedConversationAndFingerprintActions() async { diff --git a/bitchatTests/BitchatMessageMediaTests.swift b/bitchatTests/BitchatMessageMediaTests.swift new file mode 100644 index 00000000..2703b525 --- /dev/null +++ b/bitchatTests/BitchatMessageMediaTests.swift @@ -0,0 +1,90 @@ +// +// BitchatMessageMediaTests.swift +// bitchatTests +// +// Which messages render as local media rows, and which file such a row +// loads. The filename comes from (possibly remote) message text, so it must +// never resolve outside the media directory it names. +// + +import BitFoundation +import Foundation +import Testing +@testable import bitchat + +struct BitchatMessageMediaTests { + private static let meshPeerID = PeerID(str: "0011223344556677") + private static let nostrPubkey = String(repeating: "ab", count: 32) + + private func message(_ content: String, sender: String = "alice", senderPeerID: PeerID? = meshPeerID) -> BitchatMessage { + BitchatMessage(sender: sender, content: content, timestamp: Date(), isRelay: false, senderPeerID: senderPeerID) + } + + @Test + func meshMediaResolvesInsideItsCategoryDirectory() { + guard case .image(let imageURL)? = message("[image] img_1.jpg").mediaAttachment(for: "me"), + case .voice(let voiceURL)? = message("[voice] note 1.m4a").mediaAttachment(for: "me"), + case .image(let ownImageURL)? = message("[image] img_2.jpg", sender: "me").mediaAttachment(for: "me") + else { + Issue.record("Expected mesh media messages to resolve to media rows") + return + } + + #expect(imageURL.lastPathComponent == "img_1.jpg") + #expect(imageURL.deletingLastPathComponent().path.hasSuffix("/files/images/incoming")) + #expect(voiceURL.lastPathComponent == "note 1.m4a") + #expect(voiceURL.deletingLastPathComponent().path.hasSuffix("/files/voicenotes/incoming")) + #expect(ownImageURL.deletingLastPathComponent().path.hasSuffix("/files/images/outgoing")) + } + + @Test + func nostrSendersNeverGetMediaRows() { + // Geochats, geo DMs and bridged messages carry no files, so a + // media-looking line from a Nostr sender must stay text instead of + // loading some local file. + let geoChatSender = PeerID(nostr: Self.nostrPubkey) + let geoDMSender = PeerID(nostr_: Self.nostrPubkey) + let bridgedSender = PeerID(bridge: Self.nostrPubkey) + #expect(geoChatSender.isGeoChat) + #expect(geoDMSender.isGeoDM) + #expect(bridgedSender.isBridge) + + for content in ["[image] img_1.jpg", "[voice] note.m4a"] { + #expect(message(content, senderPeerID: geoChatSender).mediaAttachment(for: "me") == nil) + #expect(message(content, senderPeerID: geoDMSender).mediaAttachment(for: "me") == nil) + #expect(message(content, senderPeerID: bridgedSender).mediaAttachment(for: "me") == nil) + #expect(message(content, sender: "me", senderPeerID: geoChatSender).mediaAttachment(for: "me") == nil) + } + // A message without a sender ID keeps the mesh behavior. + #expect(message("[image] img_1.jpg", senderPeerID: nil).mediaAttachment(for: "me") != nil) + } + + @Test + func filenamesThatAreNotOnePlainComponentAreRejected() { + let unsafeNames = [ + "../outgoing/x.jpg", + "../../Library/secret.jpg", + "a/b.jpg", + "/etc/hosts", + "x.jpg/", + "..", + ".", + "a\\b.jpg", + "..\\outgoing\\x.jpg" + ] + for name in unsafeNames { + #expect(!BitchatMessage.isSafeMediaFilename(name), "\(name)") + #expect(message("[image] \(name)").mediaAttachment(for: "me") == nil, "\(name)") + #expect(message("[voice] \(name)").mediaAttachment(for: "me") == nil, "\(name)") + } + #expect(!BitchatMessage.isSafeMediaFilename("")) + #expect(message("[image] ").mediaAttachment(for: "me") == nil) + } + + @Test + func plainFilenamesAreAccepted() { + for name in ["img_20260101_120000.jpg", "note 1.m4a", "photo...jpg", "...", "émoji-😀.png"] { + #expect(BitchatMessage.isSafeMediaFilename(name), "\(name)") + } + } +} diff --git a/bitchatTests/ChatComposerCoordinatorContextTests.swift b/bitchatTests/ChatComposerCoordinatorContextTests.swift index d38ddc8a..6c37e845 100644 --- a/bitchatTests/ChatComposerCoordinatorContextTests.swift +++ b/bitchatTests/ChatComposerCoordinatorContextTests.swift @@ -22,11 +22,13 @@ import BitFoundation /// `ChatComposerCoordinator` is testable without a `ChatViewModel`. @MainActor private final class MockChatComposerContext: ChatComposerContext { - // Autocomplete UI state - var autocompleteSuggestions: [String] = [] - var autocompleteRange: NSRange? - var showAutocomplete = false - var selectedAutocompleteIndex = -1 + // Autocomplete UI state. Every write is counted: each one republishes the + // composer state (and re-renders the message rows) in the real owner. + var autocompleteSuggestions: [String] = [] { didSet { autocompleteStateWrites += 1 } } + var autocompleteRange: NSRange? { didSet { autocompleteStateWrites += 1 } } + var showAutocomplete = false { didSet { autocompleteStateWrites += 1 } } + var selectedAutocompleteIndex = -1 { didSet { autocompleteStateWrites += 1 } } + private(set) var autocompleteStateWrites = 0 var queryResult: (suggestions: [String], range: NSRange?) = ([], nil) private(set) var queriedPeerCandidates: [[String]] = [] private(set) var appliedSuggestions: [(suggestion: String, text: String, range: NSRange)] = [] @@ -158,6 +160,57 @@ struct ChatComposerCoordinatorContextTests { #expect(geoContext.queriedPeerCandidates == [["carol#dddd"]]) } + @Test @MainActor + func updateAutocomplete_withoutMentionTokenAtCursor_skipsCandidateQuery() { + let context = MockChatComposerContext() + let coordinator = ChatComposerCoordinator(context: context) + context.meshNicknamesByPeerID = [PeerID(str: "1111111111111111"): "alice"] + context.queryResult = (["@alice"], NSRange(location: 3, length: 3)) + + // Plain text, and a mention that no longer ends at the cursor: the + // query could not suggest anything, so it never runs. + coordinator.updateAutocomplete(for: "plain text", cursorPosition: 10) + coordinator.updateAutocomplete(for: "hi @al there", cursorPosition: 12) + #expect(context.queriedPeerCandidates.isEmpty) + #expect(context.autocompleteSuggestions.isEmpty) + #expect(!context.showAutocomplete) + + // The same text with the cursor right after the token queries. + coordinator.updateAutocomplete(for: "hi @al there", cursorPosition: 6) + #expect(context.queriedPeerCandidates == [["alice"]]) + #expect(context.autocompleteSuggestions == ["@alice"]) + #expect(context.showAutocomplete) + } + + @Test @MainActor + func updateAutocomplete_rewritesNothingWhenStateIsUnchanged() { + let context = MockChatComposerContext() + let coordinator = ChatComposerCoordinator(context: context) + context.meshNicknamesByPeerID = [PeerID(str: "1111111111111111"): "alice"] + + // The first clear only has to reset the highlight index. + coordinator.updateAutocomplete(for: "hello", cursorPosition: 5) + #expect(context.autocompleteStateWrites == 1) + #expect(context.selectedAutocompleteIndex == 0) + + // Typing pauses in plain text then leave the state untouched. + coordinator.updateAutocomplete(for: "hello there", cursorPosition: 11) + #expect(context.autocompleteStateWrites == 1) + + // Showing suggestions writes; re-querying the same result does not. + context.queryResult = (["@alice"], NSRange(location: 0, length: 2)) + coordinator.updateAutocomplete(for: "@a", cursorPosition: 2) + let writesAfterShowing = context.autocompleteStateWrites + #expect(writesAfterShowing == 4) + coordinator.updateAutocomplete(for: "@a", cursorPosition: 2) + #expect(context.autocompleteStateWrites == writesAfterShowing) + + // A moved highlight is still reset to the first suggestion. + context.selectedAutocompleteIndex = 2 + coordinator.updateAutocomplete(for: "@a", cursorPosition: 2) + #expect(context.selectedAutocompleteIndex == 0) + } + @Test @MainActor func completeNickname_appliesSuggestionResetsStateAndReturnsCursor() { let context = MockChatComposerContext() diff --git a/bitchatTests/ChatMessageFormatterTests.swift b/bitchatTests/ChatMessageFormatterTests.swift new file mode 100644 index 00000000..2e98a374 --- /dev/null +++ b/bitchatTests/ChatMessageFormatterTests.swift @@ -0,0 +1,99 @@ +// +// ChatMessageFormatterTests.swift +// bitchatTests +// +// This is free and unencumbered software released into the public domain. +// For more information, see +// + +import Foundation +import SwiftUI +import Testing +@testable import bitchat + +/// Counts full roster scans: `GeohashParticipantTracker.getVisiblePeople()` +/// asks its context whether each participant is blocked exactly once. +@MainActor +private final class RosterScanCountingContext: GeohashParticipantContext { + private weak var base: ChatViewModel? + private(set) var isBlockedCalls = 0 + + init(base: ChatViewModel) { + self.base = base + } + + func displayNameForPubkey(_ pubkeyHex: String) -> String { + base?.displayNameForPubkey(pubkeyHex) ?? "anon#\(pubkeyHex.suffix(4))" + } + + func isBlocked(_ pubkeyHexLowercased: String) -> Bool { + isBlockedCalls += 1 + return base?.isBlocked(pubkeyHexLowercased) ?? false + } +} + +@MainActor +struct ChatMessageFormatterTests { + private let geohash = "u4pruyd" + + /// One people-sheet render asks for a color per row. Each lookup used to + /// rebuild the palette from a fresh roster scan, making the sheet O(N²): + /// 60 rows cost 3,600 block checks before a single row was laid out. + @Test func geohashColorLookupsDoNotRescanTheRoster() { + let viewModel = makeViewModel() + let pubkeys = seedParticipants(60, in: viewModel) + let counter = RosterScanCountingContext(base: viewModel) + viewModel.participantTracker.configure(context: counter) + defer { viewModel.participantTracker.configure(context: viewModel) } + + let first = pubkeys.map { viewModel.colorForNostrPubkey($0, isDark: true) } + let second = pubkeys.map { viewModel.colorForNostrPubkey($0, isDark: true) } + + #expect(counter.isBlockedCalls == 0) + #expect(first == second) + } + + /// The palette follows roster membership: a newcomer gets a palette slot + /// (not the hash fallback) and people already on screen keep theirs. + @Test func paletteTracksMembershipChangesWithoutRecoloringExistingRows() { + let viewModel = makeViewModel() + let pubkeys = seedParticipants(10, in: viewModel) + let before = pubkeys.map { viewModel.colorForNostrPubkey($0, isDark: true) } + + let newcomer = String(format: "%064x", 0xfeed) + viewModel.participantTracker.recordParticipant(pubkeyHex: newcomer, geohash: geohash) + + // Palette colors use the configured saturation, which the hash + // fallback can never produce exactly, so inequality proves a slot. + #expect(viewModel.colorForNostrPubkey(newcomer, isDark: true) != Color(peerSeed: "nostr:" + newcomer, isDark: true)) + #expect(pubkeys.map { viewModel.colorForNostrPubkey($0, isDark: true) } == before) + } + + // MARK: - Helpers + + private func makeViewModel() -> ChatViewModel { + let keychain = MockKeychain() + // A private location manager: the shared one is switched by other + // suites running in parallel, and a switch resets the roster. + let locationSuite = "ChatMessageFormatterTests.\(UUID().uuidString)" + let locationStorage = UserDefaults(suiteName: locationSuite) ?? .standard + locationStorage.removePersistentDomain(forName: locationSuite) + return ChatViewModel( + keychain: keychain, + idBridge: NostrIdentityBridge(keychain: MockKeychainHelper()), + identityManager: MockIdentityManager(keychain), + transport: MockTransport(), + locationManager: LocationChannelManager(storage: locationStorage) + ) + } + + private func seedParticipants(_ count: Int, in viewModel: ChatViewModel) -> [String] { + let tracker = viewModel.participantTracker + tracker.setActiveGeohash(geohash) + let pubkeys = (1...count).map { String(format: "%064x", $0) } + for pubkey in pubkeys { + tracker.recordParticipant(pubkeyHex: pubkey, geohash: geohash) + } + return pubkeys + } +} diff --git a/bitchatTests/ChatNostrCoordinatorContextTests.swift b/bitchatTests/ChatNostrCoordinatorContextTests.swift index 74b0d0e2..ffe22d9f 100644 --- a/bitchatTests/ChatNostrCoordinatorContextTests.swift +++ b/bitchatTests/ChatNostrCoordinatorContextTests.swift @@ -152,7 +152,10 @@ private final class MockChatNostrContext: ChatNostrContext { private(set) var refreshTimerStopCount = 0 private(set) var activeParticipantGeohashes: [String?] = [] private(set) var recordedParticipants: [String] = [] + private(set) var recordedParticipantTimes: [Date] = [] private(set) var recordedSampledParticipants: [(pubkeyHex: String, geohash: String)] = [] + /// "nickname:" / "record:" in call order. + private(set) var presenceCallLog: [String] = [] private(set) var clearTeleportedGeoCount = 0 private(set) var clearGeoNicknamesCount = 0 var visiblePeople: [GeoPerson] = [] @@ -160,9 +163,15 @@ private final class MockChatNostrContext: ChatNostrContext { func startGeoParticipantRefreshTimer() { refreshTimerStartCount += 1 } func stopGeoParticipantRefreshTimer() { refreshTimerStopCount += 1 } func setActiveParticipantGeohash(_ geohash: String?) { activeParticipantGeohashes.append(geohash) } - func recordGeoParticipant(pubkeyHex: String) { recordedParticipants.append(pubkeyHex) } + func recordGeoParticipant(pubkeyHex: String, seenAt: Date) -> Bool { + recordedParticipants.append(pubkeyHex) + recordedParticipantTimes.append(seenAt) + presenceCallLog.append("record:\(pubkeyHex)") + // Like the tracker: activity older than the window doesn't count. + return seenAt >= Date().addingTimeInterval(-TransportConfig.uiRecentCutoffFiveMinutesSeconds) + } - func recordGeoParticipant(pubkeyHex: String, geohash: String) { + func recordGeoParticipant(pubkeyHex: String, geohash: String, seenAt: Date) { recordedSampledParticipants.append((pubkeyHex, geohash)) } @@ -170,7 +179,10 @@ private final class MockChatNostrContext: ChatNostrContext { recordedSampledParticipants.filter { $0.geohash == geohash }.count } - func setGeoNickname(_ nickname: String, forPubkey pubkeyHex: String) { geoNicknames[pubkeyHex.lowercased()] = nickname } + func setGeoNickname(_ nickname: String, forPubkey pubkeyHex: String) { + geoNicknames[pubkeyHex.lowercased()] = nickname + presenceCallLog.append("nickname:\(pubkeyHex)") + } func markGeoTeleported(_ pubkeyHexLowercased: String) { teleportedKeys.insert(pubkeyHexLowercased) } func clearGeoTeleported(_ pubkeyHexLowercased: String) { teleportedKeys.remove(pubkeyHexLowercased) } @@ -239,6 +251,18 @@ private func drainMainQueue() async { } } +/// A signed geohash message carrying the teleport tag, sent at `sentAt` +/// (the `NostrProtocol` builder always stamps now). +private func teleportedGeohashEvent(from sender: NostrIdentity, sentAt: Date) throws -> NostrEvent { + try NostrEvent( + pubkey: sender.publicKeyHex, + createdAt: sentAt, + kind: .ephemeralEvent, + tags: [["g", "u4pruyd"], ["t", "teleport"]], + content: "from earlier" + ).sign(with: sender.schnorrSigningKey()) +} + // MARK: - Coordinator Tests Against Mock Context /// Exercises `ChatNostrCoordinator` against `MockChatNostrContext` with no @@ -334,6 +358,104 @@ struct ChatNostrCoordinatorContextTests { #expect(context.handledPublicMessages.isEmpty) } + /// A newcomer's nickname is known before they're recorded, so they enter + /// the roster under their name. Live events count as activity when they + /// arrive (keeping senders with skewed clocks visible). + @Test @MainActor + func handleNostrEvent_learnsTheNicknameBeforeRecordingTheSender() async throws { + let context = MockChatNostrContext() + let coordinator = ChatNostrCoordinator(context: context) + + let sender = try NostrIdentity.generate() + let event = try NostrProtocol.createEphemeralGeohashEvent( + content: "hello", + geohash: "u4pruyd", + senderIdentity: sender, + nickname: "alice" + ) + + let beforeArrival = Date() + coordinator.inbound.handleNostrEvent(event) + await drainMainQueue() + + #expect(context.presenceCallLog == ["nickname:\(event.pubkey)", "record:\(event.pubkey)"]) + #expect(context.recordedParticipantTimes.first.map { $0 >= beforeArrival } == true) + } + + /// Stored history relays replay before EOSE counts as activity at the + /// time it happened, so joining doesn't mark an hour of authors present. + @Test @MainActor + func handleNostrEvent_stampsReplayedHistoryWithTheEventTime() async throws { + let context = MockChatNostrContext() + let coordinator = ChatNostrCoordinator(context: context) + + let sender = try NostrIdentity.generate() + let event = try NostrProtocol.createEphemeralGeohashEvent( + content: "from earlier", + geohash: "u4pruyd", + senderIdentity: sender + ) + + coordinator.inbound.handleNostrEvent(event, isHistoryReplay: true) + await drainMainQueue() + + #expect(context.recordedParticipantTimes == [Date(timeIntervalSince1970: TimeInterval(event.created_at))]) + } + + /// A teleport tag on replayed history too old to count as presence must + /// not mark its author, on either inbound path: markers are pruned only + /// as the roster changes, so one set for someone absent would still be + /// there when they came back. Recent history still marks. + @Test @MainActor + func replayedTeleportTag_marksOnlyAuthorsWhoseActivityStillCounts() async throws { + let context = MockChatNostrContext() + let coordinator = ChatNostrCoordinator(context: context) + + let longGone = try NostrIdentity.generate() + let alsoLongGone = try NostrIdentity.generate() + let stillHere = try NostrIdentity.generate() + // Ten minutes old: past the five-minute activity window. + let expired = try teleportedGeohashEvent(from: longGone, sentAt: Date().addingTimeInterval(-600)) + let expiredOnResubscribe = try teleportedGeohashEvent(from: alsoLongGone, sentAt: Date().addingTimeInterval(-600)) + let recent = try teleportedGeohashEvent(from: stillHere, sentAt: Date().addingTimeInterval(-60)) + + coordinator.inbound.handleNostrEvent(expired, isHistoryReplay: true) + coordinator.inbound.subscribeNostrEvent(expiredOnResubscribe, isHistoryReplay: true) + coordinator.inbound.handleNostrEvent(recent, isHistoryReplay: true) + await drainMainQueue() + + #expect(context.teleportedKeys == [stillHere.publicKeyHex.lowercased()]) + } + + /// The open channel is usually also a sampled cell. Its own subscription + /// records senders, so the sampled copy must not record them again + /// (that ran the roster bookkeeping twice per event); other sampled + /// cells still count. + @Test @MainActor + func presenceSampling_skipsTheOpenChannelButCountsOtherCells() async throws { + let context = MockChatNostrContext() + let coordinator = ChatNostrCoordinator(context: context) + context.activeChannel = .location(GeohashChannel(level: .neighborhood, geohash: "u4pruy")) + + let sender = try NostrIdentity.generate() + let inOpenChannel = try NostrProtocol.createEphemeralGeohashEvent( + content: "here", + geohash: "u4pruy", + senderIdentity: sender + ) + let elsewhere = try NostrProtocol.createEphemeralGeohashEvent( + content: "there", + geohash: "u4pruz", + senderIdentity: sender + ) + + coordinator.presence.subscribeNostrEvent(inOpenChannel, gh: "u4pruy") + coordinator.presence.subscribeNostrEvent(elsewhere, gh: "u4pruz") + await drainMainQueue() + + #expect(context.recordedSampledParticipants.map(\.geohash) == ["u4pruz"]) + } + @Test @MainActor func handleGiftWrap_routesEmbeddedPrivateMessageAndDeduplicates() async throws { let context = MockChatNostrContext() diff --git a/bitchatTests/ChatOutgoingCoordinatorContextTests.swift b/bitchatTests/ChatOutgoingCoordinatorContextTests.swift index 34963f0a..174f2da5 100644 --- a/bitchatTests/ChatOutgoingCoordinatorContextTests.swift +++ b/bitchatTests/ChatOutgoingCoordinatorContextTests.swift @@ -208,6 +208,8 @@ struct ChatOutgoingCoordinatorContextTests { let echo = context.appendedPublicMessages[0].message #expect(context.appendedPublicMessages[0].conversationID == .geohash("u4pruydq")) #expect(echo.sender == "me#2222") + // The echo is told apart as mine by this ID, not by its name. + #expect(echo.senderPeerID == PeerID(nostr: MockChatOutgoingContext.dummyIdentity.publicKeyHex)) #expect(context.recordedActivityKeys == ["geo:u4pruydq"]) #expect(context.sentGeohashContexts.count == 1) let geoContext = context.sentGeohashContexts[0] diff --git a/bitchatTests/ChatPrivateConversationCoordinatorContextTests.swift b/bitchatTests/ChatPrivateConversationCoordinatorContextTests.swift index aa4e8b1b..66d32d46 100644 --- a/bitchatTests/ChatPrivateConversationCoordinatorContextTests.swift +++ b/bitchatTests/ChatPrivateConversationCoordinatorContextTests.swift @@ -811,6 +811,246 @@ struct ChatPrivateConversationCoordinatorContextTests { #expect(context.notifyUIChangedCount == 1) } + @Test @MainActor + func migratePrivateChats_leavesMyGeoDMThreadOutOfANamesakesChat() async { + // My reply to a geohash stranger names me as its recipient + // (sendGeohashDM), so by nickname it reads as written to any mesh + // peer called "alice". That namesake's first DM must not take the + // thread along, or my next reply there would go to them. + let context = MockChatPrivateConversationContext() + context.nickname = "alice" + let coordinator = ChatPrivateConversationCoordinator(context: context) + let geoThread = PeerID(nostr_: String(repeating: "42", count: 32)) + let namesakePeerID = PeerID(str: "8899aabbccddeeff") + context.privateChats[geoThread] = [ + makeIncomingMessage( + id: "stranger-1", + sender: "carol#4242", + timestamp: Date().addingTimeInterval(-120), + senderPeerID: geoThread, + recipientNickname: "alice" + ), + BitchatMessage( + id: "my-reply", + sender: "alice", + content: "hi carol", + timestamp: Date().addingTimeInterval(-60), + isRelay: false, + isPrivate: true, + recipientNickname: "alice", + senderPeerID: context.myPeerID, + deliveryStatus: .sent + ) + ] + context.selectedPrivateChatPeer = geoThread + + coordinator.handlePrivateMessage( + makeIncomingMessage(id: "namesake-1", sender: "alice", senderPeerID: namesakePeerID, recipientNickname: "alice") + ) + + #expect(context.privateChats[geoThread]?.map(\.id) == ["stranger-1", "my-reply"]) + #expect(context.privateChats[namesakePeerID]?.map(\.id) == ["namesake-1"]) + #expect(context.migratedChats.isEmpty) + // The open thread is still the stranger's, and the namesake's message + // waits unread rather than being read receipted from my thread. + #expect(context.selectedPrivateChatPeer == geoThread) + #expect(context.meshReadReceipts.isEmpty) + #expect(context.unreadPrivateMessages == [namesakePeerID]) + } + + @Test @MainActor + func migratePrivateChats_leavesMyThreadAloneWhenAStrangerTakesMyOldName() async { + // I was "alice" and am now "alicia". My reply to bob still carries the + // old name, but it is mine by its sender ID, so a stranger who now + // calls themselves "alice" is not its author and must not take the + // thread (and with it my next reply) along. + let context = MockChatPrivateConversationContext() + context.nickname = "alicia" + let coordinator = ChatPrivateConversationCoordinator(context: context) + let bobThread = PeerID(str: "1122334455667788") + let strangerPeerID = PeerID(str: "8899aabbccddeeff") + context.privateChats[bobThread] = [ + makeIncomingMessage( + id: "bob-1", + sender: "bob", + timestamp: Date().addingTimeInterval(-120), + senderPeerID: bobThread, + recipientNickname: "alice" + ), + BitchatMessage( + id: "my-old-reply", + sender: "alice", + content: "hi bob", + timestamp: Date().addingTimeInterval(-60), + isRelay: false, + isPrivate: true, + recipientNickname: "bob", + senderPeerID: context.myPeerID, + deliveryStatus: .sent + ) + ] + context.selectedPrivateChatPeer = bobThread + + coordinator.handlePrivateMessage( + makeIncomingMessage(id: "stranger-1", sender: "alice", senderPeerID: strangerPeerID, recipientNickname: "alicia") + ) + + #expect(context.privateChats[bobThread]?.map(\.id) == ["bob-1", "my-old-reply"]) + #expect(context.privateChats[strangerPeerID]?.map(\.id) == ["stranger-1"]) + #expect(context.migratedChats.isEmpty) + #expect(context.selectedPrivateChatPeer == bobThread) + } + + @Test @MainActor + func migratePrivateChats_leavesMyGeoDMThreadAloneWhenAStrangerTakesMyOldName() async { + // My geo-DM replies name me as their recipient, under the name I had + // then. After a rename, a stranger who takes that old name must not + // match them and take the thread along. + let context = MockChatPrivateConversationContext() + context.nickname = "alicia" + let coordinator = ChatPrivateConversationCoordinator(context: context) + let geoThread = PeerID(nostr_: String(repeating: "45", count: 32)) + let strangerPeerID = PeerID(str: "8899aabbccddeeff") + context.privateChats[geoThread] = [ + makeIncomingMessage( + id: "carol-1", + sender: "carol#4545", + timestamp: Date().addingTimeInterval(-120), + senderPeerID: geoThread, + recipientNickname: "alice" + ), + BitchatMessage( + id: "my-old-reply", + sender: "alice", + content: "hi carol", + timestamp: Date().addingTimeInterval(-60), + isRelay: false, + isPrivate: true, + recipientNickname: "alice", + senderPeerID: context.myPeerID, + deliveryStatus: .sent + ) + ] + context.selectedPrivateChatPeer = geoThread + + coordinator.handlePrivateMessage( + makeIncomingMessage(id: "stranger-1", sender: "alice", senderPeerID: strangerPeerID, recipientNickname: "alicia") + ) + + #expect(context.privateChats[geoThread]?.map(\.id) == ["carol-1", "my-old-reply"]) + #expect(context.privateChats[strangerPeerID]?.map(\.id) == ["stranger-1"]) + #expect(context.migratedChats.isEmpty) + #expect(context.selectedPrivateChatPeer == geoThread) + } + + @Test @MainActor + func migratePrivateChats_stillMovesAGeoDMThreadWithMyRepliesByThePeersRows() async { + // My replies are no evidence in a geo-DM thread, but they don't veto + // it either: the peer's own rows still take it to their mesh chat. + // (Received geo-DM rows carry a geo name today, so this pins the rule + // rather than a path that occurs.) + let context = MockChatPrivateConversationContext() + context.nickname = "alice" + let coordinator = ChatPrivateConversationCoordinator(context: context) + let theirThread = PeerID(nostr_: String(repeating: "44", count: 32)) + let bobPeerID = PeerID(str: "8899aabbccddeeff") + context.privateChats[theirThread] = [ + makeIncomingMessage( + id: "bob-earlier", + sender: "bob", + timestamp: Date().addingTimeInterval(-120), + senderPeerID: theirThread, + recipientNickname: "alice" + ), + BitchatMessage( + id: "my-reply", + sender: "alice", + content: "hi bob", + timestamp: Date().addingTimeInterval(-60), + isRelay: false, + isPrivate: true, + recipientNickname: "alice", + senderPeerID: context.myPeerID, + deliveryStatus: .sent + ) + ] + + coordinator.handlePrivateMessage( + makeIncomingMessage(id: "bob-1", sender: "bob", senderPeerID: bobPeerID, recipientNickname: "alice") + ) + + #expect(context.privateChats[theirThread] == nil) + #expect(context.privateChats[bobPeerID]?.map(\.id) == ["bob-earlier", "my-reply", "bob-1"]) + #expect(context.migratedChats.map(\.from) == [theirThread]) + } + + @Test @MainActor + func migratePrivateChats_stillMovesAGeoDMThreadWithoutMyRowsByNickname() async { + // The skip is for threads holding my rows: a geo-DM thread of the + // peer's own rows still follows them to their mesh chat by name. + let context = MockChatPrivateConversationContext() + context.nickname = "alice" + let coordinator = ChatPrivateConversationCoordinator(context: context) + let theirThread = PeerID(nostr_: String(repeating: "43", count: 32)) + let bobPeerID = PeerID(str: "8899aabbccddeeff") + context.privateChats[theirThread] = [ + makeIncomingMessage( + id: "bob-earlier", + sender: "bob", + timestamp: Date().addingTimeInterval(-60), + senderPeerID: theirThread, + recipientNickname: "alice" + ) + ] + + coordinator.handlePrivateMessage( + makeIncomingMessage(id: "bob-1", sender: "bob", senderPeerID: bobPeerID, recipientNickname: "alice") + ) + + #expect(context.privateChats[theirThread] == nil) + #expect(context.privateChats[bobPeerID]?.map(\.id) == ["bob-earlier", "bob-1"]) + #expect(context.migratedChats.map(\.from) == [theirThread]) + } + + @Test @MainActor + func migratePrivateChats_stillMovesMyMeshThreadByNickname() async { + // Only geo-DM rows name me as their recipient. My mesh rows name the + // peer, so my thread with bob under his previous peer ID follows him + // to the new one. + let context = MockChatPrivateConversationContext() + context.nickname = "alice" + let coordinator = ChatPrivateConversationCoordinator(context: context) + let previousPeerID = PeerID(str: "1122334455667788") + let bobPeerID = PeerID(str: "8899aabbccddeeff") + context.privateChats[previousPeerID] = [ + makeIncomingMessage( + id: "bob-earlier", + sender: "bob", + timestamp: Date().addingTimeInterval(-120), + senderPeerID: previousPeerID, + recipientNickname: "alice" + ), + BitchatMessage( + id: "my-reply", + sender: "alice", + content: "hi bob", + timestamp: Date().addingTimeInterval(-60), + isRelay: false, + isPrivate: true, + recipientNickname: "bob", + senderPeerID: context.myPeerID, + deliveryStatus: .sent + ) + ] + + coordinator.handlePrivateMessage( + makeIncomingMessage(id: "bob-1", sender: "bob", senderPeerID: bobPeerID, recipientNickname: "alice") + ) + + #expect(context.privateChats[previousPeerID] == nil) + #expect(context.privateChats[bobPeerID]?.map(\.id) == ["bob-earlier", "my-reply", "bob-1"]) + } + @Test @MainActor func handlePrivateMessage_postsNotificationOnlyWhenNotViewingChat() async { let context = MockChatPrivateConversationContext() diff --git a/bitchatTests/ChatPublicConversationCoordinatorContextTests.swift b/bitchatTests/ChatPublicConversationCoordinatorContextTests.swift index 13424e0f..f53b7c9b 100644 --- a/bitchatTests/ChatPublicConversationCoordinatorContextTests.swift +++ b/bitchatTests/ChatPublicConversationCoordinatorContextTests.swift @@ -30,13 +30,8 @@ private final class MockChatPublicConversationContext: ChatPublicConversationCon var currentGeohash: String? var nickname = "me" var myPeerID = PeerID(str: "0011223344556677") - private(set) var isBatchingPublic = false private(set) var notifyUIChangedCount = 0 - func setPublicBatching(_ isBatching: Bool) { - isBatchingPublic = isBatching - } - func notifyUIChanged() { notifyUIChangedCount += 1 } @@ -541,9 +536,6 @@ struct ChatPublicConversationCoordinatorContextTests { coordinator.pipelinePrewarmMessage(pipeline, message: message) #expect(context.prewarmedMessageIDs == ["pipeline-msg"]) - - coordinator.pipelineSetBatchingState(pipeline, isBatching: true) - #expect(context.isBatchingPublic) } @Test @MainActor @@ -606,7 +598,8 @@ struct ChatPublicConversationCoordinatorContextTests { ) #expect(context.mentionNotifications.count == 1) - // My own message mentioning myself does not notify. + // My own message mentioning myself (a gossip replay of my mesh text, + // stamped with my peer ID) does not notify. coordinator.checkForMentions( BitchatMessage( id: "mention-3", @@ -614,10 +607,65 @@ struct ChatPublicConversationCoordinatorContextTests { content: "talking about @me", timestamp: Date(), isRelay: false, + senderPeerID: context.myPeerID, mentions: ["me"] ) ) #expect(context.mentionNotifications.count == 1) } + @Test @MainActor + func checkForMentions_tellsMyOwnMessagesFromNamesakesBySenderID() async { + let context = MockChatPublicConversationContext() + let coordinator = ChatPublicConversationCoordinator(context: context) + let myGeoHex = MockChatPublicConversationContext.dummyIdentity.publicKeyHex + let namesakeHex = String(repeating: "ef", count: 32) + + // A namesake shown by my bare nickname (multi-hop mesh, or the + // signed-name fallback) mentioning me still notifies. + coordinator.checkForMentions( + BitchatMessage( + id: "namesake-mesh", + sender: "me", + content: "hi @me", + timestamp: Date(), + isRelay: false, + senderPeerID: PeerID(str: "8899aabbccddeeff"), + mentions: ["me"] + ) + ) + #expect(context.mentionNotifications.map(\.message) == ["hi @me"]) + + // In a location channel, a relay echo of my own geochat message + // (NostrInboundPipeline.subscribeNostrEvent) stays quiet... + context.activeChannel = .location(GeohashChannel(level: .city, geohash: "u4pruy")) + context.currentGeohash = "u4pruy" + coordinator.checkForMentions( + BitchatMessage( + id: "own-geo-echo", + sender: "me#\(myGeoHex.suffix(4))", + content: "note to @me", + timestamp: Date(), + isRelay: false, + senderPeerID: PeerID(nostr: myGeoHex), + mentions: ["me"] + ) + ) + #expect(context.mentionNotifications.map(\.message) == ["hi @me"]) + + // ...while a geochat namesake mentioning me notifies. + coordinator.checkForMentions( + BitchatMessage( + id: "namesake-geo", + sender: "me#\(namesakeHex.suffix(4))", + content: "yo @me", + timestamp: Date(), + isRelay: false, + senderPeerID: PeerID(nostr: namesakeHex), + mentions: ["me"] + ) + ) + #expect(context.mentionNotifications.map(\.message) == ["hi @me", "yo @me"]) + } + } diff --git a/bitchatTests/ChatViewModelBootstrapperTests.swift b/bitchatTests/ChatViewModelBootstrapperTests.swift new file mode 100644 index 00000000..2db81e24 --- /dev/null +++ b/bitchatTests/ChatViewModelBootstrapperTests.swift @@ -0,0 +1,102 @@ +// +// ChatViewModelBootstrapperTests.swift +// bitchatTests +// +// This is free and unencumbered software released into the public domain. +// For more information, see +// + +import Foundation +import Testing +@testable import bitchat + +@MainActor +struct ChatViewModelBootstrapperTests { + + /// Nicknames name the authors of messages on screen, including replayed + /// history from people no longer present. Roster publishes prune presence + /// state (teleport markers) but must keep those names resolvable for + /// /msg, /block, autocomplete and DM headers. + @Test func rosterPublishesKeepNicknamesOfAuthorsWhoAreNotPresent() async { + let viewModel = makeViewModel() + // The initial (mesh) channel arrives asynchronously and resets the + // tracker; let startup settle first. + await drainMainQueue() + + let geohash = "u4pruyd" + viewModel.currentGeohash = geohash + viewModel.participantTracker.setActiveGeohash(geohash) + let author = String(repeating: "a", count: 64) + // A replayed message from ten minutes ago: named, but not present. + viewModel.setGeoNickname("troll", forPubkey: author) + viewModel.participantTracker.recordParticipant(pubkeyHex: author, seenAt: Date().addingTimeInterval(-600)) + + // Someone else arrives, so the roster publishes and the prune runs. + viewModel.participantTracker.recordParticipant(pubkeyHex: String(repeating: "b", count: 64)) + await drainMainQueue() + + #expect(viewModel.geoNicknames[author] == "troll") + } + + /// Teleport markers follow the roster, which prunes them only as it + /// changes. A teleport tag replayed from before the activity window must + /// not mark its absent author: the marker would wait for them, and when + /// they came back, no longer teleported, they'd still be badged. + @Test func expiredReplayedTeleportTagDoesNotFollowItsAuthorBackIn() async throws { + let viewModel = makeViewModel() + await drainMainQueue() + + let geohash = "u4pruyd" + viewModel.currentGeohash = geohash + viewModel.participantTracker.setActiveGeohash(geohash) + let sender = try NostrIdentity.generate() + // Replayed on join: a message they sent teleported, ten minutes ago. + let replayed = try NostrEvent( + pubkey: sender.publicKeyHex, + createdAt: Date().addingTimeInterval(-600), + kind: .ephemeralEvent, + tags: [["g", geohash], ["t", "teleport"]], + content: "from earlier" + ).sign(with: sender.schnorrSigningKey()) + viewModel.nostrCoordinator.inbound.handleNostrEvent(replayed, isHistoryReplay: true) + await drainMainQueue() + + // They come back, live and local. + let live = try NostrProtocol.createEphemeralGeohashEvent( + content: "back", + geohash: geohash, + senderIdentity: sender + ) + viewModel.nostrCoordinator.inbound.handleNostrEvent(live) + await drainMainQueue() + + let key = sender.publicKeyHex.lowercased() + #expect(viewModel.participantTracker.visiblePeople.map(\.id) == [key]) + #expect(!viewModel.teleportedGeo.contains(key)) + } + + /// A private location manager: the shared one is switched by other + /// suites running in parallel, and a switch clears nicknames and + /// teleport markers. + private func makeViewModel() -> ChatViewModel { + let keychain = MockKeychain() + let locationSuite = "ChatViewModelBootstrapperTests.\(UUID().uuidString)" + let locationStorage = UserDefaults(suiteName: locationSuite) ?? .standard + locationStorage.removePersistentDomain(forName: locationSuite) + return ChatViewModel( + keychain: keychain, + idBridge: NostrIdentityBridge(keychain: MockKeychainHelper()), + identityManager: MockIdentityManager(keychain), + transport: MockTransport(), + locationManager: LocationChannelManager(storage: locationStorage) + ) + } + + private func drainMainQueue() async { + for _ in 0..<4 { + await withCheckedContinuation { continuation in + DispatchQueue.main.async { continuation.resume() } + } + } + } +} diff --git a/bitchatTests/ChatViewModelExtensionsTests.swift b/bitchatTests/ChatViewModelExtensionsTests.swift index 51e5f7fd..3c8bf357 100644 --- a/bitchatTests/ChatViewModelExtensionsTests.swift +++ b/bitchatTests/ChatViewModelExtensionsTests.swift @@ -823,8 +823,8 @@ struct ChatViewModelGeoDMTests { /// Contracts for the owner-side intent ops that are the sole mutation paths /// for `ChatViewModel`'s shared coordinator state (`nostrKeyMapping`, -/// `sentReadReceipts`, `sentGeoDeliveryAcks`, `isBatchingPublic`, the geo -/// subscription IDs, and the selected private chat hand-off). +/// `sentReadReceipts`, `sentGeoDeliveryAcks`, the geo subscription IDs, and +/// the selected private chat hand-off). struct ChatViewModelIntentOperationTests { @Test @MainActor @@ -890,17 +890,6 @@ struct ChatViewModelIntentOperationTests { #expect(viewModel.nostrKeyMapping[PeerID(nostr_: otherHex)] == otherHex) } - @Test @MainActor - func setPublicBatching_publishesBatchingState() async { - let (viewModel, _) = makeTestableViewModel() - - #expect(!viewModel.isBatchingPublic) - viewModel.setPublicBatching(true) - #expect(viewModel.isBatchingPublic) - viewModel.setPublicBatching(false) - #expect(!viewModel.isBatchingPublic) - } - @Test @MainActor func geoSubscriptionIntentOps_setClearAndDrainSubscriptions() async { let (viewModel, _) = makeTestableViewModel() diff --git a/bitchatTests/ChatViewModelTests.swift b/bitchatTests/ChatViewModelTests.swift index 35ab2975..9306c606 100644 --- a/bitchatTests/ChatViewModelTests.swift +++ b/bitchatTests/ChatViewModelTests.swift @@ -19,7 +19,8 @@ private func makeTestableViewModel( keychain injectedKeychain: MockKeychain? = nil, panicMediaWipe: (() throws -> Void)? = nil, panicRecoveryOperations: PanicRecoveryOperations? = nil, - panicNetworkLifecycle: PanicNetworkLifecycle = .noop + panicNetworkLifecycle: PanicNetworkLifecycle = .noop, + locationManager: LocationChannelManager = .shared ) -> (viewModel: ChatViewModel, transport: MockTransport) { let keychain = injectedKeychain ?? MockKeychain() let keychainHelper = MockKeychainHelper() @@ -32,6 +33,7 @@ private func makeTestableViewModel( idBridge: idBridge, identityManager: identityManager, transport: transport, + locationManager: locationManager, panicMediaWipe: panicMediaWipe, panicRecoveryOperations: panicRecoveryOperations, panicNetworkLifecycle: panicNetworkLifecycle @@ -691,6 +693,37 @@ struct ChatViewModelFormattingTests { #expect(String(header.characters) == "<@Alice#a1b2> ") } + + @Test @MainActor + func formatMessageHeader_isCachedApartFromTheFullText() async { + let (viewModel, _) = makeTestableViewModel() + let message = BitchatMessage( + id: "fmt-3", + sender: "Alice#a1b2", + content: "hello", + timestamp: Date(), + isRelay: false, + senderPeerID: PeerID(str: "00000000000000b3") + ) + + // The full text is cached first under the same scheme, theme and + // sender flags; the header lookup must not pick it up. + let fullText = viewModel.formatMessageAsText(message, colorScheme: .dark, theme: .matrix) + let header = viewModel.formatMessageHeader(message, colorScheme: .dark, theme: .matrix) + + #expect(String(header.characters) == "<@Alice#a1b2> ") + #expect(String(fullText.characters).hasPrefix("<@Alice#a1b2> hello")) + #expect( + message.getCachedFormattedText( + isDark: true, + isSelf: false, + variant: ChatMessageFormatter.headerCacheNamespace + ) == header + ) + // Later lookups are answered from each one's own cache entry. + #expect(viewModel.formatMessageHeader(message, colorScheme: .dark, theme: .matrix) == header) + #expect(viewModel.formatMessageAsText(message, colorScheme: .dark, theme: .matrix) == fullText) + } } // MARK: - Verification Tests @@ -1068,6 +1101,46 @@ struct ChatViewModelPrivateChatTests { // At minimum, it should not crash #expect(Bool(true)) // If we get here without crash, the test passes } + + @Test @MainActor + func syncReadReceiptsForSentMessages_judgesMineBySenderIDNotNickname() async { + let (viewModel, transport) = makeTestableViewModel() + viewModel.nickname = "alice" + let peerID = PeerID(str: "0011223344556677") + viewModel.seedPrivateChat([ + // A namesake's file, delivered to me (BLEFileTransferHandler.incomingMessage): + // it still needs my READ receipt. + BitchatMessage( + id: "namesake-delivered", + sender: "alice", + content: "[image] theirs.jpg", + timestamp: Date(), + isRelay: false, + isPrivate: true, + recipientNickname: "alice", + senderPeerID: peerID, + deliveryStatus: .delivered(to: "alice", at: Date()) + ), + // My own message from before a rename, already read. + BitchatMessage( + id: "mine-before-rename", + sender: "al", + content: "hi", + timestamp: Date(), + isRelay: false, + isPrivate: true, + recipientNickname: "bob", + senderPeerID: transport.myPeerID, + deliveryStatus: .read(by: "bob", at: Date()) + ) + ], for: peerID) + + viewModel.syncReadReceiptsForSentMessages(for: peerID) + + #expect(!viewModel.hasSentReadReceipt("namesake-delivered")) + #expect(!viewModel.privateChatManager.sentReadReceipts.contains("namesake-delivered")) + #expect(viewModel.hasSentReadReceipt("mine-before-rename")) + } } // MARK: - Private Chat Selection Tests @@ -2302,6 +2375,29 @@ struct ChatViewModelPanicTests { #expect(viewModel.geoNicknames.isEmpty) #expect(viewModel.teleportedGeo.isEmpty) } + + @Test @MainActor + func panicClearAllData_wipesTheLocationStateOfItsOwnManager() throws { + // Where the device has been, persisted the way the location manager + // writes it: a teleport and a bookmark. + let suiteName = "ChatViewModelPanicTests.\(UUID().uuidString)" + let storage = try #require(UserDefaults(suiteName: suiteName)) + defer { storage.removePersistentDomain(forName: suiteName) } + storage.set(try JSONEncoder().encode(["u4pruy"]), forKey: "locationChannel.teleportedSet") + storage.set(try JSONEncoder().encode(["u4pruy"]), forKey: "locationChannel.bookmarks") + let locationManager = LocationChannelManager(storage: storage) + #expect(locationManager.bookmarks == ["u4pruy"]) + let (viewModel, _) = makeTestableViewModel(locationManager: locationManager) + + viewModel.panicClearAllData() + + // The wipe lands on the manager the view model runs on: `.shared` in + // the app, this test's own here, which leaves the process-wide one to + // the tests that select channels on it. + #expect(locationManager.bookmarks.isEmpty) + #expect(storage.object(forKey: "locationChannel.teleportedSet") == nil) + #expect(storage.object(forKey: "locationChannel.bookmarks") == nil) + } } // MARK: - Service Lifecycle Tests diff --git a/bitchatTests/CommandProcessorTests.swift b/bitchatTests/CommandProcessorTests.swift index 232aa265..183dcccb 100644 --- a/bitchatTests/CommandProcessorTests.swift +++ b/bitchatTests/CommandProcessorTests.swift @@ -292,6 +292,8 @@ struct CommandProcessorTests { Issue.record("Expected success result") } #expect(identityManager.isNostrBlocked(pubkeyHexLowercased: String(repeating: "d", count: 64))) + // The roster re-filters now rather than on its next timer tick. + #expect(context.geohashBlockListChangeCount == 1) let unblockResult = await withSelectedChannel(.mesh, context: context) { processor.process("/unblock @carol") @@ -303,6 +305,7 @@ struct CommandProcessorTests { Issue.record("Expected success result") } #expect(!identityManager.isNostrBlocked(pubkeyHexLowercased: String(repeating: "d", count: 64))) + #expect(context.geohashBlockListChangeCount == 2) } /// /fav must go through toggleFavorite (which persists by the real noise @@ -608,6 +611,7 @@ private final class MockCommandContextProvider: CommandContextProvider { private(set) var commandOutputDestinations: [CommandOutputDestination] = [] private(set) var toggledFavorites: [PeerID] = [] private(set) var favoriteNotifications: [(peerID: PeerID, isFavorite: Bool)] = [] + private(set) var geohashBlockListChangeCount = 0 init(nickname: String = "tester", idBridge: NostrIdentityBridge = NostrIdentityBridge(keychain: MockKeychain())) { self.nickname = nickname @@ -626,6 +630,10 @@ private final class MockCommandContextProvider: CommandContextProvider { displayNameToNostrPubkey[displayName] } + func geohashBlockListDidChange() { + geohashBlockListChangeCount += 1 + } + func startPrivateChat(with peerID: PeerID) { startedPrivateChats.append(peerID) } diff --git a/bitchatTests/ConversationUIModelTests.swift b/bitchatTests/ConversationUIModelTests.swift new file mode 100644 index 00000000..a4f90e6c --- /dev/null +++ b/bitchatTests/ConversationUIModelTests.swift @@ -0,0 +1,470 @@ +// +// ConversationUIModelTests.swift +// bitchatTests +// +// "Is this row mine?" drives the message list: the context-menu actions, +// the jump to the bottom on my own send, DM delivery status, the verified +// seal and which media directory a row loads from. The answer must come from +// the sender ID a row carries, never from its display name, which namesakes +// share by design (geochat shows everyone as nick#). +// +// This is free and unencumbered software released into the public domain. +// For more information, see +// + +import BitFoundation +import Foundation +import Testing +@testable import bitchat + +/// A chat stack with a known mesh peer ID and an isolated location manager, +/// so no other test's channel selection leaks in. +@MainActor +private func makeChatViewModel(nickname: String) -> (viewModel: ChatViewModel, transport: MockTransport) { + let keychain = MockKeychain() + let transport = MockTransport() + transport.myPeerID = ConversationUIModelTests.myPeerID + let suiteName = "ConversationUIModelTests.\(UUID().uuidString)" + let storage = UserDefaults(suiteName: suiteName) ?? .standard + storage.removePersistentDomain(forName: suiteName) + let viewModel = ChatViewModel( + keychain: keychain, + idBridge: NostrIdentityBridge(keychain: MockKeychainHelper()), + identityManager: MockIdentityManager(keychain), + transport: transport, + locationManager: LocationChannelManager(storage: storage) + ) + viewModel.nickname = nickname + return (viewModel, transport) +} + +/// The UI model mirrors the nickname a runloop turn late, so a test that +/// renames builds a fresh one; that keeps the rename test meaningful against +/// a helper that compares names. +@MainActor +private func makeUIModel(for viewModel: ChatViewModel) -> ConversationUIModel { + let privateConversationModel = PrivateConversationModel( + chatViewModel: viewModel, + conversations: viewModel.conversations, + locationChannelsModel: LocationChannelsModel(manager: viewModel.locationManager) + ) + return ConversationUIModel( + chatViewModel: viewModel, + privateConversationModel: privateConversationModel, + conversations: viewModel.conversations + ) +} + +private func row( + _ sender: String, + _ senderPeerID: PeerID?, + content: String = "hi", + isPrivate: Bool = false, + deliveryStatus: DeliveryStatus? = nil, + isBridged: Bool = false +) -> BitchatMessage { + BitchatMessage( + sender: sender, + content: content, + timestamp: Date(), + isRelay: false, + isPrivate: isPrivate, + senderPeerID: senderPeerID, + deliveryStatus: deliveryStatus, + isBridged: isBridged + ) +} + +/// `hex` with its first `count` characters changed. Changing the first 8 +/// gives a different geochat sender ID (`nostr:` + 8 hex) while the last 4, +/// the display suffix, stay the same. +private func altered(_ hex: String, first count: Int) -> String { + String(hex.prefix(count).map { $0 == "0" ? "1" : "0" }) + hex.dropFirst(count) +} + +struct ConversationUIModelTests { + static let myPeerID = PeerID(str: "a1b2c3d4e5f60718") + static let peerID = PeerID(str: "0f1e2d3c4b5a6978") + static let geohash = "u4pruy" + static let locationChannel = ChannelID.location(GeohashChannel(level: .city, geohash: geohash)) + + @MainActor + private static func show(geohash: String, in viewModel: ChatViewModel) { + viewModel.activeChannel = .location(GeohashChannel(level: .city, geohash: geohash)) + } + + /// Switches channels the way the channel picker does: through the + /// location manager, which the view model follows a few hops later. + /// Tests that await must switch this way, since the view model re-applies + /// the manager's selection on a later turn and would undo a direct + /// `activeChannel` write. Returns once the UI model has mirrored the + /// switch (media is off in location channels), so no channel update + /// queued before it can still reach the memo. + @MainActor + private static func switchAndSettle(to channel: ChannelID, in viewModel: ChatViewModel, uiModel: ConversationUIModel) async -> Bool { + viewModel.locationManager.select(channel) + let mediaAllowed = channel == .mesh + return await TestHelpers.waitUntil({ + viewModel.activeChannel == channel && uiModel.canSendMediaInCurrentContext == mediaAllowed + }, timeout: TestConstants.settleTimeout) + } + + @MainActor + private static func myGeoHex(_ viewModel: ChatViewModel, geohash: String = ConversationUIModelTests.geohash) throws -> String { + try viewModel.idBridge.deriveIdentity(forGeohash: geohash).publicKeyHex + } + + @Test @MainActor + func geochatNamesakesAreNotMine() throws { + let (viewModel, _) = makeChatViewModel(nickname: "alice") + let uiModel = makeUIModel(for: viewModel) + Self.show(geohash: Self.geohash, in: viewModel) + let myHex = try Self.myGeoHex(viewModel) + let theirHex = altered(myHex, first: 64) + let twinHex = altered(myHex, first: 8) + + // My own row, as ChatOutgoingCoordinator.sendGeohashPublicMessage stamps it. + #expect(uiModel.isSentByCurrentUser(row("alice#\(myHex.suffix(4))", PeerID(nostr: myHex)))) + // Another "alice": same name, different key. + #expect(!uiModel.isSentByCurrentUser(row("alice#\(theirHex.suffix(4))", PeerID(nostr: theirHex)))) + // Even a display string identical to mine, down to the 4-hex suffix. + #expect(!uiModel.isSentByCurrentUser(row("alice#\(myHex.suffix(4))", PeerID(nostr: twinHex)))) + } + + @Test @MainActor + func anonReaderDoesNotOwnAnonymousStrangers() throws { + let (viewModel, _) = makeChatViewModel(nickname: "anon") + let uiModel = makeUIModel(for: viewModel) + Self.show(geohash: Self.geohash, in: viewModel) + let myHex = try Self.myGeoHex(viewModel) + let strangerHex = altered(myHex, first: 64) + let strangerName = "anon#\(strangerHex.suffix(4))" + + // Geochat and sampled senders without an n tag + // (displayNameForNostrPubkey, GeoPresenceTracker.cooldownPerGeohash). + #expect(!uiModel.isSentByCurrentUser(row(strangerName, PeerID(nostr: strangerHex)))) + // A bridged sender without one (BridgeService.classify). + #expect(!uiModel.isSentByCurrentUser(row(strangerName, PeerID(bridge: strangerHex), isBridged: true))) + // A geo DM from an unnamed stranger, delivered to me. + #expect(!uiModel.isSentByCurrentUser(row( + strangerName, + PeerID(nostr_: strangerHex), + isPrivate: true, + deliveryStatus: .delivered(to: "anon", at: Date()) + ))) + // My own geochat row is still mine. + #expect(uiModel.isSentByCurrentUser(row("anon#\(myHex.suffix(4))", PeerID(nostr: myHex)))) + } + + @Test @MainActor + func meshAndGroupNamesakesAreNotMine() { + let (viewModel, _) = makeChatViewModel(nickname: "alice") + let uiModel = makeUIModel(for: viewModel) + let namesakeRows = [ + // Public text, suffixed while the namesake is connected + // (BLEPeerSenderDisplayName.collisionResolvedName)... + row("alice#\(Self.peerID.id.prefix(4))", Self.peerID), + // ...and by its bare signed name otherwise + // (BLEService.signedSenderDisplayName). + row("alice", Self.peerID), + // A DM; received DMs keep the default .sending status. + row("alice", Self.peerID, isPrivate: true), + // A courier-opened DM, keyed by the sender's full Noise key. + row("alice", PeerID(hexData: Data((0..<32).map(UInt8.init))), isPrivate: true), + // A group member with my name (ChatGroupCoordinator.handleGroupMessagePayload). + row("alice", PeerID(str: "f00dfacecafebeef"), isPrivate: true) + ] + for message in namesakeRows { + #expect(!uiModel.isSentByCurrentUser(message), "\(message.sender) from \(message.senderPeerID?.id ?? "nil")") + } + } + + @Test @MainActor + func ownRowsOnEveryPathStayMineAcrossARename() throws { + let (viewModel, _) = makeChatViewModel(nickname: "alice") + let myHex = try Self.myGeoHex(viewModel) + let me = Self.myPeerID + // Each row as its construction site stamps it. + let ownRows = [ + // Mesh text and the wave (ChatOutgoingCoordinator.sendMeshPublicMessage). + row("alice", me, content: "mesh text"), + // Gossip self-replay and the archived echo restored at launch + // (ChatTransportEventCoordinator.handlePublicMessage, + // ChatViewModelBootstrapper.loadArchivedEchoes). + BitchatMessage(id: "echo-0011", sender: "alice", content: "archived echo", timestamp: Date(), isRelay: false, senderPeerID: me), + // Mesh DM (ChatPrivateConversationCoordinator.sendPrivateMessage). + row("alice", me, content: "mesh dm", isPrivate: true, deliveryStatus: .delivered(to: "bob", at: Date())), + // Geo DM: plain nickname, mesh ID (ChatPrivateConversationCoordinator.sendGeohashDM). + row("alice", me, content: "geo dm", isPrivate: true, deliveryStatus: .sent), + // Group message (ChatGroupCoordinator.sendGroupMessage). + row("alice", me, content: "group message", isPrivate: true, deliveryStatus: .sent), + // Voice note (ChatMediaTransferCoordinator.enqueueMediaMessage). + row("alice", me, content: "[voice] note.m4a", isPrivate: true, deliveryStatus: .sending), + // Geochat text and its relay echo + // (ChatOutgoingCoordinator.sendGeohashPublicMessage, NostrInboundPipeline). + row("alice#\(myHex.suffix(4))", PeerID(nostr: myHex), content: "geochat text") + ] + + let uiModel = makeUIModel(for: viewModel) + Self.show(geohash: Self.geohash, in: viewModel) + for message in ownRows { + #expect(uiModel.isSentByCurrentUser(message), "\(message.content) from \(message.senderPeerID?.id ?? "nil")") + } + + // A rename changes no sender ID: everything I sent stays mine. + viewModel.nickname = "alicia" + let renamedUIModel = makeUIModel(for: viewModel) + for message in ownRows { + #expect(renamedUIModel.isSentByCurrentUser(message), "\(message.content) from \(message.senderPeerID?.id ?? "nil")") + } + } + + @Test @MainActor + func systemLinesAndRowsWithoutASenderIDAreNeverMine() throws { + let (viewModel, _) = makeChatViewModel(nickname: "alice") + let uiModel = makeUIModel(for: viewModel) + Self.show(geohash: Self.geohash, in: viewModel) + let myHex = try Self.myGeoHex(viewModel) + + // DM command output and the screenshot notice carry my mesh ID + // (ChatViewModel.addLocalPrivateSystemMessage, + // ChatLifecycleCoordinator.appendPrivateScreenshotNotice); counting + // them as mine would pull a scrolled-up reader down. + #expect(!uiModel.isSentByCurrentUser(row("system", Self.myPeerID, isPrivate: true))) + // A converted emote keeps its author's ID + // (ChatPrivateConversationCoordinator.processActionMessage). + #expect(!uiModel.isSentByCurrentUser(row("system", PeerID(nostr: myHex)))) + // Public system lines carry no sender ID... + #expect(!uiModel.isSentByCurrentUser(row("system", nil))) + // ...and a name alone never makes a row mine. + #expect(!uiModel.isSentByCurrentUser(row("alice", nil))) + } + + @Test @MainActor + func mediaRowsLoadFromTheDirectionTheirSenderIDNames() throws { + let (viewModel, _) = makeChatViewModel(nickname: "alice") + let uiModel = makeUIModel(for: viewModel) + let namesakeImage = row( + "alice", + Self.peerID, + content: "[image] theirs.jpg", + isPrivate: true, + deliveryStatus: .delivered(to: "alice", at: Date()) + ) + // Sent before I renamed myself from "al" to "alice". + let myImage = row("al", Self.myPeerID, content: "[image] mine.jpg", isPrivate: true, deliveryStatus: .sent) + + // A namesake's image is received media: blurred, deletable, no Cancel. + #expect(!uiModel.isMediaMessageFromCurrentUser(namesakeImage)) + guard case .image(let theirURL)? = uiModel.mediaAttachment(for: namesakeImage) else { + Issue.record("Expected the namesake's image to resolve to an image row") + return + } + #expect(theirURL.deletingLastPathComponent().path.hasSuffix("/images/incoming")) + + #expect(uiModel.isMediaMessageFromCurrentUser(myImage)) + guard case .image(let myURL)? = uiModel.mediaAttachment(for: myImage) else { + Issue.record("Expected my image to resolve to an image row") + return + } + #expect(myURL.deletingLastPathComponent().path.hasSuffix("/images/outgoing")) + } + + @Test @MainActor + func verifiedNamesakeKeepsTheSealOnTheirDMs() { + let (viewModel, transport) = makeChatViewModel(nickname: "alice") + let uiModel = makeUIModel(for: viewModel) + transport.peerFingerprints[Self.peerID] = "namesake-fingerprint" + viewModel.peerIdentityStore.setVerified("namesake-fingerprint", verified: true) + + // The seal is what tells a verified "alice" from an impersonator. + #expect(uiModel.showsVerifiedSeal(for: row("alice", Self.peerID, isPrivate: true))) + #expect(!uiModel.showsVerifiedSeal(for: row("alice", Self.myPeerID, isPrivate: true))) + } + + @Test @MainActor + func geochatOwnershipFollowsTheChannelOnScreen() throws { + let (viewModel, _) = makeChatViewModel(nickname: "alice") + let uiModel = makeUIModel(for: viewModel) + let hexA = try Self.myGeoHex(viewModel, geohash: "u4pruy") + let hexB = try Self.myGeoHex(viewModel, geohash: "9q8yy") + let fromA = row("alice#\(hexA.suffix(4))", PeerID(nostr: hexA)) + let fromB = row("alice#\(hexB.suffix(4))", PeerID(nostr: hexB)) + + Self.show(geohash: "u4pruy", in: viewModel) + #expect(uiModel.isSentByCurrentUser(fromA)) + #expect(!uiModel.isSentByCurrentUser(fromB)) + + // Read from the store right after the switch, with no runloop turn. + // A row of my geohash-A identity shown in B renders as a stranger + // (ChatMessageFormatter.formatMessageAsText) and is treated as one. + Self.show(geohash: "9q8yy", in: viewModel) + #expect(uiModel.isSentByCurrentUser(fromB)) + #expect(!uiModel.isSentByCurrentUser(fromA)) + + viewModel.activeChannel = .mesh + #expect(!uiModel.isSentByCurrentUser(fromA)) + #expect(!uiModel.isSentByCurrentUser(fromB)) + } + + @Test @MainActor + func switchingToMeshDropsMyMemoizedGeochatSender() async throws { + let (viewModel, _) = makeChatViewModel(nickname: "alice") + let uiModel = makeUIModel(for: viewModel) + #expect(await Self.switchAndSettle(to: Self.locationChannel, in: viewModel, uiModel: uiModel)) + let myHex = try Self.myGeoHex(viewModel) + #expect(uiModel.isSentByCurrentUser(row("alice#\(myHex.suffix(4))", PeerID(nostr: myHex)))) + #expect(uiModel.ownGeoChatSender?.peerID == PeerID(nostr: myHex)) + + // No row on #mesh reads it, so it goes with the switch rather than + // whenever a geochat row next renders. + #expect(await Self.switchAndSettle(to: .mesh, in: viewModel, uiModel: uiModel)) + #expect(uiModel.ownGeoChatSender == nil) + } + + @Test @MainActor + func panicWipeRetiresTheOldGeochatIdentity() async throws { + let (viewModel, _) = makeChatViewModel(nickname: "alice") + let uiModel = makeUIModel(for: viewModel) + #expect(await Self.switchAndSettle(to: Self.locationChannel, in: viewModel, uiModel: uiModel)) + let oldHex = try Self.myGeoHex(viewModel) + let beforeWipe = row("alice#\(oldHex.suffix(4))", PeerID(nostr: oldHex)) + #expect(uiModel.isSentByCurrentUser(beforeWipe)) + #expect(uiModel.ownGeoChatSender != nil) + + // The wipe reseeds every geohash identity and returns to the mesh, + // which takes the retired key out of the memo too. + viewModel.panicClearAllData() + #expect(await TestHelpers.waitUntil({ uiModel.ownGeoChatSender == nil }, timeout: TestConstants.settleTimeout)) + Self.show(geohash: Self.geohash, in: viewModel) + let newHex = try Self.myGeoHex(viewModel) + #expect(newHex != oldHex) + + #expect(uiModel.isSentByCurrentUser(row("\(viewModel.nickname)#\(newHex.suffix(4))", PeerID(nostr: newHex)))) + #expect(!uiModel.isSentByCurrentUser(beforeWipe)) + } + + // MARK: - Rows from the real send paths + + // With no nickname fallback, a send path that forgets to stamp the sender + // ID turns my own row into a stranger's. Each test below sends the way the + // composer does, through the UI model's `sendMessage(_:)` and + // `sendVoiceNote(at:)`, and asks the UI model about the row that send + // produced. + + @MainActor + private static func publicRow(_ content: String, in channel: ChannelID, of viewModel: ChatViewModel) -> BitchatMessage? { + viewModel.conversations.conversationsByID[ConversationID(channelID: channel)]?.messages.first { $0.content == content } + } + + @MainActor + private static func privateRow(_ content: String, with peerID: PeerID, of viewModel: ChatViewModel) -> BitchatMessage? { + viewModel.privateChats[peerID]?.first { $0.content == content } + } + + /// A voice note to send. Any bytes do: the voice-note path checks only + /// the file's size. + private static func makeVoiceNote() throws -> URL { + let url = FileManager.default.temporaryDirectory + .appendingPathComponent("voice-\(UUID().uuidString).m4a") + try Data("voice payload".utf8).write(to: url, options: .atomic) + return url + } + + @Test @MainActor + func myMeshPublicSendIsMine() throws { + let (viewModel, transport) = makeChatViewModel(nickname: "alice") + let uiModel = makeUIModel(for: viewModel) + + uiModel.sendMessage("hello mesh") + + #expect(transport.sentMessages.map(\.content) == ["hello mesh"]) + let sent = try #require(Self.publicRow("hello mesh", in: .mesh, of: viewModel)) + #expect(uiModel.isSentByCurrentUser(sent)) + } + + @Test @MainActor + func myMeshDMIsMine() throws { + let (viewModel, transport) = makeChatViewModel(nickname: "alice") + let uiModel = makeUIModel(for: viewModel) + transport.connectedPeers.insert(Self.peerID) + transport.peerNicknames[Self.peerID] = "bob" + + viewModel.startPrivateChat(with: Self.peerID) + uiModel.sendMessage("hi bob") + + #expect(transport.sentPrivateMessages.map(\.content) == ["hi bob"]) + let sent = try #require(Self.privateRow("hi bob", with: Self.peerID, of: viewModel)) + #expect(uiModel.isSentByCurrentUser(sent)) + } + + @Test @MainActor + func myGeoDMIsMine() async throws { + let (viewModel, _) = makeChatViewModel(nickname: "alice") + let uiModel = makeUIModel(for: viewModel) + #expect(await Self.switchAndSettle(to: Self.locationChannel, in: viewModel, uiModel: uiModel)) + let stranger = try NostrIdentity.generate() + let conversation = PeerID(nostr_: stranger.publicKeyHex) + viewModel.registerNostrKeyMapping(stranger.publicKeyHex, for: conversation) + + viewModel.startPrivateChat(with: conversation) + uiModel.sendMessage("hi stranger") + + let sent = try #require(Self.privateRow("hi stranger", with: conversation, of: viewModel)) + // Handed to the Nostr transport, not failed on the way there. + #expect(sent.deliveryStatus == .sent) + #expect(uiModel.isSentByCurrentUser(sent)) + } + + @Test @MainActor + func myGeochatPublicSendIsMine() async throws { + let (viewModel, _) = makeChatViewModel(nickname: "alice") + let uiModel = makeUIModel(for: viewModel) + #expect(await Self.switchAndSettle(to: Self.locationChannel, in: viewModel, uiModel: uiModel)) + let myHex = try Self.myGeoHex(viewModel) + + uiModel.sendMessage("hello geohash") + + // The echo lands once its NIP-13 nonce is mined off the main actor. + #expect(await TestHelpers.waitUntil( + { Self.publicRow("hello geohash", in: Self.locationChannel, of: viewModel) != nil }, + timeout: TestConstants.settleTimeout + )) + let sent = try #require(Self.publicRow("hello geohash", in: Self.locationChannel, of: viewModel)) + #expect(sent.senderPeerID == PeerID(nostr: myHex)) + #expect(uiModel.isSentByCurrentUser(sent)) + } + + @Test @MainActor + func myVoiceNoteOnMeshIsMine() async throws { + let (viewModel, transport) = makeChatViewModel(nickname: "alice") + let uiModel = makeUIModel(for: viewModel) + let note = try Self.makeVoiceNote() + defer { try? FileManager.default.removeItem(at: note) } + + uiModel.sendVoiceNote(at: note) + + // The row is enqueued at once; wait out the detached preparation so + // the send has finished before the test does. + #expect(await TestHelpers.waitUntil({ transport.sentBroadcastFiles.count == 1 }, timeout: TestConstants.settleTimeout)) + let sent = try #require(Self.publicRow("[voice] \(note.lastPathComponent)", in: .mesh, of: viewModel)) + #expect(uiModel.isSentByCurrentUser(sent)) + } + + @Test @MainActor + func myVoiceNoteInADMIsMine() async throws { + let (viewModel, transport) = makeChatViewModel(nickname: "alice") + let uiModel = makeUIModel(for: viewModel) + transport.connectedPeers.insert(Self.peerID) + transport.peerNicknames[Self.peerID] = "bob" + let note = try Self.makeVoiceNote() + defer { try? FileManager.default.removeItem(at: note) } + + viewModel.startPrivateChat(with: Self.peerID) + uiModel.sendVoiceNote(at: note) + + #expect(await TestHelpers.waitUntil({ transport.sentPrivateFiles.count == 1 }, timeout: TestConstants.settleTimeout)) + let sent = try #require(Self.privateRow("[voice] \(note.lastPathComponent)", with: Self.peerID, of: viewModel)) + #expect(uiModel.isSentByCurrentUser(sent)) + } +} diff --git a/bitchatTests/GeohashParticipantTrackerTests.swift b/bitchatTests/GeohashParticipantTrackerTests.swift index d05b8171..f04e6aec 100644 --- a/bitchatTests/GeohashParticipantTrackerTests.swift +++ b/bitchatTests/GeohashParticipantTrackerTests.swift @@ -6,6 +6,7 @@ // This is free and unencumbered software released into the public domain. // +import Combine import Testing import Foundation @testable import bitchat @@ -272,6 +273,189 @@ struct GeohashParticipantTrackerTests { #expect(tracker.visiblePeople.count == 1) } + // MARK: - Membership Revision Tests + + @Test func membershipRevision_bumpsWhenSomeoneJoins() async { + let tracker = GeohashParticipantTracker() + let context = MockParticipantContext() + tracker.configure(context: context) + tracker.setActiveGeohash("abc123") + let before = tracker.visibleMembershipRevision + + tracker.recordParticipant(pubkeyHex: "pubkey1") + + #expect(tracker.visibleMembershipRevision != before) + } + + @Test func membershipRevision_staysPutOnRepeatActivity() async { + let tracker = GeohashParticipantTracker() + let context = MockParticipantContext() + tracker.configure(context: context) + tracker.setActiveGeohash("abc123") + tracker.recordParticipant(pubkeyHex: "pubkey1") + tracker.recordParticipant(pubkeyHex: "pubkey2") + let before = tracker.visibleMembershipRevision + + // Heartbeats from people already present only move timestamps. + tracker.recordParticipant(pubkeyHex: "pubkey1") + tracker.recordParticipant(pubkeyHex: "pubkey2") + tracker.refresh() + + #expect(tracker.visibleMembershipRevision == before) + } + + @Test func membershipRevision_bumpsWhenSomeoneLeaves() async { + let tracker = GeohashParticipantTracker() + let context = MockParticipantContext() + tracker.configure(context: context) + tracker.setActiveGeohash("abc123") + tracker.recordParticipant(pubkeyHex: "pubkey1") + tracker.recordParticipant(pubkeyHex: "pubkey2") + let afterJoins = tracker.visibleMembershipRevision + + tracker.removeParticipant(pubkeyHex: "pubkey1") + #expect(tracker.visibleMembershipRevision != afterJoins) + + let afterRemoval = tracker.visibleMembershipRevision + tracker.setActiveGeohash(nil) + #expect(tracker.visibleMembershipRevision != afterRemoval) + } + + // MARK: - Activity Semantics + + @Test func recordParticipant_ignoresActivityOlderThanTheWindow() async { + let tracker = GeohashParticipantTracker() + let context = MockParticipantContext() + tracker.configure(context: context) + tracker.setActiveGeohash("abc123") + + var changes = 0 + let cancellable = tracker.objectWillChange.sink { _ in changes += 1 } + // Replayed history from ten minutes ago doesn't make its author present + // (nor announce a count change or rebuild the roster). + tracker.recordParticipant(pubkeyHex: "pubkey1", seenAt: Date().addingTimeInterval(-600)) + + #expect(tracker.participantCount(for: "abc123") == 0) + #expect(tracker.visiblePeople.isEmpty) + #expect(changes == 0) + _ = cancellable + } + + /// The inbound pipeline marks a teleport tag only when the activity + /// carrying it counted. Activity that makes no one present must report + /// false, or its tag leaves a marker the roster never prunes; activity + /// from someone already present must report true, or their live teleport + /// tags would stop marking them. + @Test func recordParticipant_reportsWhetherTheActivityCounted() async { + let tracker = GeohashParticipantTracker() + let context = MockParticipantContext() + tracker.configure(context: context) + let now = Date() + + // No channel open: nothing is recorded. + #expect(!tracker.recordParticipant(pubkeyHex: "pubkey1")) + + tracker.setActiveGeohash("abc123") + #expect(!tracker.recordParticipant(pubkeyHex: "pubkey1", seenAt: now.addingTimeInterval(-600))) + // Arriving, then a heartbeat from someone already present. + #expect(tracker.recordParticipant(pubkeyHex: "pubkey1", seenAt: now.addingTimeInterval(-60))) + #expect(tracker.recordParticipant(pubkeyHex: "pubkey1")) + // A late copy of earlier activity that is still inside the window. + #expect(tracker.recordParticipant(pubkeyHex: "pubkey1", seenAt: now.addingTimeInterval(-200))) + #expect(tracker.participantCount(for: "abc123") == 1) + } + + @Test func recordParticipant_neverMovesActivityBackwards() async { + let tracker = GeohashParticipantTracker() + let context = MockParticipantContext() + tracker.configure(context: context) + tracker.setActiveGeohash("abc123") + let now = Date() + + tracker.recordParticipant(pubkeyHex: "older", seenAt: now.addingTimeInterval(-120)) + tracker.recordParticipant(pubkeyHex: "newer", seenAt: now.addingTimeInterval(-60)) + // A late copy of an earlier event from "newer" must not demote them. + tracker.recordParticipant(pubkeyHex: "newer", seenAt: now.addingTimeInterval(-200)) + + #expect(tracker.getVisiblePeople().map(\.id) == ["newer", "older"]) + } + + @Test func recordParticipant_clampsFutureTimestampsToNow() async { + let tracker = GeohashParticipantTracker() + let context = MockParticipantContext() + tracker.configure(context: context) + tracker.setActiveGeohash("abc123") + + tracker.recordParticipant(pubkeyHex: "skewed", seenAt: Date().addingTimeInterval(3600)) + + #expect(tracker.getVisiblePeople().first.map { $0.lastSeen <= Date() } == true) + } + + @Test func repeatActivity_doesNotRepublishTheRoster() async { + let tracker = GeohashParticipantTracker() + let context = MockParticipantContext() + tracker.configure(context: context) + tracker.setActiveGeohash("abc123") + tracker.recordParticipant(pubkeyHex: "pubkey1") + tracker.recordParticipant(pubkeyHex: "pubkey2") + + var publishes = 0 + let cancellable = tracker.$visiblePeople.dropFirst().sink { _ in publishes += 1 } + // Heartbeats and messages from people already present. + tracker.recordParticipant(pubkeyHex: "pubkey1") + tracker.recordParticipant(pubkeyHex: "pubkey2") + tracker.refresh() + + #expect(publishes == 0) + _ = cancellable + } + + @Test func displayNameChange_republishesTheRoster() async { + let tracker = GeohashParticipantTracker() + let context = MockParticipantContext() + tracker.configure(context: context) + tracker.setActiveGeohash("abc123") + tracker.recordParticipant(pubkeyHex: "pubkey1") + #expect(tracker.visiblePeople.first?.displayName.hasPrefix("anon#") == true) + + context.nicknameMap["pubkey1"] = "alice" + tracker.noteDisplayNameChanged(pubkeyHex: "pubkey1") + + #expect(tracker.visiblePeople.first?.displayName.hasPrefix("alice#") == true) + } + + @Test func pruneExpired_dropsEntriesThatAgedOut() async { + let tracker = GeohashParticipantTracker() + let context = MockParticipantContext() + tracker.configure(context: context) + let now = Date() + tracker.recordParticipant(pubkeyHex: "quiet", geohash: "geo1", seenAt: now.addingTimeInterval(-200)) + tracker.recordParticipant(pubkeyHex: "chatty", geohash: "geo1", seenAt: now) + tracker.recordParticipant(pubkeyHex: "gone", geohash: "geo2", seenAt: now.addingTimeInterval(-200)) + + // Two minutes on, "quiet" and "gone" are past the five-minute window. + tracker.pruneExpired(now: now.addingTimeInterval(120)) + + #expect(tracker.participantCount(for: "geo1") == 1) + #expect(tracker.participantCount(for: "geo2") == 0) + } + + @Test func objectWillChange_firesOnlyWhenSomeoneNewlyCounts() async { + let tracker = GeohashParticipantTracker() + let context = MockParticipantContext() + tracker.configure(context: context) + + var changes = 0 + let cancellable = tracker.objectWillChange.sink { _ in changes += 1 } + tracker.recordParticipant(pubkeyHex: "pubkey1", geohash: "geo1") + let afterJoin = changes + tracker.recordParticipant(pubkeyHex: "pubkey1", geohash: "geo1") + + #expect(afterJoin >= 1) + #expect(changes == afterJoin) + _ = cancellable + } + // MARK: - GeoPerson Tests @Test func geoPerson_identifiable() async { diff --git a/bitchatTests/GlobePickerTests.swift b/bitchatTests/GlobePickerTests.swift new file mode 100644 index 00000000..0bc32193 --- /dev/null +++ b/bitchatTests/GlobePickerTests.swift @@ -0,0 +1,485 @@ +import CoreGraphics +import Foundation +import Testing +@testable import bitchat + +struct GlobeMathTests { + @Test func preparedProjectorMatchesReferenceProjection() { + let centers: [(Double, Double)] = [(0, 0), (45.25, 12.5), (-72, 179.5)] + let points: [(Double, Double)] = [(0, 0), (51.5074, -0.1278), (-33.8688, 151.2093), (89, -179.9)] + for (centerLat, centerLon) in centers { + let projector = GlobeMath.PreparedProjector(centerLat: centerLat, centerLon: centerLon) + for (lat, lon) in points { + let actual = projector.project(GlobeMath.Terms(lat: lat, lon: lon)) + let expected = GlobeMath.projectRaw(lat: lat, lon: lon, centerLat: centerLat, centerLon: centerLon) + #expect(abs(expected.x - actual.x) < 1e-9) + #expect(abs(expected.y - actual.y) < 1e-9) + #expect(abs(expected.cosC - actual.cosC) < 1e-9) + } + } + } + + @Test func unprojectInvertsProjection() throws { + let p = GlobeMath.projectRaw(lat: 48.2, lon: 16.4, centerLat: 40, centerLon: 10) + let location = try #require(GlobeMath.unproject(x: p.x, y: p.y, centerLat: 40, centerLon: 10)) + #expect(abs(location.lat - 48.2) < 1e-9) + #expect(abs(location.lon - 16.4) < 1e-9) + #expect(GlobeMath.unproject(x: 0.9, y: 0.9, centerLat: 0, centerLon: 0) == nil) + } + + @Test func zoomForPrecisionStaysWithinInteractiveBounds() { + for precision in 1...GlobeMath.maxPrecision { + let zoom = GlobeMath.zoomForPrecision(precision, baseRadius: 400, screenMin: 900) + #expect(zoom >= GlobeMath.minZoom) + #expect(zoom <= GlobeMath.maxZoom) + } + } + + /// The +/- buttons frame a precision; the pinch-driven precision must agree, or the + /// first pinch after a button tap would jump to another cell size. + @Test func autoPrecisionAgreesWithFramedPrecision() { + let base = 400.0, screen = 900.0 + for precision in 2...GlobeMath.maxPrecision { + let zoom = GlobeMath.zoomForPrecision(precision, baseRadius: base, screenMin: screen) + guard zoom > GlobeMath.minZoom, zoom < GlobeMath.maxZoom else { continue } + #expect(GlobeMath.autoPrecision(globeRadius: base * zoom, screenMin: screen) == precision) + } + } + + @Test func cellSpansMatchGeohashBounds() { + for precision in 1...8 { + let b = Geohash.decodeBounds(Geohash.encode(latitude: 10, longitude: 10, precision: precision)) + #expect(abs((b.latMax - b.latMin) - GlobeMath.cellSpanLat(precision: precision)) < 1e-9) + #expect(abs((b.lonMax - b.lonMin) - GlobeMath.cellSpanLon(precision: precision)) < 1e-9) + } + } +} + +struct GlobeGeometryTests { + private let square = [ + GlobeGeometry.DiscPoint(x: -0.5, y: -0.5, front: true), + GlobeGeometry.DiscPoint(x: 0.5, y: -0.5, front: true), + GlobeGeometry.DiscPoint(x: 0.5, y: 0.5, front: true), + GlobeGeometry.DiscPoint(x: -0.5, y: 0.5, front: true) + ] + + @Test func closedFullyVisibleRingConnectsLastPointToFirst() throws { + let runs = GlobeGeometry.frontRuns(square, closed: true) + let run = try #require(runs.first) + #expect(runs.count == 1) + #expect(run.count == square.count + 1) + #expect(run.first == run.last) + } + + @Test func openFullyVisibleLineDoesNotConnectLastPointToFirst() throws { + let runs = GlobeGeometry.frontRuns(square, closed: false) + let run = try #require(runs.first) + #expect(runs.count == 1) + #expect(run.count == square.count) + #expect(run.first != run.last) + } + + @Test func ringCrossingTheLimbSplitsIntoFrontRuns() { + let pts = [ + GlobeGeometry.DiscPoint(x: -0.5, y: 0, front: true), + GlobeGeometry.DiscPoint(x: 0, y: 0, front: true), + GlobeGeometry.DiscPoint(x: 0.5, y: 0, front: false), + GlobeGeometry.DiscPoint(x: 0.2, y: 0.2, front: true) + ] + let runs = GlobeGeometry.frontRuns(pts, closed: false) + #expect(runs.count == 2) + #expect(runs.allSatisfy { $0.count >= 2 }) + } + + @Test func polygonContainsDistinguishesInsideAndOutsidePoints() { + let polygon = [CGPoint(x: -10, y: -10), CGPoint(x: 10, y: -10), CGPoint(x: 10, y: 10), CGPoint(x: -10, y: 10)] + #expect(GlobeGeometry.polygonContains(polygon, x: 0, y: 0)) + #expect(!GlobeGeometry.polygonContains(polygon, x: 20, y: 0)) + } + + @Test func ringContainsDistinguishesInsideAndOutsideCoordinates() { + let ring = GlobeRing(lats: [-10, -10, 10, 10], lons: [-10, 10, 10, -10]) + #expect(GlobeGeometry.ringContains(ring, lat: 0, lon: 0)) + #expect(!GlobeGeometry.ringContains(ring, lat: 20, lon: 0)) + } + + @Test func ringContainsHandlesTheAntimeridian() { + let ring = GlobeRing(lats: [-10, -10, 10, 10], lons: [170, -170, -170, 170]) + #expect(GlobeGeometry.ringContains(ring, lat: 0, lon: 180)) + #expect(GlobeGeometry.ringContains(ring, lat: 0, lon: -175)) + #expect(!GlobeGeometry.ringContains(ring, lat: 20, lon: 180)) + #expect(!GlobeGeometry.ringContains(ring, lat: 0, lon: 0)) + } + + @Test func clipSegmentClampsToRect() throws { + let rect = GlobeGeometry.ClipRect(left: 0, top: 0, right: 10, bottom: 10) + let clipped = try #require(GlobeGeometry.clipSegment(CGPoint(x: -10, y: 5), CGPoint(x: 20, y: 5), to: rect)) + #expect(clipped.0 == CGPoint(x: 0, y: 5)) + #expect(clipped.1 == CGPoint(x: 10, y: 5)) + #expect(GlobeGeometry.clipSegment(CGPoint(x: -10, y: -5), CGPoint(x: 20, y: -5), to: rect) == nil) + } + + @Test func clipPolygonKeepsOnlyTheVisiblePart() { + let rect = GlobeGeometry.ClipRect(left: 0, top: 0, right: 10, bottom: 10) + let clipped = GlobeGeometry.clipPolygon( + [CGPoint(x: -5, y: -5), CGPoint(x: 15, y: -5), CGPoint(x: 15, y: 15), CGPoint(x: -5, y: 15)], + to: rect + ) + #expect(clipped.count == 4) + #expect(clipped.allSatisfy { $0.x >= 0 && $0.x <= 10 && $0.y >= 0 && $0.y <= 10 }) + } + + @Test func smallVisibleRingIsNotInverted() { + let ring = GlobeRing(lats: [-10, -10, 10, 10], lons: [-10, 10, 10, -10]) + let projector = GlobeMath.PreparedProjector(centerLat: 0, centerLon: 0) + let pts = ring.terms.map { terms -> GlobeGeometry.DiscPoint in + let p = projector.project(terms) + return GlobeGeometry.DiscPoint(x: p.x, y: p.y, front: p.cosC > 0.005) + } + let polygon = GlobeGeometry.fillPolygon(pts, cx: 100, cy: 100, r: 100) + #expect(!GlobeGeometry.projectedFillNeedsInversion( + polygon: polygon, ring: ring, cx: 100, cy: 100, r: 100, centerLat: 0, centerLon: 0 + )) + } +} + +struct GlobeMotionDetailTests { + @Test func fullDetailPreservesAllGlobeFeatures() { + let detail = GlobeMotionDetail.full.frame + #expect(detail.landPointStride == 1) + #expect(detail.showBorders) + #expect(detail.showCityLabels) + } + + @Test func balancedDetailPreservesOrientationAndSelection() { + let detail = GlobeMotionDetail.balanced.frame + #expect(detail.landPointStride == 2) + #expect(detail.showBorders) + #expect(!detail.showCityLabels) + } + + @Test func fastDetailUsesMinimumMovingFrameWork() { + let detail = GlobeMotionDetail.fast.frame + #expect(detail.landPointStride == 2) + #expect(!detail.showBorders) + #expect(!detail.showCityLabels) + } + + @Test func adaptiveDetailDegradesOnSlowFramesAndRecoversWithHysteresis() { + #expect(GlobeMotionDetail.full.next(averageFrameMillis: 24) == .balanced) + #expect(GlobeMotionDetail.balanced.next(averageFrameMillis: 32) == .fast) + #expect(GlobeMotionDetail.fast.next(averageFrameMillis: 17) == .balanced) + #expect(GlobeMotionDetail.balanced.next(averageFrameMillis: 17) == .full) + #expect(GlobeMotionDetail.balanced.next(averageFrameMillis: 20) == .balanced) + #expect(GlobeMotionDetail.full.next(averageFrameMillis: .nan) == .fast) + } + + private func record(_ governor: inout GlobeMotionGovernor, frames: Int, millis: Double) -> [GlobeMotionDetail] { + (0..= previous) + previous = value + } + #expect(GlobeEasing.fastOutSlowIn(0.5) > 0.7) + } +} + +@MainActor +struct GlobeStateTests { + @Test func selectionFollowsTheViewCenterOnceLaidOut() { + let state = GlobeState(targetLat: 48.2, targetLon: 16.4, initialPrecision: 4, startZoomedOut: false) + #expect(state.selectedGeohash.isEmpty) + state.setViewport(baseRadius: 170, screenMin: 390) + #expect(state.selectedGeohash == Geohash.encode(latitude: 48.2, longitude: 16.4, precision: 4)) + } + + @Test func introWithoutAnimationJumpsStraightToTheTarget() { + let state = GlobeState(targetLat: 37.77, targetLon: -122.42, initialPrecision: 5, startZoomedOut: true) + state.setViewport(baseRadius: 170, screenMin: 390, animateIntro: false) + #expect(state.precision == 5) + #expect(state.selectedGeohash == Geohash.encode(latitude: 37.77, longitude: -122.42, precision: 5)) + #expect(!state.isAnimating) + } + + @Test func pinchingInRaisesPrecisionAndRotationClampsNearThePoles() { + let state = GlobeState(targetLat: 0, targetLon: 0, initialPrecision: 1, startZoomedOut: false) + state.setViewport(baseRadius: 170, screenMin: 390) + let before = state.precision + state.zoomBy(64) + #expect(state.precision > before) + state.rotateBy(dx: 0, dy: 1_000_000) + #expect(state.centerLat <= 89) + #expect(state.selectedGeohash.count == state.precision) + } + + @Test func zoomStaysWithinBounds() { + let state = GlobeState(targetLat: 0, targetLon: 0, initialPrecision: 2, startZoomedOut: false) + state.setViewport(baseRadius: 170, screenMin: 390) + state.zoomBy(0.0001) + #expect(state.zoom == GlobeMath.minZoom) + state.zoomBy(1e12) + #expect(state.zoom == GlobeMath.maxZoom) + // Pinching tops out around block-sized cells; finer precision is button-only. + #expect(state.precision == GlobeMath.autoPrecision(globeRadius: state.globeRadius, screenMin: 390)) + #expect(state.precision >= 7) + } + + @Test func interactionCancelsAnimationsAndRestoresFullDetail() { + let state = GlobeState(targetLat: 0, targetLon: 0, initialPrecision: 2, startZoomedOut: false) + state.setViewport(baseRadius: 170, screenMin: 390) + state.animatePrecision(4) + #expect(state.isAnimating) + #expect(state.motionDetail == .balanced) + state.beginInteraction() + #expect(!state.isAnimating) + #expect(state.isInteracting) + state.endInteraction() + #expect(!state.isInMotion) + #expect(state.motionDetail == .full) + #expect(state.frameDetail == GlobeMotionDetail.full.frame) + } + + @Test func releasingIntoAFlingKeepsTheSameMotionSession() { + let state = GlobeState(targetLat: 0, targetLon: 0, initialPrecision: 2, startZoomedOut: false) + state.setViewport(baseRadius: 170, screenMin: 390) + state.beginInteraction() + #expect(state.motionDetail == .balanced) + state.endInteraction(flingVelocityX: 800, flingVelocityY: 0) + #expect(!state.isInteracting) + #expect(state.isAnimating) + #expect(state.motionDetail == .balanced) + state.beginInteraction() + #expect(!state.isAnimating) + #expect(state.motionDetail == .balanced) + state.endInteraction() + #expect(state.motionDetail == .full) + } + + /// Review regression (PR #1807): `zzzz`'s center is 89.91°, past the ±89° drag + /// limit. The animated intro used to clamp there and select `zzzf`, while the + /// Reduce Motion path kept `zzzz`. + @Test func polarIntroLandsOnTheRequestedCellWithAndWithoutAnimation() { + let target = GeohashPickerView.initialTarget(initialGeohash: "zzzz", nearbyGeohashes: []) + #expect(target.lat > 89) + + let animated = GlobeState(targetLat: target.lat, targetLon: target.lon, initialPrecision: target.precision, startZoomedOut: true) + animated.setViewport(baseRadius: 170, screenMin: 390, animateIntro: true) + #expect(animated.isAnimating) + animated.tick(100) + animated.tick(110) + #expect(!animated.isAnimating) + #expect(animated.selectedGeohash == "zzzz") + + let still = GlobeState(targetLat: target.lat, targetLon: target.lon, initialPrecision: target.precision, startZoomedOut: true) + still.setViewport(baseRadius: 170, screenMin: 390, animateIntro: false) + #expect(still.selectedGeohash == "zzzz") + #expect(still.centerLat == animated.centerLat) + } + + @Test func draggingFromAPolarTargetNeverSnapsBackToTheDragLimit() { + let center = Geohash.decodeCenter("zzzz") + let state = GlobeState(targetLat: center.lat, targetLon: center.lon, initialPrecision: 4, startZoomedOut: false) + state.setViewport(baseRadius: 170, screenMin: 390) + let start = state.centerLat + state.rotateBy(dx: 0, dy: 50) + #expect(state.centerLat == start) + state.rotateBy(dx: 0, dy: -0.01) + #expect(state.centerLat < start) + #expect(state.centerLat > 89) + state.rotateBy(dx: 0, dy: -1_000_000) + #expect(state.centerLat == -89) + } + + @Test func slowFlingsAreIgnored() { + let state = GlobeState(targetLat: 0, targetLon: 0, initialPrecision: 2, startZoomedOut: false) + state.setViewport(baseRadius: 170, screenMin: 390) + state.fling(vx: 10, vy: -10) + #expect(!state.isAnimating) + state.fling(vx: 800, vy: 0) + #expect(state.isAnimating) + state.cancelAnimations() + } +} + +struct GlobeWorldDataTests { + private static let landURL = URL(fileURLWithPath: #filePath) + .deletingLastPathComponent() + .deletingLastPathComponent() + .appendingPathComponent("bitchat/Resources/Globe/world_land.geojson") + + /// Regression: Eurasia wraps the antimeridian at Chukotka, and the old relative- + /// longitude test counted the ±180° seam as a crossing, so open ocean read as + /// inside Eurasia and its fill was flipped over the Pacific and Atlantic. + @Test func bundledLandClassifiesOceansAndContinents() throws { + let land = GlobeWorldData.parseLand(try Data(contentsOf: Self.landURL)) + #expect(land.count > 100) + func isLand(_ lat: Double, _ lon: Double) -> Bool { + land.contains { GlobeGeometry.ringContains($0, lat: lat, lon: lon) } + } + for (lat, lon) in [(0.0, -150.0), (32.3, -64.8), (40.0, -50.0), (-30.0, 80.0), (10.0, -30.0), (60.0, -85.0)] { + #expect(!isLand(lat, lon), "ocean at \(lat),\(lon) read as land") + } + for (lat, lon) in [(55.75, 37.62), (64.7, 177.5), (39.9, 116.4), (39.0, -98.0), (-15.8, -47.9), (0.0, 20.0)] { + #expect(isLand(lat, lon), "land at \(lat),\(lon) read as ocean") + } + } + + /// No visible ocean pixel may be painted by a land fill, from any vantage point. + @Test func landFillsLeaveVisibleOceanUncovered() throws { + let land = GlobeWorldData.parseLand(try Data(contentsOf: Self.landURL)) + let size = CGSize(width: 402, height: 874) + let cx = 201.0, cy = 437.0 + let clip = GlobeGeometry.ClipRect(size: size) + let oceans: [(Double, Double)] = [(32.3, -64.8), (40, -50), (30, -20), (0, -150), (-30, 80)] + for centerLat in stride(from: -60.0, through: 60, by: 30) { + for centerLon in stride(from: -180.0, to: 180, by: 30) { + for zoom in [1.0, 3, 8] { + let r = 0.44 * 402 * zoom + let projector = GlobeMath.PreparedProjector(centerLat: centerLat, centerLon: centerLon) + for ocean in oceans { + guard let p = GlobeMath.project(lat: ocean.0, lon: ocean.1, centerLat: centerLat, centerLon: centerLon), + (p.x * p.x + p.y * p.y).squareRoot() < 0.98 else { continue } + let point = CGPoint(x: cx + p.x * r, y: cy + p.y * r) + guard CGRect(origin: .zero, size: size).contains(point) else { continue } + for ring in land { + let projected = ring.terms.map { projector.project($0) } + guard projected.contains(where: { $0.cosC >= 0 }) else { continue } + let pts = projected.map { GlobeGeometry.DiscPoint(x: $0.x, y: $0.y, front: $0.cosC > 0.005) } + let polygon = GlobeGeometry.fillPolygon(pts, cx: cx, cy: cy, r: r) + let invert = projected.contains(where: { $0.cosC < 0 }) && GlobeGeometry.projectedFillNeedsInversion( + polygon: polygon, ring: ring, cx: cx, cy: cy, r: r, centerLat: centerLat, centerLon: centerLon + ) + let clipped = GlobeGeometry.clipPolygon(polygon, to: clip) + guard clipped.count >= 3 else { continue } + let path = CGMutablePath() + if invert { path.addEllipse(in: CGRect(x: cx - r, y: cy - r, width: 2 * r, height: 2 * r)) } + path.addLines(between: clipped) + path.closeSubpath() + #expect( + !path.contains(point, using: invert ? .evenOdd : .winding), + "ocean \(ocean) painted as land viewing \(centerLat),\(centerLon) at zoom \(zoom)" + ) + } + } + } + } + } + } + + @Test func parsesPolygonsMultiPolygonsAndLines() { + let land = Data(""" + {"type":"GeometryCollection","geometries":[ + {"type":"Polygon","coordinates":[[[0,0],[10,0],[10,10],[0,0]]]}, + {"type":"MultiPolygon","coordinates":[[[[20,20],[30,20],[30,30],[20,20]]],[[[1,1],[2,2]]]]} + ]} + """.utf8) + let rings = GlobeWorldData.parseLand(land) + #expect(rings.count == 2) + // GeoJSON positions are [lon, lat]. + #expect(rings[0].lons == [0, 10, 10, 0]) + #expect(rings[0].lats == [0, 0, 10, 0]) + #expect(rings[0].terms.count == rings[0].count) + + let borders = Data(""" + {"type":"GeometryCollection","geometries":[ + {"type":"LineString","coordinates":[[0,0],[1,1]]}, + {"type":"MultiLineString","coordinates":[[[2,2],[3,3],[4,4]],[[5,5]]]} + ]} + """.utf8) + let lines = GlobeWorldData.parseBorders(borders) + #expect(lines.map(\.count) == [2, 3]) + } + + @Test func parsesCities() { + let cities = GlobeWorldData.parseCities(Data(""" + {"cities":[{"n":"Vienna","r":1,"cap":1,"mega":0,"pop":1,"lon":16.37,"lat":48.2},{"n":"broken"}]} + """.utf8)) + #expect(cities.count == 1) + #expect(cities[0].name == "Vienna") + #expect(cities[0].capital) + #expect(!cities[0].megacity) + #expect(abs(cities[0].terms.sinLat - sin(48.2 * .pi / 180)) < 1e-12) + #expect(abs(cities[0].terms.sinLon - sin(16.37 * .pi / 180)) < 1e-12) + } +} + +@MainActor +struct GeohashPickerTargetTests { + @Test func prefersTheGivenGeohash() { + let target = GeohashPickerView.initialTarget(initialGeohash: "u2edk", nearbyGeohashes: ["u2"]) + let center = Geohash.decodeCenter("u2edk") + #expect(target.lat == center.lat) + #expect(target.lon == center.lon) + #expect(target.precision == 5) + } + + @Test func fallsBackToTheCoarsestNearbyChannel() { + let target = GeohashPickerView.initialTarget(initialGeohash: "", nearbyGeohashes: ["u2edk", "u2e", "u2edk7q"]) + #expect(target.precision == 3) + #expect(target.lat == Geohash.decodeCenter("u2e").lat) + } + + @Test func defaultsToAWideWorldView() { + let target = GeohashPickerView.initialTarget(initialGeohash: nil, nearbyGeohashes: []) + #expect(target.lat == 20) + #expect(target.lon == 0) + #expect(target.precision == 2) + } + + @Test func coverageMatchesTheChannelLevels() { + #expect(GeohashCoverage.level(forLength: 1) == .region) + #expect(GeohashCoverage.level(forLength: 4) == .province) + #expect(GeohashCoverage.level(forLength: 5) == .city) + #expect(GeohashCoverage.level(forLength: 12) == .building) + #expect(GeohashCoverage.string(forPrecision: 5, locale: Locale(identifier: "de_DE")) == "~4.9 km") + #expect(GeohashCoverage.string(forPrecision: 2, locale: Locale(identifier: "en_US")) == "~777 mi") + } +} diff --git a/bitchatTests/LocalizationCoverageTests.swift b/bitchatTests/LocalizationCoverageTests.swift index 29bea3b8..918bb8b6 100644 --- a/bitchatTests/LocalizationCoverageTests.swift +++ b/bitchatTests/LocalizationCoverageTests.swift @@ -16,11 +16,15 @@ struct LocalizationCoverageTests { var allLocales: Set { coverage.values.reduce(into: []) { $0.formUnion($1) } } } - private static func loadCatalog(_ relativePath: String) throws -> Catalog { - let url = repoRoot.appendingPathComponent(relativePath) - let data = try Data(contentsOf: url) + /// The catalog's `strings` table: key -> entry. + private static func loadStrings(_ relativePath: String) throws -> [String: Any] { + let data = try Data(contentsOf: repoRoot.appendingPathComponent(relativePath)) let root = try #require(try JSONSerialization.jsonObject(with: data) as? [String: Any]) - let strings = try #require(root["strings"] as? [String: Any]) + return try #require(root["strings"] as? [String: Any]) + } + + private static func loadCatalog(_ relativePath: String) throws -> Catalog { + let strings = try loadStrings(relativePath) var coverage: [String: Set] = [:] for (key, value) in strings { @@ -70,6 +74,59 @@ struct LocalizationCoverageTests { #expect(missing.isEmpty, "share extension is missing locales: \(missing.joined(separator: ", "))") } + /// SwiftPM's default build system on Swift 6.4+ (swiftbuild) generates a + /// Swift symbol for every manually managed catalog key, and fails the + /// whole build on a key it cannot name ("%@", "#%@", "%lld/%lld"). CI may + /// still run the native build system, which never generates symbols, so + /// check the rule here rather than wait for the runner image to move. + /// This covers nameability only: the tool also fails on two manual keys + /// that generate the same symbol ("1" and "_1") and on skipped positional + /// arguments ("%1$@ %3$@"), which this does not check. + @Test func everyManualKeyCanDeriveAGeneratedSymbol() throws { + for path in [Self.mainCatalogPath, Self.shareExtensionCatalogPath] { + let unnameable = try Self.loadStrings(path).compactMap { key, value -> String? in + guard (value as? [String: Any])?["extractionState"] as? String == "manual" else { return nil } + return Self.canDeriveSymbol(from: key) ? nil : key + }.sorted() + #expect( + unnameable.isEmpty, + """ + manual keys in \(path) that string catalog symbol generation \ + cannot name, which breaks `swift build`: \(unnameable). Use \ + Text(verbatim:) at the call site, or give the key a name. + """ + ) + } + } + + /// Mirrors `xcstringstool generate-symbols`: printf-style format specifiers + /// split the key into words, and a character (grapheme cluster) can only + /// be part of the symbol name if every scalar in it can be part of a Swift + /// identifier. This approximates that, erring towards rejection, with + /// letters, numbers, marks, `_`, `$`, the joiners ZWJ and ZWNJ, and emoji + /// outside the Basic Multilingual Plane. So 🔒, 👋🏽 and 🧑‍🎄 count, but BMP + /// emoji (✅ ⚡ ❤️) and sequences built on one (🏃‍♂️ ✌🏽) do not. + private static func canDeriveSymbol(from key: String) -> Bool { + let words = key.replacingOccurrences( + of: #"%(\d+\$)?[-+0]*\d*(\.\d+)?(hh|h|ll|l|q|L|z|t|j)?[@dDiuUxXoOfFeEgGcCsSpaA]|%%"#, + with: " ", + options: .regularExpression + ) + return words.contains { character in + character.unicodeScalars.allSatisfy { scalar in + switch scalar.properties.generalCategory { + case .uppercaseLetter, .lowercaseLetter, .titlecaseLetter, .modifierLetter, .otherLetter, + .decimalNumber, .letterNumber, .otherNumber, + .nonspacingMark, .spacingMark, .enclosingMark: + return true + default: + return scalar == "_" || scalar == "$" || scalar == "\u{200C}" || scalar == "\u{200D}" + || (scalar.value >= 0x10000 && scalar.properties.isEmoji) + } + } + } + } + /// The catalog tests above validate the CATALOG; this one validates the /// CODE. A `String(localized:)` whose key is absent from the catalog its /// target actually ships compiles and runs fine — it just silently ships diff --git a/bitchatTests/LocationPresenceStoreTests.swift b/bitchatTests/LocationPresenceStoreTests.swift new file mode 100644 index 00000000..42d731b7 --- /dev/null +++ b/bitchatTests/LocationPresenceStoreTests.swift @@ -0,0 +1,44 @@ +// +// LocationPresenceStoreTests.swift +// bitchatTests +// +// This is free and unencumbered software released into the public domain. +// For more information, see +// + +import Combine +import Testing +@testable import bitchat + +@MainActor +struct LocationPresenceStoreTests { + + @Test func setNickname_reportsWhetherTheNameChanged() { + let store = LocationPresenceStore() + + #expect(store.setNickname("alice", for: "AA") == true) + // Chat events repeat the sender's nickname every time. + #expect(store.setNickname("alice", for: "aa") == false) + #expect(store.setNickname("alicia", for: "aa") == true) + #expect(store.geoNicknames["aa"] == "alicia") + } + + /// Every write republishes, and the people list rebuilds on these + /// publishers, so pruning that removes nothing must not write. + @Test func pruningThatRemovesNothingDoesNotRepublish() { + let store = LocationPresenceStore() + store.markTeleported("aa") + store.setNickname("alice", for: "aa") + + var changes = 0 + let cancellable = store.objectWillChange.sink { _ in changes += 1 } + store.retainTeleportedGeo(keeping: ["aa", "bb"]) + store.clearTeleported("cc") + #expect(changes == 0) + + store.retainTeleportedGeo(keeping: ["bb"]) + #expect(changes == 1) + #expect(store.teleportedGeo.isEmpty) + _ = cancellable + } +} diff --git a/bitchatTests/MessageFormattingEngineTests.swift b/bitchatTests/MessageFormattingEngineTests.swift index 5de2adea..1a4e6493 100644 --- a/bitchatTests/MessageFormattingEngineTests.swift +++ b/bitchatTests/MessageFormattingEngineTests.swift @@ -332,6 +332,40 @@ struct MessageFormattingEngineTests { #expect(content.isLongForDisplay()) } + @Test func contentScan_matchesTheStringScansAndIsCachedOnTheMessage() { + let cashu = "cashuA" + String(repeating: "a", count: 40) + let invoice = "lnbc1" + String(repeating: "q", count: 60) + let long = String(repeating: "a", count: TransportConfig.uiLongMessageLengthThreshold + 1) + let contents = [ + "plain words", + "pay \(cashu) or lightning:\(invoice) or \(invoice)", + "\(long) \(cashu)", + "same \(cashu) twice \(cashu)" + ] + + for content in contents { + let message = BitchatMessage(sender: "alice", content: content, timestamp: Date(), isRelay: false) + #expect(message.getCachedContentScan() == nil) + + let scan = message.contentScan + #expect(scan.cashuLinks == content.extractCashuLinks()) + #expect(scan.lightningLinks == content.extractLightningLinks()) + #expect(scan.isLongForDisplay == content.isLongForDisplay()) + #expect(message.getCachedContentScan() == scan) + } + } + + @Test func contentScan_servesTheCachedScanWithoutRescanning() { + let cashu = "cashuA" + String(repeating: "a", count: 40) + let message = BitchatMessage(sender: "alice", content: "pay \(cashu)", timestamp: Date(), isRelay: false) + // A sentinel no scan of this content could produce. + let sentinel = BitchatMessage.ContentScan(cashuLinks: [], lightningLinks: ["lightning:sentinel"], isLongForDisplay: true) + + message.setCachedContentScan(sentinel) + + #expect(message.contentScan == sentinel) + } + @MainActor @Test func formatMessage_longCashuMessageFallsBackToPlainContentPath() { let context = MockMessageFormattingContext(nickname: "carol") diff --git a/bitchatTests/MessageListScrollPolicyTests.swift b/bitchatTests/MessageListScrollPolicyTests.swift new file mode 100644 index 00000000..9d6534d0 --- /dev/null +++ b/bitchatTests/MessageListScrollPolicyTests.swift @@ -0,0 +1,400 @@ +// +// MessageListScrollPolicyTests.swift +// bitchatTests +// +// The pure rules behind MessageListView's scroll position: appended-message +// counting (including at the store cap, where the count stops moving), the +// window size that keeps a scrolled-up reader's first row in place, the +// reaction to a timeline change (land, follow, keep position, hold), which +// row callbacks count, and the gates on expansion and follow-scrolls. +// + +import BitFoundation +import Foundation +import Testing +@testable import bitchat + +private typealias Policy = MessageListScrollPolicy + +private let baseDate = Date(timeIntervalSince1970: 1_700_000_000) + +private func message(_ index: Int, sender: String = "alice", content: String? = nil, at timestamp: Double? = nil) -> BitchatMessage { + BitchatMessage( + id: "m\(index)", + sender: sender, + content: content ?? "message \(index)", + timestamp: baseDate.addingTimeInterval(timestamp ?? Double(index)), + isRelay: false + ) +} + +private func timeline(_ range: Range) -> [BitchatMessage] { + range.map { message($0) } +} + +/// Inserts a late message (older timestamp) just before `index`. +private func inserting(_ late: BitchatMessage, before index: Int, in messages: [BitchatMessage]) -> [BitchatMessage] { + var copy = messages + copy.insert(late, at: index) + return copy +} + +struct MessageListScrollPolicyTests { + + // MARK: - Timeline marks + + @Test + func timelineMark_recordsTheNewestMessageAndTheWindowsFirstRow() { + let messages = timeline(0..<10) + let mark = Policy.TimelineMark(contextKey: "mesh", messages: messages, windowCount: 4) + + #expect(mark.newestMessageID == "m9") + #expect(mark.newestTimestamp == messages[9].timestamp) + #expect(mark.windowFirstMessageID == "m6") + #expect(mark.windowCount == 4) + + // A window wider than the timeline starts at its oldest message. + #expect(Policy.TimelineMark(contextKey: "mesh", messages: messages, windowCount: 300).windowFirstMessageID == "m0") + // An empty timeline marks nothing. + let empty = Policy.TimelineMark(contextKey: "mesh", messages: [], windowCount: 300) + #expect(empty.newestMessageID == nil) + #expect(empty.windowFirstMessageID == nil) + } + + @Test + func timelineMark_withWindowCountRetakesOnlyTheWindow() { + let messages = timeline(0..<10) + let mark = Policy.TimelineMark(contextKey: "geo:u4pruy", messages: Array(messages.prefix(8)), windowCount: 4) + + let expanded = mark.withWindowCount(7, in: messages) + + #expect(expanded.contextKey == "geo:u4pruy") + // What was seen stays as it was; the window is re-taken. + #expect(expanded.newestMessageID == "m7") + #expect(expanded.windowFirstMessageID == "m3") + #expect(expanded.windowCount == 7) + } + + // MARK: - Appended messages + + @Test + func appended_countsOnlyMessagesAfterTheMarkedNewest() { + let mark = Policy.TimelineMark(contextKey: "mesh", messages: timeline(0..<6), windowCount: 300) + var messages = timeline(0..<9) + messages.append(message(9, sender: "system")) + messages.append(message(10, content: " ")) + + let appended = Policy.appended(since: mark, in: messages) + + // m6, m7, m8, a system line and a whitespace-only message landed; the + // pill counts only the three human messages. + #expect(appended == Policy.Appended(total: 5, unseen: 3)) + } + + @Test + func appended_countsEverythingWhenTheTimelineWasEmpty() { + let mark = Policy.TimelineMark(contextKey: "mesh", messages: [], windowCount: 300) + + #expect(Policy.appended(since: mark, in: timeline(0..<3)) == Policy.Appended(total: 3, unseen: 3)) + #expect(Policy.appended(since: mark, in: []) == Policy.Appended()) + } + + @Test + func appended_keepsCountingAtTheStoreCap() { + // At the cap every append evicts the oldest message: the count never + // moves, but the appended messages are still found after the newest. + let capped = timeline(0..<10) + let mark = Policy.TimelineMark(contextKey: "mesh", messages: capped, windowCount: 300) + let afterThreeAppends = timeline(3..<13) + #expect(afterThreeAppends.count == capped.count) + + #expect(Policy.appended(since: mark, in: afterThreeAppends) == Policy.Appended(total: 3, unseen: 3)) + } + + @Test + func appended_doesNotCountLateMessagesLandingAboveTheNewest() { + let messages = timeline(0..<10) + let mark = Policy.TimelineMark(contextKey: "mesh", messages: messages, windowCount: 300) + let late = message(100, at: 7.5) + + let withLate = inserting(late, before: 8, in: messages) + + #expect(Policy.appended(since: mark, in: withLate) == Policy.Appended()) + } + + @Test + func appended_fallsBackToTimestampsWhenTheNewestIsGone() { + let mark = Policy.TimelineMark(contextKey: "mesh", messages: timeline(0..<10), windowCount: 300) + + // The newest seen message was removed (e.g. a block purge); two + // newer ones landed since. + let removedNewest = timeline(0..<9) + timeline(10..<12) + #expect(Policy.appended(since: mark, in: removedNewest) == Policy.Appended(total: 2, unseen: 2)) + + // A burst larger than the cap evicted it: everything left is newer. + let evictedNewest = timeline(20..<30) + #expect(Policy.appended(since: mark, in: evictedNewest) == Policy.Appended(total: 10, unseen: 10)) + } + + // MARK: - Window growth + + @Test + func windowCountKeepingFirstRow_growsOverMessagesAppendedBelowIt() { + let messages = timeline(0..<20) + let mark = Policy.TimelineMark(contextKey: "mesh", messages: messages, windowCount: 10) + + let grown = Policy.windowCountKeepingFirstRow( + current: 10, + mark: mark, + appendedCount: 0, + in: messages + timeline(20..<23) + ) + + #expect(grown == 13) + #expect((messages + timeline(20..<23)).suffix(grown).first?.id == "m10") + } + + @Test + func windowCountKeepingFirstRow_absorbsLateMessagesInsertedBelowIt() { + let messages = timeline(0..<20) + let mark = Policy.TimelineMark(contextKey: "mesh", messages: messages, windowCount: 10) + + // Below the first row: the window grows to keep it. + let lateInside = inserting(message(100, at: 15.5), before: 16, in: messages) + #expect(Policy.windowCountKeepingFirstRow(current: 10, mark: mark, appendedCount: 0, in: lateInside) == 11) + + // Above the first row: the suffix already keeps it. + let lateAbove = inserting(message(101, at: 4.5), before: 5, in: messages) + #expect(Policy.windowCountKeepingFirstRow(current: 10, mark: mark, appendedCount: 0, in: lateAbove) == 10) + } + + @Test + func windowCountKeepingFirstRow_keepsTheFirstRowAtTheStoreCap() { + let capped = timeline(0..<20) + let mark = Policy.TimelineMark(contextKey: "mesh", messages: capped, windowCount: 10) + // Two appends, two head evictions: same count, first row two places up. + let afterTwoAppends = timeline(2..<22) + + let grown = Policy.windowCountKeepingFirstRow(current: 10, mark: mark, appendedCount: 2, in: afterTwoAppends) + + #expect(grown == 12) + #expect(afterTwoAppends.suffix(grown).first?.id == "m10") + } + + @Test + func windowCountKeepingFirstRow_growsByTheAppendedCountWithoutAUsableMark() { + let messages = timeline(0..<30) + + // No mark (fresh context): grow by what was appended. + #expect(Policy.windowCountKeepingFirstRow(current: 10, mark: nil, appendedCount: 3, in: messages) == 13) + + // A mark taken at another window size (the window was expanded since). + let stale = Policy.TimelineMark(contextKey: "mesh", messages: timeline(0..<27), windowCount: 8) + #expect(Policy.windowCountKeepingFirstRow(current: 10, mark: stale, appendedCount: 3, in: messages) == 13) + + // The first row itself is gone (removed or evicted). + let mark = Policy.TimelineMark(contextKey: "mesh", messages: timeline(0..<27), windowCount: 10) + let withoutFirstRow = messages.filter { $0.id != "m17" } + #expect(Policy.windowCountKeepingFirstRow(current: 10, mark: mark, appendedCount: 3, in: withoutFirstRow) == 13) + + // Nothing appended and nothing to hold: the window stays. + #expect(Policy.windowCountKeepingFirstRow(current: 10, mark: nil, appendedCount: 0, in: messages) == 10) + } + + @Test + func windowCountKeepingFirstRow_neverShrinksNorOutgrowsTheTimeline() { + // A timeline shorter than the window keeps the window size. + let short = timeline(0..<5) + let shortMark = Policy.TimelineMark(contextKey: "mesh", messages: short, windowCount: 300) + #expect(Policy.windowCountKeepingFirstRow(current: 300, mark: shortMark, appendedCount: 2, in: short + timeline(5..<7)) == 300) + + // Growth stops at the timeline's length. + let messages = timeline(0..<12) + #expect(Policy.windowCountKeepingFirstRow(current: 10, mark: nil, appendedCount: 50, in: messages) == 12) + + // Removals below the first row never shrink the window. + let mark = Policy.TimelineMark(contextKey: "mesh", messages: messages, windowCount: 10) + let removedBelow = messages.filter { $0.id != "m9" && $0.id != "m10" } + #expect(Policy.windowCountKeepingFirstRow(current: 10, mark: mark, appendedCount: 0, in: removedBelow) == 10) + } + + // MARK: - Gates + + @Test + func canExpandWindow_waitsForTheRestoreAndForTheBottomOfThisContext() { + #expect(Policy.canExpandWindow(isRestoringExpansion: false, bottomSettledContextKey: "mesh", contextKey: "mesh")) + // A previous expansion's position restore is still queued. + #expect(!Policy.canExpandWindow(isRestoringExpansion: true, bottomSettledContextKey: "mesh", contextKey: "mesh")) + // The initial scroll to the bottom has not landed yet. + #expect(!Policy.canExpandWindow(isRestoringExpansion: false, bottomSettledContextKey: nil, contextKey: "mesh")) + // It landed in another conversation. + #expect(!Policy.canExpandWindow(isRestoringExpansion: false, bottomSettledContextKey: "geo:u4pruy", contextKey: "mesh")) + } + + @Test + func shouldRunDeferredFollowScroll_requiresTheBottomOfTheSameTimeline() { + #expect(Policy.shouldRunDeferredFollowScroll(isAtBottom: true, scheduledContextKey: "mesh", currentContextKey: "mesh")) + // The reader dragged away while the timer was held back. + #expect(!Policy.shouldRunDeferredFollowScroll(isAtBottom: false, scheduledContextKey: "mesh", currentContextKey: "mesh")) + // The timeline was switched before the timer fired. + #expect(!Policy.shouldRunDeferredFollowScroll(isAtBottom: true, scheduledContextKey: "mesh", currentContextKey: "geo:u4pruy")) + } + + @Test + func needsScroll_skipsTheBottomRetryOnceTheNewestRowIsOnScreen() { + #expect(Policy.needsScroll(toNewestRowID: "mesh|m9", bottomRowID: "mesh|m8")) + #expect(Policy.needsScroll(toNewestRowID: "mesh|m9", bottomRowID: nil)) + // The first scroll landed: the retry would be a queued no-op. + #expect(!Policy.needsScroll(toNewestRowID: "mesh|m9", bottomRowID: "mesh|m9")) + // No row to scroll to. + #expect(!Policy.needsScroll(toNewestRowID: nil, bottomRowID: nil)) + } + + // MARK: - Row callbacks + + @Test + func isRow_matchesOnlyRowsOfItsOwnContext() { + #expect(Policy.isRow("mesh|m1", inContext: "mesh")) + #expect(Policy.isRow("geo:u4pruy|m1", inContext: "geo:u4pruy")) + #expect(Policy.isRow("dm:0011223344556677|m1", inContext: "dm:0011223344556677")) + // The old timeline's rows after a switch. + #expect(!Policy.isRow("geo:u4pruy|m1", inContext: "mesh")) + #expect(!Policy.isRow("dm:aaaa|m1", inContext: "dm:bbbb")) + // A context that is a prefix of another is not that context. + #expect(!Policy.isRow("geo:u4pruyd|m1", inContext: "geo:u4pruy")) + #expect(!Policy.isRow("mesh", inContext: "mesh")) + } + + // MARK: - Reactions + + private func reaction( + mark: Policy.TimelineMark?, + _ messages: [BitchatMessage], + newestIsOwn: Bool = false, + appended: Int = 0, + windowCount: Int = 10, + isAtBottom: Bool + ) -> Policy.TimelineReaction { + Policy.reaction( + mark: mark, + messages: messages, + newestIsOwn: newestIsOwn, + appendedCount: appended, + windowCount: windowCount, + isAtBottom: isAtBottom + ) + } + + @Test + func reaction_landsInATimelineWithoutAMarkInItsContext() { + // A channel or DM switch: whatever isAtBottom says (the old + // timeline's rows report on their way out), the list lands. + #expect(reaction(mark: nil, timeline(0..<10), isAtBottom: false) == .land) + #expect(reaction(mark: nil, timeline(0..<10), newestIsOwn: true, isAtBottom: true) == .land) + // Even into an empty timeline. + #expect(reaction(mark: nil, [], isAtBottom: false) == .land) + } + + @Test + func reaction_followsAtTheBottomWheneverTheRenderedRowsMayHaveMoved() { + let messages = timeline(0..<20) + let mark = Policy.TimelineMark(contextKey: "mesh", messages: messages, windowCount: 10) + + // Appended below the bottom. + #expect(reaction(mark: mark, messages + timeline(20..<22), appended: 2, isAtBottom: true) == .follow) + // A late message landing among the visible rows pushes the newest one + // down: nothing was appended, but the bottom moved. + let lateAmongVisibleRows = inserting(message(100, at: 18.5), before: 19, in: messages) + #expect(reaction(mark: mark, lateAmongVisibleRows, isAtBottom: true) == .follow) + // A removal changes the rows too. + #expect(reaction(mark: mark, messages.filter { $0.id != "m15" }, isAtBottom: true) == .follow) + } + + @Test + func reaction_holdsAtTheBottomWhenTheRenderedRowsAreUnchanged() { + // At the store cap a late message landing above the window evicts the + // oldest message, also above it: the rendered rows are the same, and + // a scroll would be a queued no-op that snaps the next drag back. + let capped = timeline(0..<20) + let mark = Policy.TimelineMark(contextKey: "mesh", messages: capped, windowCount: 10) + let lateAboveTheWindow = Array(inserting(message(100, at: 4.5), before: 5, in: capped).dropFirst()) + + #expect(reaction(mark: mark, lateAboveTheWindow, isAtBottom: true) == .hold) + } + + @Test + func reaction_keepsAScrolledUpReaderInPlace() { + let messages = timeline(0..<10) + let mark = Policy.TimelineMark(contextKey: "mesh", messages: messages, windowCount: 300) + + #expect(reaction(mark: mark, messages + timeline(10..<13), appended: 3, isAtBottom: false) == .keepPosition) + #expect(reaction(mark: mark, messages, isAtBottom: false) == .keepPosition) + } + + @Test + func reaction_followsTheReadersOwnNewMessageFromAnywhere() { + let messages = timeline(0..<10) + let mark = Policy.TimelineMark(contextKey: "mesh", messages: messages, windowCount: 300) + + #expect(reaction(mark: mark, messages + [message(10)], newestIsOwn: true, appended: 1, isAtBottom: false) == .follow) + // A message of mine that was already the newest (m9) does not pull a + // scrolled-up reader down when late messages land above it. + let lateAboveMine = inserting(message(100, at: 7.5), before: 8, in: messages) + #expect(reaction(mark: mark, lateAboveMine, newestIsOwn: true, isAtBottom: false) == .keepPosition) + } + + @Test + func reaction_followsOnlyAMessageOfMineThatLandedSinceTheMark() { + // m8 is mine; m9 after it, the newest seen, is a bridge alias. + let messages = timeline(0..<10) + let mark = Policy.TimelineMark(contextKey: "mesh", messages: messages, windowCount: 300) + + // The radio copy retracts the alias a batch before it lands itself: + // m8 is the newest again, but nothing landed since the mark. + let retracted = Array(messages.dropLast()) + let appended = Policy.appended(since: mark, in: retracted) + #expect(appended == Policy.Appended()) + #expect(reaction(mark: mark, retracted, newestIsOwn: true, appended: appended.total, isAtBottom: false) == .keepPosition) + // At the bottom the removal still moves the rows. + #expect(reaction(mark: mark, retracted, newestIsOwn: true, appended: appended.total, windowCount: 300, isAtBottom: true) == .follow) + + // A message of mine landing in the same change is new. + let retractedWithMine = retracted + [message(10)] + let appendedWithMine = Policy.appended(since: mark, in: retractedWithMine) + #expect(appendedWithMine == Policy.Appended(total: 1, unseen: 1)) + #expect(reaction(mark: mark, retractedWithMine, newestIsOwn: true, appended: appendedWithMine.total, isAtBottom: false) == .follow) + } + + @Test + func reaction_holdsWhenTheTimelineEmptied() { + let mark = Policy.TimelineMark(contextKey: "mesh", messages: timeline(0..<10), windowCount: 300) + + #expect(reaction(mark: mark, [], isAtBottom: false) == .hold) + #expect(reaction(mark: mark, [], isAtBottom: true) == .hold) + } + + @Test + func isRenderedWindowUnchanged_onlyForAFullWindowOfTheSameRows() { + let capped = timeline(0..<20) + let mark = Policy.TimelineMark(contextKey: "mesh", messages: capped, windowCount: 10) + func isUnchanged(_ messages: [BitchatMessage], appended: Int = 0, windowCount: Int = 10) -> Bool { + Policy.isRenderedWindowUnchanged(since: mark, appendedCount: appended, windowCount: windowCount, in: messages) + } + + // Late message above the window at the cap (the oldest evicted). + #expect(isUnchanged(Array(inserting(message(100, at: 4.5), before: 5, in: capped).dropFirst()))) + // Late message inside the window at the cap: its first row moves. + #expect(!isUnchanged(Array(inserting(message(101, at: 14.5), before: 15, in: capped).dropFirst()))) + // Below the cap any insert changes the count. + #expect(!isUnchanged(inserting(message(102, at: 4.5), before: 5, in: capped))) + // Something appended. + #expect(!isUnchanged(Array((capped + [message(20)]).dropFirst()), appended: 1)) + // The window was resized since the mark. + #expect(!isUnchanged(capped, windowCount: 12)) + + // A timeline shorter than its window renders every message. + let short = timeline(0..<5) + let shortMark = Policy.TimelineMark(contextKey: "mesh", messages: short, windowCount: 10) + #expect(!Policy.isRenderedWindowUnchanged(since: shortMark, appendedCount: 0, windowCount: 10, in: short)) + } +} diff --git a/bitchatTests/PeerListModelTests.swift b/bitchatTests/PeerListModelTests.swift new file mode 100644 index 00000000..d7b32017 --- /dev/null +++ b/bitchatTests/PeerListModelTests.swift @@ -0,0 +1,113 @@ +// +// PeerListModelTests.swift +// bitchatTests +// +// This is free and unencumbered software released into the public domain. +// For more information, see +// + +import BitFoundation +import Combine +import Foundation +import Testing +@testable import bitchat + +@MainActor +struct PeerListModelTests { + + /// Every @Published write re-renders every view observing the model + /// (root view, header, open people sheet), so a refresh trigger that + /// leaves the rows as they were must not write anything. + @Test func refreshThatChangesNothingDoesNotRepublish() async { + let viewModel = makeViewModel() + let model = PeerListModel( + chatViewModel: viewModel, + conversations: viewModel.conversations, + locationChannelsModel: LocationChannelsModel(manager: makeLocationManager()) + ) + await drainMainQueue() + + var changes = 0 + let cancellable = model.objectWillChange.sink { _ in changes += 1 } + let roster = viewModel.allPeers + for _ in 0..<5 { + NotificationCenter.default.post(name: Notification.Name("peerStatusUpdated"), object: nil) + // Every mesh snapshot republishes the roster, usually unchanged. + viewModel.allPeers = roster + } + await drainMainQueue() + + #expect(changes == 0) + _ = cancellable + } + + /// `BitchatPeer.==` compares only peer IDs, so a roster in which someone + /// changed name, connection or favorite compares equal to the previous + /// one. Their row must still be rebuilt from it. + @Test func rosterChangeWithTheSameIDsUpdatesTheRow() async throws { + let transport = MockTransport() + let viewModel = makeViewModel(transport: transport) + let model = PeerListModel( + chatViewModel: viewModel, + conversations: viewModel.conversations, + locationChannelsModel: LocationChannelsModel(manager: makeLocationManager()) + ) + let peerID = PeerID(str: "00000000000000c7") + let noiseKey = Data(repeating: 0xC7, count: 32) + func snapshots(nickname: String) -> [TransportPeerSnapshot] { + [TransportPeerSnapshot( + peerID: peerID, + nickname: nickname, + isConnected: true, + noisePublicKey: noiseKey, + lastSeen: Date() + )] + } + + // Through the transport rather than assigning `viewModel.allPeers`: + // anything else that rebuilds the roster (a favorites change from a + // parallel test) then yields these same peers. + transport.updatePeerSnapshots(snapshots(nickname: "alice")) + let listed = await TestHelpers.waitUntil({ + model.meshRows.contains { $0.peerID == peerID && $0.displayName == "alice" } + }, timeout: TestConstants.settleTimeout) + try #require(listed) + + // Same peer, same place in the roster, new name. + transport.updatePeerSnapshots(snapshots(nickname: "alicia")) + let renamed = await TestHelpers.waitUntil({ + model.meshRows.contains { $0.peerID == peerID && $0.displayName == "alicia" } + }, timeout: TestConstants.settleTimeout) + #expect(renamed) + } + + // MARK: - Helpers + + private func makeViewModel(transport: MockTransport = MockTransport()) -> ChatViewModel { + let keychain = MockKeychain() + return ChatViewModel( + keychain: keychain, + idBridge: NostrIdentityBridge(keychain: MockKeychainHelper()), + identityManager: MockIdentityManager(keychain), + transport: transport, + locationManager: makeLocationManager() + ) + } + + private func makeLocationManager() -> LocationChannelManager { + let suiteName = "PeerListModelTests.\(UUID().uuidString)" + let storage = UserDefaults(suiteName: suiteName) ?? .standard + storage.removePersistentDomain(forName: suiteName) + return LocationChannelManager(storage: storage) + } + + /// The model's triggers hop to the main queue and then coalesce onto one + /// more hop, so let a few main-queue turns run. + private func drainMainQueue() async { + for _ in 0..<4 { + await withCheckedContinuation { continuation in + DispatchQueue.main.async { continuation.resume() } + } + } + } +} diff --git a/bitchatTests/PeopleListOrderingTests.swift b/bitchatTests/PeopleListOrderingTests.swift new file mode 100644 index 00000000..1622830f --- /dev/null +++ b/bitchatTests/PeopleListOrderingTests.swift @@ -0,0 +1,44 @@ +// +// PeopleListOrderingTests.swift +// bitchatTests +// +// This is free and unencumbered software released into the public domain. +// For more information, see +// + +import Testing +@testable import bitchat + +struct PeopleListOrderingTests { + + @Test func firstLayoutUsesProducerOrder() { + let order = PeopleListOrdering.stableOrder(previous: [], current: ["c", "a", "b"]) + #expect(order == ["c", "a", "b"]) + } + + @Test func shownRowsKeepTheirPlaceWhenTheProducerReorders() { + // A heartbeat moved "b" to the front of the recency-sorted roster; + // the open list must not reshuffle under the reader. + let order = PeopleListOrdering.stableOrder(previous: ["a", "b", "c"], current: ["b", "c", "a"]) + #expect(order == ["a", "b", "c"]) + } + + @Test func newcomersAppendInProducerOrder() { + let order = PeopleListOrdering.stableOrder(previous: ["a", "b"], current: ["e", "b", "d", "a"]) + #expect(order == ["a", "b", "e", "d"]) + } + + @Test func departuresDropOut() { + let order = PeopleListOrdering.stableOrder(previous: ["a", "b", "c"], current: ["c", "a"]) + #expect(order == ["a", "c"]) + } + + @Test func duplicateIDsCollapseToTheFirstOccurrence() { + let order = PeopleListOrdering.stableOrder(previous: ["a", "a"], current: ["b", "a", "b"]) + #expect(order == ["a", "b"]) + } + + @Test func emptyRosterClearsTheOrder() { + #expect(PeopleListOrdering.stableOrder(previous: ["a", "b"], current: []).isEmpty) + } +} diff --git a/bitchatTests/Performance/PerformanceBaselineTests+Geochat.swift b/bitchatTests/Performance/PerformanceBaselineTests+Geochat.swift new file mode 100644 index 00000000..a9c46fd6 --- /dev/null +++ b/bitchatTests/Performance/PerformanceBaselineTests+Geochat.swift @@ -0,0 +1,185 @@ +// +// PerformanceBaselineTests+Geochat.swift +// bitchatTests +// +// Geochat (location channel) benchmarks at a busy-room size. Each guards a +// cost that used to grow with the number of participants N: +// +// - the people sheet resolved every row's color by rebuilding the whole +// roster, so one render was O(N^2); +// - every roster rebuild hex-encoded our own key once per participant with +// String(format:) per byte; +// - every inbound event (presence heartbeats arrive ~N/60 times a second) +// rebuilt and republished the roster. +// +// perf-floors.json keeps each floor far above those regression values. +// + +import XCTest +import BitFoundation +@testable import bitchat + +extension PerformanceBaselineTests { + /// The room size at which the regressions above cost seconds. + private static let geochatParticipants = 500 + + // MARK: - Geochat people list colors + + /// One people-sheet render resolves a color for every row. + func testGeochatPeopleListColors() { + let fixture = GeochatPerfFixture(participants: Self.geochatParticipants) + let pubkeys = fixture.pubkeys + var samples: [TimeInterval] = [] + + measure { + let start = Date() + for pubkey in pubkeys { + _ = fixture.viewModel.colorForNostrPubkey(pubkey, isDark: true) + } + samples.append(Date().timeIntervalSince(start)) + } + + reportThroughput("geochat.peopleListColors", samples: samples, operations: pubkeys.count, unit: "rows") + } + + // MARK: - Geochat participant heartbeats + + /// Presence heartbeats and messages from people already in the room. + func testGeochatParticipantHeartbeats() { + let fixture = GeochatPerfFixture(participants: Self.geochatParticipants) + let tracker = fixture.viewModel.participantTracker + let pubkeys = fixture.pubkeys + let events = 2_000 + var samples: [TimeInterval] = [] + + measure { + let start = Date() + for index in 0.. XCTest's default 10 measure iterations + let batchSize = 200 + let batches: [[BitchatMessage]] = (0.. 0 ? Double(operations) / avg : .infinity @@ -712,8 +713,11 @@ private final class PerfNostrContext: ChatNostrContext { func stopGeoParticipantRefreshTimer() {} func setActiveParticipantGeohash(_ geohash: String?) {} private(set) var participantRecords = 0 - func recordGeoParticipant(pubkeyHex: String) { participantRecords += 1 } - func recordGeoParticipant(pubkeyHex: String, geohash: String) { participantRecords += 1 } + func recordGeoParticipant(pubkeyHex: String, seenAt: Date) -> Bool { + participantRecords += 1 + return true + } + func recordGeoParticipant(pubkeyHex: String, geohash: String, seenAt: Date) { participantRecords += 1 } func geoParticipantCount(for geohash: String) -> Int { 0 } func setGeoNickname(_ nickname: String, forPubkey pubkeyHex: String) { geoNicknames[pubkeyHex.lowercased()] = nickname } func markGeoTeleported(_ pubkeyHexLowercased: String) { teleportedKeys.insert(pubkeyHexLowercased) } diff --git a/bitchatTests/Performance/perf-floors.json b/bitchatTests/Performance/perf-floors.json index 751caf74..3426d105 100644 --- a/bitchatTests/Performance/perf-floors.json +++ b/bitchatTests/Performance/perf-floors.json @@ -34,6 +34,16 @@ "store.steadyStateAppend_before": 2315, "store.steadyStateAppend": 53976 }, + "_reference_local_numbers_2026_10": { + "geochat.peopleListColors_before": 112, + "geochat.peopleListColors": 406134, + "geochat.participantHeartbeat_before": 110, + "geochat.participantHeartbeat": 1581264, + "geochat.formatMessage_before": 107, + "geochat.formatMessage": 18006, + "hex.encodePublicKey_before": 64366, + "hex.encodePublicKey": 1194627 + }, "floors": { "nostrInbound.fresh": 450, "nostrInbound.duplicate": 250000, @@ -46,7 +56,11 @@ "pipeline.publicIngest": 2400, "store.append": 48000, "store.steadyStateAppend": 10000, - "store.audit": 70 + "store.audit": 70, + "geochat.peopleListColors": 40000, + "geochat.participantHeartbeat": 150000, + "geochat.formatMessage": 2500, + "hex.encodePublicKey": 250000 }, "_slowest_observed_ci_numbers_2026_06": { "nostrInbound.fresh": 918, @@ -60,5 +74,11 @@ "pipeline.publicIngest": 5006, "store.append": 97423, "store.audit": 140 + }, + "_slowest_observed_ci_numbers_2026_10": { + "geochat.peopleListColors": 212895, + "geochat.participantHeartbeat": 717459, + "geochat.formatMessage": 5176, + "hex.encodePublicKey": 655398 } } diff --git a/bitchatTests/PublicMessagePipelineTests.swift b/bitchatTests/PublicMessagePipelineTests.swift index 4ab270a4..5b084b60 100644 --- a/bitchatTests/PublicMessagePipelineTests.swift +++ b/bitchatTests/PublicMessagePipelineTests.swift @@ -21,7 +21,6 @@ private final class TestPipelineDelegate: PublicMessagePipelineDelegate { /// Message IDs the commit rejects (simulates the store's ID dedup). var rejectedMessageIDs: Set = [] private(set) var recordedContentKeys: [String] = [] - private(set) var batchingStates: [Bool] = [] func messages(in conversationID: ConversationID) -> [BitchatMessage] { committed.filter { $0.conversationID == conversationID }.map(\.message) @@ -47,10 +46,6 @@ private final class TestPipelineDelegate: PublicMessagePipelineDelegate { } func pipelinePrewarmMessage(_: PublicMessagePipeline, message: BitchatMessage) {} - - func pipelineSetBatchingState(_: PublicMessagePipeline, isBatching: Bool) { - batchingStates.append(isBatching) - } } @MainActor @@ -80,8 +75,6 @@ struct PublicMessagePipelineTests { pipeline.flushIfNeeded() #expect(delegate.messages(in: .mesh).map { $0.id } == ["b", "a"]) - // Batching state wrapped the flush. - #expect(delegate.batchingStates == [true, false]) } @Test @MainActor diff --git a/bitchatTests/Services/AutocompleteServiceTests.swift b/bitchatTests/Services/AutocompleteServiceTests.swift index f12426bf..d35c1f75 100644 --- a/bitchatTests/Services/AutocompleteServiceTests.swift +++ b/bitchatTests/Services/AutocompleteServiceTests.swift @@ -35,6 +35,40 @@ struct AutocompleteServiceTests { #expect(result.range == nil) } + @Test("Mention token detection is true exactly where suggestions are possible") + func hasMentionTokenMatchesSuggestionContext() { + let service = AutocompleteService() + let samples: [(text: String, cursor: Int, hasToken: Bool)] = [ + ("", 0, false), + ("plain text", 10, false), + ("hi @al there", 12, false), + ("a @b-c", 6, false), + ("@", 1, true), + ("hi @al", 6, true), + ("hi @al there", 6, true), + ("@@al", 4, true), + ("salut @émi", 10, true), + ("@x_1", 4, true), + ("mail me@host", 12, true) + ] + + for sample in samples { + #expect( + AutocompleteService.hasMentionToken(in: sample.text, cursorPosition: sample.cursor) == sample.hasToken, + "\(sample.text) @ \(sample.cursor)" + ) + // A peer named after the token's own prefix always matches it, so + // suggestions appear exactly when a token is detected. + let prefix = String(sample.text.prefix(sample.cursor).split(separator: "@", omittingEmptySubsequences: false).last ?? "") + let result = service.getSuggestions( + for: sample.text, + peers: [prefix + "z"], + cursorPosition: sample.cursor + ) + #expect(result.suggestions.isEmpty == !sample.hasToken, "\(sample.text) @ \(sample.cursor)") + } + } + @Test("Applying suggestions replaces the range and adds command spacing only when needed") func applySuggestionReplacesRangeAndHandlesCommandSpacing() { let service = AutocompleteService() diff --git a/bitchatTests/Services/BLEAnnounceHandlerTests.swift b/bitchatTests/Services/BLEAnnounceHandlerTests.swift index 8e3f533d..fdfdfa40 100644 --- a/bitchatTests/Services/BLEAnnounceHandlerTests.swift +++ b/bitchatTests/Services/BLEAnnounceHandlerTests.swift @@ -741,14 +741,14 @@ struct BLEAnnounceHandlerTests { ) let handler = BLEAnnounceHandler(environment: environment) - func makeSignedAnnounce(nickname: String, signer: NoiseEncryptionService) throws -> BitchatPacket { + func makeSignedAnnounce(nickname: String, signer: NoiseEncryptionService) -> BitchatPacket? { let announcement = AnnouncementPacket( nickname: nickname, noisePublicKey: victimNoiseKey, signingPublicKey: signer.getSigningPublicKeyData(), directNeighbors: nil ) - let payload = try #require(announcement.encode()) + guard let payload = announcement.encode() else { return nil } let packet = BitchatPacket( type: MessageType.announce.rawValue, senderID: Data(hexString: peerID.id) ?? Data(), @@ -758,11 +758,11 @@ struct BLEAnnounceHandlerTests { signature: nil, ttl: TransportConfig.messageTTLDefault ) - return try #require(signer.signPacket(packet)) + return signer.signPacket(packet) } // Legitimate announce from the victim is accepted and pinned. - let victimAnnounce = try makeSignedAnnounce(nickname: "victim", signer: victim) + let victimAnnounce = try #require(makeSignedAnnounce(nickname: "victim", signer: victim)) handler.handle(victimAnnounce, from: peerID) #expect(box.registry.info(for: peerID)?.nickname == "victim") @@ -770,7 +770,7 @@ struct BLEAnnounceHandlerTests { #expect(box.persistedIdentities.count == 1) // Attacker announce with a valid self-signature must be rejected. - let attackerAnnounce = try makeSignedAnnounce(nickname: "attacker", signer: attacker) + let attackerAnnounce = try #require(makeSignedAnnounce(nickname: "attacker", signer: attacker)) handler.handle(attackerAnnounce, from: peerID) #expect(box.registry.info(for: peerID)?.nickname == "victim") @@ -778,7 +778,7 @@ struct BLEAnnounceHandlerTests { #expect(box.persistedIdentities.count == 1) // The victim's subsequent announces (same pinned key) still work. - let victimRename = try makeSignedAnnounce(nickname: "victim-renamed", signer: victim) + let victimRename = try #require(makeSignedAnnounce(nickname: "victim-renamed", signer: victim)) handler.handle(victimRename, from: peerID) #expect(box.registry.info(for: peerID)?.nickname == "victim-renamed") @@ -862,14 +862,14 @@ struct BLEAnnounceHandlerTests { } let handler = BLEAnnounceHandler(environment: makeEnvironment(identityManager: identityManager)) - func makeSignedAnnounce(nickname: String, signer: NoiseEncryptionService) throws -> BitchatPacket { + func makeSignedAnnounce(nickname: String, signer: NoiseEncryptionService) -> BitchatPacket? { let announcement = AnnouncementPacket( nickname: nickname, noisePublicKey: victimNoiseKey, signingPublicKey: signer.getSigningPublicKeyData(), directNeighbors: nil ) - let payload = try #require(announcement.encode()) + guard let payload = announcement.encode() else { return nil } let packet = BitchatPacket( type: MessageType.announce.rawValue, senderID: Data(hexString: peerID.id) ?? Data(), @@ -879,7 +879,7 @@ struct BLEAnnounceHandlerTests { signature: nil, ttl: TransportConfig.messageTTLDefault ) - return try #require(signer.signPacket(packet)) + return signer.signPacket(packet) } func persistedIdentity() -> CryptographicIdentity? { @@ -888,7 +888,7 @@ struct BLEAnnounceHandlerTests { } // 1. Victim announces: pinned in the registry and persisted. - handler.handle(try makeSignedAnnounce(nickname: "victim", signer: victim), from: peerID) + handler.handle(try #require(makeSignedAnnounce(nickname: "victim", signer: victim)), from: peerID) #expect(box.registry.info(for: peerID)?.signingPublicKey == victim.getSigningPublicKeyData()) #expect(persistedIdentity()?.signingPublicKey == victim.getSigningPublicKeyData()) @@ -898,13 +898,13 @@ struct BLEAnnounceHandlerTests { // 3. Attacker replay with own signing key: rejected via the persisted // pin, and neither the registry nor the persisted identity change. - handler.handle(try makeSignedAnnounce(nickname: "attacker", signer: attacker), from: peerID) + handler.handle(try #require(makeSignedAnnounce(nickname: "attacker", signer: attacker)), from: peerID) #expect(box.registry.info(for: peerID) == nil) #expect(persistedIdentity()?.signingPublicKey == victim.getSigningPublicKeyData()) #expect(identityManager.getSocialIdentity(for: victimNoiseKey.sha256Fingerprint())?.claimedNickname == "victim") // 4. Victim re-announces with the same signing key: accepted again. - handler.handle(try makeSignedAnnounce(nickname: "victim", signer: victim), from: peerID) + handler.handle(try #require(makeSignedAnnounce(nickname: "victim", signer: victim)), from: peerID) #expect(box.registry.info(for: peerID)?.nickname == "victim") #expect(box.registry.info(for: peerID)?.signingPublicKey == victim.getSigningPublicKeyData()) @@ -919,7 +919,7 @@ struct BLEAnnounceHandlerTests { ) box.registry = BLEPeerRegistry() let restartedHandler = BLEAnnounceHandler(environment: makeEnvironment(identityManager: reloadedManager)) - restartedHandler.handle(try makeSignedAnnounce(nickname: "attacker", signer: attacker), from: peerID) + restartedHandler.handle(try #require(makeSignedAnnounce(nickname: "attacker", signer: attacker)), from: peerID) #expect(box.registry.info(for: peerID) == nil) #expect( reloadedManager.getCryptoIdentitiesByPeerIDPrefix(peerID).first?.signingPublicKey @@ -927,7 +927,7 @@ struct BLEAnnounceHandlerTests { ) // ...while the victim is accepted after the restart. - restartedHandler.handle(try makeSignedAnnounce(nickname: "victim", signer: victim), from: peerID) + restartedHandler.handle(try #require(makeSignedAnnounce(nickname: "victim", signer: victim)), from: peerID) #expect(box.registry.info(for: peerID)?.signingPublicKey == victim.getSigningPublicKeyData()) } diff --git a/bitchatTests/Services/ComposerDraftStoreTests.swift b/bitchatTests/Services/ComposerDraftStoreTests.swift index ff071ae5..d4f0a603 100644 --- a/bitchatTests/Services/ComposerDraftStoreTests.swift +++ b/bitchatTests/Services/ComposerDraftStoreTests.swift @@ -6,14 +6,14 @@ import BitFoundation @Suite(.serialized) struct ComposerDraftStoreTests { /// Isolate each test from leftover in-memory drafts. - private func withCleanStore(_ body: () throws -> Void) rethrows { + private func withCleanStore(_ body: () -> Void) { ComposerDraftStore.replaceAllForTesting([:]) defer { ComposerDraftStore.replaceAllForTesting([:]) } - try body() + body() } - @Test func emptyDraftIsNotStored() throws { - try withCleanStore { + @Test func emptyDraftIsNotStored() { + withCleanStore { ComposerDraftStore.save("hello", for: .mesh) ComposerDraftStore.save(" ", for: .mesh) // Whitespace-only is still a draft the user typed; empty string clears. @@ -23,8 +23,8 @@ struct ComposerDraftStoreTests { } } - @Test func draftsAreIsolatedPerConversation() throws { - try withCleanStore { + @Test func draftsAreIsolatedPerConversation() { + withCleanStore { let peer = PeerID(str: "aabbccddeeff0011") ComposerDraftStore.save("mesh draft", for: .mesh) ComposerDraftStore.save("geo draft", for: .location(geohash: "u4pruy")) @@ -37,8 +37,8 @@ struct ComposerDraftStoreTests { } } - @Test func geohashKeysAreCaseInsensitive() throws { - try withCleanStore { + @Test func geohashKeysAreCaseInsensitive() { + withCleanStore { ComposerDraftStore.save("city chat", for: .location(geohash: "U4PRUY")) #expect(ComposerDraftStore.load(.location(geohash: "u4pruy")) == "city chat") } @@ -61,16 +61,16 @@ struct ComposerDraftStoreTests { #expect(withoutFP == .privateChat(stableID: peer.id)) } - @Test func longDraftsAreTruncated() throws { - try withCleanStore { + @Test func longDraftsAreTruncated() { + withCleanStore { let long = String(repeating: "a", count: ComposerDraftStore.maxDraftLength + 50) ComposerDraftStore.save(long, for: .mesh) #expect(ComposerDraftStore.load(.mesh).count == ComposerDraftStore.maxDraftLength) } } - @Test func resetClearsAllDrafts() throws { - try withCleanStore { + @Test func resetClearsAllDrafts() { + withCleanStore { ComposerDraftStore.save("keep quiet", for: .mesh) ComposerDraftStore.reset() #expect(ComposerDraftStore.load(.mesh).isEmpty) @@ -78,8 +78,8 @@ struct ComposerDraftStoreTests { } } - @Test func maxDraftCountEvictsOldestKeys() throws { - try withCleanStore { + @Test func maxDraftCountEvictsOldestKeys() { + withCleanStore { for index in 0.. [CommandGeoParticipant] { [] } func nostrPubkeyForDisplayName(_ displayName: String) -> String? { nil } + func geohashBlockListDidChange() {} func startPrivateChat(with peerID: PeerID) {} func sendPrivateMessage(_ content: String, to peerID: PeerID) {} func clearCurrentPublicTimeline() {} diff --git a/bitchatTests/Services/PrivateChatManagerTests.swift b/bitchatTests/Services/PrivateChatManagerTests.swift index 69b49aaf..f0ad8437 100644 --- a/bitchatTests/Services/PrivateChatManagerTests.swift +++ b/bitchatTests/Services/PrivateChatManagerTests.swift @@ -258,6 +258,147 @@ struct PrivateChatManagerTests { #expect(!manager.unreadMessages.contains(tempPeerID)) } + @Test @MainActor + func consolidateMessages_leavesMyGeoDMThreadOutOfANamesakesChat() async { + // My geo DMs carry my plain nickname (sendGeohashDM), so a thread of + // my rows matches any mesh peer who shares that nickname, though my + // rows say nothing about who the thread is with. Folded into the + // namesake's chat, my thread with a geohash stranger would send a + // reply typed there to the namesake. + let transport = MockTransport() + transport.myPeerID = PeerID(str: "a1b2c3d4e5f60718") + let (manager, store) = Self.makeManager(transport: transport) + let namesakePeerID = PeerID(str: "0011223344556677") + let tempPeerID = PeerID(nostr_: String(repeating: "42", count: 32)) + + store.append( + BitchatMessage( + id: "my-geo-dm", + sender: "alice", + content: "hi from the geohash", + timestamp: Date(), + isRelay: false, + isPrivate: true, + recipientNickname: "alice", + senderPeerID: transport.myPeerID, + deliveryStatus: .delivered(to: "alice", at: Date()) + ), + to: .directPeer(tempPeerID) + ) + + _ = manager.consolidateMessages(for: namesakePeerID, peerNickname: "alice", persistedReadReceipts: []) + + // The thread stays where it is, my row still mine... + #expect(manager.privateChats[tempPeerID]?.map(\.id) == ["my-geo-dm"]) + #expect(manager.privateChats[tempPeerID]?.first?.senderPeerID == transport.myPeerID) + // ...and no thread with the namesake appears. + #expect(manager.privateChats[namesakePeerID] == nil) + + // Opening the namesake's chat finds no sent rows of mine to sync + // receipts for, and sends none. + var externalReceipts = Set() + manager.syncReadReceiptsForSentMessages(peerID: namesakePeerID, externalReceipts: &externalReceipts) + #expect(externalReceipts.isEmpty) + #expect(manager.sentReadReceipts.isEmpty) + manager.markAsRead(from: namesakePeerID) + #expect(transport.sentReadReceipts.isEmpty) + } + + @Test @MainActor + func consolidateMessages_stillMovesThePeersOwnGeoDMThreadBesideMine() async { + // Skipping my thread is per thread: the peer's own thread, with the + // same nickname, still folds into their chat. + let transport = MockTransport() + transport.myPeerID = PeerID(str: "a1b2c3d4e5f60718") + let (manager, store) = Self.makeManager(transport: transport) + let peerID = PeerID(str: "0011223344556677") + let myThread = PeerID(nostr_: String(repeating: "42", count: 32)) + let theirThread = PeerID(nostr_: String(repeating: "43", count: 32)) + + store.append( + BitchatMessage( + id: "my-geo-dm", + sender: "alice", + content: "hi from the geohash", + timestamp: Date(), + isRelay: false, + isPrivate: true, + recipientNickname: "alice", + senderPeerID: transport.myPeerID, + deliveryStatus: .sent + ), + to: .directPeer(myThread) + ) + store.append( + BitchatMessage( + id: "their-geo-dm", + sender: "alice", + content: "hi from them", + timestamp: Date(), + isRelay: false, + isPrivate: true, + recipientNickname: "alice", + senderPeerID: theirThread + ), + to: .directPeer(theirThread) + ) + store.markUnread(.directPeer(theirThread)) + + let hadUnread = manager.consolidateMessages(for: peerID, peerNickname: "alice", persistedReadReceipts: []) + + #expect(hadUnread) + #expect(manager.privateChats[theirThread] == nil) + #expect(manager.privateChats[peerID]?.map(\.id) == ["their-geo-dm"]) + #expect(manager.privateChats[peerID]?.first?.senderPeerID == peerID) + #expect(manager.unreadMessages.contains(peerID)) + #expect(manager.privateChats[myThread]?.map(\.id) == ["my-geo-dm"]) + } + + @Test @MainActor + func consolidateMessages_leavesAThreadWithMyRepliesOutOfANamesakesChat() async { + // One row of mine is enough, not a thread of only mine: their rows + // and my replies all read "alice", so the nickname check alone would + // fold the thread, my replies with it. + let transport = MockTransport() + transport.myPeerID = PeerID(str: "a1b2c3d4e5f60718") + let (manager, store) = Self.makeManager(transport: transport) + let namesakePeerID = PeerID(str: "0011223344556677") + let thread = PeerID(nostr_: String(repeating: "44", count: 32)) + + store.append( + BitchatMessage( + id: "their-geo-dm", + sender: "alice", + content: "hi from them", + timestamp: Date().addingTimeInterval(-60), + isRelay: false, + isPrivate: true, + recipientNickname: "alice", + senderPeerID: thread + ), + to: .directPeer(thread) + ) + store.append( + BitchatMessage( + id: "my-reply", + sender: "alice", + content: "hi back", + timestamp: Date(), + isRelay: false, + isPrivate: true, + recipientNickname: "alice", + senderPeerID: transport.myPeerID, + deliveryStatus: .sent + ), + to: .directPeer(thread) + ) + + _ = manager.consolidateMessages(for: namesakePeerID, peerNickname: "alice", persistedReadReceipts: []) + + #expect(manager.privateChats[thread]?.map(\.id) == ["their-geo-dm", "my-reply"]) + #expect(manager.privateChats[namesakePeerID] == nil) + } + @Test @MainActor func syncReadReceiptsForSentMessages_onlyCopiesDeliveredAndRead() async { let transport = MockTransport() @@ -304,7 +445,7 @@ struct PrivateChatManagerTests { } var externalReceipts = Set() - manager.syncReadReceiptsForSentMessages(peerID: peerID, nickname: "Me", externalReceipts: &externalReceipts) + manager.syncReadReceiptsForSentMessages(peerID: peerID, externalReceipts: &externalReceipts) #expect(externalReceipts == Set(["sent-read", "sent-delivered"])) #expect(manager.sentReadReceipts == Set(["sent-read", "sent-delivered"])) diff --git a/bitchatTests/ThemedRootBackgroundTests.swift b/bitchatTests/ThemedRootBackgroundTests.swift new file mode 100644 index 00000000..6d32b8bb --- /dev/null +++ b/bitchatTests/ThemedRootBackgroundTests.swift @@ -0,0 +1,68 @@ +import CoreGraphics +import SwiftUI +import Testing +@testable import bitchat + +/// The themed backdrop has to cover the safe-area insets too. If it stops at +/// the safe area, a sheet's own background shows through the home-indicator +/// inset: a dark-gray band under the Matrix people list in dark mode. +@Suite("ThemedRootBackground") +@MainActor +struct ThemedRootBackgroundTests { + @Test(arguments: AppTheme.allCases, ColorScheme.allCases) + func sheetBackground_fillsBottomSafeAreaInset(theme: AppTheme, colorScheme: ColorScheme) throws { + // A SwiftUI safe-area inset stands in for the home indicator: it + // reserves the bottom 20 pt, the way a sheet's bottom inset does. + let view = Color.clear + .themedSheetBackground() + .safeAreaInset(edge: .bottom, spacing: 0) { + Color.clear.frame(height: 20) + } + .frame(width: 40, height: 100) + .environment(\.appTheme, theme) + .environment(\.colorScheme, colorScheme) + + let image = try RenderedPixels(view) + // Sanity check: the backdrop renders inside the safe area. + #expect(image.alpha(x: 20, y: 40) == 255) + // Regression: the backdrop also covers the inset. + #expect(image.alpha(x: 20, y: 90) == 255) + } +} + +/// RGBA8 pixels of a view rendered offscreen at 1x. +@MainActor +private struct RenderedPixels { + private let width: Int + private let bytes: [UInt8] + + init(_ view: some View) throws { + let renderer = ImageRenderer(content: view) + renderer.scale = 1 + let image = try #require(renderer.cgImage) + width = image.width + var buffer = [UInt8](repeating: 0, count: image.width * image.height * 4) + let drawn = buffer.withUnsafeMutableBytes { raw -> Bool in + guard let context = CGContext( + data: raw.baseAddress, + width: image.width, + height: image.height, + bitsPerComponent: 8, + bytesPerRow: image.width * 4, + space: CGColorSpaceCreateDeviceRGB(), + bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue + ) else { + return false + } + context.draw(image, in: CGRect(x: 0, y: 0, width: image.width, height: image.height)) + return true + } + try #require(drawn) + bytes = buffer + } + + /// Alpha at (x, y), with y measured from the top edge. + func alpha(x: Int, y: Int) -> UInt8 { + bytes[(y * width + x) * 4 + 3] + } +} diff --git a/bitchatTests/ViewSmokeTests.swift b/bitchatTests/ViewSmokeTests.swift index 6ab5290e..f12832d0 100644 --- a/bitchatTests/ViewSmokeTests.swift +++ b/bitchatTests/ViewSmokeTests.swift @@ -669,6 +669,8 @@ struct ViewSmokeTests { isPrivate: false, deliveryStatus: .sent ) + // Stamped with my peer ID, as every DM I send is, so the row takes + // the own-DM delivery-status branch. let paymentMessage = BitchatMessage( sender: viewModel.nickname, content: "lightning:lnbc1test cashuA_test-token", @@ -676,6 +678,7 @@ struct ViewSmokeTests { isRelay: false, isPrivate: true, recipientNickname: "Bob", + senderPeerID: viewModel.meshService.myPeerID, deliveryStatus: .partiallyDelivered(reached: 1, total: 2) ) diff --git a/localPackages/BitFoundation/Sources/BitFoundation/BitchatMessage.swift b/localPackages/BitFoundation/Sources/BitFoundation/BitchatMessage.swift index 064cd5da..d07d815e 100644 --- a/localPackages/BitFoundation/Sources/BitFoundation/BitchatMessage.swift +++ b/localPackages/BitFoundation/Sources/BitFoundation/BitchatMessage.swift @@ -44,7 +44,19 @@ public final class BitchatMessage: Codable { public func setCachedFormattedText(_ text: AttributedString, isDark: Bool, isSelf: Bool, variant: String = "") { _cachedFormattedText["\(variant)\(isDark)-\(isSelf)"] = text } - + + // Cached content scan for row rendering (not included in Codable). + // `content` is immutable, so a cached scan never goes stale. + private var _cachedContentScan: ContentScan? + + public func getCachedContentScan() -> ContentScan? { + _cachedContentScan + } + + public func setCachedContentScan(_ scan: ContentScan) { + _cachedContentScan = scan + } + // Codable implementation enum CodingKeys: String, CodingKey { case id, sender, content, timestamp, isRelay, originalSender @@ -100,6 +112,26 @@ public final class BitchatMessage: Codable { } } +// MARK: - Content Scan + +extension BitchatMessage { + /// What a message row derives from `content`: the payment links rendered + /// as chips and whether the text collapses behind "show more". Deriving + /// them takes several regex passes over the content, so the renderer + /// computes them once and caches the result on the message. + public struct ContentScan: Equatable { + public let cashuLinks: [String] + public let lightningLinks: [String] + public let isLongForDisplay: Bool + + public init(cashuLinks: [String], lightningLinks: [String], isLongForDisplay: Bool) { + self.cashuLinks = cashuLinks + self.lightningLinks = lightningLinks + self.isLongForDisplay = isLongForDisplay + } + } +} + // MARK: - Equatable Conformance extension BitchatMessage: Equatable { diff --git a/localPackages/BitFoundation/Sources/BitFoundation/Data+Hex.swift b/localPackages/BitFoundation/Sources/BitFoundation/Data+Hex.swift index 8b60e0b1..9e5aa99c 100644 --- a/localPackages/BitFoundation/Sources/BitFoundation/Data+Hex.swift +++ b/localPackages/BitFoundation/Sources/BitFoundation/Data+Hex.swift @@ -9,13 +9,28 @@ import struct Foundation.Data public extension Data { + /// Lowercase hex, two digits per byte, no separators. + /// + /// Table lookup instead of `String(format:)` per byte: Nostr public keys + /// are re-encoded on hot paths (geochat roster rebuilds touch one per + /// participant), and the formatted version cost ~14 µs per 32-byte key. func hexEncodedString() -> String { if self.isEmpty { return "" } - return self.map { String(format: "%02x", $0) }.joined() + return String(unsafeUninitializedCapacity: count * 2) { buffer in + var index = 0 + for byte in self { + buffer[index] = Self.lowercaseHexDigits[Int(byte >> 4)] + buffer[index + 1] = Self.lowercaseHexDigits[Int(byte & 0x0F)] + index += 2 + } + return index + } } + private static let lowercaseHexDigits: [UInt8] = Array("0123456789abcdef".utf8) + /// Initialize Data from a hex string. /// - Parameter hexString: A hex string, optionally prefixed with "0x" or "0X". /// Whitespace is trimmed. Must have even length after prefix removal. diff --git a/localPackages/BitFoundation/Tests/BitFoundationTests/DataHexTests.swift b/localPackages/BitFoundation/Tests/BitFoundationTests/DataHexTests.swift index 9940fb50..d748f869 100644 --- a/localPackages/BitFoundation/Tests/BitFoundationTests/DataHexTests.swift +++ b/localPackages/BitFoundation/Tests/BitFoundationTests/DataHexTests.swift @@ -32,6 +32,39 @@ struct DataHexTests { #expect(Data(hexString: bytes.hexEncodedString()) == bytes) } + // MARK: - Encoding + + /// Hex strings are identities (Nostr pubkeys, peer IDs) and wire values, + /// so the encoder must stay byte-identical to the `%02x` formatting it + /// replaced: lowercase, zero-padded, no separators. + @Test func encodes_every_byte_like_printf_hex() { + let bytes = Data((0...255).map { UInt8($0) }) + let expected = bytes.map { String(format: "%02x", $0) }.joined() + #expect(bytes.hexEncodedString() == expected) + } + + @Test func encodes_empty_data_as_empty_string() { + #expect(Data().hexEncodedString() == "") + } + + @Test func encodes_slices_from_their_own_start_index() { + let bytes = Data([0x00, 0xde, 0xad, 0xbe, 0xef, 0xff]) + let slice = bytes[1..<5] + #expect(slice.hexEncodedString() == "deadbeef") + } + + @Test func encodes_varied_lengths_like_printf_hex() { + var state: UInt64 = 0x9E37_79B9_7F4A_7C15 + for length in 1...96 { + let bytes = Data((0..> 56) + }) + let expected = bytes.map { String(format: "%02x", $0) }.joined() + #expect(bytes.hexEncodedString() == expected) + } + } + // MARK: - Rejected forms @Test func rejects_odd_length() {