Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Modules/Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Modules/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ let package = Package(
.package(url: "https://github.com/wordpress-mobile/GutenbergKit", from: "0.19.0"),
.package(
url: "https://github.com/automattic/wordpress-rs",
exact: "0.7.0"
exact: "0.8.0"
),
.package(
url: "https://github.com/Automattic/color-studio",
Expand Down
4 changes: 2 additions & 2 deletions Modules/Sources/WordPressComments/Models/CommentDetail.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct CommentDetail: Equatable, Sendable {
let parentID: Int64? // nil when the wire value is 0 (top-level)
let contentHTML: String
let link: URL?
let date: Date
let date: Date?
var status: CommentListItem.Status
/// False when the fetch fell back to view context (no email/IP; M3 edit
/// needs content.raw, also unavailable).
Expand Down Expand Up @@ -69,7 +69,7 @@ struct CommentDetail: Equatable, Sendable {
parentID: Int64,
contentHTML: String,
link: String,
date: Date,
date: Date?,
status: CommentListItem.Status,
hasEditContext: Bool
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ struct CommentListItem: Identifiable, Equatable, Sendable {
let avatarURL: URL?
let postID: Int64
let snippet: String
let date: Date
let date: Date?
var status: Status

init(
Expand All @@ -28,7 +28,7 @@ struct CommentListItem: Identifiable, Equatable, Sendable {
avatarURL: URL?,
postID: Int64,
snippet: String,
date: Date,
date: Date?,
status: Status
) {
self.id = id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final class CommentDetailViewModel: ObservableObject {
let authorName: String
let avatarURL: URL?
let postID: Int64
let date: Date
let date: Date?
let status: CommentListItem.Status
}

Expand Down
8 changes: 5 additions & 3 deletions Modules/Sources/WordPressComments/Views/CommentRowView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ struct CommentRowView: View {
.font(.subheadline)
.foregroundStyle(.secondary)
.lineLimit(2)
Text(item.date, format: .relative(presentation: .named))
.font(.caption)
.foregroundStyle(.secondary)
if let date = item.date {
Text(date, format: .relative(presentation: .named))
.font(.caption)
.foregroundStyle(.secondary)
}
}
}
.accessibilityElement(children: .combine)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ struct CommentAuthorHeader: View {
Text(header.authorName)
.font(.subheadline.weight(.semibold))
postLine
Text(header.date, format: .relative(presentation: .named))
.font(.caption)
.foregroundStyle(.secondary)
if let date = header.date {
Text(date, format: .relative(presentation: .named))
.font(.caption)
.foregroundStyle(.secondary)
}
}
Spacer(minLength: 0)
Image(systemName: "info.circle")
Expand Down Expand Up @@ -73,7 +75,9 @@ private struct CommentAuthorInfoSheet: View {
var body: some View {
NavigationStack {
List {
LabeledContent(Strings.infoDateLabel, value: header.date.formatted(.dateTime))
if let date = header.date {
LabeledContent(Strings.infoDateLabel, value: date.formatted(.dateTime))
}
if let url = detail?.authorURL {
Link(destination: url) {
LabeledContent(Strings.infoWebsiteLabel, value: url.absoluteString)
Expand Down
5 changes: 5 additions & 0 deletions Modules/Tests/WordPressCommentsTests/CommentDetailTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,9 @@ struct CommentDetailTests {
let detail = CommentDetail(comment: .detailBuilder(authorName: ""))
#expect(detail.authorName == Strings.anonymousAuthor)
}

@Test func missingDateMapsToNil() {
let detail = CommentDetail(comment: .detailBuilder(date: nil))
#expect(detail.date == nil)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ struct CommentListItemTests {
#expect(item.avatarURL == nil)
}

@Test func missingDateMapsToNil() {
let item = CommentListItem(comment: makeComment(date: nil))
#expect(item.date == nil)
}

@Test func statusMapping() {
#expect(CommentListItem(comment: makeComment(status: .approved)).status == .approved)
#expect(CommentListItem(comment: makeComment(status: .spam)).status == .spam)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ func makeComment(
content: String = "<p>Hello <strong>world</strong></p>",
post: Int64 = 10,
status: CommentStatus = .approved,
date: Date = Date(timeIntervalSince1970: 1_700_000_000)
date: Date? = Date(timeIntervalSince1970: 1_700_000_000)
) -> CommentWithViewContext {
CommentWithViewContext(
id: id,
author: 1,
authorName: authorName,
authorUrl: "",
content: CommentContentWithViewContext(rendered: content),
date: "2023-11-14T22:13:20",
date: WpDateString(value: "2023-11-14T22:13:20"),
dateGmt: date,
link: "https://example.com/?p=\(post)#comment-\(id)",
parent: 0,
Expand Down Expand Up @@ -49,15 +49,15 @@ extension CommentWithViewContext {
post: Int64 = 10,
parent: Int64 = 0,
status: CommentStatus = .approved,
date: Date = Date(timeIntervalSince1970: 1_700_000_000)
date: Date? = Date(timeIntervalSince1970: 1_700_000_000)
) -> CommentWithViewContext {
CommentWithViewContext(
id: id,
author: 1,
authorName: authorName,
authorUrl: authorUrl,
content: CommentContentWithViewContext(rendered: content),
date: "2023-11-14T22:13:20",
date: WpDateString(value: "2023-11-14T22:13:20"),
dateGmt: date,
link: "https://example.com/?p=\(post)#comment-\(id)",
parent: parent,
Expand All @@ -82,7 +82,7 @@ extension CommentWithEditContext {
post: Int64 = 10,
parent: Int64 = 0,
status: CommentStatus = .approved,
date: Date = Date(timeIntervalSince1970: 1_700_000_000)
date: Date? = Date(timeIntervalSince1970: 1_700_000_000)
) -> CommentWithEditContext {
CommentWithEditContext(
id: id,
Expand All @@ -93,7 +93,7 @@ extension CommentWithEditContext {
authorUrl: authorUrl,
authorUserAgent: "",
content: CommentContentWithEditContext(raw: content, rendered: content),
date: "2023-11-14T22:13:20",
date: WpDateString(value: "2023-11-14T22:13:20"),
dateGmt: date,
link: "https://example.com/?p=\(post)#comment-\(id)",
parent: parent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ final class MockUsersRequestExecutor: UsersRequestExecutor, @unchecked Sendable
locale: "en_US",
nickname: "testuser",
slug: "testuser",
registeredDate: "2024-01-01T00:00:00",
registeredDate: Date(timeIntervalSince1970: 1_704_067_200), // 2024-01-01

roles: [],
capabilities: UserCapabilitiesMap(map: [:]),
extraCapabilities: UserCapabilitiesMap(map: [:]),
Expand Down
4 changes: 2 additions & 2 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -358,11 +358,11 @@ private func makeRemotePost(
) -> AnyPostWithEditContext {
AnyPostWithEditContext(
id: PostId(1),
date: "2025-01-01T00:00:00",
date: WpDateString(value: "2025-01-01T00:00:00"),
dateGmt: Date(timeIntervalSince1970: 0),
guid: PostGuidWithEditContext(raw: nil, rendered: ""),
link: "https://example.com",
modified: "2025-01-01T00:00:00",
modified: WpDateString(value: "2025-01-01T00:00:00"),
modifiedGmt: Date(timeIntervalSince1970: 0),
slug: "test-post",
status: .draft,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,11 @@ private func makePostWithDisabledConnection(
let additionalFields = try WpAdditionalFields.fromJsonString(json: json)
return AnyPostWithEditContext(
id: PostId(1),
date: "2025-01-01T00:00:00",
date: WpDateString(value: "2025-01-01T00:00:00"),
dateGmt: Date(timeIntervalSince1970: 0),
guid: PostGuidWithEditContext(raw: nil, rendered: ""),
link: "https://example.com",
modified: "2025-01-01T00:00:00",
modified: WpDateString(value: "2025-01-01T00:00:00"),
modifiedGmt: Date(timeIntervalSince1970: 0),
slug: "test-post",
status: status,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1484,11 +1484,11 @@ private func makeRemotePost(
) -> AnyPostWithEditContext {
AnyPostWithEditContext(
id: PostId(1),
date: "2025-01-01T00:00:00",
date: WpDateString(value: "2025-01-01T00:00:00"),
dateGmt: Date(timeIntervalSince1970: 0),
guid: PostGuidWithEditContext(raw: nil, rendered: ""),
link: "https://example.com",
modified: "2025-01-01T00:00:00",
modified: WpDateString(value: "2025-01-01T00:00:00"),
modifiedGmt: Date(timeIntervalSince1970: 0),
slug: "test-post",
status: .draft,
Expand Down
2 changes: 1 addition & 1 deletion WordPress/Classes/Login/SelfHostedSiteAuthenticator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ private extension SelfHostedSiteAuthenticator {
}
}

private final class EmptyAppNotifier: WpAppNotifier {
final class EmptyAppNotifier: WpAppNotifier {
func requestedWithInvalidAuthentication(requestUrl: String) async {
// Do nothing.
}
Expand Down
9 changes: 7 additions & 2 deletions WordPress/Classes/Networking/JetpackSocialFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,13 @@ public final class JetpackSocialFactory: Sendable {
}
let service = SiteSocialConnectionsService(
client: WPComApiClient(
urlSession: URLSession(configuration: .ephemeral),
authentication: configuration.authentication
delegate: WpApiClientDelegate(
authProvider: .staticWithAuth(auth: configuration.authentication),
requestExecutor: WpRequestExecutor(urlSession: URLSession(configuration: .ephemeral)),
middlewarePipeline: .default,
appNotifier: EmptyAppNotifier(),
languageProvider: WPComDeviceLanguageProvider()
)
),
siteId: configuration.siteId,
canMarkAsShared: canMarkAsShared
Expand Down
19 changes: 18 additions & 1 deletion WordPress/Classes/Networking/WordPressDotComClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ actor WordPressDotComClient: MediaHostProtocol {
middlewarePipeline: WpApiMiddlewarePipeline(middlewares: [
WpComTrafficDebugger()
]),
appNotifier: WpComNotifier()
appNotifier: WpComNotifier(),
languageProvider: WPComDeviceLanguageProvider()
)

self.api = WPComApiClient(delegate: delegate)
Expand Down Expand Up @@ -173,3 +174,19 @@ extension RequestMethod: @retroactive CustomStringConvertible {
}
}
}

/// Asks WordPress.com to localize responses to the first of the user's preferred languages that
/// WordPress.com supports.
///
/// Maps through the wordpress-rs language table, so regional variants such as `en-gb` resolve.
/// Sends no locale when none of the preferred languages is supported.
final class WPComDeviceLanguageProvider: WpComLanguageProvider {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should've put this in wprs?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good.

func currentLanguage() -> WpComLanguage? {
for identifier in Locale.preferredLanguages {
if let language = WpComLanguage(locale: Locale(identifier: identifier)) {
return language
}
}
return nil
}
}
15 changes: 6 additions & 9 deletions WordPress/Classes/Services/ApplicationPasswordService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ extension ApplicationPasswordService: ApplicationTokenListDataProvider {
}

if self.currentApplicationPasswordUUID == nil {
self.currentApplicationPasswordUUID = try? await apiClient.api.applicationPasswords.retrieveCurrentWithViewContext().data.uuid.uuid
self.currentApplicationPasswordUUID = try? await apiClient.api.applicationPasswords
.retrieveCurrentWithViewContext().data.uuid.uuid
}

return try await fetchTokens(forUserId: userId)
Expand All @@ -47,21 +48,17 @@ extension ApplicationPasswordService: ApplicationTokenListDataProvider {

extension ApplicationTokenItem {
init?(_ rawToken: ApplicationPasswordWithEditContext) {
guard
let uuid = UUID(uuidString: rawToken.uuid.uuid),
let createdAt = Date.fromWordPressDate(rawToken.created)
else {
guard let uuid = UUID(uuidString: rawToken.uuid.uuid) else {
return nil
}

let lastUsed = rawToken.lastUsed.flatMap(Date.fromWordPressDate(_:))

// wordpress-rs 0.8.0 delivers these as parsed `Date`s, not strings.
self = ApplicationTokenItem(
name: rawToken.name,
uuid: uuid,
appId: rawToken.appId.appId,
createdAt: createdAt,
lastUsed: lastUsed,
createdAt: rawToken.created,
lastUsed: rawToken.lastUsed,
lastIpAddress: rawToken.lastIp?.value
)
}
Expand Down