Skip to content

Commit

Permalink
Merge branch 'develop' into issue/1965-take-a-photo-failure
Browse files Browse the repository at this point in the history
  • Loading branch information
ceyhun authored Jun 15, 2020
2 parents d664c98 + 3bdd11f commit f8e596f
Show file tree
Hide file tree
Showing 22 changed files with 1,431 additions and 86 deletions.
4 changes: 2 additions & 2 deletions Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ def wordpress_ui
end

def wordpress_kit
pod 'WordPressKit', '~> 5.0.0-beta.1'
pod 'WordPressKit', '~> 5.0.0-beta.2'
#pod 'WordPressKit', :git => 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', :tag => ''
#pod 'WordPressKit', :git => 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', :branch => ''
#pod 'WordPressKit', :git => 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', :branch => 'issue/14224-add-zendesk-plan-field'
#pod 'WordPressKit', :git => 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', :commit => ''
#pod 'WordPressKit', :path => '../WordPressKit-iOS'
end
Expand Down
8 changes: 4 additions & 4 deletions Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ PODS:
- WordPressKit (~> 5.0.0-beta.1)
- WordPressShared (~> 1.9.0-beta.1)
- WordPressUI (~> 1.7.0)
- WordPressKit (5.0.0-beta.1):
- WordPressKit (5.0.0-beta.2):
- Alamofire (~> 4.8.0)
- CocoaLumberjack (~> 3.4)
- NSObject-SafeExpectations (= 0.0.4)
Expand Down Expand Up @@ -484,7 +484,7 @@ DEPENDENCIES:
- SVProgressHUD (= 2.2.5)
- WordPress-Editor-iOS (~> 1.19.2)
- WordPressAuthenticator (~> 1.18.0-beta.9)
- WordPressKit (~> 5.0.0-beta.1)
- WordPressKit (~> 5.0.0-beta.2)
- WordPressMocks (~> 0.0.8)
- WordPressShared (~> 1.9.0-beta.1)
- WordPressUI (~> 1.7.0)
Expand Down Expand Up @@ -704,7 +704,7 @@ SPEC CHECKSUMS:
WordPress-Aztec-iOS: d01bf0c5e150ae6a046f06ba63b7cc2762061c0b
WordPress-Editor-iOS: 5b726489e5ae07b7281a2862d69aba2d5c83f140
WordPressAuthenticator: 8567813769caf5e570d3370c907422a17c174c2b
WordPressKit: 48ef1d76727cde146db44097cfb89852b171aa72
WordPressKit: 94d62968d29761a38534e26df103fa2fe222130c
WordPressMocks: b4064b99a073117bbc304abe82df78f2fbe60992
WordPressShared: bc1a056b5d4da040e3addf4f510c0de67651ab1b
WordPressUI: 1cf47a3b78154faf69caa18569ee7ece1e510fa0
Expand All @@ -720,6 +720,6 @@ SPEC CHECKSUMS:
ZendeskSupportSDK: a87ab1e4badace92c75eb11dc77ede1e995b2adc
ZIPFoundation: 249fa8890597086cd536bb2df5c9804d84e122b0

PODFILE CHECKSUM: f0b1fb4b6308ca3d34ea36afd78ce9e587f5e747
PODFILE CHECKSUM: e883e836d5fe11167803b7446b3aa621e5580a02

COCOAPODS: 1.8.4
2 changes: 2 additions & 0 deletions RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
* Block editor: [**] Adds editor support for theme defined colors and theme defined gradients on cover and button blocks.
* [*] Fixed a bug where "Follow another site" was using the wrong steps in the "Grow Your Audience" Quick Start tour.
* [*] Fix a bug where Quick Start completed tasks were not communicated to VoiceOver users.
* [**] Quick Start: added VoiceOver support to the Next Steps section.
* [*] Fixed a bug where the "Publish a post" Quick Start tour didn't reflect the app's new information architecture
* [***] Free GIFs can now be added to the media library, posts, and pages.
* [**] You can now set pages as your site's homepage or posts page directly from the Pages list.
* [*] Block editor: Fix 'Take a Photo' option failing after adding an image to gallery block

