Skip to content

Commit 517977b

Browse files
authored
Merge pull request #647 from session-foundation/dev
Release 2.14.8 RC2
2 parents 50efdef + 926c64f commit 517977b

File tree

4 files changed

+54
-87
lines changed

4 files changed

+54
-87
lines changed

Session.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8568,7 +8568,7 @@
85688568
CODE_SIGN_IDENTITY = "iPhone Developer";
85698569
COMPILE_LIB_SESSION = "";
85708570
COPY_PHASE_STRIP = NO;
8571-
CURRENT_PROJECT_VERSION = 678;
8571+
CURRENT_PROJECT_VERSION = 680;
85728572
ENABLE_BITCODE = NO;
85738573
ENABLE_STRICT_OBJC_MSGSEND = YES;
85748574
ENABLE_TESTABILITY = YES;
@@ -8649,7 +8649,7 @@
86498649
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
86508650
CODE_SIGN_IDENTITY = "iPhone Distribution";
86518651
COMPILE_LIB_SESSION = "";
8652-
CURRENT_PROJECT_VERSION = 678;
8652+
CURRENT_PROJECT_VERSION = 680;
86538653
ENABLE_BITCODE = NO;
86548654
ENABLE_MODULE_VERIFIER = YES;
86558655
ENABLE_STRICT_OBJC_MSGSEND = YES;
@@ -9349,7 +9349,7 @@
93499349
CODE_SIGN_IDENTITY = "iPhone Developer";
93509350
COMPILE_LIB_SESSION = YES;
93519351
COPY_PHASE_STRIP = NO;
9352-
CURRENT_PROJECT_VERSION = 678;
9352+
CURRENT_PROJECT_VERSION = 680;
93539353
ENABLE_BITCODE = NO;
93549354
ENABLE_STRICT_OBJC_MSGSEND = YES;
93559355
ENABLE_TESTABILITY = YES;
@@ -9938,7 +9938,7 @@
99389938
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
99399939
CODE_SIGN_IDENTITY = "iPhone Distribution";
99409940
COMPILE_LIB_SESSION = YES;
9941-
CURRENT_PROJECT_VERSION = 678;
9941+
CURRENT_PROJECT_VERSION = 680;
99429942
ENABLE_BITCODE = NO;
99439943
ENABLE_STRICT_OBJC_MSGSEND = YES;
99449944
GCC_NO_COMMON_BLOCKS = YES;

