Skip to content

Commit

Permalink
Improve robustness of the URL handler
Browse files Browse the repository at this point in the history
This commit improves reliability on the handling of
external URLs.

This was achieved through the following improvements:
1. The URL handler interface is now well-defined, with more clear inputs
   and outputs, to avoid silent failures and error paths that are hard to see
   within convoluted logic paths
2. Side effects during URL parsing were almost completely removed for
   more predictable behavior
3. Error handling logic was added to present errors to the user in a user-friendly manner,
   instead of silently failing
4. Event loading logic was moved into a special new thread view, which
   makes its own internal state evident to the user (i.e. whether
   the note is loading, loaded, or if the note could not be found)

These changes make the URL opening logic more predictable, easy to
refactor, and helps ensure the user always gets some outcome from
opening a URL, even if it means showing a "not found" or "error" screen,
to eliminate cases where nothing seems to happen.

Closes: damus-io#2429
Changelog-Fixed: Improved robustness of the URL handler
Changelog-Added: Added user-friendly error view for errors around the app that would not fit in other places
Signed-off-by: Daniel D’Aquino <[email protected]>
  • Loading branch information
danieldaquino committed Jan 9, 2025
1 parent 282bf80 commit db8476b
Show file tree
Hide file tree
Showing 10 changed files with 623 additions and 87 deletions.
32 changes: 32 additions & 0 deletions damus.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1448,10 +1448,19 @@
D74AAFD22B155E78006CF0F4 /* WalletConnect.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C7D09612A098D0E00943473 /* WalletConnect.swift */; };
D74AAFD42B155ECB006CF0F4 /* Zaps+.swift in Sources */ = {isa = PBXBuildFile; fileRef = D74AAFD32B155ECB006CF0F4 /* Zaps+.swift */; };
D74AAFD62B155F0C006CF0F4 /* WalletConnect+.swift in Sources */ = {isa = PBXBuildFile; fileRef = D74AAFD52B155F0C006CF0F4 /* WalletConnect+.swift */; };
D74EA08A2D2BF2A7002290DD /* URLHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = D767066E2C8BB3CE00F09726 /* URLHandler.swift */; };
D74EA08E2D2E271E002290DD /* ErrorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D74EA08D2D2E271E002290DD /* ErrorView.swift */; };
D74EA08F2D2E271E002290DD /* ErrorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D74EA08D2D2E271E002290DD /* ErrorView.swift */; };
D74EA0902D2E271E002290DD /* ErrorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D74EA08D2D2E271E002290DD /* ErrorView.swift */; };
D74EA0912D2E3464002290DD /* URLHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = D767066E2C8BB3CE00F09726 /* URLHandler.swift */; };
D74EA0932D2E77B9002290DD /* LoadableThreadView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D74EA0922D2E77B9002290DD /* LoadableThreadView.swift */; };
D74EA0942D2E77B9002290DD /* LoadableThreadView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D74EA0922D2E77B9002290DD /* LoadableThreadView.swift */; };
D74EA0952D2E77B9002290DD /* LoadableThreadView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D74EA0922D2E77B9002290DD /* LoadableThreadView.swift */; };
D74F430A2B23F0BE00425B75 /* DamusPurple.swift in Sources */ = {isa = PBXBuildFile; fileRef = D74F43092B23F0BE00425B75 /* DamusPurple.swift */; };
D74F430C2B23FB9B00425B75 /* StoreObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = D74F430B2B23FB9B00425B75 /* StoreObserver.swift */; };
D753CEAA2BE9DE04001C3A5D /* MutingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D753CEA92BE9DE04001C3A5D /* MutingTests.swift */; };
D76556D62B1E6C08001B0CCC /* DamusPurpleWelcomeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D76556D52B1E6C08001B0CCC /* DamusPurpleWelcomeView.swift */; };
D767066F2C8BB3CF00F09726 /* URLHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = D767066E2C8BB3CE00F09726 /* URLHandler.swift */; };
D76874F32AE3632B00FB0F68 /* ProfileZapLinkView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D76874F22AE3632B00FB0F68 /* ProfileZapLinkView.swift */; };
D773BC5F2C6D538500349F0A /* CommentItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = D773BC5E2C6D538500349F0A /* CommentItem.swift */; };
D773BC602C6D538500349F0A /* CommentItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = D773BC5E2C6D538500349F0A /* CommentItem.swift */; };
Expand Down Expand Up @@ -2429,10 +2438,13 @@
D74AAFCE2B155D8C006CF0F4 /* ZapDataModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ZapDataModel.swift; sourceTree = "<group>"; };
D74AAFD32B155ECB006CF0F4 /* Zaps+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Zaps+.swift"; sourceTree = "<group>"; };
D74AAFD52B155F0C006CF0F4 /* WalletConnect+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "WalletConnect+.swift"; sourceTree = "<group>"; };
D74EA08D2D2E271E002290DD /* ErrorView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ErrorView.swift; sourceTree = "<group>"; };
D74EA0922D2E77B9002290DD /* LoadableThreadView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadableThreadView.swift; sourceTree = "<group>"; };
D74F43092B23F0BE00425B75 /* DamusPurple.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DamusPurple.swift; sourceTree = "<group>"; };
D74F430B2B23FB9B00425B75 /* StoreObserver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StoreObserver.swift; sourceTree = "<group>"; };
D753CEA92BE9DE04001C3A5D /* MutingTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MutingTests.swift; sourceTree = "<group>"; };
D76556D52B1E6C08001B0CCC /* DamusPurpleWelcomeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DamusPurpleWelcomeView.swift; sourceTree = "<group>"; };
D767066E2C8BB3CE00F09726 /* URLHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLHandler.swift; sourceTree = "<group>"; };
D76874F22AE3632B00FB0F68 /* ProfileZapLinkView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileZapLinkView.swift; sourceTree = "<group>"; };
D773BC5E2C6D538500349F0A /* CommentItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommentItem.swift; sourceTree = "<group>"; };
D77BFA0A2AE3051200621634 /* ProfileActionSheetView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileActionSheetView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2727,6 +2739,7 @@
D7D2A3802BF815D000E4B42B /* PushNotificationClient.swift */,
5CC8529C2BD741CD0039FFC5 /* HighlightEvent.swift */,
D773BC5E2C6D538500349F0A /* CommentItem.swift */,
D767066E2C8BB3CE00F09726 /* URLHandler.swift */,
);
path = Models;
sourceTree = "<group>";
Expand Down Expand Up @@ -3067,6 +3080,7 @@
4C75EFA227FA576C0006080F /* Views */ = {
isa = PBXGroup;
children = (
D74EA08C2D2E26E6002290DD /* ErrorHandling */,
D7D68FF72C9E01A80015A515 /* Utils */,
D78DB85D2C20FE9E00F0AB12 /* Chat */,
D71AC4CA2BA8E3320076268E /* Extensions */,
Expand Down Expand Up @@ -3138,6 +3152,7 @@
D783A63E2AD4E53D00658DDA /* SuggestedHashtagsView.swift */,
D77BFA0A2AE3051200621634 /* ProfileActionSheetView.swift */,
D71AD8FC2CEC176A002E2C3C /* AppAccessibilityIdentifiers.swift */,
D74EA0922D2E77B9002290DD /* LoadableThreadView.swift */,
);
path = Views;
sourceTree = "<group>";
Expand Down Expand Up @@ -3858,6 +3873,14 @@
path = Mocking;
sourceTree = "<group>";
};
D74EA08C2D2E26E6002290DD /* ErrorHandling */ = {
isa = PBXGroup;
children = (
D74EA08D2D2E271E002290DD /* ErrorView.swift */,
);
path = ErrorHandling;
sourceTree = "<group>";
};
D74F43082B23F09300425B75 /* Purple */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -4642,6 +4665,7 @@
4CA927612A290E340098A105 /* EventShell.swift in Sources */,
4C363AA428296DEE006E126D /* SearchModel.swift in Sources */,
4C8D00CC29DF92DF0036AF10 /* Hashtags.swift in Sources */,
D74EA0942D2E77B9002290DD /* LoadableThreadView.swift in Sources */,
4CEE2AF3280B25C500AB5EEF /* ProfilePicView.swift in Sources */,
4CC7AAF6297F1A6A00430951 /* EventBody.swift in Sources */,
D76556D62B1E6C08001B0CCC /* DamusPurpleWelcomeView.swift in Sources */,
Expand Down Expand Up @@ -4748,6 +4772,7 @@
D7CB5D4E2B11728000AD4105 /* NewEventsBits.swift in Sources */,
4CC7AAFA297F64AC00430951 /* EventMenu.swift in Sources */,
B57B4C622B312BD700A232C0 /* ReconnectRelaysNotify.swift in Sources */,
D767066F2C8BB3CF00F09726 /* URLHandler.swift in Sources */,
D7ADD3DE2B53854300F104C4 /* DamusPurpleURL.swift in Sources */,
E4FA1C032A24BB7F00482697 /* SearchSettingsView.swift in Sources */,
4C75EFBB2804A34C0006080F /* ProofOfWork.swift in Sources */,
Expand All @@ -4760,6 +4785,7 @@
4C9AA14A2A4587A6003F49FD /* NotificationStatusModel.swift in Sources */,
D7100C5C2B77016700C59298 /* IAPProductStateView.swift in Sources */,
4CB9D4A72992D02B00A9A7E4 /* ProfileNameView.swift in Sources */,
D74EA0902D2E271E002290DD /* ErrorView.swift in Sources */,
4CE4F0F429D779B5005914DB /* PostBox.swift in Sources */,
BA37598E2ABCCE500018D73B /* VideoCaptureProcessor.swift in Sources */,
4C9B0DF32A65C46800CBDA21 /* ProfileEditButton.swift in Sources */,
Expand Down Expand Up @@ -4905,6 +4931,7 @@
82D6FAEC2CD99F7900C925F4 /* OnlyZapsNotify.swift in Sources */,
82D6FAED2CD99F7900C925F4 /* PostNotify.swift in Sources */,
82D6FAEE2CD99F7900C925F4 /* PresentSheetNotify.swift in Sources */,
D74EA0932D2E77B9002290DD /* LoadableThreadView.swift in Sources */,
82D6FAEF2CD99F7900C925F4 /* ProfileUpdatedNotify.swift in Sources */,
82D6FAF02CD99F7900C925F4 /* ReportNotify.swift in Sources */,
82D6FAF12CD99F7900C925F4 /* ScrollToTopNotify.swift in Sources */,
Expand Down Expand Up @@ -5071,6 +5098,7 @@
82D6FB922CD99F7900C925F4 /* Wallet.swift in Sources */,
82D6FB932CD99F7900C925F4 /* Report.swift in Sources */,
82D6FB942CD99F7900C925F4 /* LibreTranslateServer.swift in Sources */,
D74EA08E2D2E271E002290DD /* ErrorView.swift in Sources */,
82D6FB952CD99F7900C925F4 /* TranslationService.swift in Sources */,
82D6FB962CD99F7900C925F4 /* DeepLPlan.swift in Sources */,
82D6FB972CD99F7900C925F4 /* ZapsModel.swift in Sources */,
Expand Down Expand Up @@ -5252,6 +5280,7 @@
82D6FC492CD99F7900C925F4 /* BigButton.swift in Sources */,
82D6FC4A2CD99F7900C925F4 /* AddRelayView.swift in Sources */,
82D6FC4B2CD99F7900C925F4 /* BlocksView.swift in Sources */,
D74EA0912D2E3464002290DD /* URLHandler.swift in Sources */,
82D6FC4C2CD99F7900C925F4 /* BookmarksView.swift in Sources */,
82D6FC4D2CD99F7900C925F4 /* CarouselView.swift in Sources */,
82D6FC4E2CD99F7900C925F4 /* ConfigView.swift in Sources */,
Expand Down Expand Up @@ -5342,6 +5371,7 @@
D73E5E3A2C6A97F4007EB227 /* SwipeToDismiss.swift in Sources */,
D73E5E3B2C6A97F4007EB227 /* MusicController.swift in Sources */,
D73E5E3C2C6A97F4007EB227 /* UserStatusView.swift in Sources */,
D74EA08F2D2E271E002290DD /* ErrorView.swift in Sources */,
D73E5E3E2C6A97F4007EB227 /* SearchHeaderView.swift in Sources */,
D73E5E3F2C6A97F4007EB227 /* DamusGradient.swift in Sources */,
D73E5E402C6A97F4007EB227 /* AlbyGradient.swift in Sources */,
Expand Down Expand Up @@ -5437,6 +5467,7 @@
D73E5E9C2C6A97F4007EB227 /* Reply.swift in Sources */,
D73E5E9D2C6A97F4007EB227 /* SearchModel.swift in Sources */,
D73E5E9E2C6A97F4007EB227 /* NostrFilter+Hashable.swift in Sources */,
D74EA0952D2E77B9002290DD /* LoadableThreadView.swift in Sources */,
D73E5F912C6AA71B007EB227 /* InputDismissKeyboard.swift in Sources */,
D73E5E9F2C6A97F4007EB227 /* CreateAccountModel.swift in Sources */,
D73E5EA12C6A97F4007EB227 /* SignalModel.swift in Sources */,
Expand Down Expand Up @@ -5765,6 +5796,7 @@
D703D7622C670ACB00A400EA /* ByteBuffer.swift in Sources */,
D703D79A2C670DFD00A400EA /* bech32.c in Sources */,
D703D7B62C67118200A400EA /* String+extension.swift in Sources */,
D74EA08A2D2BF2A7002290DD /* URLHandler.swift in Sources */,
D703D76C2C670B3900A400EA /* Post.swift in Sources */,
D703D77A2C670BEB00A400EA /* VeriferOptions.swift in Sources */,
D73E5F9E2C6AA9F7007EB227 /* nostrscript.c in Sources */,
Expand Down
Loading

0 comments on commit db8476b

Please sign in to comment.