15.0
Expand Down
24 changes: 24 additions & 0 deletions WordPress/Classes/Models/Page.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,28 @@ class Page: AbstractPost {
hash(for: parentID?.intValue ?? 0)
]
}

// MARK: - Homepage Settings

@objc var isSiteHomepage: Bool {
guard let postID = postID,
let homepageID = blog.homepagePageID,
let homepageType = blog.homepageType,
homepageType == .page else {
return false
}

return homepageID == postID.intValue
}

@objc var isSitePostsPage: Bool {
guard let postID = postID,
let postsPageID = blog.homepagePostsPageID,
let homepageType = blog.homepageType,
homepageType == .page else {
return false
}

return postsPageID == postID.intValue
}
}
3 changes: 3 additions & 0 deletions WordPress/Classes/Models/Plan.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@ public class Plan: NSManagedObject {
@NSManaged public var summary: String
@NSManaged public var features: String
@NSManaged public var icon: String
@NSManaged public var supportPriority: Int16
@NSManaged public var supportName: String
@NSManaged public var nonLocalizedShortname: String
}
21 changes: 17 additions & 4 deletions WordPress/Classes/Services/HomepageSettingsService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,28 @@ struct HomepageSettingsService {
success: @escaping () -> Void,
failure: @escaping (Error) -> Void) {

// Keep track of the original settings in case we need to revert
let originalHomepageType = blog.homepageType
let originalHomePageID = blog.homepagePageID
let originalPostsPageID = blog.homepagePostsPageID

switch type {
case .page:
blog.homepageType = .page
blog.homepagePostsPageID = postsPageID
blog.homepagePageID = homePageID
if let postsPageID = postsPageID {
blog.homepagePostsPageID = postsPageID
if postsPageID == originalHomePageID {
// Don't allow the same page to be set for both values
blog.homepagePageID = 0
}
}
if let homePageID = homePageID {
blog.homepagePageID = homePageID
if homePageID == originalPostsPageID {
// Don't allow the same page to be set for both values
blog.homepagePostsPageID = 0
}
}
case .posts:
blog.homepageType = .posts
}
Expand All @@ -48,8 +61,8 @@ struct HomepageSettingsService {

remote.setHomepageType(type: type.remoteType,
for: siteID,
withPostsPageID: postsPageID,
homePageID: homePageID,
withPostsPageID: blog.homepagePostsPageID,
homePageID: blog.homepagePageID,
success: success,
failure: { error in
self.context.performAndWait {
Expand Down
3 changes: 3 additions & 0 deletions WordPress/Classes/Services/PlanService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ open class PlanService: LocalCoreDataService {
plan?.summary = remotePlan.description
plan?.features = remotePlan.features
plan?.icon = remotePlan.icon
plan?.nonLocalizedShortname = remotePlan.nonLocalizedShortname
plan?.supportName = remotePlan.supportName
plan?.supportPriority = Int16(remotePlan.supportPriority)

plansToKeep.append(plan!)
}
Expand Down
139 changes: 99 additions & 40 deletions WordPress/Classes/Utility/ZendeskUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -188,24 +188,48 @@ extension NSNotification.Name {
}
}

func cacheUnlocalizedSitePlans() {
guard !WordPressComLanguageDatabase().deviceLanguage.slug.hasPrefix("en") else {
// Don't fetch if its already "en".
return
}

func cacheUnlocalizedSitePlans(accountService: AccountService? = nil, planService: PlanService? = nil) {
let context = ContextManager.shared.mainContext
let accountService = AccountService(managedObjectContext: context)
let accountService = accountService ?? AccountService(managedObjectContext: context)
guard let account = accountService.defaultWordPressComAccount() else {
return
}

let planService = PlanService(managedObjectContext: context)
let planService = planService ?? PlanService(managedObjectContext: context)
planService.getAllSitesNonLocalizedPlanDescriptionsForAccount(account, success: { plans in
self.sitePlansCache = plans
}, failure: { error in })
}

func createRequest(planService: PlanService? = nil) -> RequestUiConfiguration {

let requestConfig = RequestUiConfiguration()

// Set Zendesk ticket form to use
requestConfig.ticketFormID = TicketFieldIDs.form as NSNumber

// Set form field values
var ticketFields = [CustomField]()
ticketFields.append(CustomField(fieldId: TicketFieldIDs.appVersion, value: ZendeskUtils.appVersion))
ticketFields.append(CustomField(fieldId: TicketFieldIDs.allBlogs, value: ZendeskUtils.getBlogInformation()))
ticketFields.append(CustomField(fieldId: TicketFieldIDs.deviceFreeSpace, value: ZendeskUtils.getDeviceFreeSpace()))
ticketFields.append(CustomField(fieldId: TicketFieldIDs.networkInformation, value: ZendeskUtils.getNetworkInformation()))
ticketFields.append(CustomField(fieldId: TicketFieldIDs.logs, value: ZendeskUtils.getLogFile()))
ticketFields.append(CustomField(fieldId: TicketFieldIDs.currentSite, value: ZendeskUtils.getCurrentSiteDescription()))
ticketFields.append(CustomField(fieldId: TicketFieldIDs.sourcePlatform, value: Constants.sourcePlatform))
ticketFields.append(CustomField(fieldId: TicketFieldIDs.appLanguage, value: ZendeskUtils.appLanguage))
ticketFields.append(CustomField(fieldId: TicketFieldIDs.plan, value: ZendeskUtils.getHighestPriorityPlan(planService: planService)))
requestConfig.customFields = ticketFields

// Set tags
requestConfig.tags = ZendeskUtils.getTags()

// Set the ticket subject
requestConfig.subject = Constants.ticketSubject

return requestConfig
}

// MARK: - Device Registration

/// Sets the device ID to be registered with Zendesk for push notifications.
Expand Down Expand Up @@ -445,33 +469,7 @@ private extension ZendeskUtils {
}
}

func createRequest() -> RequestUiConfiguration {

let requestConfig = RequestUiConfiguration()

// Set Zendesk ticket form to use
requestConfig.ticketFormID = TicketFieldIDs.form as NSNumber

// Set form field values
var ticketFields = [CustomField]()
ticketFields.append(CustomField(fieldId: TicketFieldIDs.appVersion, value: ZendeskUtils.appVersion))
ticketFields.append(CustomField(fieldId: TicketFieldIDs.allBlogs, value: ZendeskUtils.getBlogInformation()))
ticketFields.append(CustomField(fieldId: TicketFieldIDs.deviceFreeSpace, value: ZendeskUtils.getDeviceFreeSpace()))
ticketFields.append(CustomField(fieldId: TicketFieldIDs.networkInformation, value: ZendeskUtils.getNetworkInformation()))
ticketFields.append(CustomField(fieldId: TicketFieldIDs.logs, value: ZendeskUtils.getLogFile()))
ticketFields.append(CustomField(fieldId: TicketFieldIDs.currentSite, value: ZendeskUtils.getCurrentSiteDescription()))
ticketFields.append(CustomField(fieldId: TicketFieldIDs.sourcePlatform, value: Constants.sourcePlatform))
ticketFields.append(CustomField(fieldId: TicketFieldIDs.appLanguage, value: ZendeskUtils.appLanguage))
requestConfig.customFields = ticketFields

// Set tags
requestConfig.tags = ZendeskUtils.getTags()

// Set the ticket subject
requestConfig.subject = Constants.ticketSubject

return requestConfig
}

// MARK: - View

Expand Down Expand Up @@ -659,11 +657,7 @@ private extension ZendeskUtils {
return [Constants.wpComTag]
}

// Get all unique site plans
var tags = ZendeskUtils.sharedInstance.sitePlansCache.values.compactMap { $0.name }.unique
if tags.count == 0 {
tags = allBlogs.compactMap { $0.planTitle }.unique
}
var tags = [String]()

// If any of the sites have jetpack installed, add jetpack tag.
let jetpackBlog = allBlogs.first { $0.jetpack?.isInstalled == true }
Expand Down Expand Up @@ -931,6 +925,71 @@ private extension ZendeskUtils {
}
}

// MARK: - Plans

/// Retrieves the highest priority plan, if it exists
/// - Returns: the highest priority plan found, or an empty string if none was foundq
static func getHighestPriorityPlan(planService: PlanService? = nil) -> String {

let availablePlans = getAvailablePlansWithPriority(planService: planService)
if !ZendeskUtils.sharedInstance.sitePlansCache.isEmpty {
let plans = Set(ZendeskUtils.sharedInstance.sitePlansCache.values.compactMap { $0.name })

for availablePlan in availablePlans {
if plans.contains(availablePlan.nonLocalizedName) {
return availablePlan.supportName
}
}
} else {
// fail safe: if the plan cache call fails for any reason, at least let's use the cached blogs
// and compare the localized names
let blogService = BlogService(managedObjectContext: ContextManager.shared.mainContext)
let plans = Set(blogService.blogsForAllAccounts().compactMap { $0.planTitle })

for availablePlan in availablePlans {
if plans.contains(availablePlan.name) {
return availablePlan.supportName
}
}
}
return ""
}

/// Obtains the available plans, sorted by priority
static func getAvailablePlansWithPriority(planService: PlanService? = nil) -> [SupportPlan] {
let planService = planService ?? PlanService(managedObjectContext: ContextManager.shared.mainContext)
return planService.allPlans().map {
SupportPlan(priority: $0.supportPriority,
name: $0.shortname,
nonLocalizedName: $0.nonLocalizedShortname,
supportName: $0.supportName)

}
.sorted { $0.priority > $1.priority }
}

struct SupportPlan {
let priority: Int
let name: String
let nonLocalizedName: String
let supportName: String

// used to resolve discrepancies of unlocalized names between endpoints
let mappings = ["E-commerce": "eCommerce"]

init(priority: Int16,
name: String,
nonLocalizedName: String,
supportName: String) {

self.priority = Int(priority)
self.name = name
self.nonLocalizedName = mappings[nonLocalizedName] ?? nonLocalizedName
self.supportName = supportName
}
}


// MARK: - Constants

struct Constants {
Expand Down Expand Up @@ -962,7 +1021,7 @@ private extension ZendeskUtils {
// Zendesk expects this as NSNumber. However, it is defined as Int64 to satisfy 32-bit devices (ex: iPhone 5).
// Which means it has to be converted to NSNumber when sending to Zendesk.
static let form: Int64 = 360000010286

static let plan: Int64 = 25175963
static let appVersion: Int64 = 360000086866
static let allBlogs: Int64 = 360000087183
static let deviceFreeSpace: Int64 = 360000089123
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14865.1" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="16097" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14819.2"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="16087"/>
<capability name="Named colors" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
Expand All @@ -16,6 +16,7 @@
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="OEo-2z-Cmk">
<rect key="frame" x="273" y="0.0" width="44" height="36"/>
<accessibility key="accessibilityConfiguration" label="More menu"/>
<constraints>
<constraint firstAttribute="width" constant="44" id="NQj-8B-nY9"/>
<constraint firstAttribute="height" constant="36" id="j12-ha-Xlw"/>
Expand Down Expand Up @@ -53,7 +54,7 @@
</objects>
<resources>
<namedColor name="Gray50">
<color red="0.40392156862745099" green="0.41568627450980394" blue="0.45490196078431372" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color red="0.39215686274509803" green="0.41176470588235292" blue="0.4392156862745098" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</namedColor>
</resources>
</document>
Loading

0 comments on commit f8e596f

Please sign in to comment.