Session/Meta/Translations/InfoPlist.xcstrings

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,6 +1558,12 @@
15581558
"value" : "Session necesita acceso a la red local para realizar llamadas de voz y video."
15591559
}
15601560
},
1561+
"fi" : {
1562+
"stringUnit" : {
1563+
"state" : "translated",
1564+
"value" : "Session tarvitsee pääsyn paikalliseen verkkoon soittaakseen ääni- ja videopuheluja."
1565+
}
1566+
},
15611567
"fr" : {
15621568
"stringUnit" : {
15631569
"state" : "translated",

Session/Utilities/IP2Country.swift

Lines changed: 38 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -160,15 +160,16 @@ fileprivate class IP2Country: IP2CountryCacheType {
160160
/// We found a separator so create a string from the bytes we just passed
161161
let length: Int = (i - (lastIndex - contentData.startIndex))
162162

163-
if length > 0 {
164-
let dataChunk: Data = Data(
165-
bytes: baseAddress.advanced(by: lastIndex - contentData.startIndex),
166-
count: length
167-
)
168-
169-
if let stringValue: String = String(data: dataChunk, encoding: .utf8) {
170-
result.append(stringValue)
171-
}
163+
let dataChunk: Data = Data(
164+
bytes: baseAddress.advanced(by: lastIndex - contentData.startIndex),
165+
count: length
166+
)
167+
168+
if let stringValue: String = String(data: dataChunk, encoding: .utf8) {
169+
result.append(stringValue)
170+
}
171+
else {
172+
result.append("") /// Need to insert empty entries as well to ensure the indexes are correct
172173
}
173174

174175
/// Move past the separator
@@ -214,87 +215,43 @@ fileprivate class IP2Country: IP2CountryCacheType {
214215

215216
init(using dependencies: Dependencies) {
216217
/// Ensure the lookup tables get loaded in the background
217-
DispatchQueue.global(qos: .utility).async { [weak self] in
218+
Task.detached(priority: .utility) { [weak self] in
218219
_ = self?.cache
219-
220-
/// Then register for path change callbacks which will be used to update the country name cache
221-
self?.registerNetworkObservables(using: dependencies)
220+
self?._cacheLoaded.send(true)
221+
Log.info(.ip2Country, "IP2Country cache loaded.")
222222
}
223223
}
224224

225225
// MARK: - Functions
226226

227-
private func registerNetworkObservables(using dependencies: Dependencies) {
228-
/// Register for path change callbacks which will be used to update the country name cache
229-
dependencies[cache: .libSessionNetwork].paths
230-
.subscribe(on: DispatchQueue.global(qos: .utility), using: dependencies)
231-
.receive(on: DispatchQueue.global(qos: .utility), using: dependencies)
232-
.sink(
233-
receiveCompletion: { [weak self] _ in
234-
/// If the stream completes it means the network cache was reset in which case we want to
235-
/// re-register for updates in the next run loop (as the new cache should be created by then)
236-
DispatchQueue.global(qos: .background).async {
237-
self?.registerNetworkObservables(using: dependencies)
238-
}
239-
},
240-
receiveValue: { [weak self] paths in
241-
dependencies.mutate(cache: .ip2Country) { _ in
242-
self?.populateCacheIfNeeded(paths: paths)
243-
}
244-
}
245-
)
246-
.store(in: &disposables)
247-
}
248-
249-
private func populateCacheIfNeeded(paths: [[LibSession.Snode]]) {
250-
guard !paths.isEmpty else { return }
251-
252-
paths.forEach { path in
253-
path.forEach { snode in
254-
self.cacheCountry(for: snode.ip, inCache: &countryNamesCache)
255-
}
256-
}
257-
258-
self._cacheLoaded.send(true)
259-
Log.info(.ip2Country, "Update onion request path countries.")
260-
}
261-
262-
private func cacheCountry(for ip: String, inCache nameCache: inout [String: String]) {
263-
let currentLocale: String = self.currentLocale // Store local copy for efficiency
264-
265-
guard nameCache["\(ip)-\(currentLocale)"] == nil else { return }
266-
267-
/// Code block checks if IP passed is unknown, not supported or blocked
268-
guard
269-
let ipAsInt: Int64 = IPv4.toInt(ip),
270-
let countryBlockGeonameIdIndex: Int = cache.countryBlocksIPInt.firstIndex(where: { $0 > ipAsInt }).map({ $0 - 1 })
271-
else { return }
272-
273-
/// Get local index for the current locale
274-
/// When index is not found it should fallback to english
275-
var validLocaleStartIndex: Int? {
276-
cache.countryLocationsLocaleCode.firstIndex(of: currentLocale)
277-
?? cache.countryLocationsLocaleCode.firstIndex(of: "en")
278-
}
279-
280-
guard
281-
let localeStartIndex: Int = validLocaleStartIndex,
282-
let countryNameIndex: Int = Array(cache.countryLocationsGeonameId[localeStartIndex...]).firstIndex(where: { geonameId in
283-
geonameId == cache.countryBlocksGeonameId[countryBlockGeonameIdIndex]
284-
}),
285-
(localeStartIndex + countryNameIndex) < cache.countryLocationsCountryName.count
286-
else { return }
287-
288-
let result: String = cache.countryLocationsCountryName[localeStartIndex + countryNameIndex]
289-
nameCache["\(ip)-\(currentLocale)"] = result
290-
}
291-
292-
// MARK: - Functions
293-
294227
public func country(for ip: String) -> String {
295228
guard _cacheLoaded.value else { return "resolving".localized() }
296229

297-
return (countryNamesCache["\(ip)-\(currentLocale)"] ?? "onionRoutingPathUnknownCountry".localized())
230+
/// Get local index for the current locale (when index is not found it should fallback to english)
231+
let validLocaleStartIndex: Int? = (
232+
cache.countryLocationsLocaleCode.firstIndex(of: currentLocale) ??
233+
cache.countryLocationsLocaleCode.firstIndex(of: "en")
234+
)
235+
let key: String = "\(ip)-\(currentLocale)"
236+
237+
switch countryNamesCache[key] {
238+
case .some(let value): return value
239+
case .none:
240+
guard
241+
let ipAsInt: Int64 = IPv4.toInt(ip),
242+
let countryBlockGeonameIdIndex: Int = cache.countryBlocksIPInt.firstIndex(where: { $0 > ipAsInt }).map({ $0 - 1 }),
243+
let localeStartIndex: Int = validLocaleStartIndex,
244+
let countryNameIndex: Int = Array(cache.countryLocationsGeonameId[localeStartIndex...]).firstIndex(where: { geonameId in
245+
geonameId == cache.countryBlocksGeonameId[countryBlockGeonameIdIndex]
246+
}),
247+
(localeStartIndex + countryNameIndex) < cache.countryLocationsCountryName.count
248+
else { return "onionRoutingPathUnknownCountry".localized() }
249+
250+
let result: String = cache.countryLocationsCountryName[localeStartIndex + countryNameIndex]
251+
countryNamesCache[key] = result
252+
253+
return result
254+
}
298255
}
299256
}
300257

SessionMessagingKit/Shared Models/SessionThreadViewModel.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,15 +1052,19 @@ public extension SessionThreadViewModel {
10521052

10531053
return SQL("""
10541054
(IFNULL(\(thread[.pinnedPriority]), 0) > 0) DESC,
1055-
IFNULL(\(interaction[.timestampMs]), (\(thread[.creationDateTimestamp]) * 1000)) DESC
1055+
IFNULL(\(interaction[.timestampMs]), (\(thread[.creationDateTimestamp]) * 1000)) DESC,
1056+
\(thread[.id]) DESC
10561057
""")
10571058
}()
10581059

10591060
static let messageRequestsOrderSQL: SQL = {
10601061
let thread: TypedTableAlias<SessionThread> = TypedTableAlias()
10611062
let interaction: TypedTableAlias<Interaction> = TypedTableAlias()
10621063

1063-
return SQL("IFNULL(\(interaction[.timestampMs]), (\(thread[.creationDateTimestamp]) * 1000)) DESC")
1064+
return SQL("""
1065+
IFNULL(\(interaction[.timestampMs]), (\(thread[.creationDateTimestamp]) * 1000)) DESC,
1066+
\(thread[.id]) DESC
1067+
""")
10641068
}()
10651069
}
10661070

0 commit comments

Comments
 (0)