Skip to content
This repository was archived by the owner on Sep 19, 2023. It is now read-only.

Commit

Permalink
feature/support-soap-link (#522)
Browse files Browse the repository at this point in the history
* started supporting

* updates

* clean up url sharing

* added

* fix
  • Loading branch information
decanus authored Apr 22, 2021
1 parent 2d3bea7 commit 0742381
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## [Unreleased]

- We added nicer short links, no more soapbox.social now its just soap.link!
- Fixed sharing to telegram.
- Added a settings button on profile, made things clearer.
- Fixes the fact that rooms were sometimes reordered on the feed.
Expand Down
1 change: 1 addition & 0 deletions Entitlements/debug.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<key>com.apple.developer.associated-domains</key>
<array>
<string>applinks:soapbox.social</string>
<string>applinks:soap.link</string>
</array>
</dict>
</plist>
1 change: 1 addition & 0 deletions Entitlements/release.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<key>com.apple.developer.associated-domains</key>
<array>
<string>applinks:soapbox.social</string>
<string>applinks:soap.link</string>
</array>
</dict>
</plist>
2 changes: 1 addition & 1 deletion Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>2.27.2</string>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
Expand Down
37 changes: 33 additions & 4 deletions Sources/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,26 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}

func application(_: UIApplication, continue userActivity: NSUserActivity, restorationHandler _: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
guard userActivity.activityType == NSUserActivityTypeBrowsingWeb,
let incomingURL = userActivity.webpageURL,
let components = URLComponents(url: incomingURL, resolvingAgainstBaseURL: true) else {
guard userActivity.activityType == NSUserActivityTypeBrowsingWeb, let incomingURL = userActivity.webpageURL else {
return false
}

let pathComponents = incomingURL.pathComponents
switch incomingURL.host {
case "soapbox.social":
return handleLegacySoapbox(incomingURL)
case "soap.link":
return handleSoapShortLinks(incomingURL)
default:
return false
}
}

private func handleLegacySoapbox(_ url: URL) -> Bool {
guard let components = URLComponents(url: url, resolvingAgainstBaseURL: true) else {
return false
}

let pathComponents = url.pathComponents
if pathComponents.count < 2 {
return false
}
Expand All @@ -113,6 +126,22 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}
}

private func handleSoapShortLinks(_ url: URL) -> Bool {
let pathComponents = url.pathComponents
if pathComponents.count != 2 {
return false
}

var path = pathComponents[1]

if path.prefix(1) == "@" {
path.remove(at: path.startIndex)
return handleUserURL(username: path)
}

return handleRoomURL(room: path)
}

private func handlePinURL(components: URLComponents) -> Bool {
guard let param = components.queryItems?.first(where: { $0.name == "pin" }), let pin = param.value else {
return false
Expand Down
2 changes: 1 addition & 1 deletion Sources/Scenes/Profile/ProfileViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ class ProfileViewController: ViewControllerWithRemoteContent<APIClient.Profile>

sheet.add(action: ActionSheet.Action(title: NSLocalizedString("share_profile", comment: ""), style: .default, handler: { _ in
let items: [Any] = [
URL(string: "https://soapbox.social/user/" + self.content.username)!,
URL(string: "https://soap.link/@" + self.content.username)!,
]

let ac = UIActivityViewController(activityItems: items, applicationActivities: nil)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ extension ShareSheetDrawerViewController {
}

private func roomURL() -> URL {
return URL(string: "https://soapbox.social/room/" + room.state.id)!
return URL(string: "https://soap.link/" + room.state.id)!
}
}

Expand Down

0 comments on commit 0742381

Please sign in to comment.