Skip to content

Commit 642e124

Browse files
wpmobilebotkean
andauthored
Merge release/26.3.1 into trunk (#24862)
* Bump version number * Fix an issue with top posts not loading for some reason * Fix crash in Reader Article view * Remove the refreshing indicator for posts --------- Co-authored-by: Alex Grebenyuk <[email protected]>
1 parent f693ae8 commit 642e124

13 files changed

+93
-28
lines changed

Modules/Sources/WordPressKit/StatsFileDownloadsTimeIntervalData.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ extension StatsFileDownloadsTimeIntervalData: StatsTimeIntervalData {
4444
public init?(date: Date, period: StatsPeriodUnit, jsonDictionary: [String: AnyObject]) {
4545
guard
4646
let unwrappedDays = type(of: self).unwrapDaysDictionary(jsonDictionary: jsonDictionary),
47-
let fileDownloadsDict = unwrappedDays["files"] as? [[String: AnyObject]]
47+
let fileDownloadsDict = Bamboozled.parseArray(unwrappedDays["files"])
4848
else {
4949
return nil
5050
}

Modules/Sources/WordPressKit/StatsSearchTermTimeIntervalData.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ extension StatsSearchTermTimeIntervalData: StatsTimeIntervalData {
4545
let totalSearchTerms = unwrappedDays["total_search_terms"] as? Int,
4646
let hiddenSearchTerms = unwrappedDays["encrypted_search_terms"] as? Int,
4747
let otherSearchTerms = unwrappedDays["other_search_terms"] as? Int,
48-
let searchTermsDict = unwrappedDays["search_terms"] as? [[String: AnyObject]]
48+
let searchTermsDict = Bamboozled.parseArray(unwrappedDays["search_terms"])
4949
else {
5050
return nil
5151
}

Modules/Sources/WordPressKit/StatsServiceRemoteV2.swift

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,37 @@ extension StatsTimeIntervalData {
444444
}
445445
return nil
446446
}
447+
}
447448

449+
enum Bamboozled {
450+
/// Sometimes PHP returns a dictionary with numbers as keys instead of an
451+
/// actual array. This fixes it.
452+
static func parseArray(_ object: AnyObject?) -> [[String: AnyObject]]? {
453+
guard let object else {
454+
return nil
455+
}
456+
if let array = object as? [[String: AnyObject]] {
457+
return array
458+
}
459+
if let dictionary = object as? [String: [String: AnyObject]] {
460+
return dictionary.sorted { lhs, rhs in
461+
if let lhs = Int(lhs.key), let rhs = Int(rhs.key) {
462+
return lhs < rhs
463+
}
464+
return lhs.key.compare(rhs.key, options: .numeric) == .orderedAscending
465+
}.map {
466+
$0.value
467+
}
468+
}
469+
if let dictionary = object as? [Int: [String: AnyObject]] {
470+
return dictionary.sorted { lhs, rhs in
471+
lhs.key < rhs.key
472+
}.map {
473+
$0.value
474+
}
475+
}
476+
return nil
477+
}
448478
}
449479

450480
// We'll bring `StatsPeriodUnit` into this file when the "old" `WPStatsServiceRemote` gets removed.

Modules/Sources/WordPressKit/StatsTopAuthorsTimeIntervalData.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ extension StatsTopAuthorsTimeIntervalData: StatsTimeIntervalData {
7070
public init?(date: Date, period: StatsPeriodUnit, jsonDictionary: [String: AnyObject]) {
7171
guard
7272
let unwrappedDays = type(of: self).unwrapDaysDictionary(jsonDictionary: jsonDictionary),
73-
let authors = unwrappedDays["authors"] as? [[String: AnyObject]]
73+
let authors = Bamboozled.parseArray(unwrappedDays["authors"])
7474
else {
7575
return nil
7676
}
@@ -87,7 +87,7 @@ extension StatsTopAuthor {
8787
let name = jsonDictionary["name"] as? String,
8888
let views = jsonDictionary["views"] as? Int,
8989
let avatar = jsonDictionary["avatar"] as? String,
90-
let posts = jsonDictionary["posts"] as? [[String: AnyObject]]
90+
let posts = Bamboozled.parseArray(jsonDictionary["posts"])
9191
else {
9292
return nil
9393
}

Modules/Sources/WordPressKit/StatsTopClicksTimeIntervalData.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ extension StatsTopClicksTimeIntervalData: StatsTimeIntervalData {
5050
public init?(date: Date, period: StatsPeriodUnit, jsonDictionary: [String: AnyObject]) {
5151
guard
5252
let unwrappedDays = type(of: self).unwrapDaysDictionary(jsonDictionary: jsonDictionary),
53-
let clicks = unwrappedDays["clicks"] as? [[String: AnyObject]]
53+
let clicks = Bamboozled.parseArray(unwrappedDays["clicks"])
5454
else {
5555
return nil
5656
}

Modules/Sources/WordPressKit/StatsTopCountryTimeIntervalData.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ extension StatsTopCountryTimeIntervalData: StatsTimeIntervalData {
4343
public init?(date: Date, period: StatsPeriodUnit, jsonDictionary: [String: AnyObject]) {
4444
guard
4545
let unwrappedDays = type(of: self).unwrapDaysDictionary(jsonDictionary: jsonDictionary),
46-
let countriesViews = unwrappedDays["views"] as? [[String: AnyObject]]
46+
let countriesViews = Bamboozled.parseArray(unwrappedDays["views"])
4747
else {
4848
return nil
4949
}

Modules/Sources/WordPressKit/StatsTopPostsTimeIntervalData.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ extension StatsTopPostsTimeIntervalData: StatsTimeIntervalData {
2828
public init?(date: Date, period: StatsPeriodUnit, jsonDictionary: [String: AnyObject]) {
2929
guard
3030
let unwrappedDays = type(of: self).unwrapDaysDictionary(jsonDictionary: jsonDictionary),
31-
let posts = unwrappedDays["postviews"] as? [[String: AnyObject]]
31+
let posts = Bamboozled.parseArray(unwrappedDays["postviews"])
3232
else {
3333
return nil
3434
}

Modules/Sources/WordPressKit/StatsTopReferrersTimeIntervalData.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ extension StatsTopReferrersTimeIntervalData: StatsTimeIntervalData {
5151
public init?(date: Date, period: StatsPeriodUnit, jsonDictionary: [String: AnyObject]) {
5252
guard
5353
let unwrappedDays = type(of: self).unwrapDaysDictionary(jsonDictionary: jsonDictionary),
54-
let referrers = unwrappedDays["groups"] as? [[String: AnyObject]]
54+
let referrers = Bamboozled.parseArray(unwrappedDays["groups"])
5555
else {
5656
return nil
5757
}

Modules/Sources/WordPressKit/StatsTopVideosTimeIntervalData.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ extension StatsTopVideosTimeIntervalData: StatsTimeIntervalData {
4848
let unwrappedDays = type(of: self).unwrapDaysDictionary(jsonDictionary: jsonDictionary),
4949
let totalPlayCount = unwrappedDays["total_plays"] as? Int,
5050
let otherPlays = unwrappedDays["other_plays"] as? Int,
51-
let videos = unwrappedDays["plays"] as? [[String: AnyObject]]
51+
let videos = Bamboozled.parseArray(unwrappedDays["plays"])
5252
else {
5353
return nil
5454
}

RELEASE-NOTES.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
26.4
22
-----
33

4+
26.3.1
5+
------
6+
* [*] Fix an issue with Top Posts not loading for some users [#24860]
7+
* [*] Fix crash in Reader Article view [#24857]
8+
* [*] Fix more minor visual glitches on iOS 26 [#24858]
49

510
26.3
611
-----

0 commit comments

Comments
 (0)