Compare commits

..

71 Commits

Author SHA1 Message Date
99d8859319 Add trie-based user search cache to replace non-performant linear scans
Changelog-Added: Add trie-based user search cache to replace non-performant linear scans

Bounty: lnbc500u1pj2pj5upp5mgcxn3893hayv839vqhxsljk337zf3e4xswde2eschd802x696esdqqcqzzsxqyz5vqsp5s28vfqgu9tqhamuu2hn4mltmhhznhcjsh7fjnm696z0n5naf046s9qyyssq6ylrtgtqzkxz8xc00as887qzsxzwgjrl3wz08r8n223lcmq7y2qsskgtmt9hwgzgxa37g7ajwm9uvejwkctjuz636fh7gr2lm0jymqqqmk7fyg
2023-07-02 17:35:12 -04:00
William Casarin
6a9b3cad20 Merge remote-tracking branch 'github/translations' 2023-07-02 13:34:04 -07:00
William Casarin
e5bd52b1f6 New paid email patch policy 2023-07-02 13:15:24 -07:00
Bryan Montz
7cd3aef157 Updated test target to deployment target of iOS 16.0
Changelog-Updated: Bumped minimum verison to iOS 16.0
Signed-off-by: Bryan Montz <bryanmontz@me.com>
2023-07-02 13:03:13 -07:00
transifex-integration[bot]
8f3d8ced90 Translate Localizable.stringsdict in es_ES
100% translated source file: 'Localizable.stringsdict'
on 'es_ES'.
2023-07-02 19:51:54 +00:00
transifex-integration[bot]
98ff4ee363 Translate Localizable.stringsdict in es_ES
100% translated source file: 'Localizable.stringsdict'
on 'es_ES'.
2023-07-02 19:51:22 +00:00
transifex-integration[bot]
ce7c4799c9 Translate Localizable.stringsdict in es_ES
100% translated source file: 'Localizable.stringsdict'
on 'es_ES'.
2023-07-02 19:50:09 +00:00
transifex-integration[bot]
11a4a85bdf Translate Localizable.strings in es_ES
100% translated source file: 'Localizable.strings'
on 'es_ES'.
2023-07-02 19:47:59 +00:00
transifex-integration[bot]
6fe4ac1bd0 Translate Localizable.stringsdict in ja
100% translated source file: 'Localizable.stringsdict'
on 'ja'.
2023-07-02 09:13:54 +00:00
William Casarin
f702733654 nav: remove environmentObjects
environment objects are implicit arguments that cannot be checked by the
compiler. They are a common source of crashes. Use a main
NavigationCoordinator in DamusState for the core app, and pass in other
coordinators in the account setup view for the parts of the app that
don't have a DamusState.
2023-06-30 09:59:58 -07:00
Scott Penrose
9008c609e2 Switch to NavigationStack
Changelog-Changed: Drop iOS15 support
Changelog-Fixed: Fixed navigation popping issues
2023-06-30 06:44:26 -07:00
William Casarin
5bac6405b9 validation: make sure to run on a detached task
so we don't do sig validation on the main thread accidentally
2023-06-30 06:42:56 -07:00
Scott Penrose
69663b8207 A few more navigation links from rebase 2023-06-30 06:42:56 -07:00
Scott Penrose
58a707685c Fix FollowUserView not allowing profile tapping 2023-06-30 06:42:56 -07:00
Scott Penrose
a76ddea7da Remove popToRoot when tapping damus:// internal links 2023-06-30 06:42:56 -07:00
Scott Penrose
0018e7ad57 Convert remaining navigation links 2023-06-30 06:42:56 -07:00
Scott Penrose
8258c5beb0 Convert ContentView navigation links 2023-06-30 06:42:56 -07:00
Scott Penrose
f361f55bd5 Convert wallet NavigationLinks 2023-06-30 06:42:56 -07:00
Scott Penrose
c50ccef56d Convert onboarding flow navigation links 2023-06-30 06:42:56 -07:00
Scott Penrose
242455410e Convert more NavigationLinks to router 2023-06-30 06:42:56 -07:00
Scott Penrose
f0b0eade37 Convert to NavigationStack
- Fixes linking issues on SideMenu and tab switching issues
- I currently bumped to iOS 16+ to get iterate and get this working.
2023-06-30 06:42:56 -07:00
William Casarin
3e3b689647 readme: include new mailing lists 2023-06-29 07:45:50 -07:00
transifex-integration[bot]
67e3ee8978 Translate Localizable.strings in es_419
100% translated source file: 'Localizable.strings'
on 'es_419'.
2023-06-28 21:22:27 +00:00
transifex-integration[bot]
90891622e4 Translate Localizable.stringsdict in es_419
100% translated source file: 'Localizable.stringsdict'
on 'es_419'.
2023-06-28 21:20:50 +00:00
William Casarin
62f052daa5 nozaps: fix zap button in freedom edition 2023-06-28 21:16:56 +02:00
25b3df8b89 Disable post button when media upload in progress
Changelog-Fixed: Disable post button when media upload in progress
Closes: #1324
2023-06-28 19:31:57 +02:00
14accd222e Fix taps on mentions in note drafts to not redirect to other Nostr clients
Changelog-Fixed: Fix taps on mentions in note drafts to not redirect to other Nostr clients
Closes: #1319
2023-06-28 19:31:16 +02:00
William Casarin
abcff3b928 profile: allow post button on every profile and prefill user tag
Changelog-Added: Add post button to profile pages
2023-06-28 17:40:27 +02:00
William Casarin
c8f18958a2 refactor: cleanup processFocusedWordForMention 2023-06-28 17:09:08 +02:00
transifex-integration[bot]
7a055efda8 Translate Localizable.stringsdict in hu_HU
100% translated source file: 'Localizable.stringsdict'
on 'hu_HU'.
2023-06-28 15:01:14 +00:00
transifex-integration[bot]
1ad8773c26 Translate Localizable.strings in hu_HU
100% translated source file: 'Localizable.strings'
on 'hu_HU'.
2023-06-28 14:57:46 +00:00
William Casarin
3b07a207c4 post: extract createUserTag so it can be re-used 2023-06-28 16:26:59 +02:00
William Casarin
d9a06e69ae misc: remove some dead code 2023-06-28 16:25:04 +02:00
32c71a4770 Add post button when logged in with private key and on own profile view
Changelog-Added: Add post button when logged in with private key and on own profile view
Closes: #1325
2023-06-28 15:49:34 +02:00
Bryan Montz
087d3e16a1 After loading the user's relays from their contact event, connect to new relays
Closes: #1298
2023-06-28 15:16:36 +02:00
7cae61a86a Fix missing profile zap notification text
Changelog-Fixed: Fix missing profile zap notification text
Closes: #1332
2023-06-28 14:48:06 +02:00
transifex-integration[bot]
b868119277 Translate Localizable.strings in ja
100% translated source file: 'Localizable.strings'
on 'ja'.
2023-06-28 08:15:41 +00:00
William Casarin
82c53e43e5 v1.5 (8) 2023-06-27 06:30:50 +02:00
William Casarin
3e274a820a nozaps: restore zap button with zap info, just make it not clickable 2023-06-27 06:04:36 +02:00
William Casarin
1a0282fe21 Revert "nozaps: don't pull thread zaps in nozaps mode"
This reverts commit 6003a3c6f8.
2023-06-27 05:59:59 +02:00
William Casarin
b2b687fb79 Revert "nozaps: hide zap total"
This reverts commit 57789de5cd.
2023-06-27 05:59:33 +02:00
William Casarin
94448a10bd Revert "nozaps: hide zap details on notes for now"
This reverts commit b0d6d33573.
2023-06-27 05:58:42 +02:00
William Casarin
66db4c5215 Revert "nozaps: don't show note zaps in notifications"
This reverts commit c5b0e539d8.
2023-06-27 05:58:39 +02:00
William Casarin
1e2326cccf v1.5 (7)
rip zap button
2023-06-27 05:35:53 +02:00
William Casarin
959f208e36 profile: make profile loading more lightweight for now 2023-06-27 05:31:22 +02:00
William Casarin
7d80985b06 nozaps: remove zap button on posts 2023-06-27 05:31:14 +02:00
transifex-integration[bot]
3b085ab826 Translate Localizable.strings in zh_HK
100% translated source file: 'Localizable.strings'
on 'zh_HK'.
2023-06-26 10:46:06 +00:00
transifex-integration[bot]
28077ab91d Translate Localizable.stringsdict in zh_HK
100% translated source file: 'Localizable.stringsdict'
on 'zh_HK'.
2023-06-26 10:45:27 +00:00
transifex-integration[bot]
8d0a8909b9 Translate Localizable.strings in zh_TW
100% translated source file: 'Localizable.strings'
on 'zh_TW'.
2023-06-26 10:43:34 +00:00
transifex-integration[bot]
23bc6d0710 Translate Localizable.stringsdict in zh_TW
100% translated source file: 'Localizable.stringsdict'
on 'zh_TW'.
2023-06-26 10:41:55 +00:00
transifex-integration[bot]
993444d24b Translate Localizable.stringsdict in zh_CN
100% translated source file: 'Localizable.stringsdict'
on 'zh_CN'.
2023-06-26 10:40:49 +00:00
transifex-integration[bot]
cd30154990 Translate Localizable.strings in zh_CN
100% translated source file: 'Localizable.strings'
on 'zh_CN'.
2023-06-26 10:40:42 +00:00
transifex-integration[bot]
4513863c95 Translate Localizable.strings in zh_CN
100% translated source file: 'Localizable.strings'
on 'zh_CN'.
2023-06-26 10:37:50 +00:00
transifex-integration[bot]
19684bae36 Translate Localizable.strings in zh_CN
100% translated source file: 'Localizable.strings'
on 'zh_CN'.
2023-06-26 10:37:19 +00:00
transifex-integration[bot]
6b878e96cd Translate Localizable.stringsdict in zh_CN
100% translated source file: 'Localizable.stringsdict'
on 'zh_CN'.
2023-06-26 10:32:17 +00:00
William Casarin
40a51edafe readme: patchstr bounties 2023-06-26 12:03:05 +02:00
cfe14fac23 Deduplicate users in group notifications
Changelog-Fixed: Deduplicate users in notifications
Closes: #1326
2023-06-26 11:31:36 +02:00
2046fe5502 Fix notification content rendering of repost and reaction events
Closes: #1318
Changelog-Fixed: Fix notification content rendering of repost and reaction events
2023-06-26 11:20:11 +02:00
Bryan Montz
2d4ddc7b9c Fix crash related to VideoPlayer and CMTime
Closes: #1321
Changelog-Fixed: Fix crash related to VideoPlayer
2023-06-26 11:20:11 +02:00
William Casarin
6003a3c6f8 nozaps: don't pull thread zaps in nozaps mode 2023-06-26 11:20:11 +02:00
transifex-integration[bot]
572cae7dc5 Translate Localizable.strings in nl
100% translated source file: 'Localizable.strings'
on 'nl'.
2023-06-26 08:59:40 +00:00
transifex-integration[bot]
8d7d3d0d37 Translate Localizable.stringsdict in nl
100% translated source file: 'Localizable.stringsdict'
on 'nl'.
2023-06-26 08:58:56 +00:00
transifex-integration[bot]
c76fc5bcce Translate Localizable.stringsdict in nl
100% translated source file: 'Localizable.stringsdict'
on 'nl'.
2023-06-26 08:58:25 +00:00
transifex-integration[bot]
3a357c8d82 Translate Localizable.stringsdict in nl
100% translated source file: 'Localizable.stringsdict'
on 'nl'.
2023-06-26 08:58:10 +00:00
transifex-integration[bot]
ac59ee6285 Translate Localizable.strings in el_GR
100% translated source file: 'Localizable.strings'
on 'el_GR'.
2023-06-26 08:52:08 +00:00
transifex-integration[bot]
a870b86490 Translate Localizable.stringsdict in el_GR
100% translated source file: 'Localizable.stringsdict'
on 'el_GR'.
2023-06-26 08:43:40 +00:00
transifex-integration[bot]
cb2da7f3c6 Translate Localizable.stringsdict in sv_SE
100% translated source file: 'Localizable.stringsdict'
on 'sv_SE'.
2023-06-26 06:28:24 +00:00
transifex-integration[bot]
71f3b9b013 Translate Localizable.strings in sv_SE
100% translated source file: 'Localizable.strings'
on 'sv_SE'.
2023-06-26 06:27:13 +00:00
e220b0756f Export strings for translation 2023-06-25 23:46:53 -04:00
transifex-integration[bot]
83abedb4d6 Translate Localizable.stringsdict in sv_SE
100% translated source file: 'Localizable.stringsdict'
on 'sv_SE'.
2023-06-25 23:45:19 -04:00
transifex-integration[bot]
23b057779a Translate Localizable.strings in sv_SE
100% translated source file: 'Localizable.strings'
on 'sv_SE'.
2023-06-25 23:45:19 -04:00
80 changed files with 1549 additions and 676 deletions

View File

@@ -94,10 +94,33 @@ damus implements the following [Nostr Implementation Possibilities][nips]
Contributors welcome! Start by examining known issues: https://github.com/damus-io/damus/issues.
### Mailing lists
We have a few mailing lists that anyone can join to get involved in damus development:
- [dev][dev-list] - development discussions
- [patches][patches-list] - code submission and review
- [product][product-list] - product discussions
- [design][design-list] - design discussions
[dev-list]: https://damus.io/list/dev
[patches-list]: https://damus.io/list/patches
[product-list]: https://damus.io/list/product
[design-list]: https://damus.io/list/design
### Code
[Email patches][git-send-email] to jb55@jb55.com are preferred, but I accept PRs on GitHub as well.
[Email patches][git-send-email] to patches@damus.io are preferred, but I accept PRs on GitHub as well. Patches sent via email may include a bolt11 lightning invoice, choosing the price you think the patch is worth, and I will pay it once the patch is accepted and if I think the price isn't unreasonable. You can also send an any-amount invoice and I will pay what I think it's worth if you prefer not to choose. You can include the bolt11 in the commit body or email so that it can be paid once it is applied.
Recommended settings when submitting code via email:
```
$ git config sendemail.to "patches@damus.io"
$ git config format.subjectPrefix "PATCH damus"
$ git config --global sendemail.annotate yes
$ git config format.signOff yes
```
[git-send-email]: http://git-send-email.io
### Privacy

View File

@@ -20,7 +20,11 @@
3A4325A82961E11400BFCD9D /* Localizable.stringsdict in Resources */ = {isa = PBXBuildFile; fileRef = 3A4325AA2961E11400BFCD9D /* Localizable.stringsdict */; };
3A4647CF2A413ADC00386AD8 /* CondensedProfilePicturesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A4647CE2A413ADC00386AD8 /* CondensedProfilePicturesView.swift */; };
3A48E7B029DFBE9D006E787E /* MutedThreadsManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A48E7AF29DFBE9D006E787E /* MutedThreadsManager.swift */; };
3A5E47C52A4A6CF400C0D090 /* Trie.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A5E47C42A4A6CF400C0D090 /* Trie.swift */; };
3A5E47C72A4A76C800C0D090 /* TrieTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A5E47C62A4A76C800C0D090 /* TrieTests.swift */; };
3A8CC6CC2A2CFEF900940F5F /* StringUtil.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A8CC6CB2A2CFEF900940F5F /* StringUtil.swift */; };
3A90B1812A4EA3AF00000D94 /* UserSearchCache.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A90B1802A4EA3AF00000D94 /* UserSearchCache.swift */; };
3A90B1832A4EA3C600000D94 /* UserSearchCacheTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A90B1822A4EA3C600000D94 /* UserSearchCacheTests.swift */; };
3AA247FD297E3CFF0090C62D /* RepostsModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AA247FC297E3CFF0090C62D /* RepostsModel.swift */; };
3AA247FF297E3D900090C62D /* RepostsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AA247FE297E3D900090C62D /* RepostsView.swift */; };
3AA24802297E3DC20090C62D /* RepostView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AA24801297E3DC20090C62D /* RepostView.swift */; };
@@ -304,6 +308,7 @@
9CA876E229A00CEA0003B9A3 /* AttachMediaUtility.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9CA876E129A00CE90003B9A3 /* AttachMediaUtility.swift */; };
BA693074295D649800ADDB87 /* UserSettingsStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA693073295D649800ADDB87 /* UserSettingsStore.swift */; };
BAB68BED29543FA3007BA466 /* SelectWalletView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BAB68BEC29543FA3007BA466 /* SelectWalletView.swift */; };
D2277EEA2A089BD5006C3807 /* Router.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2277EE92A089BD5006C3807 /* Router.swift */; };
DD597CBD2963D85A00C64D32 /* MarkdownTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD597CBC2963D85A00C64D32 /* MarkdownTests.swift */; };
E4FA1C032A24BB7F00482697 /* SearchSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4FA1C022A24BB7F00482697 /* SearchSettingsView.swift */; };
E990020F2955F837003BBC5A /* EditMetadataView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E990020E2955F837003BBC5A /* EditMetadataView.swift */; };
@@ -376,6 +381,8 @@
3A5CAE1D298DC0DB00B5334F /* zh-CN */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-CN"; path = "zh-CN.lproj/InfoPlist.strings"; sourceTree = "<group>"; };
3A5CAE1E298DC0DB00B5334F /* zh-CN */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-CN"; path = "zh-CN.lproj/Localizable.strings"; sourceTree = "<group>"; };
3A5CAE1F298DC0DB00B5334F /* zh-CN */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = "zh-CN"; path = "zh-CN.lproj/Localizable.stringsdict"; sourceTree = "<group>"; };
3A5E47C42A4A6CF400C0D090 /* Trie.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Trie.swift; sourceTree = "<group>"; };
3A5E47C62A4A76C800C0D090 /* TrieTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TrieTests.swift; sourceTree = "<group>"; };
3A66D927299472FA008B44F4 /* ja */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ja; path = ja.lproj/InfoPlist.strings; sourceTree = "<group>"; };
3A66D928299472FA008B44F4 /* ja */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ja; path = ja.lproj/Localizable.strings; sourceTree = "<group>"; };
3A66D929299472FA008B44F4 /* ja */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = ja; path = ja.lproj/Localizable.stringsdict; sourceTree = "<group>"; };
@@ -389,6 +396,8 @@
3A8624DA299E82BE00BD8BE9 /* cs */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = cs; path = cs.lproj/Localizable.strings; sourceTree = "<group>"; };
3A8624DB299E82BE00BD8BE9 /* cs */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = cs; path = cs.lproj/Localizable.stringsdict; sourceTree = "<group>"; };
3A8CC6CB2A2CFEF900940F5F /* StringUtil.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StringUtil.swift; sourceTree = "<group>"; };
3A90B1802A4EA3AF00000D94 /* UserSearchCache.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UserSearchCache.swift; sourceTree = "<group>"; };
3A90B1822A4EA3C600000D94 /* UserSearchCacheTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserSearchCacheTests.swift; sourceTree = "<group>"; };
3A929C20297F2CF80090925E /* it-IT */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "it-IT"; path = "it-IT.lproj/InfoPlist.strings"; sourceTree = "<group>"; };
3A929C21297F2CF80090925E /* it-IT */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "it-IT"; path = "it-IT.lproj/Localizable.strings"; sourceTree = "<group>"; };
3A929C22297F2CF80090925E /* it-IT */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = "it-IT"; path = "it-IT.lproj/Localizable.stringsdict"; sourceTree = "<group>"; };
@@ -753,6 +762,7 @@
9CA876E129A00CE90003B9A3 /* AttachMediaUtility.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AttachMediaUtility.swift; sourceTree = "<group>"; };
BA693073295D649800ADDB87 /* UserSettingsStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserSettingsStore.swift; sourceTree = "<group>"; };
BAB68BEC29543FA3007BA466 /* SelectWalletView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectWalletView.swift; sourceTree = "<group>"; };
D2277EE92A089BD5006C3807 /* Router.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Router.swift; sourceTree = "<group>"; };
DD597CBC2963D85A00C64D32 /* MarkdownTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MarkdownTests.swift; sourceTree = "<group>"; };
E4FA1C022A24BB7F00482697 /* SearchSettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchSettingsView.swift; sourceTree = "<group>"; };
E990020E2955F837003BBC5A /* EditMetadataView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditMetadataView.swift; sourceTree = "<group>"; };
@@ -919,6 +929,8 @@
3A48E7AF29DFBE9D006E787E /* MutedThreadsManager.swift */,
4C7D09772A0B0CC900943473 /* WalletModel.swift */,
3A23838D2A297DD200E5AA2E /* ZapButtonModel.swift */,
3A5E47C42A4A6CF400C0D090 /* Trie.swift */,
3A90B1802A4EA3AF00000D94 /* UserSearchCache.swift */,
);
path = Models;
sourceTree = "<group>";
@@ -1155,6 +1167,7 @@
50B5685229F97CB400A23243 /* CredentialHandler.swift */,
4C7D09582A05BEAD00943473 /* KeyboardVisible.swift */,
3A8CC6CB2A2CFEF900940F5F /* StringUtil.swift */,
D2277EE92A089BD5006C3807 /* Router.swift */,
);
path = Util;
sourceTree = "<group>";
@@ -1307,7 +1320,9 @@
4CE6DEE427F7A08100C66700 /* Products */,
4CEE2AE62804F57B00AB5EEF /* Frameworks */,
);
indentWidth = 4;
sourceTree = "<group>";
tabWidth = 4;
};
4CE6DEE427F7A08100C66700 /* Products */ = {
isa = PBXGroup;
@@ -1374,6 +1389,8 @@
4C8D00D329E3C5D40036AF10 /* NIP19Tests.swift */,
501F8C812A0224EB001AFC1D /* KeychainStorageTests.swift */,
3AFBF3FC29FDA7CC00E79C7C /* CustomZapViewTests.swift */,
3A5E47C62A4A76C800C0D090 /* TrieTests.swift */,
3A90B1822A4EA3C600000D94 /* UserSearchCacheTests.swift */,
);
path = damusTests;
sourceTree = "<group>";
@@ -1726,6 +1743,7 @@
4C3D52B8298DB5C6001C5831 /* TextEvent.swift in Sources */,
4C216F362870A9A700040376 /* InputDismissKeyboard.swift in Sources */,
4C8D1A6F29F31E5000ACDF75 /* FriendsButton.swift in Sources */,
3A5E47C52A4A6CF400C0D090 /* Trie.swift in Sources */,
4C216F382871EDE300040376 /* DirectMessageModel.swift in Sources */,
4C75EFA627FF87A20006080F /* Nostr.swift in Sources */,
4CB883A62975F83C00DC99E7 /* LNUrlPayRequest.swift in Sources */,
@@ -1861,6 +1879,8 @@
5C6E1DAD2A193EC2008FC15A /* GradientButtonStyle.swift in Sources */,
4C8EC52529D1FA6C0085D9A8 /* DamusColors.swift in Sources */,
3A4647CF2A413ADC00386AD8 /* CondensedProfilePicturesView.swift in Sources */,
D2277EEA2A089BD5006C3807 /* Router.swift in Sources */,
3A90B1812A4EA3AF00000D94 /* UserSearchCache.swift in Sources */,
4C5C7E6A284EDE2E00A22DF5 /* SearchResultsView.swift in Sources */,
4CE1399429F0669900AC6A0B /* BigButton.swift in Sources */,
7C60CAEF298471A1009C80D6 /* CoreSVG.swift in Sources */,
@@ -1952,6 +1972,7 @@
buildActionMask = 2147483647;
files = (
5019CADD2A0FB0A9000069E1 /* ProfileDatabaseTests.swift in Sources */,
3A90B1832A4EA3C600000D94 /* UserSearchCacheTests.swift in Sources */,
3A3040ED29A5CB86008A0F29 /* ReplyDescriptionTests.swift in Sources */,
4C8D00D429E3C5D40036AF10 /* NIP19Tests.swift in Sources */,
3A30410129AB12AA008A0F29 /* EventGroupViewTests.swift in Sources */,
@@ -1966,6 +1987,7 @@
4CB883AA297612FF00DC99E7 /* ZapTests.swift in Sources */,
4CB8839A297322D200DC99E7 /* DMTests.swift in Sources */,
F944F56E29EA9CCC0067B3BF /* DamusParseContentTests.swift in Sources */,
3A5E47C72A4A76C800C0D090 /* TrieTests.swift in Sources */,
4CB883AE2976FA9300DC99E7 /* FormatTests.swift in Sources */,
4C363AA02828A8DD006E126D /* LikeTests.swift in Sources */,
4C90BD1C283AC38E008EE7EF /* Bech32Tests.swift in Sources */,
@@ -2236,7 +2258,7 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = damus/damus.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 6;
CURRENT_PROJECT_VERSION = 8;
DEVELOPMENT_ASSET_PATHS = "\"damus/Preview Content\"";
DEVELOPMENT_TEAM = XK7H4JAB3D;
ENABLE_PREVIEWS = YES;
@@ -2254,6 +2276,7 @@
INFOPLIST_KEY_UILaunchStoryboardName = Launch.storyboard;
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
@@ -2284,7 +2307,7 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = damus/damus.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 6;
CURRENT_PROJECT_VERSION = 8;
DEVELOPMENT_ASSET_PATHS = "\"damus/Preview Content\"";
DEVELOPMENT_TEAM = XK7H4JAB3D;
ENABLE_PREVIEWS = YES;
@@ -2302,6 +2325,7 @@
INFOPLIST_KEY_UILaunchStoryboardName = Launch.storyboard;
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
@@ -2332,7 +2356,7 @@
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = XK7H4JAB3D;
GENERATE_INFOPLIST_FILE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 15.3;
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.jb55.damusTests;
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -2352,7 +2376,7 @@
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = XK7H4JAB3D;
GENERATE_INFOPLIST_FILE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 15.3;
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.jb55.damusTests;
PRODUCT_NAME = "$(TARGET_NAME)";

View File

@@ -11,21 +11,10 @@ struct UserViewRow: View {
let damus_state: DamusState
let pubkey: String
@State var navigating: Bool = false
var body: some View {
let dest = ProfileView(damus_state: damus_state, pubkey: pubkey)
UserView(damus_state: damus_state, pubkey: pubkey)
.contentShape(Rectangle())
.background(
NavigationLink(destination: dest, isActive: $navigating) {
EmptyView()
}
)
.onTapGesture {
navigating = true
}
.background(.clear)
}
}

View File

@@ -38,10 +38,6 @@ struct ZapButton: View {
}
var zap_img: String {
if damus_state.settings.nozaps {
return "zap"
}
switch our_zap {
case .none:
return "zap"
@@ -53,10 +49,6 @@ struct ZapButton: View {
}
var zap_color: Color {
if damus_state.settings.nozaps {
return Color.gray
}
if our_zap == nil {
return Color.gray
}
@@ -114,17 +106,19 @@ struct ZapButton: View {
var body: some View {
HStack(spacing: 4) {
Button(action: {
}, label: {
Image(zap_img)
.resizable()
.foregroundColor(zap_color)
.font(.footnote.weight(.medium))
.aspectRatio(contentMode: .fit)
.frame(width:20, height: 20)
})
if !damus_state.settings.nozaps || zaps.zap_total > 0 {
Button(action: {
}, label: {
Image(zap_img)
.resizable()
.foregroundColor(zap_color)
.font(.footnote.weight(.medium))
.aspectRatio(contentMode: .fit)
.frame(width:20, height: 20)
})
}
if !damus_state.settings.nozaps && zaps.zap_total > 0 {
if zaps.zap_total > 0 {
Text(verbatim: format_msats_abbrev(zaps.zap_total))
.font(.footnote)
.foregroundColor(zap_color)
@@ -132,21 +126,14 @@ struct ZapButton: View {
}
.accessibilityLabel(NSLocalizedString("Zap", comment: "Accessibility label for zap button"))
.simultaneousGesture(LongPressGesture().onEnded {_ in
// when we don't have nozaps mode enable, long press shows the zap customizer
if !damus_state.settings.nozaps {
present_sheet(.zap(target: target, lnurl: lnurl))
}
guard !damus_state.settings.nozaps else { return }
// long press does nothing in nozaps mode
present_sheet(.zap(target: target, lnurl: lnurl))
})
.highPriorityGesture(TapGesture().onEnded {
// when we have appstore mode on, only show the zap customizer as "user zaps"
if damus_state.settings.nozaps {
present_sheet(.zap(target: target, lnurl: lnurl))
} else {
// otherwise we restore the original behavior of one-tap zaps
tap()
}
guard !damus_state.settings.nozaps else { return }
tap()
})
}
}

View File

@@ -82,14 +82,6 @@ struct ContentView: View {
@State var damus_state: DamusState? = nil
@SceneStorage("ContentView.selected_timeline") var selected_timeline: Timeline = .home
@State var is_deleted_account: Bool = false
@State var active_profile: String? = nil
@State var active_search: NostrFilter? = nil
@State var active_event: NostrEvent? = nil
@State var profile_open: Bool = false
@State var thread_open: Bool = false
@State var search_open: Bool = false
@State var wallet_open: Bool = false
@State var active_nwc: WalletConnectURL? = nil
@State var muting: String? = nil
@State var confirm_mute: Bool = false
@State var user_muted_confirm: Bool = false
@@ -97,6 +89,7 @@ struct ContentView: View {
@SceneStorage("ContentView.filter_state") var filter_state : FilterState = .posts_and_replies
@State private var isSideBarOpened = false
var home: HomeModel = HomeModel()
@StateObject var navigationCoordinator: NavigationCoordinator = NavigationCoordinator()
let sub_id = UUID().description
@@ -128,7 +121,7 @@ struct ContentView: View {
if privkey != nil {
PostButtonContainer(is_left_handed: damus_state?.settings.left_handed ?? false) {
self.active_sheet = .post(.posting)
self.active_sheet = .post(.posting(.none))
}
}
}
@@ -155,10 +148,7 @@ struct ContentView: View {
}
func popToRoot() {
profile_open = false
thread_open = false
search_open = false
wallet_open = false
navigationCoordinator.popToRoot()
isSideBarOpened = false
}
@@ -169,21 +159,6 @@ struct ContentView: View {
func MainContent(damus: DamusState) -> some View {
VStack {
NavigationLink(destination: WalletView(damus_state: damus, model: damus_state!.wallet), isActive: $wallet_open) {
EmptyView()
}
NavigationLink(destination: MaybeProfileView, isActive: $profile_open) {
EmptyView()
}
if let active_event {
let thread = ThreadModel(event: active_event, damus_state: damus_state!)
NavigationLink(destination: ThreadView(state: damus_state!, thread: thread), isActive: $thread_open) {
EmptyView()
}
}
NavigationLink(destination: MaybeSearchView, isActive: $search_open) {
EmptyView()
}
switch selected_timeline {
case .search:
if #available(iOS 16.0, *) {
@@ -225,28 +200,6 @@ struct ContentView: View {
}
}
var MaybeSearchView: some View {
Group {
if let search = self.active_search {
SearchView(appstate: damus_state!, search: SearchModel(state: damus_state!, search: search))
} else {
EmptyView()
}
}
}
var MaybeProfileView: some View {
Group {
if let pk = self.active_profile {
let profile_model = ProfileModel(pubkey: pk, damus: damus_state!)
let followers = FollowersModel(damus_state: damus_state!, target: pk)
ProfileView(damus_state: damus_state!, profile: profile_model, followers: followers)
} else {
EmptyView()
}
}
}
func MaybeReportView(target: ReportTarget) -> some View {
Group {
if let damus_state {
@@ -262,32 +215,30 @@ struct ContentView: View {
}
func open_event(ev: NostrEvent) {
popToRoot()
self.active_event = ev
self.thread_open = true
let thread = ThreadModel(event: ev, damus_state: damus_state!)
navigationCoordinator.push(route: Route.Thread(thread: thread))
}
func open_wallet(nwc: WalletConnectURL) {
self.damus_state!.wallet.new(nwc)
self.wallet_open = true
navigationCoordinator.push(route: Route.Wallet(wallet: damus_state!.wallet))
}
func open_profile(id: String) {
popToRoot()
self.active_profile = id
self.profile_open = true
let profile_model = ProfileModel(pubkey: id, damus: damus_state!)
let followers = FollowersModel(damus_state: damus_state!, target: id)
navigationCoordinator.push(route: Route.Profile(profile: profile_model, followers: followers))
}
func open_search(filt: NostrFilter) {
popToRoot()
self.active_search = filt
self.search_open = true
let search = SearchModel(state: damus_state!, search: filt)
navigationCoordinator.push(route: Route.Search(search: search))
}
var body: some View {
VStack(alignment: .leading, spacing: 0) {
if let damus = self.damus_state {
NavigationView {
NavigationStack(path: $navigationCoordinator.path) {
TabView { // Prevents navbar appearance change on scroll
MainContent(damus: damus)
.toolbar() {
@@ -327,6 +278,12 @@ struct ContentView: View {
.overlay(
SideMenuView(damus_state: damus, isSidebarVisible: $isSideBarOpened.animation())
)
.navigationDestination(for: Route.self) { route in
route.view(navigationCordinator: navigationCoordinator, damusState: damus_state!)
}
.onReceive(handle_notify(.switched_timeline)) { _ in
navigationCoordinator.popToRoot()
}
}
.navigationViewStyle(.stack)
@@ -520,8 +477,8 @@ struct ContentView: View {
switch local.type {
case .dm:
selected_timeline = .dms
damus_state.dms.open_dm_by_pk(target.pubkey)
damus_state.dms.set_active_dm(target.pubkey)
navigationCoordinator.push(route: Route.DMChat(dms: damus_state.dms.active_model))
case .like: fallthrough
case .zap: fallthrough
case .mention: fallthrough
@@ -667,13 +624,14 @@ struct ContentView: View {
let nwc = WalletConnectURL(str: nwc_str) {
try? pool.add_relay(.nwc(url: nwc.relay))
}
let user_search_cache = UserSearchCache()
self.damus_state = DamusState(pool: pool,
keypair: keypair,
likes: EventCounter(our_pubkey: pubkey),
boosts: EventCounter(our_pubkey: pubkey),
contacts: Contacts(our_pubkey: pubkey),
profiles: Profiles(),
profiles: Profiles(user_search_cache: user_search_cache),
dms: home.dms,
previews: PreviewCache(),
zaps: Zaps(our_pubkey: pubkey),
@@ -688,7 +646,9 @@ struct ContentView: View {
bootstrap_relays: bootstrap_relays,
replies: ReplyCounter(our_pubkey: pubkey),
muted_threads: MutedThreadsManager(keypair: keypair),
wallet: WalletModel(settings: settings)
wallet: WalletModel(settings: settings),
nav: self.navigationCoordinator,
user_search_cache: user_search_cache
)
home.damus_state = self.damus_state!
@@ -918,17 +878,18 @@ func handle_unfollow(state: DamusState, notif: Notification) {
let target = notif.object as! FollowTarget
let pk = target.pubkey
let old_contacts = state.contacts.event
if let ev = unfollow_user(postbox: state.postbox,
our_contacts: state.contacts.event,
our_contacts: old_contacts,
pubkey: state.pubkey,
privkey: privkey,
unfollow: pk) {
notify(.unfollowed, pk)
state.contacts.event = ev
state.contacts.remove_friend(pk)
//friend_events = friend_events.filter { $0.pubkey != pk }
state.user_search_cache.updateOwnContactsPetnames(id: state.pubkey, oldEvent: old_contacts, newEvent: ev)
}
}

View File

@@ -30,6 +30,8 @@ struct DamusState {
let replies: ReplyCounter
let muted_threads: MutedThreadsManager
let wallet: WalletModel
let nav: NavigationCoordinator
let user_search_cache: UserSearchCache
@discardableResult
func add_zap(zap: Zapping) -> Bool {
@@ -57,5 +59,6 @@ struct DamusState {
}
static var empty: DamusState {
return DamusState.init(pool: RelayPool(), keypair: Keypair(pubkey: "", privkey: ""), likes: EventCounter(our_pubkey: ""), boosts: EventCounter(our_pubkey: ""), contacts: Contacts(our_pubkey: ""), profiles: Profiles(), dms: DirectMessagesModel(our_pubkey: ""), previews: PreviewCache(), zaps: Zaps(our_pubkey: ""), lnurls: LNUrls(), settings: UserSettingsStore(), relay_filters: RelayFilters(our_pubkey: ""), relay_metadata: RelayMetadatas(), drafts: Drafts(), events: EventCache(), bookmarks: BookmarksManager(pubkey: ""), postbox: PostBox(pool: RelayPool()), bootstrap_relays: [], replies: ReplyCounter(our_pubkey: ""), muted_threads: MutedThreadsManager(keypair: Keypair(pubkey: "", privkey: nil)), wallet: WalletModel(settings: UserSettingsStore())) }
let user_search_cache = UserSearchCache()
return DamusState.init(pool: RelayPool(), keypair: Keypair(pubkey: "", privkey: ""), likes: EventCounter(our_pubkey: ""), boosts: EventCounter(our_pubkey: ""), contacts: Contacts(our_pubkey: ""), profiles: Profiles(user_search_cache: user_search_cache), dms: DirectMessagesModel(our_pubkey: ""), previews: PreviewCache(), zaps: Zaps(our_pubkey: ""), lnurls: LNUrls(), settings: UserSettingsStore(), relay_filters: RelayFilters(our_pubkey: ""), relay_metadata: RelayMetadatas(), drafts: Drafts(), events: EventCache(), bookmarks: BookmarksManager(pubkey: ""), postbox: PostBox(pool: RelayPool()), bootstrap_relays: [], replies: ReplyCounter(our_pubkey: ""), muted_threads: MutedThreadsManager(keypair: Keypair(pubkey: "", privkey: nil)), wallet: WalletModel(settings: UserSettingsStore()), nav: NavigationCoordinator(), user_search_cache: user_search_cache) }
}

View File

@@ -30,16 +30,6 @@ class DirectMessagesModel: ObservableObject {
self.active_model = model
}
func open_dm_by_pk(_ pubkey: String) {
self.set_active_dm(pubkey)
self.open_dm = true
}
func open_dm_by_model(_ model: DirectMessageModel) {
self.set_active_dm_model(model)
self.open_dm = true
}
func set_active_dm(_ pubkey: String) {
for model in self.dms where model.pubkey == pubkey {
self.set_active_dm_model(model)

View File

@@ -612,7 +612,8 @@ func add_contact_if_friend(contacts: Contacts, ev: NostrEvent) {
contacts.add_friend_contact(ev)
}
func load_our_contacts(contacts: Contacts, m_old_ev: NostrEvent?, ev: NostrEvent) {
func load_our_contacts(state: DamusState, m_old_ev: NostrEvent?, ev: NostrEvent) {
let contacts = state.contacts
var new_pks = Set<String>()
// our contacts
for tag in ev.tags {
@@ -641,6 +642,8 @@ func load_our_contacts(contacts: Contacts, m_old_ev: NostrEvent?, ev: NostrEvent
contacts.remove_friend(pk)
}
}
state.user_search_cache.updateOwnContactsPetnames(id: contacts.our_pubkey, oldEvent: m_old_ev, newEvent: ev)
}
@@ -701,7 +704,9 @@ func process_metadata_profile(our_pubkey: String, profiles: Profiles, profile: P
}
var old_nip05: String? = nil
if let mprof = profiles.lookup_with_timestamp(id: ev.pubkey) {
let mprof = profiles.lookup_with_timestamp(id: ev.pubkey)
if let mprof {
old_nip05 = mprof.profile.nip05
if mprof.event.created_at > ev.created_at {
// skip if we already have an newer profile
@@ -752,7 +757,7 @@ func guard_valid_event(events: EventCache, ev: NostrEvent, callback: @escaping (
switch validated {
case .unknown:
Task {
Task.detached(priority: .medium) {
let result = validate_event(ev: ev)
DispatchQueue.main.async {
@@ -810,7 +815,7 @@ func load_our_stuff(state: DamusState, ev: NostrEvent) {
let m_old_ev = state.contacts.event
state.contacts.event = ev
load_our_contacts(contacts: state.contacts, m_old_ev: m_old_ev, ev: ev)
load_our_contacts(state: state, m_old_ev: m_old_ev, ev: ev)
load_our_relays(state: state, m_old_ev: m_old_ev, ev: ev)
}
@@ -858,6 +863,7 @@ func load_our_relays(state: DamusState, m_old_ev: NostrEvent?, ev: NostrEvent) {
if changed {
save_bootstrap_relays(pubkey: state.pubkey, relays: Array(new))
state.pool.connect()
notify(.relays_changed, ())
}
}
@@ -1076,7 +1082,7 @@ func zap_notification_title(_ zap: Zap) -> String {
func zap_notification_body(profiles: Profiles, zap: Zap, locale: Locale = Locale.current) -> String {
let src = zap.request.ev
let pk = zap.is_anon ? "anon" : src.pubkey
let pk = zap.is_anon ? ANON_PUBKEY : src.pubkey
let profile = profiles.lookup(id: pk)
let sats = NSNumber(value: (Double(zap.invoice.amount) / 1000.0))
let formattedSats = format_msats_abbrev(zap.invoice.amount)
@@ -1164,13 +1170,15 @@ func process_local_notification(damus_state: DamusState, event ev: NostrEvent) {
create_local_notification(profiles: damus_state.profiles, notify: notify )
}
} else if type == .boost && damus_state.settings.repost_notification, let inner_ev = ev.get_inner_event(cache: damus_state.events) {
let notify = LocalNotification(type: .repost, event: ev, target: inner_ev, content: inner_ev.content)
let content = NSAttributedString(render_note_content(ev: inner_ev, profiles: damus_state.profiles, privkey: damus_state.keypair.privkey).content.attributed).string
let notify = LocalNotification(type: .repost, event: ev, target: inner_ev, content: content)
create_local_notification(profiles: damus_state.profiles, notify: notify)
} else if type == .like && damus_state.settings.like_notification,
let evid = ev.referenced_ids.last?.ref_id,
let liked_event = damus_state.events.lookup(evid)
{
let notify = LocalNotification(type: .like, event: ev, target: liked_event, content: liked_event.content)
let content = NSAttributedString(render_note_content(ev: liked_event, profiles: damus_state.profiles, privkey: damus_state.keypair.privkey).content.attributed).string
let notify = LocalNotification(type: .like, event: ev, target: liked_event, content: content)
create_local_notification(profiles: damus_state.profiles, notify: notify)
}

View File

@@ -76,7 +76,7 @@ class ProfileModel: ObservableObject, Equatable {
profile_filter.authors = [pubkey]
text_filter.authors = [pubkey]
text_filter.limit = 500
text_filter.limit = 50
print("subscribing to profile \(pubkey) with sub_id \(sub_id)")
print_filters(relay_id: "profile", filters: [[text_filter], [profile_filter]])

129
damus/Models/Trie.swift Normal file
View File

@@ -0,0 +1,129 @@
//
// Trie.swift
// damus
//
// Created by Terry Yiu on 6/26/23.
//
import Foundation
/// Tree data structure of all the substring permutations of a collection of strings optimized for searching for values of type V.
///
/// Each node in the tree can have child nodes.
/// Each node represents a single character in substrings, and each of its child nodes represent the subsequent character in those substrings.
///
/// A node that has no children mean that there are no substrings with any additional characters beyond the branch of letters leading up to that node.
///
/// A node that has values mean that there are strings that end in the character represented by the node and contain the substring represented by the branch of letters leading up to that node.
///
/// https://en.wikipedia.org/wiki/Trie
class Trie<V: Hashable> {
private var children: [Character : Trie] = [:]
/// Separate exact matches from strict substrings so that exact matches appear first in returned results.
private var exactMatchValues = Set<V>()
private var substringMatchValues = Set<V>()
private var parent: Trie? = nil
}
extension Trie {
var hasChildren: Bool {
return !self.children.isEmpty
}
var hasValues: Bool {
return !self.exactMatchValues.isEmpty || !self.substringMatchValues.isEmpty
}
/// Finds the branch that matches the specified key and returns the values from all of its descendant nodes.
func find(key: String) -> [V] {
var currentNode = self
// Find branch with matching prefix.
for char in key {
if let child = currentNode.children[char] {
currentNode = child
} else {
return []
}
}
// Perform breadth-first search from matching branch and collect values from all descendants.
var exactMatches = Set<V>()
var substringMatches = Set<V>()
var queue = [currentNode]
while !queue.isEmpty {
let node = queue.removeFirst()
exactMatches.formUnion(node.exactMatchValues)
substringMatches.formUnion(node.substringMatchValues)
queue.append(contentsOf: node.children.values)
}
return Array(exactMatches) + substringMatches
}
/// Inserts value of type V into this trie for the specified key. This function stores all substring endings of the key, not only the key itself.
/// Runtime performance is O(n^2) and storage cost is O(n), where n is the number of characters in the key.
func insert(key: String, value: V) {
// Create root branches for each character of the key to enable substring searches instead of only just prefix searches.
// Hence the nested loop.
for i in 0..<key.count {
var currentNode = self
// Find branch with matching prefix.
for char in key[key.index(key.startIndex, offsetBy: i)...] {
if let child = currentNode.children[char] {
currentNode = child
} else {
let child = Trie()
child.parent = currentNode
currentNode.children[char] = child
currentNode = child
}
}
if i == 0 {
currentNode.exactMatchValues.insert(value)
} else {
currentNode.substringMatchValues.insert(value)
}
}
}
/// Removes value of type V from this trie for the specified key.
func remove(key: String, value: V) {
for i in 0..<key.count {
var currentNode = self
var foundLeafNode = true
// Find branch with matching prefix.
for j in i..<key.count {
let char = key[key.index(key.startIndex, offsetBy: j)]
if let child = currentNode.children[char] {
currentNode = child
} else {
foundLeafNode = false
break
}
}
if foundLeafNode {
currentNode.exactMatchValues.remove(value)
currentNode.substringMatchValues.remove(value)
// Clean up the tree if this leaf node no longer holds values or children.
for j in (i..<key.count).reversed() {
if let parent = currentNode.parent, !currentNode.hasValues && !currentNode.hasChildren {
currentNode = parent
let char = key[key.index(key.startIndex, offsetBy: j)]
currentNode.children.removeValue(forKey: char)
}
}
}
}
}
}

View File

@@ -0,0 +1,107 @@
//
// UserSearchCache.swift
// damus
//
// Created by Terry Yiu on 6/27/23.
//
import Foundation
/// Cache of searchable users by name, display_name, NIP-05 identifier, or own contact list petname.
/// Optimized for fast searches of substrings by using a Trie.
/// Optimal for performing user searches that could be initiated by typing quickly on a keyboard into a text input field.
class UserSearchCache {
private let trie = Trie<String>()
func search(key: String) -> [String] {
let results = trie.find(key: key)
return results
}
/// Computes the differences between an old profile, if it exists, and a new profile, and updates the user search cache accordingly.
func updateProfile(id: String, profiles: Profiles, oldProfile: Profile?, newProfile: Profile) {
// Remove searchable keys tied to the old profile if they differ from the new profile
// to keep the trie clean without empty nodes while avoiding excessive graph searching.
if let oldProfile {
if let oldName = oldProfile.name, newProfile.name?.caseInsensitiveCompare(oldName) != .orderedSame {
trie.remove(key: oldName.lowercased(), value: id)
}
if let oldDisplayName = oldProfile.display_name, newProfile.display_name?.caseInsensitiveCompare(oldDisplayName) != .orderedSame {
trie.remove(key: oldDisplayName.lowercased(), value: id)
}
if let oldNip05 = oldProfile.nip05, newProfile.nip05?.caseInsensitiveCompare(oldNip05) != .orderedSame {
trie.remove(key: oldNip05.lowercased(), value: id)
}
}
addProfile(id: id, profiles: profiles, profile: newProfile)
}
/// Adds a profile to the user search cache.
private func addProfile(id: String, profiles: Profiles, profile: Profile) {
// Searchable by name.
if let name = profile.name {
trie.insert(key: name.lowercased(), value: id)
}
// Searchable by display name.
if let displayName = profile.display_name {
trie.insert(key: displayName.lowercased(), value: id)
}
// Searchable by NIP-05 identifier.
if let nip05 = profiles.is_validated(id) {
trie.insert(key: "\(nip05.username.lowercased())@\(nip05.host.lowercased())", value: id)
}
}
/// Computes the diffences between an old contacts event and a new contacts event for our own user, and updates the search cache accordingly.
func updateOwnContactsPetnames(id: String, oldEvent: NostrEvent?, newEvent: NostrEvent) {
guard newEvent.known_kind == .contacts && newEvent.pubkey == id else {
return
}
var petnames: [String: String] = [:]
// Gets all petnames from our new contacts list.
newEvent.tags.forEach { tag in
guard tag.count >= 4 && tag[0] == "p" else {
return
}
let pubkey = tag[1]
let petname = tag[3]
petnames[pubkey] = petname
}
// Compute the diff with the old contacts list, if it exists,
// mark the ones that are the same to not be removed from the user search cache,
// and remove the old ones that are different from the user search cache.
if let oldEvent, oldEvent.known_kind == .contacts && oldEvent.pubkey == id {
oldEvent.tags.forEach { tag in
guard tag.count >= 4 && tag[0] == "p" else {
return
}
let pubkey = tag[1]
let oldPetname = tag[3]
if let newPetname = petnames[pubkey] {
if newPetname.caseInsensitiveCompare(oldPetname) == .orderedSame {
petnames.removeValue(forKey: pubkey)
} else {
trie.remove(key: oldPetname, value: pubkey)
}
} else {
trie.remove(key: oldPetname, value: pubkey)
}
}
}
// Add the new petnames to the user search cache.
for (pubkey, petname) in petnames {
trie.insert(key: petname, value: pubkey)
}
}
}

View File

@@ -23,6 +23,12 @@ class Profiles {
var zappers: [String: String] = [:]
private let database = ProfileDatabase()
let user_search_cache: UserSearchCache
init(user_search_cache: UserSearchCache) {
self.user_search_cache = user_search_cache
}
func is_validated(_ pk: String) -> NIP05? {
validated[pk]
@@ -40,7 +46,9 @@ class Profiles {
func add(id: String, profile: TimestampedProfile) {
queue.async(flags: .barrier) {
let old_timestamped_profile = self.profiles[id]
self.profiles[id] = profile
self.user_search_cache.updateProfile(id: id, profiles: self, oldProfile: old_timestamped_profile?.profile, newProfile: profile.profile)
}
Task {

View File

@@ -38,7 +38,7 @@ enum DisplayName {
func parse_display_name(profile: Profile?, pubkey: String) -> DisplayName {
if pubkey == "anon" {
if pubkey == ANON_PUBKEY {
return .one(NSLocalizedString("Anonymous", comment: "Placeholder display name of anonymous user."))
}

View File

@@ -9,6 +9,7 @@ import Foundation
import secp256k1
let PUBKEY_HRP = "npub"
let ANON_PUBKEY = "anon"
struct FullKeypair: Equatable {
let pubkey: String

276
damus/Util/Router.swift Normal file
View File

@@ -0,0 +1,276 @@
//
// Router.swift
// damus
//
// Created by Scott Penrose on 5/7/23.
//
import SwiftUI
enum Route: Hashable {
case ProfileByKey(pubkey: String)
case Profile(profile: ProfileModel, followers: FollowersModel)
case Followers(followers: FollowersModel)
case Relay(relay: String, showActionButtons: Binding<Bool>)
case RelayDetail(relay: String, metadata: RelayMetadata)
case Following(following: FollowingModel)
case MuteList(users: [String])
case RelayConfig
case Bookmarks
case Config
case EditMetadata
case DMChat(dms: DirectMessageModel)
case UserRelays(relays: [String])
case KeySettings(keypair: Keypair)
case AppearanceSettings(settings: UserSettingsStore)
case NotificationSettings(settings: UserSettingsStore)
case ZapSettings(settings: UserSettingsStore)
case TranslationSettings(settings: UserSettingsStore)
case SearchSettings(settings: UserSettingsStore)
case Thread(thread: ThreadModel)
case Reposts(reposts: RepostsModel)
case Reactions(reactions: ReactionsModel)
case Zaps(target: ZapTarget)
case Search(search: SearchModel)
case EULA
case Login
case CreateAccount
case SaveKeys(account: CreateAccountModel)
case Wallet(wallet: WalletModel)
case WalletScanner(result: Binding<WalletScanResult>)
case FollowersYouKnow(friendedFollowers: [String], followers: FollowersModel)
@ViewBuilder
func view(navigationCordinator: NavigationCoordinator, damusState: DamusState) -> some View {
switch self {
case .ProfileByKey(let pubkey):
ProfileView(damus_state: damusState, pubkey: pubkey)
case .Profile(let profile, let followers):
ProfileView(damus_state: damusState, profile: profile, followers: followers)
case .Followers(let followers):
FollowersView(damus_state: damusState, followers: followers)
case .Relay(let relay, let showActionButtons):
RelayView(state: damusState, relay: relay, showActionButtons: showActionButtons)
case .RelayDetail(let relay, let metadata):
RelayDetailView(state: damusState, relay: relay, nip11: metadata)
case .Following(let following):
FollowingView(damus_state: damusState, following: following)
case .MuteList(let users):
MutelistView(damus_state: damusState, users: users)
case .RelayConfig:
RelayConfigView(state: damusState)
case .Bookmarks:
BookmarksView(state: damusState)
case .Config:
ConfigView(state: damusState)
case .EditMetadata:
EditMetadataView(damus_state: damusState)
case .DMChat(let dms):
DMChatView(damus_state: damusState, dms: dms)
case .UserRelays(let relays):
UserRelaysView(state: damusState, relays: relays)
case .KeySettings(let keypair):
KeySettingsView(keypair: keypair)
case .AppearanceSettings(let settings):
AppearanceSettingsView(settings: settings)
case .NotificationSettings(let settings):
NotificationSettingsView(settings: settings)
case .ZapSettings(let settings):
ZapSettingsView(settings: settings)
case .TranslationSettings(let settings):
NotificationSettingsView(settings: settings)
case .SearchSettings(let settings):
SearchSettingsView(settings: settings)
case .Thread(let thread):
ThreadView(state: damusState, thread: thread)
case .Reposts(let reposts):
RepostsView(damus_state: damusState, model: reposts)
case .Reactions(let reactions):
ReactionsView(damus_state: damusState, model: reactions)
case .Zaps(let target):
ZapsView(state: damusState, target: target)
case .Search(let search):
SearchView(appstate: damusState, search: search)
case .EULA:
EULAView(nav: navigationCordinator)
case .Login:
LoginView(nav: navigationCordinator)
case .CreateAccount:
CreateAccountView(nav: navigationCordinator)
case .SaveKeys(let account):
SaveKeysView(account: account)
case .Wallet(let walletModel):
WalletView(damus_state: damusState, model: walletModel)
case .WalletScanner(let walletScanResult):
WalletScannerView(result: walletScanResult)
case .FollowersYouKnow(let friendedFollowers, let followers):
FollowersYouKnowView(damus_state: damusState, friended_followers: friendedFollowers, followers: followers)
}
}
static func == (lhs: Route, rhs: Route) -> Bool {
switch (lhs, rhs) {
case (.ProfileByKey (let lhs_pubkey), .ProfileByKey(let rhs_pubkey)):
return lhs_pubkey == rhs_pubkey
case (.Profile (let lhs_profile, _), .Profile(let rhs_profile, _)):
return lhs_profile == rhs_profile
case (.Followers (_), .Followers (_)):
return true
case (.Relay (let lhs_relay, _), .Relay (let rhs_relay, _)):
return lhs_relay == rhs_relay
case (.RelayDetail(let lhs_relay, _), .RelayDetail(let rhs_relay, _)):
return lhs_relay == rhs_relay
case (.Following(_), .Following(_)):
return true
case (.MuteList(let lhs_users), .MuteList(let rhs_users)):
return lhs_users == rhs_users
case (.RelayConfig, .RelayConfig):
return true
case (.Bookmarks, .Bookmarks):
return true
case (.Config, .Config):
return true
case (.EditMetadata, .EditMetadata):
return true
case (.DMChat(let lhs_dms), .DMChat(let rhs_dms)):
return lhs_dms.our_pubkey == rhs_dms.our_pubkey
case (.UserRelays(let lhs_relays), .UserRelays(let rhs_relays)):
return lhs_relays == rhs_relays
case (.KeySettings(let lhs_keypair), .KeySettings(let rhs_keypair)):
return lhs_keypair.pubkey == rhs_keypair.pubkey
case (.AppearanceSettings(_), .AppearanceSettings(_)):
return true
case (.NotificationSettings(_), .NotificationSettings(_)):
return true
case (.ZapSettings(_), .ZapSettings(_)):
return true
case (.TranslationSettings(_), .TranslationSettings(_)):
return true
case (.SearchSettings(_), .SearchSettings(_)):
return true
case (.Thread(let lhs_threadModel), .Thread(thread: let rhs_threadModel)):
return lhs_threadModel.event.id == rhs_threadModel.event.id
case (.Reposts(let lhs_reposts), .Reposts(let rhs_reposts)):
return lhs_reposts.target == rhs_reposts.target
case (.Reactions(let lhs_reactions), .Reactions(let rhs_reactions)):
return lhs_reactions.target == rhs_reactions.target
case (.Zaps(let lhs_target), .Zaps(let rhs_target)):
return lhs_target == rhs_target
case (.Search(let lhs_search), .Search(let rhs_search)):
return lhs_search.sub_id == rhs_search.sub_id && lhs_search.profiles_subid == rhs_search.profiles_subid
case (.EULA, .EULA):
return true
case (.Login, .Login):
return true
case (.CreateAccount, .CreateAccount):
return true
case (.SaveKeys(let lhs_account), .SaveKeys(let rhs_account)):
return lhs_account.pubkey == rhs_account.pubkey
case (.Wallet(_), .Wallet(_)):
return true
case (.WalletScanner(_), .WalletScanner(_)):
return true
case (.FollowersYouKnow(_, _), .FollowersYouKnow(_, _)):
return true
default:
return false
}
}
func hash(into hasher: inout Hasher) {
switch self {
case .ProfileByKey(let pubkey):
hasher.combine("profilebykey")
hasher.combine(pubkey)
case .Profile(let profile, _):
hasher.combine("profile")
hasher.combine(profile.pubkey)
case .Followers(_):
hasher.combine("followers")
case .Relay(let relay, _):
hasher.combine("relay")
hasher.combine(relay)
case .RelayDetail(let relay, _):
hasher.combine("relayDetail")
hasher.combine(relay)
case .Following(_):
hasher.combine("following")
case .MuteList(let users):
hasher.combine("muteList")
hasher.combine(users)
case .RelayConfig:
hasher.combine("relayConfig")
case .Bookmarks:
hasher.combine("bookmarks")
case .Config:
hasher.combine("config")
case .EditMetadata:
hasher.combine("editMetadata")
case .DMChat(let dms):
hasher.combine("dms")
hasher.combine(dms.our_pubkey)
case .UserRelays(let relays):
hasher.combine("userRelays")
hasher.combine(relays)
case .KeySettings(let keypair):
hasher.combine("keySettings")
hasher.combine(keypair.pubkey)
case .AppearanceSettings(_):
hasher.combine("appearanceSettings")
case .NotificationSettings(_):
hasher.combine("notificationSettings")
case .ZapSettings(_):
hasher.combine("zapSettings")
case .TranslationSettings(_):
hasher.combine("translationSettings")
case .SearchSettings(_):
hasher.combine("searchSettings")
case .Thread(let threadModel):
hasher.combine("thread")
hasher.combine(threadModel.event.id)
case .Reposts(let reposts):
hasher.combine("reposts")
hasher.combine(reposts.target)
case .Zaps(let target):
hasher.combine("zaps")
hasher.combine(target.id)
hasher.combine(target.pubkey)
case .Reactions(let reactions):
hasher.combine("reactions")
hasher.combine(reactions.target)
case .Search(let search):
hasher.combine("search")
hasher.combine(search.sub_id)
hasher.combine(search.profiles_subid)
case .EULA:
hasher.combine("eula")
case .Login:
hasher.combine("login")
case .CreateAccount:
hasher.combine("createAccount")
case .SaveKeys(let account):
hasher.combine("saveKeys")
hasher.combine(account.pubkey)
case .Wallet(_):
hasher.combine("wallet")
case .WalletScanner(_):
hasher.combine("walletScanner")
case .FollowersYouKnow(let friendedFollowers, let followers):
hasher.combine("followersYouKnow")
hasher.combine(friendedFollowers)
hasher.combine(followers.sub_id)
}
}
}
class NavigationCoordinator: ObservableObject {
@Published var path = [Route]()
func push(route: Route) {
path.append(route)
}
func popToRoot() {
path = []
}
}

View File

@@ -19,17 +19,13 @@ struct EventDetailBar: View {
self.target = target
self.target_pk = target_pk
self._bar = ObservedObject(wrappedValue: make_actionbar_model(ev: target, damus: state))
}
var ZapDetails: Text {
let noun = Text(verbatim: zapsCountString(bar.zaps)).foregroundColor(.gray)
return Text("\(Text(verbatim: bar.zaps.formatted()).font(.body.bold())) \(noun)", comment: "Sentence composed of 2 variables to describe how many zap payments there are on a post. In source English, the first variable is the number of zap payments, and the second variable is 'Zap' or 'Zaps'.")
}
var body: some View {
HStack {
if bar.boosts > 0 {
NavigationLink(destination: RepostsView(damus_state: state, model: RepostsModel(state: state, target: target))) {
NavigationLink(value: Route.Reposts(reposts: RepostsModel(state: state, target: target))) {
let noun = Text(verbatim: repostsCountString(bar.boosts)).foregroundColor(.gray)
Text("\(Text(verbatim: bar.boosts.formatted()).font(.body.bold())) \(noun)", comment: "Sentence composed of 2 variables to describe how many reposts. In source English, the first variable is the number of reposts, and the second variable is 'Repost' or 'Reposts'.")
}
@@ -37,18 +33,19 @@ struct EventDetailBar: View {
}
if bar.likes > 0 && !state.settings.onlyzaps_mode {
NavigationLink(destination: ReactionsView(damus_state: state, model: ReactionsModel(state: state, target: target))) {
NavigationLink(value: Route.Reactions(reactions: ReactionsModel(state: state, target: target))) {
let noun = Text(verbatim: reactionsCountString(bar.likes)).foregroundColor(.gray)
Text("\(Text(verbatim: bar.likes.formatted()).font(.body.bold())) \(noun)", comment: "Sentence composed of 2 variables to describe how many reactions there are on a post. In source English, the first variable is the number of reactions, and the second variable is 'Reaction' or 'Reactions'.")
}
.buttonStyle(PlainButtonStyle())
}
if !state.settings.nozaps && bar.zaps > 0 {
let dst = ZapsView(state: state, target: .note(id: target, author: target_pk))
NavigationLink(destination: dst) {
ZapDetails
}.buttonStyle(PlainButtonStyle())
if bar.zaps > 0 {
NavigationLink(value: Route.Zaps(target: .note(id: target, author: target_pk))) {
let noun = Text(verbatim: zapsCountString(bar.zaps)).foregroundColor(.gray)
Text("\(Text(verbatim: bar.zaps.formatted()).font(.body.bold())) \(noun)", comment: "Sentence composed of 2 variables to describe how many zap payments there are on a post. In source English, the first variable is the number of zap payments, and the second variable is 'Zap' or 'Zaps'.")
}
.buttonStyle(PlainButtonStyle())
}
}
}

View File

@@ -38,7 +38,6 @@ struct BookmarksView: View {
} else {
ScrollView {
InnerTimelineView(events: EventHolder(events: bookmarks, incoming: []), damus: state, filter: noneFilter)
}
}
}

View File

@@ -18,16 +18,16 @@ struct ConfigView: View {
@State var delete_account_warning: Bool = false
@State var confirm_delete_account: Bool = false
@State var delete_text: String = ""
@ObservedObject var settings: UserSettingsStore
private let DELETE_KEYWORD = "DELETE"
init(state: DamusState) {
self.state = state
_settings = ObservedObject(initialValue: state.settings)
}
func textColor() -> Color {
colorScheme == .light ? DamusColors.black : DamusColors.white
}
@@ -36,31 +36,30 @@ struct ConfigView: View {
ZStack(alignment: .leading) {
Form {
Section {
NavigationLink(destination: KeySettingsView(keypair: state.keypair)) {
NavigationLink(value: Route.KeySettings(keypair: state.keypair)) {
IconLabel(NSLocalizedString("Keys", comment: "Settings section for managing keys"), img_name: "key", color: .purple)
}
NavigationLink(destination: AppearanceSettingsView(settings: settings)) {
NavigationLink(value: Route.AppearanceSettings(settings: settings)) {
IconLabel(NSLocalizedString("Appearance", comment: "Section header for text and appearance settings"), img_name: "eye", color: .red)
}
NavigationLink(destination: SearchSettingsView(settings: settings)) {
NavigationLink(value: Route.SearchSettings(settings: settings)) {
IconLabel(NSLocalizedString("Search/Universe", comment: "Section header for search/universe settings"), img_name: "magnifyingglass", color: .red)
}
NavigationLink(destination: NotificationSettingsView(settings: settings)) {
NavigationLink(value: Route.NotificationSettings(settings: settings)) {
IconLabel(NSLocalizedString("Notifications", comment: "Section header for Damus notifications"), img_name: "notification-bell-on", color: .blue)
}
NavigationLink(destination: ZapSettingsView(settings: settings)) {
NavigationLink(value: Route.ZapSettings(settings: settings)) {
IconLabel(NSLocalizedString("Zaps", comment: "Section header for zap settings"), img_name: "zap.fill", color: .orange)
}
NavigationLink(destination: TranslationSettingsView(settings: settings)) {
NavigationLink(value: Route.TranslationSettings(settings: settings)) {
IconLabel(NSLocalizedString("Translation", comment: "Section header for text and appearance settings"), img_name: "globe", color: .green)
}
}
Section(NSLocalizedString("Sign Out", comment: "Section title for signing out")) {
Button(action: {
@@ -116,11 +115,11 @@ struct ConfigView: View {
guard let full_kp = state.keypair.to_full() else {
return
}
guard delete_text == DELETE_KEYWORD else {
return
}
let ev = created_deleted_account_profile(keypair: full_kp)
state.postbox.send(ev)
notify(.logout, ())
@@ -164,7 +163,7 @@ func handle_string_amount(new_value: String) -> Int? {
guard let amt = NumberFormatter().number(from: filtered) as? Int else {
return nil
}
return amt
}

View File

@@ -10,8 +10,7 @@ import SwiftUI
struct CreateAccountView: View {
@StateObject var account: CreateAccountModel = CreateAccountModel()
@StateObject var profileUploadViewModel = ProfileUploadingViewModel()
@State var is_done: Bool = false
var nav: NavigationCoordinator
func SignupForm<FormContent: View>(@ViewBuilder content: () -> FormContent) -> some View {
return VStack(alignment: .leading, spacing: 10.0, content: content)
@@ -25,10 +24,6 @@ struct CreateAccountView: View {
var body: some View {
ZStack(alignment: .top) {
NavigationLink(destination: SaveKeysView(account: account), isActive: $is_done) {
EmptyView()
}
VStack {
VStack(alignment: .center) {
ProfilePictureSelector(pubkey: account.pubkey, viewModel: profileUploadViewModel, callback: uploadedProfilePicture(image_url:))
@@ -63,7 +58,7 @@ struct CreateAccountView: View {
.padding(.top, 10)
Button(action: {
self.is_done = true
nav.push(route: Route.SaveKeys(account: account))
}) {
HStack {
Text("Create account now", comment: "Button to create account.")
@@ -135,7 +130,7 @@ extension View {
struct CreateAccountView_Previews: PreviewProvider {
static var previews: some View {
let model = CreateAccountModel(real: "", nick: "jb55", about: "")
return CreateAccountView(account: model)
return CreateAccountView(account: model, nav: .init())
}
}

View File

@@ -61,8 +61,7 @@ struct DMChatView: View, KeyboardReadable {
var Header: some View {
let profile = damus_state.profiles.lookup(id: pubkey)
let profile_page = ProfileView(damus_state: damus_state, pubkey: pubkey)
return NavigationLink(destination: profile_page) {
return NavigationLink(value: Route.ProfileByKey(pubkey: pubkey)) {
HStack {
ProfilePicView(pubkey: pubkey, size: 24, highlight: .none, profiles: damus_state.profiles, disable_animation: damus_state.settings.disable_animation)

View File

@@ -18,13 +18,9 @@ struct DirectMessagesView: View {
@State var dm_type: DMType = .friend
@ObservedObject var model: DirectMessagesModel
@ObservedObject var settings: UserSettingsStore
func MainContent(requests: Bool) -> some View {
ScrollView {
let chat = DMChatView(damus_state: damus_state, dms: model.active_model)
NavigationLink(destination: chat, isActive: $model.open_dm) {
EmptyView()
}
LazyVStack(spacing: 0) {
if model.dms.isEmpty, !model.loading {
EmptyTimelineView()
@@ -54,7 +50,8 @@ struct DirectMessagesView: View {
if ok, let ev = model.events.last {
EventView(damus: damus_state, event: ev, pubkey: model.pubkey, options: options)
.onTapGesture {
self.model.open_dm_by_model(model)
self.model.set_active_dm_model(model)
damus_state.nav.push(route: Route.DMChat(dms: self.model.active_model))
}
Divider()

View File

@@ -56,18 +56,13 @@ By using our Application, you signify your acceptance of this EULA. If you do no
"""
struct EULAView: View {
@State private var login = false
@State var accepted = false
@Environment(\.colorScheme) var colorScheme
@Environment(\.dismiss) var dismiss
var nav: NavigationCoordinator
var body: some View {
ZStack {
ScrollView {
NavigationLink(destination: LoginView(accepted: $accepted), isActive: $login) {
EmptyView()
}
Text(Markdown.parse(content: eula))
.padding()
}
@@ -96,8 +91,7 @@ struct EULAView: View {
}
Button(action: {
accepted = true
login.toggle()
nav.push(route: Route.Login)
}) {
HStack {
Text("Accept", comment: "Button to accept the end user license agreement before being allowed into the app.")
@@ -126,6 +120,6 @@ struct EULAView: View {
struct EULAView_Previews: PreviewProvider {
static var previews: some View {
EULAView()
EULAView(nav: .init())
}
}

View File

@@ -72,8 +72,7 @@ struct BuilderEventView: View {
if let event {
let ev = event.get_inner_event(cache: damus.events) ?? event
let thread = ThreadModel(event: ev, damus_state: damus)
let dest = ThreadView(state: damus, thread: thread)
NavigationLink(destination: dest) {
NavigationLink(value: Route.Thread(thread: thread)) {
EventView(damus: damus, event: event, options: .embedded)
.padding([.top, .bottom], 8)
}.buttonStyle(.plain)

View File

@@ -37,7 +37,7 @@ struct EventProfile: View {
var body: some View {
HStack(alignment: .center) {
VStack {
NavigationLink(destination: ProfileView(damus_state: damus_state, pubkey: pubkey)) {
NavigationLink(value: Route.ProfileByKey(pubkey: pubkey)) {
ProfilePicView(pubkey: pubkey, size: pfp_size, highlight: .none, profiles: damus_state.profiles, disable_animation: disable_animation)
}
}

View File

@@ -132,7 +132,7 @@ struct TextEvent: View {
func ProfileName(is_anon: Bool) -> some View {
let profile = damus.profiles.lookup(id: pubkey)
let pk = is_anon ? "anon" : pubkey
let pk = is_anon ? ANON_PUBKEY : pubkey
return EventProfileName(pubkey: pk, profile: profile, damus: damus, size: .normal)
}

View File

@@ -12,16 +12,13 @@ struct FollowUserView: View {
let damus_state: DamusState
static let markdown = Markdown()
@State var navigating: Bool = false
var body: some View {
let dest = ProfileView(damus_state: damus_state, pubkey: target.pubkey)
NavigationLink(destination: dest, isActive: $navigating) {
EmptyView()
}
HStack {
UserViewRow(damus_state: damus_state, pubkey: target.pubkey)
.onTapGesture {
damus_state.nav.push(route: Route.ProfileByKey(pubkey: target.pubkey))
}
FollowButtonView(target: target, follows_you: false, follow_state: damus_state.contacts.follow_state(target.pubkey))
}
@@ -32,8 +29,7 @@ struct FollowUserView: View {
struct FollowersYouKnowView: View {
let damus_state: DamusState
let friended_followers: [String]
@EnvironmentObject var followers: FollowersModel
@ObservedObject var followers: FollowersModel
var body: some View {
ScrollView {
@@ -50,8 +46,7 @@ struct FollowersYouKnowView: View {
struct FollowersView: View {
let damus_state: DamusState
@EnvironmentObject var followers: FollowersModel
@ObservedObject var followers: FollowersModel
var body: some View {
ScrollView {
@@ -76,6 +71,7 @@ struct FollowingView: View {
let damus_state: DamusState
let following: FollowingModel
var body: some View {
ScrollView {

View File

@@ -33,13 +33,11 @@ enum ParsedKey {
}
struct LoginView: View {
@State private var create_account = false
@State var key: String = ""
@State var is_pubkey: Bool = false
@State var error: String? = nil
@State private var credential_handler = CredentialHandler()
@Binding var accepted: Bool
var nav: NavigationCoordinator
func get_error(parsed_key: ParsedKey?) -> String? {
if self.error != nil {
@@ -55,12 +53,6 @@ struct LoginView: View {
var body: some View {
ZStack(alignment: .top) {
if accepted {
NavigationLink(destination: CreateAccountView(), isActive: $create_account) {
EmptyView()
}
}
VStack {
SignInHeader()
.padding(.top, 100)
@@ -107,7 +99,7 @@ struct LoginView: View {
.padding(.top, 10)
}
CreateAccountPrompt(create_account: $create_account)
CreateAccountPrompt(nav: nav)
.padding(.top, 10)
Spacer()
@@ -337,14 +329,14 @@ struct SignInEntry: View {
}
struct CreateAccountPrompt: View {
@Binding var create_account: Bool
var nav: NavigationCoordinator
var body: some View {
HStack {
Text("New to Nostr?", comment: "Ask the user if they are new to Nostr")
.foregroundColor(Color("DamusMediumGrey"))
Button(NSLocalizedString("Create account", comment: "Button to navigate to create account view.")) {
create_account.toggle()
nav.push(route: Route.CreateAccount)
}
Spacer()
@@ -358,8 +350,8 @@ struct LoginView_Previews: PreviewProvider {
let pubkey = "npub18m76awca3y37hkvuneavuw6pjj4525fw90necxmadrvjg0sdy6qsngq955"
let bech32_pubkey = "KeyInput"
Group {
LoginView(key: pubkey, accepted: .constant(true))
LoginView(key: bech32_pubkey, accepted: .constant(true))
LoginView(key: pubkey, nav: .init())
LoginView(key: bech32_pubkey, nav: .init())
}
}
}

View File

@@ -56,16 +56,11 @@ enum ReactingTo {
case your_profile
}
func determine_reacting_to(our_pubkey: String, ev: NostrEvent?, group: EventGroupType, nozaps: Bool) -> ReactingTo {
func determine_reacting_to(our_pubkey: String, ev: NostrEvent?) -> ReactingTo {
guard let ev else {
return .your_profile
}
if nozaps && group.is_note_zap {
// ZAPPING NOTES IS NOT ALLOWED!!!! EVIL!!!
return .your_profile
}
if ev.pubkey == our_pubkey {
return .your_note
}
@@ -78,19 +73,42 @@ func event_author_name(profiles: Profiles, pubkey: String) -> String {
return Profile.displayName(profile: alice_prof, pubkey: pubkey).username.truncate(maxLength: 50)
}
func event_group_author_name(profiles: Profiles, ind: Int, group: EventGroupType) -> String {
func event_group_unique_pubkeys(profiles: Profiles, group: EventGroupType) -> [String] {
var seen = Set<String>()
var sorted = [String]()
if let zapgrp = group.zap_group {
let zap = zapgrp.zaps[ind]
if zap.is_anon {
return NSLocalizedString("Anonymous", comment: "Placeholder author name of the anonymous person who zapped an event.")
let zaps = zapgrp.zaps
for i in 0..<zaps.count {
let zap = zapgrp.zaps[i]
let pubkey: String
if zap.is_anon {
pubkey = ANON_PUBKEY
} else {
pubkey = zap.request.ev.pubkey
}
if !seen.contains(pubkey) {
seen.insert(pubkey)
sorted.append(pubkey)
}
}
return event_author_name(profiles: profiles, pubkey: zap.request.ev.pubkey)
} else {
let ev = group.events[ind]
return event_author_name(profiles: profiles, pubkey: ev.pubkey)
let events = group.events
for i in 0..<events.count {
let ev = events[i]
let pubkey = ev.pubkey
if !seen.contains(pubkey) {
seen.insert(pubkey)
sorted.append(pubkey)
}
}
}
return sorted
}
/**
@@ -130,29 +148,29 @@ func event_group_author_name(profiles: Profiles, ind: Int, group: EventGroupType
"zapped_your_profile_2" - returned when 2 zaps occurred to the current user's profile
"zapped_your_profile_3" - returned when 3 or more zaps occurred to the current user's profile
*/
func reacting_to_text(profiles: Profiles, our_pubkey: String, group: EventGroupType, ev: NostrEvent?, nozaps: Bool, locale: Locale? = nil) -> String {
func reacting_to_text(profiles: Profiles, our_pubkey: String, group: EventGroupType, ev: NostrEvent?, pubkeys: [String], locale: Locale? = nil) -> String {
if group.events.count == 0 {
return "??"
}
let verb = reacting_to_verb(group: group)
let reacting_to = determine_reacting_to(our_pubkey: our_pubkey, ev: ev, group: group, nozaps: nozaps)
let localization_key = "\(verb)_\(reacting_to)_\(min(group.events.count, 3))"
let reacting_to = determine_reacting_to(our_pubkey: our_pubkey, ev: ev)
let localization_key = "\(verb)_\(reacting_to)_\(min(pubkeys.count, 3))"
let format = localizedStringFormat(key: localization_key, locale: locale)
switch group.events.count {
switch pubkeys.count {
case 1:
let display_name = event_group_author_name(profiles: profiles, ind: 0, group: group)
let display_name = event_author_name(profiles: profiles, pubkey: pubkeys[0])
return String(format: format, locale: locale, display_name)
case 2:
let alice_name = event_group_author_name(profiles: profiles, ind: 0, group: group)
let bob_name = event_group_author_name(profiles: profiles, ind: 1, group: group)
let alice_name = event_author_name(profiles: profiles, pubkey: pubkeys[0])
let bob_name = event_author_name(profiles: profiles, pubkey: pubkeys[1])
return String(format: format, locale: locale, alice_name, bob_name)
default:
let alice_name = event_group_author_name(profiles: profiles, ind: 0, group: group)
let count = group.events.count - 1
let alice_name = event_author_name(profiles: profiles, pubkey: pubkeys[0])
let count = pubkeys.count - 1
return String(format: format, locale: locale, count, alice_name)
}
@@ -174,9 +192,9 @@ struct EventGroupView: View {
let state: DamusState
let event: NostrEvent?
let group: EventGroupType
var GroupDescription: some View {
Text(verbatim: "\(reacting_to_text(profiles: state.profiles, our_pubkey: state.pubkey, group: group, ev: event, nozaps: state.settings.nozaps))")
func GroupDescription(_ pubkeys: [String]) -> some View {
Text(verbatim: "\(reacting_to_text(profiles: state.profiles, our_pubkey: state.pubkey, group: group, ev: event, pubkeys: pubkeys))")
}
func ZapIcon(_ zapgrp: ZapGroup) -> some View {
@@ -216,25 +234,24 @@ struct EventGroupView: View {
.frame(width: PFP_SIZE + 10)
VStack(alignment: .leading) {
ProfilePicturesView(state: state, pubkeys: group.events.map { $0.pubkey })
let unique_pubkeys = event_group_unique_pubkeys(profiles: state.profiles, group: group)
ProfilePicturesView(state: state, pubkeys: unique_pubkeys)
if let event {
let thread = ThreadModel(event: event, damus_state: state)
let dest = ThreadView(state: state, thread: thread)
GroupDescription
if !state.settings.nozaps || !group.is_note_zap {
NavigationLink(destination: dest) {
VStack(alignment: .leading) {
EventBody(damus_state: state, event: event, size: .normal, options: [.truncate_content])
.padding([.top], 1)
.padding([.trailing])
.foregroundColor(.gray)
}
NavigationLink(value: Route.Thread(thread: thread)) {
VStack(alignment: .leading) {
GroupDescription(unique_pubkeys)
EventBody(damus_state: state, event: event, size: .normal, options: [.truncate_content])
.padding([.top], 1)
.padding([.trailing])
.foregroundColor(.gray)
}
.buttonStyle(.plain)
}
.buttonStyle(.plain)
} else {
GroupDescription
GroupDescription(unique_pubkeys)
}
}
}

View File

@@ -59,7 +59,7 @@ struct NotificationItemView: View {
EventGroupView(state: state, event: ev, group: .reaction(evgrp))
case .reply(let ev):
NavigationLink(destination: ThreadView(state: state, thread: ThreadModel(event: ev, damus_state: state))) {
NavigationLink(value: Route.Thread(thread: ThreadModel(event: ev, damus_state: state))) {
EventView(damus: state, event: ev, options: options)
}
.buttonStyle(.plain)

View File

@@ -10,20 +10,13 @@ import SwiftUI
struct ProfilePicturesView: View {
let state: DamusState
let pubkeys: [String]
@State var nav_target: String? = nil
@State var navigating: Bool = false
var body: some View {
NavigationLink(destination: ProfileView(damus_state: state, pubkey: nav_target ?? ""), isActive: $navigating) {
EmptyView()
}
HStack {
ForEach(pubkeys.prefix(8), id: \.self) { pubkey in
ProfilePicView(pubkey: pubkey, size: 32.0, highlight: .none, profiles: state.profiles, disable_animation: state.settings.disable_animation)
.onTapGesture {
nav_target = pubkey
navigating = true
state.nav.push(route: Route.ProfileByKey(pubkey: pubkey))
}
}
}

View File

@@ -19,10 +19,15 @@ class TagModel: ObservableObject {
var diff = 0
}
enum PostTarget {
case none
case user(String)
}
enum PostAction {
case replying_to(NostrEvent)
case quoting(NostrEvent)
case posting
case posting(PostTarget)
var ev: NostrEvent? {
switch self {
@@ -125,6 +130,14 @@ struct PostView: View {
var is_post_empty: Bool {
return post.string.allSatisfy { $0.isWhitespace } && uploadedMedias.isEmpty
}
var uploading_disabled: Bool {
return image_upload.progress != nil
}
var posting_disabled: Bool {
return is_post_empty || uploading_disabled
}
var ImageButton: some View {
Button(action: {
@@ -149,7 +162,7 @@ struct PostView: View {
ImageButton
CameraButton
}
.disabled(image_upload.progress != nil)
.disabled(uploading_disabled)
}
var PostButton: some View {
@@ -160,18 +173,29 @@ struct PostView: View {
self.send_post()
}
}
.disabled(is_post_empty)
.disabled(posting_disabled)
.font(.system(size: 14, weight: .bold))
.frame(width: 80, height: 30)
.foregroundColor(.white)
.background(LINEAR_GRADIENT)
.opacity(is_post_empty ? 0.5 : 1.0)
.opacity(posting_disabled ? 0.5 : 1.0)
.clipShape(Capsule())
}
var isEmpty: Bool {
self.uploadedMedias.count == 0 &&
self.post.mutableString.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty
func isEmpty() -> Bool {
return self.uploadedMedias.count == 0 &&
self.post.mutableString.trimmingCharacters(in: .whitespacesAndNewlines) ==
initialString().mutableString.trimmingCharacters(in: .whitespacesAndNewlines)
}
func initialString() -> NSMutableAttributedString {
guard case .posting(let target) = action,
case .user(let pubkey) = target else {
return .init(string: "")
}
let profile = damus_state.profiles.lookup(id: pubkey)
return user_tag_attr_string(profile: profile, pubkey: pubkey)
}
func clear_draft() {
@@ -186,15 +210,17 @@ struct PostView: View {
}
func load_draft() {
func load_draft() -> Bool {
guard let draft = load_draft_for_post(drafts: self.damus_state.drafts, action: self.action) else {
self.post = NSMutableAttributedString("")
self.uploadedMedias = []
return
return false
}
self.uploadedMedias = draft.media
self.post = draft.content
return true
}
func post_changed(post: NSMutableAttributedString, media: [UploadedMedia]) {
@@ -335,6 +361,11 @@ struct PostView: View {
.padding(.horizontal)
}
func fill_target_content(target: PostTarget) {
self.post = initialString()
self.tagModel.diff = post.string.count
}
var body: some View {
GeometryReader { (deviceSize: GeometryProxy) in
VStack(alignment: .leading, spacing: 0) {
@@ -404,7 +435,7 @@ struct PostView: View {
}
}
.onAppear() {
load_draft()
let loaded_draft = load_draft()
switch action {
case .replying_to(let replying_to):
@@ -413,8 +444,10 @@ struct PostView: View {
case .quoting(let quoting):
references = gather_quote_ids(our_pubkey: damus_state.pubkey, from: quoting)
originalReferences = references
case .posting:
break
case .posting(let target):
guard !loaded_draft else { break }
fill_target_content(target: target)
}
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
@@ -422,7 +455,7 @@ struct PostView: View {
}
}
.onDisappear {
if isEmpty {
if isEmpty() {
clear_draft()
}
}
@@ -462,7 +495,7 @@ func get_searching_string(_ word: String?) -> String? {
struct PostView_Previews: PreviewProvider {
static var previews: some View {
PostView(action: .posting, damus_state: test_damus_state())
PostView(action: .posting(.none), damus_state: test_damus_state())
}
}

View File

@@ -8,7 +8,6 @@
import SwiftUI
struct SearchedUser: Identifiable {
let petname: String?
let profile: Profile?
let pubkey: String
@@ -28,18 +27,14 @@ struct UserSearch: View {
@EnvironmentObject var tagModel: TagModel
var users: [SearchedUser] {
guard let contacts = damus_state.contacts.event else {
return search_profiles(profiles: damus_state.profiles, search: search)
}
return search_users_for_autocomplete(profiles: damus_state.profiles, tags: contacts.tags, search: search)
return search_profiles(profiles: damus_state.profiles, search: search)
}
func on_user_tapped(user: SearchedUser) {
guard let pk = bech32_pubkey(user.pubkey) else {
return
}
let tagAttributedString = createUserTag(for: user, with: pk)
let tagAttributedString = user_tag_attr_string(profile: user.profile, pubkey: pk)
appendUserTag(withTag: tagAttributedString)
}
@@ -57,27 +52,6 @@ struct UserSearch: View {
newCursorIndex = wordRange.location + tagAttributedString.string.count
}
private func createUserTag(for user: SearchedUser, with pk: String) -> NSMutableAttributedString {
let name = Profile.displayName(profile: user.profile, pubkey: pk).username.truncate(maxLength: 50)
let tagString = "@\(name)\u{200B} "
let tagAttributedString = NSMutableAttributedString(string: tagString,
attributes: [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 18.0),
// Add damus: URI so that taps within the post creation view redirect internally within Damus instead of redirecting to a different Nostr client. The damus: prefix will be stripped out prior to sending the note to relays.
NSAttributedString.Key.link: "damus:nostr:\(pk)"])
tagAttributedString.removeAttribute(.link, range: NSRange(location: tagAttributedString.length - 2, length: 2))
tagAttributedString.addAttributes([NSAttributedString.Key.foregroundColor: UIColor.label], range: NSRange(location: tagAttributedString.length - 2, length: 2))
return tagAttributedString
}
private func appendUserTag(_ tagAttributedString: NSMutableAttributedString) {
let mutableString = NSMutableAttributedString()
mutableString.append(post)
mutableString.append(tagAttributedString)
post = mutableString
}
var body: some View {
VStack(spacing: 0) {
Divider()
@@ -120,52 +94,17 @@ struct UserSearch_Previews: PreviewProvider {
}
}
func user_tag_attr_string(profile: Profile?, pubkey: String) -> NSMutableAttributedString {
let display_name = Profile.displayName(profile: profile, pubkey: pubkey)
let name = display_name.username.truncate(maxLength: 50)
let tagString = "@\(name)\u{200B} "
func search_users_for_autocomplete(profiles: Profiles, tags: [[String]], search _search: String) -> [SearchedUser] {
var seen_user = Set<String>()
let search = _search.lowercased()
let tagAttributedString = NSMutableAttributedString(string: tagString,
attributes: [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 18.0),
NSAttributedString.Key.link: "nostr:\(pubkey)"])
tagAttributedString.removeAttribute(.link, range: NSRange(location: tagAttributedString.length - 2, length: 2))
tagAttributedString.addAttributes([NSAttributedString.Key.foregroundColor: UIColor.label], range: NSRange(location: tagAttributedString.length - 2, length: 2))
var matches = tags.reduce(into: Array<SearchedUser>()) { arr, tag in
guard tag.count >= 2 && tag[0] == "p" else {
return
}
let pubkey = tag[1]
guard !seen_user.contains(pubkey) else {
return
}
seen_user.insert(pubkey)
var petname: String? = nil
if tag.count >= 4 {
petname = tag[3]
}
let profile = profiles.lookup(id: pubkey)
guard ((petname?.lowercased().hasPrefix(search) ?? false) ||
(profile?.name?.lowercased().hasPrefix(search) ?? false) ||
(profile?.display_name?.lowercased().hasPrefix(search) ?? false)) else {
return
}
let searched_user = SearchedUser(petname: petname, profile: profile, pubkey: pubkey)
arr.append(searched_user)
}
// search profile cache as well
for tup in profiles.enumerated() {
let pk = tup.element.key
let prof = tup.element.value.profile
guard !seen_user.contains(pk) else {
continue
}
if let match = profile_search_matches(profiles: profiles, profile: prof, pubkey: pk, search: search) {
matches.append(match)
}
}
return matches
return tagAttributedString
}

View File

@@ -28,7 +28,7 @@ struct MaybeAnonPfpView: View {
.font(.largeTitle)
.frame(width: size, height: size)
} else {
NavigationLink(destination: ProfileView(damus_state: state, pubkey: pubkey)) {
NavigationLink(value: Route.ProfileByKey(pubkey: pubkey)) {
ProfilePicView(pubkey: pubkey, size: size, highlight: .none, profiles: state.profiles, disable_animation: state.settings.disable_animation)
}
}
@@ -38,6 +38,6 @@ struct MaybeAnonPfpView: View {
struct MaybeAnonPfpView_Previews: PreviewProvider {
static var previews: some View {
MaybeAnonPfpView(state: test_damus_state(), is_anon: true, pubkey: "anon", size: PFP_SIZE)
MaybeAnonPfpView(state: test_damus_state(), is_anon: true, pubkey: ANON_PUBKEY, size: PFP_SIZE)
}
}

View File

@@ -162,7 +162,8 @@ func get_profile_url(picture: String?, pubkey: String, profiles: Profiles) -> UR
}
func make_preview_profiles(_ pubkey: String) -> Profiles {
let profiles = Profiles()
let user_search_cache = UserSearchCache()
let profiles = Profiles(user_search_cache: user_search_cache)
let picture = "http://cdn.jb55.com/img/red-me.jpg"
let profile = Profile(name: "jb55", display_name: "William Casarin", about: "It's me", picture: picture, banner: "", website: "https://jb55.com", lud06: nil, lud16: nil, nip05: "jb55.com", damus_donation: nil)
let ts_profile = TimestampedProfile(profile: profile, timestamp: 0, event: test_event)

View File

@@ -73,11 +73,11 @@ func followedByString(_ friend_intersection: [String], profiles: Profiles, local
struct EditButton: View {
let damus_state: DamusState
@Environment(\.colorScheme) var colorScheme
var body: some View {
NavigationLink(destination: EditMetadataView(damus_state: damus_state)) {
NavigationLink(value: Route.EditMetadata) {
Text("Edit", comment: "Button to edit user's profile.")
.frame(height: 30)
.padding(.horizontal,25)
@@ -92,11 +92,11 @@ struct EditButton: View {
.lineLimit(1)
}
}
func fillColor() -> Color {
colorScheme == .light ? DamusColors.black : DamusColors.white
}
func borderColor() -> Color {
colorScheme == .light ? DamusColors.black : DamusColors.white
}
@@ -104,11 +104,11 @@ struct EditButton: View {
struct VisualEffectView: UIViewRepresentable {
var effect: UIVisualEffect?
func makeUIView(context: UIViewRepresentableContext<Self>) -> UIVisualEffectView {
UIVisualEffectView()
}
func updateUIView(_ uiView: UIVisualEffectView, context: UIViewRepresentableContext<Self>) {
uiView.effect = effect
}
@@ -120,52 +120,52 @@ struct ProfileView: View {
let bannerHeight: CGFloat = 150.0
static let markdown = Markdown()
@State var is_zoomed: Bool = false
@State var show_share_sheet: Bool = false
@State var show_qr_code: Bool = false
@State var action_sheet_presented: Bool = false
@State var filter_state : FilterState = .posts
@State var yOffset: CGFloat = 0
@StateObject var profile: ProfileModel
@StateObject var followers: FollowersModel
@StateObject var zap_button_model: ZapButtonModel = ZapButtonModel()
init(damus_state: DamusState, profile: ProfileModel, followers: FollowersModel) {
self.damus_state = damus_state
self._profile = StateObject(wrappedValue: profile)
self._followers = StateObject(wrappedValue: followers)
}
init(damus_state: DamusState, pubkey: String) {
self.damus_state = damus_state
self._profile = StateObject(wrappedValue: ProfileModel(pubkey: pubkey, damus: damus_state))
self._followers = StateObject(wrappedValue: FollowersModel(damus_state: damus_state, target: pubkey))
}
@Environment(\.dismiss) var dismiss
@Environment(\.colorScheme) var colorScheme
@Environment(\.presentationMode) var presentationMode
func imageBorderColor() -> Color {
colorScheme == .light ? DamusColors.white : DamusColors.black
}
func bannerBlurViewOpacity() -> Double {
let progress = -(yOffset + navbarHeight) / 100
return Double(-yOffset > navbarHeight ? progress : 0)
}
var bannerSection: some View {
GeometryReader { proxy -> AnyView in
let minY = proxy.frame(in: .global).minY
DispatchQueue.main.async {
self.yOffset = minY
}
return AnyView(
VStack(spacing: 0) {
ZStack {
@@ -173,10 +173,10 @@ struct ProfileView: View {
.aspectRatio(contentMode: .fill)
.frame(width: proxy.size.width, height: minY > 0 ? bannerHeight + minY : bannerHeight)
.clipped()
VisualEffectView(effect: UIBlurEffect(style: .systemUltraThinMaterial)).opacity(bannerBlurViewOpacity())
}
Divider().opacity(bannerBlurViewOpacity())
}
.frame(height: minY > 0 ? bannerHeight + minY : nil)
@@ -187,11 +187,11 @@ struct ProfileView: View {
.frame(height: bannerHeight)
.allowsHitTesting(false)
}
var navbarHeight: CGFloat {
return 100.0 - (Theme.safeAreaInsets?.top ?? 0)
}
@ViewBuilder
func navImage(img: String) -> some View {
Image(img)
@@ -199,7 +199,7 @@ struct ProfileView: View {
.background(Color.black.opacity(0.6))
.clipShape(Circle())
}
var navBackButton: some View {
Button {
presentationMode.wrappedValue.dismiss()
@@ -207,7 +207,7 @@ struct ProfileView: View {
navImage(img: "chevron-left")
}
}
var navActionSheetButton: some View {
Button(action: {
action_sheet_presented = true
@@ -218,7 +218,7 @@ struct ProfileView: View {
Button(NSLocalizedString("Share", comment: "Button to share the link to a profile.")) {
show_share_sheet = true
}
Button(NSLocalizedString("QR Code", comment: "Button to view profile's qr code.")) {
show_qr_code = true
}
@@ -238,7 +238,7 @@ struct ProfileView: View {
else {
return
}
guard let new_ev = remove_from_mutelist(keypair: keypair, prev: mutelist, to_remove: profile.pubkey) else {
return
}
@@ -254,7 +254,7 @@ struct ProfileView: View {
}
}
}
var customNavbar: some View {
HStack {
navBackButton
@@ -265,7 +265,7 @@ struct ProfileView: View {
.padding(.horizontal)
.accentColor(DamusColors.white)
}
func lnButton(lnurl: String, profile: Profile) -> some View {
let button_img = profile.reactions == false ? "zap.fill" : "zap"
return Button(action: {
@@ -278,7 +278,7 @@ struct ProfileView: View {
if profile.reactions == false {
Text("OnlyZaps Enabled", comment: "Non-tappable text in context menu that shows up when the zap button on profile is long pressed to indicate that the user has enabled OnlyZaps, meaning that they would like to be only zapped and not accept reactions to their notes.")
}
if let addr = profile.lud16 {
Button {
UIPasteboard.general.string = addr
@@ -293,31 +293,30 @@ struct ProfileView: View {
}
}
}
}
.cornerRadius(24)
}
var dmButton: some View {
let dm_model = damus_state.dms.lookup_or_create(profile.pubkey)
let dmview = DMChatView(damus_state: damus_state, dms: dm_model)
return NavigationLink(destination: dmview) {
return NavigationLink(value: Route.DMChat(dms: dm_model)) {
Image("messages")
.profile_button_style(scheme: colorScheme)
}
}
func actionSection(profile_data: Profile?) -> some View {
return Group {
if let profile = profile_data {
if let lnurl = profile.lnurl, lnurl != "" {
lnButton(lnurl: lnurl, profile: profile)
}
}
dmButton
if profile.pubkey != damus_state.pubkey {
FollowButtonView(
target: profile.get_follow_target(),
@@ -325,26 +324,26 @@ struct ProfileView: View {
follow_state: damus_state.contacts.follow_state(profile.pubkey)
)
} else if damus_state.keypair.privkey != nil {
NavigationLink(destination: EditMetadataView(damus_state: damus_state)) {
NavigationLink(value: Route.EditMetadata) {
EditButton(damus_state: damus_state)
}
}
}
}
func pfpOffset() -> CGFloat {
let progress = -yOffset / navbarHeight
let offset = (pfp_size / 4.0) * (progress < 1.0 ? progress : 1)
return offset > 0 ? offset : 0
}
func pfpScale() -> CGFloat {
let progress = -yOffset / navbarHeight
let scale = 1.0 - (0.5 * (progress < 1.0 ? progress : 1))
return scale < 1 ? scale : 1
}
func nameSection(profile_data: Profile?) -> some View {
return Group {
HStack(alignment: .center) {
@@ -358,17 +357,17 @@ struct ProfileView: View {
.fullScreenCover(isPresented: $is_zoomed) {
ProfilePicImageView(pubkey: profile.pubkey, profiles: damus_state.profiles, disable_animation: damus_state.settings.disable_animation)
}
Spacer()
actionSection(profile_data: profile_data)
}
let follows_you = profile.pubkey != damus_state.pubkey && profile.follows(pubkey: damus_state.pubkey)
ProfileNameView(pubkey: profile.pubkey, profile: profile_data, follows_you: follows_you, damus: damus_state)
}
}
var followersCount: some View {
HStack {
if followers.count == nil {
@@ -385,26 +384,26 @@ struct ProfileView: View {
}
}
}
var aboutSection: some View {
VStack(alignment: .leading, spacing: 8.0) {
let profile_data = damus_state.profiles.lookup(id: profile.pubkey)
nameSection(profile_data: profile_data)
if let about = profile_data?.about {
AboutView(state: damus_state, about: about)
}
if let url = profile_data?.website_url {
WebsiteLink(url: url)
}
HStack {
if let contact = profile.contacts {
let contacts = contact.referenced_pubkeys.map { $0.ref_id }
let following_model = FollowingModel(damus_state: damus_state, contacts: contacts)
NavigationLink(destination: FollowingView(damus_state: damus_state, following: following_model)) {
NavigationLink(value: Route.Following(following: following_model)) {
HStack {
let noun_text = Text(verbatim: "\(followingCountString(profile.following))").font(.subheadline).foregroundColor(.gray)
Text("\(Text(verbatim: profile.following.formatted()).font(.subheadline.weight(.medium))) \(noun_text)", comment: "Sentence composed of 2 variables to describe how many profiles a user is following. In source English, the first variable is the number of profiles being followed, and the second variable is 'Following'.")
@@ -412,10 +411,9 @@ struct ProfileView: View {
}
.buttonStyle(PlainButtonStyle())
}
let fview = FollowersView(damus_state: damus_state)
.environmentObject(followers)
if followers.contacts != nil {
NavigationLink(destination: fview) {
NavigationLink(value: Route.Followers(followers: followers)) {
followersCount
}
.buttonStyle(PlainButtonStyle())
@@ -427,18 +425,18 @@ struct ProfileView: View {
followers.subscribe()
}
}
if let relays = profile.relays {
// Only open relay config view if the user is logged in with private key and they are looking at their own profile.
let noun_text = Text(verbatim: relaysCountString(relays.keys.count)).font(.subheadline).foregroundColor(.gray)
let relay_text = Text("\(Text(verbatim: relays.keys.count.formatted()).font(.subheadline.weight(.medium))) \(noun_text)", comment: "Sentence composed of 2 variables to describe how many relay servers a user is connected. In source English, the first variable is the number of relay servers, and the second variable is 'Relay' or 'Relays'.")
if profile.pubkey == damus_state.pubkey && damus_state.is_privkey_user {
NavigationLink(destination: RelayConfigView(state: damus_state)) {
NavigationLink(value: Route.RelayConfig) {
relay_text
}
.buttonStyle(PlainButtonStyle())
} else {
NavigationLink(destination: UserRelaysView(state: damus_state, relays: Array(relays.keys).sorted())) {
NavigationLink(value: Route.UserRelays(relays: Array(relays.keys).sorted())) {
relay_text
}
.buttonStyle(PlainButtonStyle())
@@ -451,7 +449,7 @@ struct ProfileView: View {
if !friended_followers.isEmpty {
Spacer()
NavigationLink(destination: FollowersYouKnowView(damus_state: damus_state, friended_followers: friended_followers)) {
NavigationLink(value: Route.FollowersYouKnow(friendedFollowers: friended_followers, followers: followers)) {
HStack {
CondensedProfilePicturesView(state: damus_state, pubkeys: friended_followers, maxPictures: 3)
Text(followedByString(friended_followers, profiles: damus_state.profiles))
@@ -464,62 +462,70 @@ struct ProfileView: View {
}
.padding(.horizontal)
}
var body: some View {
ScrollView(.vertical) {
VStack(spacing: 0) {
bannerSection
.zIndex(1)
VStack() {
aboutSection
VStack(spacing: 0) {
CustomPicker(selection: $filter_state, content: {
Text("Notes", comment: "Label for filter for seeing only your notes (instead of notes and replies).").tag(FilterState.posts)
Text("Notes & Replies", comment: "Label for filter for seeing your notes and replies (instead of only your notes).").tag(FilterState.posts_and_replies)
})
Divider()
.frame(height: 1)
}
.background(colorScheme == .dark ? Color.black : Color.white)
ZStack {
ScrollView(.vertical) {
VStack(spacing: 0) {
bannerSection
.zIndex(1)
if filter_state == FilterState.posts {
InnerTimelineView(events: profile.events, damus: damus_state, filter: FilterState.posts.filter)
VStack() {
aboutSection
VStack(spacing: 0) {
CustomPicker(selection: $filter_state, content: {
Text("Notes", comment: "Label for filter for seeing only your notes (instead of notes and replies).").tag(FilterState.posts)
Text("Notes & Replies", comment: "Label for filter for seeing your notes and replies (instead of only your notes).").tag(FilterState.posts_and_replies)
})
Divider()
.frame(height: 1)
}
.background(colorScheme == .dark ? Color.black : Color.white)
if filter_state == FilterState.posts {
InnerTimelineView(events: profile.events, damus: damus_state, filter: FilterState.posts.filter)
}
if filter_state == FilterState.posts_and_replies {
InnerTimelineView(events: profile.events, damus: damus_state, filter: FilterState.posts_and_replies.filter)
}
}
if filter_state == FilterState.posts_and_replies {
InnerTimelineView(events: profile.events, damus: damus_state, filter: FilterState.posts_and_replies.filter)
}
}
.padding(.horizontal, Theme.safeAreaInsets?.left)
.zIndex(-yOffset > navbarHeight ? 0 : 1)
}
}
.ignoresSafeArea()
.navigationTitle("")
.navigationBarHidden(true)
.overlay(customNavbar, alignment: .top)
.onReceive(handle_notify(.switched_timeline)) { _ in
dismiss()
}
.onAppear() {
profile.subscribe()
//followers.subscribe()
}
.onDisappear {
profile.unsubscribe()
followers.unsubscribe()
// our profilemodel needs a bit more help
}
.sheet(isPresented: $show_share_sheet) {
if let npub = bech32_pubkey(profile.pubkey) {
if let url = URL(string: "https://damus.io/" + npub) {
ShareSheet(activityItems: [url])
.padding(.horizontal, Theme.safeAreaInsets?.left)
.zIndex(-yOffset > navbarHeight ? 0 : 1)
}
}
.ignoresSafeArea()
.navigationTitle("")
.navigationBarHidden(true)
.overlay(customNavbar, alignment: .top)
.onReceive(handle_notify(.switched_timeline)) { _ in
dismiss()
}
.onAppear() {
profile.subscribe()
//followers.subscribe()
}
.onDisappear {
profile.unsubscribe()
followers.unsubscribe()
// our profilemodel needs a bit more help
}
.sheet(isPresented: $show_share_sheet) {
if let npub = bech32_pubkey(profile.pubkey) {
if let url = URL(string: "https://damus.io/" + npub) {
ShareSheet(activityItems: [url])
}
}
}
.fullScreenCover(isPresented: $show_qr_code) {
QRCodeView(damus_state: damus_state, pubkey: profile.pubkey)
}
if damus_state.is_privkey_user {
PostButtonContainer(is_left_handed: damus_state.settings.left_handed) {
notify(.compose, PostAction.posting(.user(profile.pubkey)))
}
}
}
.fullScreenCover(isPresented: $show_qr_code) {
QRCodeView(damus_state: damus_state, pubkey: profile.pubkey)
}
}
}
@@ -534,7 +540,7 @@ struct ProfileView_Previews: PreviewProvider {
func test_damus_state() -> DamusState {
let pubkey = "3efdaebb1d8923ebd99c9e7ace3b4194ab45512e2be79c1b7d68d9243e0d2681"
let damus = DamusState.empty
let prof = Profile(name: "damus", display_name: "damus", about: "iOS app!", picture: "https://damus.io/img/logo.png", banner: "", website: "https://damus.io", lud06: nil, lud16: "jb55@sendsats.lol", nip05: "damus.io", damus_donation: nil)
let tsprof = TimestampedProfile(profile: prof, timestamp: 0, event: test_event)
damus.profiles.add(id: pubkey, profile: tsprof)
@@ -543,15 +549,15 @@ func test_damus_state() -> DamusState {
struct KeyView: View {
let pubkey: String
@Environment(\.colorScheme) var colorScheme
@State private var isCopied = false
func keyColor() -> Color {
colorScheme == .light ? DamusColors.black : DamusColors.white
}
private func copyPubkey(_ pubkey: String) {
UIPasteboard.general.string = pubkey
UIImpactFeedbackGenerator(style: .medium).impactOccurred()
@@ -564,10 +570,10 @@ struct KeyView: View {
}
}
}
var body: some View {
let bech32 = bech32_pubkey(pubkey) ?? pubkey
HStack {
Text(verbatim: "\(abbrev_pubkey(bech32, amount: 16))")
.font(.footnote)
@@ -575,7 +581,7 @@ struct KeyView: View {
.padding(5)
.padding([.leading, .trailing], 5)
.background(RoundedRectangle(cornerRadius: 11).foregroundColor(DamusColors.adaptableGrey))
if isCopied != true {
Button {
copyPubkey(bech32)

View File

@@ -47,14 +47,11 @@ struct QRCodeView: View {
@Environment(\.presentationMode) var presentationMode
@State private var selectedTab = 0
@State var scanResult: ProfileScanResult? = nil
@State var showProfileView: Bool = false
@State var profile: Profile? = nil
@State var error: String? = nil
@State private var outerTrimEnd: CGFloat = 0
var animationDuration: Double = 0.5
let generator = UIImpactFeedbackGenerator(style: .light)
@@ -209,13 +206,6 @@ struct QRCodeView: View {
Spacer()
if let scanResult {
let dst = ProfileView(damus_state: damus_state, pubkey: scanResult.pubkey)
NavigationLink(destination: dst, isActive: $showProfileView) {
EmptyView()
}
}
Spacer()
Button(action: {
@@ -271,9 +261,10 @@ struct QRCodeView: View {
func show_profile_after_delay() {
DispatchQueue.main.asyncAfter(deadline: .now() + animationDuration) {
showProfileView = true
if let scanResult {
damus_state.nav.push(route: Route.ProfileByKey(pubkey: scanResult.pubkey))
}
}
}
func cameraAnimate(completion: @escaping () -> Void) {

View File

@@ -10,9 +10,6 @@ import SwiftUI
struct RelayFilterView: View {
let state: DamusState
let timeline: Timeline
//@State var relays: [RelayDescriptor]
//@EnvironmentObject var user_settings: UserSettingsStore
//@State var relays: [RelayDescriptor]
init(state: DamusState, timeline: Timeline) {
self.state = state

View File

@@ -42,9 +42,7 @@ struct RecommendedRelayView: View {
Text(relay).layoutPriority(1)
if let meta = damus.relay_metadata.lookup(relay_id: relay) {
NavigationLink ( destination:
RelayDetailView(state: damus, relay: relay, nip11: meta)
){
NavigationLink(value: Route.RelayDetail(relay: relay, metadata: meta)){
EmptyView()
}
.opacity(0.0)

View File

@@ -72,7 +72,9 @@ struct RelayDetailView: View {
if let pubkey = nip11.pubkey {
Section(NSLocalizedString("Admin", comment: "Label to display relay contact user.")) {
UserViewRow(damus_state: state, pubkey: pubkey)
NavigationLink(value: Route.ProfileByKey(pubkey: pubkey), label: {
UserViewRow(damus_state: state, pubkey: pubkey)
})
}
}
if let relay_connection {

View File

@@ -30,8 +30,9 @@ struct RelayView: View {
if let meta = state.relay_metadata.lookup(relay_id: relay) {
Text(relay)
.background(
NavigationLink("", destination: RelayDetailView(state: state, relay: relay, nip11: meta)).opacity(0.0)
.disabled(showActionButtons)
NavigationLink(value: Route.RelayDetail(relay: relay, metadata: meta), label: {
EmptyView()
}).opacity(0.0).disabled(showActionButtons)
)
Spacer()

View File

@@ -14,7 +14,7 @@ struct SignalView: View {
var body: some View {
Group {
if signal.signal != signal.max_signal {
NavigationLink(destination: RelayConfigView(state: state)) {
NavigationLink(value: Route.RelayConfig) {
Text("\(signal.signal)/\(signal.max_signal)", comment: "Fraction of how many of the user's relay servers that are operational.")
.font(.callout)
.foregroundColor(.gray)

View File

@@ -16,9 +16,8 @@ struct RepostedEvent: View {
var body: some View {
VStack(alignment: .leading) {
let prof = damus.profiles.lookup(id: event.pubkey)
let booster_profile = ProfileView(damus_state: damus, pubkey: event.pubkey)
NavigationLink(destination: booster_profile) {
NavigationLink(value: Route.ProfileByKey(pubkey: event.pubkey)) {
Reposted(damus: damus, pubkey: event.pubkey, profile: prof)
.padding(.horizontal)
}

View File

@@ -100,14 +100,12 @@ struct SearchingEventView: View {
.progressViewStyle(.circular)
}
case .found(let ev):
NavigationLink(destination: ThreadView(state: state, thread: ThreadModel(event: ev, damus_state: state))) {
NavigationLink(value: Route.Thread(thread: ThreadModel(event: ev, damus_state: state))) {
EventView(damus: state, event: ev)
}
.buttonStyle(PlainButtonStyle())
case .found_profile(let pk):
NavigationLink(destination: ProfileView(damus_state: state, pubkey: pk)) {
NavigationLink(value: Route.ProfileByKey(pubkey: pk)) {
FollowUserView(target: .pubkey(pk), damus_state: state)
}
.buttonStyle(PlainButtonStyle())

View File

@@ -126,9 +126,6 @@ struct SearchHomeView: View {
struct SearchHomeView_Previews: PreviewProvider {
static var previews: some View {
let state = test_damus_state()
SearchHomeView(
damus_state: state,
model: SearchHomeModel(damus_state: state)
)
SearchHomeView(damus_state: state, model: SearchHomeModel(damus_state: state))
}
}

View File

@@ -44,8 +44,7 @@ struct InnerSearchResults: View {
func HashtagSearch(_ ht: String) -> some View {
let search_model = SearchModel(state: damus_state, search: .filter_hashtag([ht]))
let dst = SearchView(appstate: damus_state, search: search_model)
return NavigationLink(destination: dst) {
return NavigationLink(value: Route.Search(search: search_model)) {
Text("Search hashtag: #\(ht)", comment: "Navigation link to search hashtag.")
}
}
@@ -181,33 +180,21 @@ func make_hashtagable(_ str: String) -> String {
}
func search_profiles(profiles: Profiles, search: String) -> [SearchedUser] {
// Search by hex pubkey.
if search.count == 64 && hex_decode(search) != nil, let profile = profiles.lookup(id: search) {
return [SearchedUser(profile: profile, pubkey: search)]
}
// Search by npub pubkey.
if search.starts(with: "npub"), let bech32_key = decode_bech32_key(search), case Bech32Key.pub(let hex) = bech32_key, let profile = profiles.lookup(id: hex) {
return [SearchedUser(profile: profile, pubkey: hex)]
}
let new = search.lowercased()
return profiles.enumerated().reduce(into: []) { acc, els in
let pk = els.element.key
let prof = els.element.value.profile
if let searched = profile_search_matches(profiles: profiles, profile: prof, pubkey: pk, search: new) {
acc.append(searched)
}
}
}
let matched_pubkeys = profiles.user_search_cache.search(key: new)
func profile_search_matches(profiles: Profiles, profile prof: Profile, pubkey pk: String, search new: String) -> SearchedUser? {
let lowname = prof.name.map { $0.lowercased() }
let lownip05 = profiles.is_validated(pk).map { $0.host.lowercased() }
let lowdisp = prof.display_name.map { $0.lowercased() }
let ok = new.count == 1 ?
((lowname?.starts(with: new) ?? false) ||
(lownip05?.starts(with: new) ?? false) ||
(lowdisp?.starts(with: new) ?? false)) : (pk.starts(with: new) || String(new.dropFirst()) == pk
|| lowname?.contains(new) ?? false
|| lownip05?.contains(new) ?? false
|| lowdisp?.contains(new) ?? false)
if ok {
return SearchedUser(petname: nil, profile: prof, pubkey: pk)
}
return nil
return matched_pubkeys
.map { ($0, profiles.lookup(id: $0)) }
.filter { $1 != nil }
.map { SearchedUser(profile: $1, pubkey: $0) }
}

View File

@@ -17,16 +17,12 @@ func hex_col(r: UInt8, g: UInt8, b: UInt8) -> Color {
struct SetupView: View {
@State private var eula = false
@StateObject var navigationCoordinator: NavigationCoordinator = NavigationCoordinator()
var body: some View {
NavigationView {
NavigationStack(path: $navigationCoordinator.path) {
ZStack {
VStack(alignment: .center) {
NavigationLink(destination: EULAView(), isActive: $eula) {
EmptyView()
}
Spacer()
Image("logo-nobg")
@@ -53,7 +49,7 @@ struct SetupView: View {
Spacer()
Button(action: {
eula.toggle()
navigationCoordinator.push(route: Route.EULA)
}) {
HStack {
Text("Let's get started!", comment: "Button to continue to login page.")
@@ -72,6 +68,9 @@ struct SetupView: View {
.ignoresSafeArea(),
alignment: .top
)
.navigationDestination(for: Route.self) { route in
route.view(navigationCordinator: navigationCoordinator, damusState: DamusState.empty)
}
}
.navigationBarTitleDisplayMode(.inline)
.navigationViewStyle(StackNavigationViewStyle())

View File

@@ -11,23 +11,22 @@ struct SideMenuView: View {
let damus_state: DamusState
@Binding var isSidebarVisible: Bool
@State var confirm_logout: Bool = false
@State private var showQRCode = false
@Environment(\.colorScheme) var colorScheme
var sideBarWidth = min(UIScreen.main.bounds.size.width * 0.65, 400.0)
let verticalSpacing: CGFloat = 20
let padding: CGFloat = 30
func fillColor() -> Color {
colorScheme == .light ? DamusColors.white : DamusColors.black
}
func textColor() -> Color {
colorScheme == .light ? DamusColors.black : DamusColors.white
}
var body: some View {
ZStack {
GeometryReader { _ in
@@ -42,20 +41,20 @@ struct SideMenuView: View {
content
}
}
func SidemenuItems(profile_model: ProfileModel, followers: FollowersModel) -> some View {
return VStack(spacing: verticalSpacing) {
NavigationLink(destination: ProfileView(damus_state: damus_state, profile: profile_model, followers: followers)) {
NavigationLink(value: Route.Profile(profile: profile_model, followers: followers)) {
navLabel(title: NSLocalizedString("Profile", comment: "Sidebar menu label for Profile view."), img: "user")
}
NavigationLink(destination: WalletView(damus_state: damus_state, model: damus_state.wallet)) {
NavigationLink(value: Route.Wallet(wallet: damus_state.wallet)) {
navLabel(title: NSLocalizedString("Wallet", comment: "Sidebar menu label for Wallet view."), img: "wallet")
/*
HStack {
Image("wallet")
.tint(DamusColors.adaptableBlack)
Text(NSLocalizedString("wallet", comment: "Sidebar menu label for Wallet view."))
.font(.title2)
.foregroundColor(textColor())
@@ -63,36 +62,35 @@ struct SideMenuView: View {
.dynamicTypeSize(.xSmall)
}*/
}
NavigationLink(destination: MutelistView(damus_state: damus_state, users: get_mutelist_users(damus_state.contacts.mutelist) )) {
NavigationLink(value: Route.MuteList(users: get_mutelist_users(damus_state.contacts.mutelist))) {
navLabel(title: NSLocalizedString("Muted", comment: "Sidebar menu label for muted users view."), img: "mute")
}
NavigationLink(destination: RelayConfigView(state: damus_state)) {
NavigationLink(value: Route.RelayConfig) {
navLabel(title: NSLocalizedString("Relays", comment: "Sidebar menu label for Relays view."), img: "world-relays")
}
NavigationLink(destination: BookmarksView(state: damus_state)) {
NavigationLink(value: Route.Bookmarks) {
navLabel(title: NSLocalizedString("Bookmarks", comment: "Sidebar menu label for Bookmarks view."), img: "bookmark")
}
NavigationLink(destination: ConfigView(state: damus_state)) {
NavigationLink(value: Route.Config) {
navLabel(title: NSLocalizedString("Settings", comment: "Sidebar menu label for accessing the app settings"), img: "settings")
}
}
}
var MainSidemenu: some View {
VStack(alignment: .leading, spacing: 0) {
let profile = damus_state.profiles.lookup(id: damus_state.pubkey)
let followers = FollowersModel(damus_state: damus_state, target: damus_state.pubkey)
let profile_model = ProfileModel(pubkey: damus_state.pubkey, damus: damus_state)
NavigationLink(destination: ProfileView(damus_state: damus_state, profile: profile_model, followers: followers)) {
NavigationLink(value: Route.Profile(profile: profile_model, followers: followers), label: {
HStack {
ProfilePicView(pubkey: damus_state.pubkey, size: 60, highlight: .none, profiles: damus_state.profiles, disable_animation: damus_state.settings.disable_animation)
VStack(alignment: .leading) {
if let display_name = profile?.display_name {
Text(display_name)
@@ -109,10 +107,10 @@ struct SideMenuView: View {
}
}
.padding(.bottom, verticalSpacing)
}
})
Divider()
ScrollView {
SidemenuItems(profile_model: profile_model, followers: followers)
.labelStyle(SideMenuLabelStyle())
@@ -120,21 +118,21 @@ struct SideMenuView: View {
}
}
}
var content: some View {
HStack(alignment: .top) {
ZStack(alignment: .top) {
fillColor()
.ignoresSafeArea()
VStack(alignment: .leading, spacing: 0) {
MainSidemenu
.simultaneousGesture(TapGesture().onEnded {
isSidebarVisible = false
})
Divider()
HStack() {
Button(action: {
//ConfigView(state: damus_state)
@@ -150,9 +148,9 @@ struct SideMenuView: View {
.frame(maxWidth: .infinity, alignment: .leading)
.dynamicTypeSize(.xSmall)
})
Spacer()
Button(action: {
showQRCode.toggle()
}, label: {
@@ -186,20 +184,20 @@ struct SideMenuView: View {
Spacer()
}
}
@ViewBuilder
func navLabel(title: String, img: String) -> some View {
Image(img)
.tint(DamusColors.adaptableBlack)
Text(title)
.font(.title2)
.foregroundColor(textColor())
.frame(maxWidth: .infinity, alignment: .leading)
.dynamicTypeSize(.xSmall)
}
struct SideMenuLabelStyle: LabelStyle {
func makeBody(configuration: Configuration) -> some View {
HStack(alignment: .center, spacing: 8) {

View File

@@ -70,17 +70,21 @@ struct TextViewWrapper: UIViewRepresentable {
}
private func processFocusedWordForMention(textView: UITextView) {
if let selectedRange = textView.selectedTextRange {
var val: (String?, NSRange?)
if let wordRange = textView.tokenizer.rangeEnclosingPosition(selectedRange.start, with: .word, inDirection: .init(rawValue: UITextLayoutDirection.left.rawValue)) {
if let startPosition = textView.position(from: wordRange.start, offset: -1),
let cursorPosition = textView.position(from: selectedRange.start, offset: 0) {
let word = textView.text(in: textView.textRange(from: startPosition, to: cursorPosition)!)
val = (word, convertToNSRange(startPosition, cursorPosition, textView))
}
}
getFocusWordForMention?(val.0, val.1)
var val: (String?, NSRange?) = (nil, nil)
guard let selectedRange = textView.selectedTextRange else { return }
let wordRange = textView.tokenizer.rangeEnclosingPosition(selectedRange.start, with: .word, inDirection: .init(rawValue: UITextLayoutDirection.left.rawValue))
if let wordRange,
let startPosition = textView.position(from: wordRange.start, offset: -1),
let cursorPosition = textView.position(from: selectedRange.start, offset: 0)
{
let word = textView.text(in: textView.textRange(from: startPosition, to: cursorPosition)!)
val = (word, convertToNSRange(startPosition, cursorPosition, textView))
}
getFocusWordForMention?(val.0, val.1)
}
private func convertToNSRange( _ startPosition: UITextPosition, _ endPosition: UITextPosition, _ textView: UITextView) -> NSRange? {

View File

@@ -12,8 +12,6 @@ struct InnerTimelineView: View {
@ObservedObject var events: EventHolder
let state: DamusState
let filter: (NostrEvent) -> Bool
@State var nav_target: NostrEvent
@State var navigating: Bool = false
static var count: Int = 0
@@ -23,8 +21,6 @@ struct InnerTimelineView: View {
self.filter = filter
print("rendering InnerTimelineView \(InnerTimelineView.count)")
InnerTimelineView.count += 1
// dummy event to avoid MaybeThreadView
self._nav_target = State(initialValue: test_event)
}
var event_options: EventViewOptions {
@@ -36,11 +32,6 @@ struct InnerTimelineView: View {
}
var body: some View {
let thread = ThreadModel(event: nav_target, damus_state: state)
let dest = ThreadView(state: state, thread: thread)
NavigationLink(destination: dest, isActive: $navigating) {
EmptyView()
}
LazyVStack(spacing: 0) {
let events = self.events.events
if events.isEmpty {
@@ -53,8 +44,9 @@ struct InnerTimelineView: View {
let ind = tup.1
EventView(damus: state, event: ev, options: event_options)
.onTapGesture {
nav_target = ev.get_inner_event(cache: state.events) ?? ev
navigating = true
let event = ev.get_inner_event(cache: state.events) ?? ev
let thread = ThreadModel(event: event, damus_state: state)
state.nav.push(route: Route.Thread(thread: thread))
}
.padding(.top, 7)
.onAppear {

View File

@@ -48,7 +48,8 @@ public class VideoPlayerModel: ObservableObject {
@Published var has_audio: Bool? = nil
@Published var contentMode: UIView.ContentMode = .scaleAspectFill
var time: CMTime = CMTime()
fileprivate var time: CMTime?
var handlers: [VideoHandler] = []
init() {
@@ -262,8 +263,9 @@ extension VideoPlayer: UIViewRepresentable {
uiView.isMuted = model.muted
uiView.isAutoReplay = model.autoReplay
if let observerTime = context.coordinator.observerTime, model.time != observerTime {
uiView.seek(to: model.time, toleranceBefore: model.time, toleranceAfter: model.time, completion: { _ in })
if let observerTime = context.coordinator.observerTime, let modelTime = model.time,
modelTime != observerTime && modelTime.isValid && modelTime.isNumeric {
uiView.seek(to: modelTime, completion: { _ in })
}
}

View File

@@ -14,6 +14,7 @@ struct ConnectWalletView: View {
@State var scanning: Bool = false
@State var error: String? = nil
@State var wallet_scan_result: WalletScanResult = .scanning
var nav: NavigationCoordinator
var body: some View {
MainContent
@@ -63,17 +64,13 @@ struct ConnectWalletView: View {
}
var ConnectWallet: some View {
VStack {
NavigationLink(destination: WalletScannerView(result: $wallet_scan_result), isActive: $scanning) {
EmptyView()
}
VStack {
AlbyButton() {
openURL(URL(string:"https://nwc.getalby.com/apps/new?c=Damus")!)
}
BigButton(NSLocalizedString("Attach Wallet", comment: "Text for button to attach Nostr Wallet Connect lightning wallet.")) {
scanning = true
nav.push(route: Route.WalletScanner(result: $wallet_scan_result))
}
if let err = self.error {
@@ -99,6 +96,6 @@ struct ConnectWalletView: View {
struct ConnectWalletView_Previews: PreviewProvider {
static var previews: some View {
ConnectWalletView(model: WalletModel(settings: UserSettingsStore()))
ConnectWalletView(model: WalletModel(settings: UserSettingsStore()), nav: .init())
}
}

View File

@@ -155,9 +155,9 @@ struct WalletView: View {
var body: some View {
switch model.connect_state {
case .new:
ConnectWalletView(model: model)
ConnectWalletView(model: model, nav: damus_state.nav)
case .none:
ConnectWalletView(model: model)
ConnectWalletView(model: model, nav: damus_state.nav)
case .existing(let nwc):
MainWalletView(nwc: nwc)
.onAppear() {

View File

@@ -23,6 +23,6 @@ struct ZapUserView: View {
struct ZapUserView_Previews: PreviewProvider {
static var previews: some View {
ZapUserView(state: test_damus_state(), pubkey: "anon")
ZapUserView(state: test_damus_state(), pubkey: ANON_PUBKEY)
}
}

View File

@@ -18,6 +18,22 @@
<string>... %d άλλες σημειώσεις ...</string>
</dict>
</dict>
<key>followed_by_three_and_others</key>
<dict>
<key>NSStringLocalizedFormatKey</key>
<string>%#@OTHERS@</string>
<key>OTHERS</key>
<dict>
<key>NSStringFormatSpecTypeKey</key>
<string>NSStringPluralRuleType</string>
<key>NSStringFormatValueTypeKey</key>
<string>d</string>
<key>one</key>
<string>Σας ακολούθησε %2$@, %3$@, %4$@ &amp; %1$d ακόμα</string>
<key>other</key>
<string>Σας ακολούθησαν %2$@, %3$@, %4$@ &amp; %1$d ακόμα</string>
</dict>
</dict>
<key>followers_count</key>
<dict>
<key>NSStringLocalizedFormatKey</key>
@@ -317,9 +333,9 @@
<key>NSStringFormatValueTypeKey</key>
<string>d</string>
<key>one</key>
<string>%2$@ και %1$d ακόμα έστειλε zap στο προφίλ σας</string>
<string>%2$@ και %1$d ακόμα σας έστειλε zap</string>
<key>other</key>
<string>%2$@ και %1$d ακόμα έστειλαν zap στο προφίλ σας</string>
<string>%2$@ και %1$d ακόμα σας έστειλαν zap</string>
</dict>
</dict>
<key>zaps_count</key>

View File

@@ -45,7 +45,7 @@
<trans-unit id="%@ %@" xml:space="preserve">
<source>%@ %@</source>
<target>%@ %@</target>
<note>Sentence composed of 2 variables to describe how many reposts. In source English, the first variable is the number of reposts, and the second variable is 'Repost' or 'Reposts'.
<note>Sentence composed of 2 variables to describe how many zap payments there are on a post. In source English, the first variable is the number of zap payments, and the second variable is 'Zap' or 'Zaps'.
Sentence composed of 2 variables to describe how many people are following a user. In source English, the first variable is the number of followers, and the second variable is 'Follower' or 'Followers'.</note>
</trans-unit>
<trans-unit id="%@ has been muted" xml:space="preserve">
@@ -276,11 +276,6 @@ Sentence composed of 2 variables to describe how many people are following a use
<note>Sidebar menu label for Bookmarks view.
Title of bookmarks view</note>
</trans-unit>
<trans-unit id="Boosts" xml:space="preserve">
<source>Boosts</source>
<target>Boosts</target>
<note>Accessibility label for boosts button</note>
</trans-unit>
<trans-unit id="Broadcast" xml:space="preserve">
<source>Broadcast</source>
<target>Broadcast</target>
@@ -576,11 +571,31 @@ Sentence composed of 2 variables to describe how many people are following a use
<target>Follow me on Nostr</target>
<note>Text on QR code view to prompt viewer looking at screen to follow the user.</note>
</trans-unit>
<trans-unit id="Followed by %@" xml:space="preserve">
<source>Followed by %@</source>
<target>Followed by %@</target>
<note>Text to indicate that the user is followed by one of our follows.</note>
</trans-unit>
<trans-unit id="Followed by %@ &amp; %@" xml:space="preserve">
<source>Followed by %1$@ &amp; %2$@</source>
<target>Followed by %1$@ &amp; %2$@</target>
<note>Text to indicate that the user is followed by two of our follows.</note>
</trans-unit>
<trans-unit id="Followed by %@, %@ &amp; %@" xml:space="preserve">
<source>Followed by %1$@, %2$@ &amp; %3$@</source>
<target>Followed by %1$@, %2$@ &amp; %3$@</target>
<note>Text to indicate that the user is followed by three of our follows.</note>
</trans-unit>
<trans-unit id="Followers" xml:space="preserve">
<source>Followers</source>
<target>Followers</target>
<note>Navigation bar title for view that shows who is following a user.</note>
</trans-unit>
<trans-unit id="Followers You Know" xml:space="preserve">
<source>Followers You Know</source>
<target>Followers You Know</target>
<note>Navigation bar title for view that shows who is following a user.</note>
</trans-unit>
<trans-unit id="Following" xml:space="preserve">
<source>Following</source>
<target>Following</target>
@@ -1151,7 +1166,8 @@ Button text to indicate that the zap type is a private zap.</note>
<trans-unit id="Reposts" xml:space="preserve">
<source>Reposts</source>
<target>Reposts</target>
<note>Navigation bar title for Reposts view.
<note>Accessibility label for boosts button
Navigation bar title for Reposts view.
Setting to enable Repost Local Notification</note>
</trans-unit>
<trans-unit id="Requests" xml:space="preserve">
@@ -1230,9 +1246,9 @@ Button text to indicate that the zap type is a private zap.</note>
<target>Send a message to start the conversation...</target>
<note>Text prompt for user to send a message to the other user.</note>
</trans-unit>
<trans-unit id="Send a reply with your zap..." xml:space="preserve">
<source>Send a reply with your zap...</source>
<target>Send a reply with your zap...</target>
<trans-unit id="Send a message with your zap..." xml:space="preserve">
<source>Send a message with your zap...</source>
<target>Send a message with your zap...</target>
<note>Placeholder text for a comment to send as part of a zap to the user.</note>
</trans-unit>
<trans-unit id="Server" xml:space="preserve">
@@ -1620,9 +1636,13 @@ YOU WILL NO LONGER BE ABLE TO LOG INTO DAMUS USING THIS ACCOUNT KEY.
<source>Zap</source>
<target>Zap</target>
<note>Accessibility label for zap button
Button to send a zap.
Title of notification when a non-private zap is received.</note>
</trans-unit>
<trans-unit id="Zap User" xml:space="preserve">
<source>Zap User</source>
<target>Zap User</target>
<note>Button to send a zap.</note>
</trans-unit>
<trans-unit id="Zap Vibration" xml:space="preserve">
<source>Zap Vibration</source>
<target>Zap Vibration</target>
@@ -1834,6 +1854,21 @@ YOU WILL NO LONGER BE ABLE TO LOG INTO DAMUS USING THIS ACCOUNT KEY.
<target>%#@NOTES@</target>
<note/>
</trans-unit>
<trans-unit id="/followed_by_three_and_others:dict/NSStringLocalizedFormatKey:dict/:string" xml:space="preserve">
<source>%#@OTHERS@</source>
<target>%#@OTHERS@</target>
<note/>
</trans-unit>
<trans-unit id="/followed_by_three_and_others:dict/OTHERS:dict/one:dict/:string" xml:space="preserve">
<source>Followed by %2$@, %3$@, %4$@ &amp; %1$d other</source>
<target>Followed by %2$@, %3$@, %4$@ &amp; %1$d other</target>
<note/>
</trans-unit>
<trans-unit id="/followed_by_three_and_others:dict/OTHERS:dict/other:dict/:string" xml:space="preserve">
<source>Followed by %2$@, %3$@, %4$@ &amp; %1$d others</source>
<target>Followed by %2$@, %3$@, %4$@ &amp; %1$d others</target>
<note/>
</trans-unit>
<trans-unit id="/followers_count:dict/FOLLOWERS:dict/one:dict/:string" xml:space="preserve">
<source>Follower</source>
<target>Follower</target>

View File

@@ -18,6 +18,22 @@
<string>... %d other notes ...</string>
</dict>
</dict>
<key>followed_by_three_and_others</key>
<dict>
<key>NSStringLocalizedFormatKey</key>
<string>%#@OTHERS@</string>
<key>OTHERS</key>
<dict>
<key>NSStringFormatSpecTypeKey</key>
<string>NSStringPluralRuleType</string>
<key>NSStringFormatValueTypeKey</key>
<string>d</string>
<key>one</key>
<string>Followed by %2$@, %3$@, %4$@ &amp; %1$d other</string>
<key>other</key>
<string>Followed by %2$@, %3$@, %4$@ &amp; %1$d others</string>
</dict>
</dict>
<key>followers_count</key>
<dict>
<key>NSStringLocalizedFormatKey</key>

View File

@@ -20,6 +20,24 @@
<string>... %d otras notas...</string>
</dict>
</dict>
<key>followed_by_three_and_others</key>
<dict>
<key>NSStringLocalizedFormatKey</key>
<string>%#@OTHERS@</string>
<key>OTHERS</key>
<dict>
<key>NSStringFormatSpecTypeKey</key>
<string>NSStringPluralRuleType</string>
<key>NSStringFormatValueTypeKey</key>
<string>d</string>
<key>one</key>
<string>Seguido por %2$@, %3$@, %4$@ y %1$d persona más</string>
<key>many</key>
<string>Seguido por %2$@, %3$@, %4$@ y %1$d personas más</string>
<key>other</key>
<string>Seguido por %2$@, %3$@, %4$@ y %1$d personas más</string>
</dict>
</dict>
<key>followers_count</key>
<dict>
<key>NSStringLocalizedFormatKey</key>
@@ -67,14 +85,14 @@
<key>NSStringFormatValueTypeKey</key>
<string>d</string>
<key>one</key>
<string>%2$@ y %1$d persona más reaccionaron a una publicación en la que te etiquetaron</string>
<string>%2$@ y %1$d persona más reaccionaron a una nota en la que te etiquetaron</string>
<key>many</key>
<string>%2$@ y %1$d personas más reaccionaron a una publicación en la que te etiquetaron</string>
<string>%2$@ y %1$d personas más reaccionaron a una nota en la que te etiquetaron</string>
<key>other</key>
<string>%2$@ y %1$d personas más reaccionaron a una publicación en la que te etiquetaron</string>
<string>%2$@ y %1$d personas más reaccionaron a una nota en la que te etiquetaron</string>
</dict>
</dict>
<key>reacted_your_post_3</key>
<key>reacted_your_note_3</key>
<dict>
<key>NSStringLocalizedFormatKey</key>
<string>%#@REACTED@</string>
@@ -85,11 +103,11 @@
<key>NSStringFormatValueTypeKey</key>
<string>d</string>
<key>one</key>
<string>%2$@ y %1$d persona más reaccionaron a tu publicación</string>
<string>%2$@ y %1$d persona más reaccionaron a tu nota</string>
<key>many</key>
<string>%2$@ y %1$d personas más reaccionaron a tu publicación</string>
<string>%2$@ y %1$d personas más reaccionaron a tu nota</string>
<key>other</key>
<string>%2$@ y %1$d personas más reaccionaron a tu publicación</string>
<string>%2$@ y %1$d personas más reaccionaron a tu nota</string>
</dict>
</dict>
<key>reacted_your_profile_3</key>
@@ -175,14 +193,14 @@
<key>NSStringFormatValueTypeKey</key>
<string>d</string>
<key>one</key>
<string>%2$@ y %1$d persona más republicaron una publicación en la que te etiquetaron</string>
<string>%2$@ y %1$d persona más republicaron una nota en la que te etiquetaron</string>
<key>many</key>
<string>%2$@ y %1$d personas más republicaron una publicación en la que te etiquetaron</string>
<string>%2$@ y %1$d personas más republicaron una nota en la que te etiquetaron</string>
<key>other</key>
<string>%2$@ y %1$d personas más republicaron una publicación en la que te etiquetaron</string>
<string>%2$@ y %1$d personas más republicaron una nota en la que te etiquetaron</string>
</dict>
</dict>
<key>reposted_your_post_3</key>
<key>reposted_your_note_3</key>
<dict>
<key>NSStringLocalizedFormatKey</key>
<string>%#@REPOSTED@</string>
@@ -193,11 +211,11 @@
<key>NSStringFormatValueTypeKey</key>
<string>d</string>
<key>one</key>
<string>%2$@ y %1$d persona más republicaron tu publicación</string>
<string>%2$@ y %1$d persona más republicaron tu nota</string>
<key>many</key>
<string>%2$@ y %1$d personas más republicaron tu publicación</string>
<string>%2$@ y %1$d personas más republicaron tu nota</string>
<key>other</key>
<string>%2$@ y %1$d personas más republicaron tu publicación</string>
<string>%2$@ y %1$d personas más republicaron tu nota</string>
</dict>
</dict>
<key>reposted_your_profile_3</key>
@@ -301,11 +319,11 @@
<key>NSStringFormatValueTypeKey</key>
<string>@</string>
<key>one</key>
<string>Recibiste %2$@ sat de %3$@: "%4$@"</string>
<string>Recibiste %2$@ sat de %3$@: &quot;%4$@&quot;</string>
<key>many</key>
<string>Recibiste %2$@ sats de %3$@: "%4$@"</string>
<string>Recibiste %2$@ sats de %3$@: &quot;%4$@&quot;</string>
<key>other</key>
<string>Recibiste %2$@ sats de %3$@: "%4$@"</string>
<string>Recibiste %2$@ sats de %3$@: &quot;%4$@&quot;</string>
</dict>
</dict>
<key>zapped_tagged_in_3</key>
@@ -319,14 +337,14 @@
<key>NSStringFormatValueTypeKey</key>
<string>d</string>
<key>one</key>
<string>%2$@ y %1$d persona más zapearon una publicación en la que te etiquetaron</string>
<string>%2$@ y %1$d persona más zapearon una nota en la que te etiquetaron</string>
<key>many</key>
<string>%2$@ y %1$d personas más zapearon una publicación en la que te etiquetaron</string>
<string>%2$@ y %1$d personas más zapearon una nota en la que te etiquetaron</string>
<key>other</key>
<string>%2$@ y %1$d personas más zapearon una publicación en la que te etiquetaron</string>
<string>%2$@ y %1$d personas más zapearon una nota en la que te etiquetaron</string>
</dict>
</dict>
<key>zapped_your_post_3</key>
<key>zapped_your_note_3</key>
<dict>
<key>NSStringLocalizedFormatKey</key>
<string>%#@ZAPPED@</string>
@@ -337,11 +355,11 @@
<key>NSStringFormatValueTypeKey</key>
<string>d</string>
<key>one</key>
<string>%2$@ y %1$d persona más zapearon tu publicación</string>
<string>%2$@ y %1$d persona más zapearon tu nota</string>
<key>many</key>
<string>%2$@ y %1$d personas más zapearon tu publicación</string>
<string>%2$@ y %1$d personas más zapearon tu nota</string>
<key>other</key>
<string>%2$@ y %1$d personas más zapearon tu publicación</string>
<string>%2$@ y %1$d personas más zapearon tu nota</string>
</dict>
</dict>
<key>zapped_your_profile_3</key>
@@ -355,11 +373,11 @@
<key>NSStringFormatValueTypeKey</key>
<string>d</string>
<key>one</key>
<string>%2$@ y %1$d persona más zapearon tu perfil</string>
<string>%2$@ y %1$d persona más te zapearon</string>
<key>many</key>
<string>%2$@ y %1$d personas más zapearon tu perfil</string>
<string>%2$@ y %1$d personas más te zapearon</string>
<key>other</key>
<string>%2$@ y %1$d personas más zapearon tu perfil</string>
<string>%2$@ y %1$d personas más te zapearon</string>
</dict>
</dict>
<key>zaps_count</key>

View File

@@ -20,6 +20,24 @@
<string>... %d otras notas ...</string>
</dict>
</dict>
<key>followed_by_three_and_others</key>
<dict>
<key>NSStringLocalizedFormatKey</key>
<string>%#@OTHERS@</string>
<key>OTHERS</key>
<dict>
<key>NSStringFormatSpecTypeKey</key>
<string>NSStringPluralRuleType</string>
<key>NSStringFormatValueTypeKey</key>
<string>d</string>
<key>one</key>
<string>Seguido por %2$@, %3$@, %4$@ y %1$d más</string>
<key>many</key>
<string>Seguido por %2$@, %3$@, %4$@ y %1$d más</string>
<key>other</key>
<string>Seguido por %2$@, %3$@, %4$@ y %1$d más</string>
</dict>
</dict>
<key>followers_count</key>
<dict>
<key>NSStringLocalizedFormatKey</key>
@@ -157,11 +175,11 @@
<key>NSStringFormatValueTypeKey</key>
<string>d</string>
<key>one</key>
<string>Respondiendo a %2$@, %3$@ &amp; %1$d más</string>
<string>Respondiendo a %2$@, %3$@ y %1$d más</string>
<key>many</key>
<string>Respondiendo a %2$@, %3$@ &amp; %1$d más</string>
<string>Respondiendo a %2$@, %3$@ y %1$d más</string>
<key>other</key>
<string>Respondiendo a %2$@, %3$@ &amp; %1$d más</string>
<string>Respondiendo a %2$@, %3$@ y %1$d más</string>
</dict>
</dict>
<key>reposted_tagged_in_3</key>

View File

@@ -18,6 +18,22 @@
<string>... %d további bejegyzések ...</string>
</dict>
</dict>
<key>followed_by_three_and_others</key>
<dict>
<key>NSStringLocalizedFormatKey</key>
<string>%#@OTHERS@</string>
<key>OTHERS</key>
<dict>
<key>NSStringFormatSpecTypeKey</key>
<string>NSStringPluralRuleType</string>
<key>NSStringFormatValueTypeKey</key>
<string>d</string>
<key>one</key>
<string>Téged követ %2$@, %3$@, %4$@ &amp; %1$d más</string>
<key>other</key>
<string>Téged követ %2$@, %3$@, %4$@ &amp; %1$d mások</string>
</dict>
</dict>
<key>followers_count</key>
<dict>
<key>NSStringLocalizedFormatKey</key>
@@ -66,7 +82,7 @@
<string>%2$@ és %1$d mások reagáltak egy bejegyzésre amiben meg voltál jelölve</string>
</dict>
</dict>
<key>reacted_your_post_3</key>
<key>reacted_your_note_3</key>
<dict>
<key>NSStringLocalizedFormatKey</key>
<string>%#@REACTED@</string>
@@ -162,7 +178,7 @@
<string>%2$@ és %1$d mások megosztották azt a bejegyzést amiben meg voltál jelölve</string>
</dict>
</dict>
<key>reposted_your_post_3</key>
<key>reposted_your_note_3</key>
<dict>
<key>NSStringLocalizedFormatKey</key>
<string>%#@REPOSTED@</string>
@@ -269,9 +285,9 @@
<key>NSStringFormatValueTypeKey</key>
<string>@</string>
<key>one</key>
<string>%2$@ sat kaptál %3$@: "%4$@"-tól</string>
<string>%2$@ sat kaptál %3$@: &quot;%4$@&quot;-tól</string>
<key>other</key>
<string>%2$@ sats kaptál %3$@: "%4$@"-tól</string>
<string>%2$@ sats kaptál %3$@: &quot;%4$@&quot;-tól</string>
</dict>
</dict>
<key>zapped_tagged_in_3</key>
@@ -290,7 +306,7 @@
<string>%2$@ és %1$d mások Zap-eltek egy bejegyzést amiben meg voltál jelölve</string>
</dict>
</dict>
<key>zapped_your_post_3</key>
<key>zapped_your_note_3</key>
<dict>
<key>NSStringLocalizedFormatKey</key>
<string>%#@ZAPPED@</string>
@@ -317,9 +333,9 @@
<key>NSStringFormatValueTypeKey</key>
<string>d</string>
<key>one</key>
<string>%2$@ és %1$d más Zap-elte a profilodat</string>
<string>%2$@ és %1$d más Zap-elt téged</string>
<key>other</key>
<string>%2$@ és %1$d mások Zap-elték a profilodat</string>
<string>%2$@ és %1$d mások Zap-elt téged</string>
</dict>
</dict>
<key>zaps_count</key>

Binary file not shown.

View File

@@ -16,6 +16,20 @@
<string>... 他%d件の投稿 ...</string>
</dict>
</dict>
<key>followed_by_three_and_others</key>
<dict>
<key>NSStringLocalizedFormatKey</key>
<string>%#@OTHERS@</string>
<key>OTHERS</key>
<dict>
<key>NSStringFormatSpecTypeKey</key>
<string>NSStringPluralRuleType</string>
<key>NSStringFormatValueTypeKey</key>
<string>d</string>
<key>other</key>
<string> %2$@、%3$@、%4$@他%1$d人にフォローされています</string>
</dict>
</dict>
<key>followers_count</key>
<dict>
<key>NSStringLocalizedFormatKey</key>

Binary file not shown.

View File

@@ -18,6 +18,22 @@
<string>... %d andere notities ...</string>
</dict>
</dict>
<key>followed_by_three_and_others</key>
<dict>
<key>NSStringLocalizedFormatKey</key>
<string>%#@OTHERS@</string>
<key>OTHERS</key>
<dict>
<key>NSStringFormatSpecTypeKey</key>
<string>NSStringPluralRuleType</string>
<key>NSStringFormatValueTypeKey</key>
<string>d</string>
<key>one</key>
<string>Gevolgd door %2$@, %3$@, %4$@ en %1$d andere gebruiker</string>
<key>other</key>
<string>Gevolgd door %2$@, %3$@, %4$@ en %1$d andere gebruikers</string>
</dict>
</dict>
<key>followers_count</key>
<dict>
<key>NSStringLocalizedFormatKey</key>

View File

@@ -18,6 +18,22 @@
<string>...%d andra anteckningar...</string>
</dict>
</dict>
<key>followed_by_three_and_others</key>
<dict>
<key>NSStringLocalizedFormatKey</key>
<string>%#@OTHERS@</string>
<key>OTHERS</key>
<dict>
<key>NSStringFormatSpecTypeKey</key>
<string>NSStringPluralRuleType</string>
<key>NSStringFormatValueTypeKey</key>
<string>d</string>
<key>one</key>
<string>Följd av %2$@, %3$@, %4$@ &amp; %1$d andra</string>
<key>other</key>
<string>Följd av %2$@, %3$@, %4$@ &amp; %1$d andra</string>
</dict>
</dict>
<key>followers_count</key>
<dict>
<key>NSStringLocalizedFormatKey</key>
@@ -317,9 +333,9 @@
<key>NSStringFormatValueTypeKey</key>
<string>d</string>
<key>one</key>
<string>%2$@ och %1$d annan zappade din profil</string>
<string>%2$@ och %1$d andra zapped dig</string>
<key>other</key>
<string>%2$@ och %1$d andra zappade din profil</string>
<string>%2$@ och %1$d andra zapped dig</string>
</dict>
</dict>
<key>zaps_count</key>

View File

@@ -16,6 +16,20 @@
<string>... %d 条更多笔记...</string>
</dict>
</dict>
<key>followed_by_three_and_others</key>
<dict>
<key>NSStringLocalizedFormatKey</key>
<string>%#@OTHERS@</string>
<key>OTHERS</key>
<dict>
<key>NSStringFormatSpecTypeKey</key>
<string>NSStringPluralRuleType</string>
<key>NSStringFormatValueTypeKey</key>
<string>d</string>
<key>other</key>
<string>被 %2$@、%3$@、%4$@ 和 %1$d 个其他用户关注</string>
</dict>
</dict>
<key>followers_count</key>
<dict>
<key>NSStringLocalizedFormatKey</key>
@@ -125,7 +139,7 @@
<key>NSStringFormatValueTypeKey</key>
<string>d</string>
<key>other</key>
<string>正在回复%2$@, %3$@ &amp; %1$d 个其他用户</string>
<string>正在回复%2$@, %3$@ %1$d 个其他用户</string>
</dict>
</dict>
<key>reposted_tagged_in_3</key>

View File

@@ -16,6 +16,20 @@
<string>...還有%d 条筆記...</string>
</dict>
</dict>
<key>followed_by_three_and_others</key>
<dict>
<key>NSStringLocalizedFormatKey</key>
<string>%#@OTHERS@</string>
<key>OTHERS</key>
<dict>
<key>NSStringFormatSpecTypeKey</key>
<string>NSStringPluralRuleType</string>
<key>NSStringFormatValueTypeKey</key>
<string>d</string>
<key>other</key>
<string>被 %2$@、%3$@、%4$@ 和 %1$d 個其他用戶關注</string>
</dict>
</dict>
<key>followers_count</key>
<dict>
<key>NSStringLocalizedFormatKey</key>

View File

@@ -16,6 +16,20 @@
<string>...還有%d 条筆記...</string>
</dict>
</dict>
<key>followed_by_three_and_others</key>
<dict>
<key>NSStringLocalizedFormatKey</key>
<string>%#@OTHERS@</string>
<key>OTHERS</key>
<dict>
<key>NSStringFormatSpecTypeKey</key>
<string>NSStringPluralRuleType</string>
<key>NSStringFormatValueTypeKey</key>
<string>d</string>
<key>other</key>
<string>被 %2$@、%3$@、%4$@ 和 %1$d 個其他用戶關注</string>
</dict>
</dict>
<key>followers_count</key>
<dict>
<key>NSStringLocalizedFormatKey</key>

View File

@@ -18,6 +18,27 @@ final class EventGroupViewTests: XCTestCase {
// Put teardown code here. This method is called after the invocation of each test method in the class.
}
func testEventAuthorName() {
let damusState = test_damus_state()
XCTAssertEqual(event_author_name(profiles: damusState.profiles, pubkey: "pk1"), "pk1:pk1")
XCTAssertEqual(event_author_name(profiles: damusState.profiles, pubkey: "pk2"), "pk2:pk2")
XCTAssertEqual(event_author_name(profiles: damusState.profiles, pubkey: "anon"), "Anonymous")
}
func testEventGroupUniquePubkeys() {
let damusState = test_damus_state()
let encodedPost = "{\"id\": \"8ba545ab96959fe0ce7db31bc10f3ac3aa5353bc4428dbf1e56a7be7062516db\",\"pubkey\": \"7e27509ccf1e297e1df164912a43406218f8bd80129424c3ef798ca3ef5c8444\",\"created_at\": 1677013417,\"kind\": 1,\"tags\": [],\"content\": \"hello\",\"sig\": \"93684f15eddf11f42afbdd81828ee9fc35350344d8650c78909099d776e9ad8d959cd5c4bff7045be3b0b255144add43d0feef97940794a1bc9c309791bebe4a\"}"
let repost1 = NostrEvent(id: "", content: encodedPost, pubkey: "pk1", kind: NostrKind.boost.rawValue, tags: [], createdAt: 1)
let repost2 = NostrEvent(id: "", content: encodedPost, pubkey: "pk2", kind: NostrKind.boost.rawValue, tags: [], createdAt: 1)
let repost3 = NostrEvent(id: "", content: encodedPost, pubkey: "pk3", kind: NostrKind.boost.rawValue, tags: [], createdAt: 1)
XCTAssertEqual(event_group_unique_pubkeys(profiles: damusState.profiles, group: .repost(EventGroup(events: []))), [])
XCTAssertEqual(event_group_unique_pubkeys(profiles: damusState.profiles, group: .repost(EventGroup(events: [repost1]))), ["pk1"])
XCTAssertEqual(event_group_unique_pubkeys(profiles: damusState.profiles, group: .repost(EventGroup(events: [repost1, repost2]))), ["pk1", "pk2"])
XCTAssertEqual(event_group_unique_pubkeys(profiles: damusState.profiles, group: .repost(EventGroup(events: [repost1, repost2, repost3]))), ["pk1", "pk2", "pk3"])
}
func testReactingToText() throws {
let enUsLocale = Locale(identifier: "en-US")
let damusState = test_damus_state()
@@ -25,18 +46,19 @@ final class EventGroupViewTests: XCTestCase {
let encodedPost = "{\"id\": \"8ba545ab96959fe0ce7db31bc10f3ac3aa5353bc4428dbf1e56a7be7062516db\",\"pubkey\": \"7e27509ccf1e297e1df164912a43406218f8bd80129424c3ef798ca3ef5c8444\",\"created_at\": 1677013417,\"kind\": 1,\"tags\": [],\"content\": \"hello\",\"sig\": \"93684f15eddf11f42afbdd81828ee9fc35350344d8650c78909099d776e9ad8d959cd5c4bff7045be3b0b255144add43d0feef97940794a1bc9c309791bebe4a\"}"
let repost1 = NostrEvent(id: "", content: encodedPost, pubkey: "pk1", kind: NostrKind.boost.rawValue, tags: [], createdAt: 1)
let repost2 = NostrEvent(id: "", content: encodedPost, pubkey: "pk2", kind: NostrKind.boost.rawValue, tags: [], createdAt: 1)
let repost3 = NostrEvent(id: "", content: encodedPost, pubkey: "pk3", kind: NostrKind.boost.rawValue, tags: [], createdAt: 1)
let nozaps = true
XCTAssertEqual(reacting_to_text(profiles: damusState.profiles, our_pubkey: damusState.pubkey, group: .repost(EventGroup(events: [])), ev: test_event, nozaps: nozaps, locale: enUsLocale), "??")
XCTAssertEqual(reacting_to_text(profiles: damusState.profiles, our_pubkey: damusState.pubkey, group: .repost(EventGroup(events: [repost1])), ev: test_event, nozaps: nozaps, locale: enUsLocale), "pk1:pk1 reposted a note you were tagged in")
XCTAssertEqual(reacting_to_text(profiles: damusState.profiles, our_pubkey: damusState.pubkey, group: .repost(EventGroup(events: [repost1, repost2])), ev: test_event, nozaps: nozaps, locale: enUsLocale), "pk1:pk1 and pk2:pk2 reposted a note you were tagged in")
XCTAssertEqual(reacting_to_text(profiles: damusState.profiles, our_pubkey: damusState.pubkey, group: .repost(EventGroup(events: [repost1, repost2, repost2])), ev: test_event, nozaps: nozaps, locale: enUsLocale), "pk1:pk1 and 2 others reposted a note you were tagged in")
XCTAssertEqual(reacting_to_text(profiles: damusState.profiles, our_pubkey: damusState.pubkey, group: .repost(EventGroup(events: [])), ev: test_event, pubkeys: [], locale: enUsLocale), "??")
XCTAssertEqual(reacting_to_text(profiles: damusState.profiles, our_pubkey: damusState.pubkey, group: .repost(EventGroup(events: [repost1])), ev: test_event, pubkeys: ["pk1"], locale: enUsLocale), "pk1:pk1 reposted a note you were tagged in")
XCTAssertEqual(reacting_to_text(profiles: damusState.profiles, our_pubkey: damusState.pubkey, group: .repost(EventGroup(events: [repost1, repost2])), ev: test_event, pubkeys: ["pk1", "pk2"], locale: enUsLocale), "pk1:pk1 and pk2:pk2 reposted a note you were tagged in")
XCTAssertEqual(reacting_to_text(profiles: damusState.profiles, our_pubkey: damusState.pubkey, group: .repost(EventGroup(events: [repost1, repost2, repost2])), ev: test_event, pubkeys: ["pk1", "pk2", "pk3"], locale: enUsLocale), "pk1:pk1 and 2 others reposted a note you were tagged in")
Bundle.main.localizations.map { Locale(identifier: $0) }.forEach {
XCTAssertNoThrow(reacting_to_text(profiles: damusState.profiles, our_pubkey: damusState.pubkey, group: .repost(EventGroup(events: [])), ev: test_event, nozaps: nozaps, locale: $0), "??")
XCTAssertNoThrow(reacting_to_text(profiles: damusState.profiles, our_pubkey: damusState.pubkey, group: .repost(EventGroup(events: [repost1])), ev: test_event, nozaps: nozaps, locale: $0))
XCTAssertNoThrow(reacting_to_text(profiles: damusState.profiles, our_pubkey: damusState.pubkey, group: .repost(EventGroup(events: [repost1, repost2])), ev: test_event, nozaps: nozaps, locale: $0))
XCTAssertNoThrow(reacting_to_text(profiles: damusState.profiles, our_pubkey: damusState.pubkey, group: .repost(EventGroup(events: [repost1, repost2, repost2])), ev: test_event, nozaps: nozaps, locale: $0))
XCTAssertNoThrow(reacting_to_text(profiles: damusState.profiles, our_pubkey: damusState.pubkey, group: .repost(EventGroup(events: [])), ev: test_event, pubkeys: [], locale: $0), "??")
XCTAssertNoThrow(reacting_to_text(profiles: damusState.profiles, our_pubkey: damusState.pubkey, group: .repost(EventGroup(events: [repost1])), ev: test_event, pubkeys: ["pk1"], locale: $0))
XCTAssertNoThrow(reacting_to_text(profiles: damusState.profiles, our_pubkey: damusState.pubkey, group: .repost(EventGroup(events: [repost1, repost2])), ev: test_event, pubkeys: ["pk1", "pk2"], locale: $0))
XCTAssertNoThrow(reacting_to_text(profiles: damusState.profiles, our_pubkey: damusState.pubkey, group: .repost(EventGroup(events: [repost1, repost2, repost3])), ev: test_event, pubkeys: ["pk1", "pk2", "pk3"], locale: $0))
}
}

View File

@@ -0,0 +1,79 @@
//
// TrieTests.swift
// damusTests
//
// Created by Terry Yiu on 6/26/23.
//
import XCTest
@testable import damus
final class TrieTests: XCTestCase {
func testFind() throws {
let trie = Trie<String>()
let keys = ["foobar", "food", "foo", "somethingelse", "duplicate", "duplicate"]
keys.forEach {
trie.insert(key: $0, value: $0)
}
let allResults = trie.find(key: "")
XCTAssertEqual(Set(allResults), Set(["foobar", "food", "foo", "somethingelse", "duplicate"]))
let fooResults = trie.find(key: "foo")
XCTAssertEqual(fooResults.first, "foo")
XCTAssertEqual(Set(fooResults), Set(["foobar", "food", "foo"]))
let foodResults = trie.find(key: "food")
XCTAssertEqual(foodResults, ["food"])
let ooResults = trie.find(key: "oo")
XCTAssertEqual(Set(ooResults), Set(["foobar", "food", "foo"]))
let aResults = trie.find(key: "a")
XCTAssertEqual(Set(aResults), Set(["foobar", "duplicate"]))
let notFoundResults = trie.find(key: "notfound")
XCTAssertEqual(notFoundResults, [])
// Sanity check that the root node has children.
XCTAssertTrue(trie.hasChildren)
// Sanity check that the root node has no values.
XCTAssertFalse(trie.hasValues)
}
func testRemove() {
let trie = Trie<String>()
let keys = ["foobar", "food", "foo", "somethingelse", "duplicate", "duplicate"]
keys.forEach {
trie.insert(key: $0, value: $0)
}
keys.forEach {
trie.remove(key: $0, value: $0)
}
let allResults = trie.find(key: "")
XCTAssertTrue(allResults.isEmpty)
let fooResults = trie.find(key: "foo")
XCTAssertTrue(fooResults.isEmpty)
let foodResults = trie.find(key: "food")
XCTAssertTrue(foodResults.isEmpty)
let ooResults = trie.find(key: "oo")
XCTAssertTrue(ooResults.isEmpty)
let aResults = trie.find(key: "a")
XCTAssertTrue(aResults.isEmpty)
// Verify that removal of values from all the keys that were inserted in the trie previously also resulted in the cleanup of the trie.
XCTAssertFalse(trie.hasChildren)
XCTAssertFalse(trie.hasValues)
}
}

View File

@@ -0,0 +1,141 @@
//
// UserSearchCacheTests.swift
// damusTests
//
// Created by Terry Yiu on 6/30/23.
//
import XCTest
@testable import damus
final class UserSearchCacheTests: XCTestCase {
var keypair: Keypair? = nil
let damusState = DamusState.empty
let nip05 = "_@somedomain.com"
override func setUpWithError() throws {
keypair = try XCTUnwrap(generate_new_keypair())
if let keypair {
let pubkey = keypair.pubkey
damusState.profiles.validated[pubkey] = NIP05.parse(nip05)
let profile = Profile(name: "tyiu", display_name: "Terry Yiu", about: nil, picture: nil, banner: nil, website: nil, lud06: nil, lud16: nil, nip05: nip05, damus_donation: nil)
let timestampedProfile = TimestampedProfile(profile: profile, timestamp: 0, event: test_event)
damusState.profiles.add(id: pubkey, profile: timestampedProfile)
// Lookup to synchronize access on profiles dictionary to avoid race conditions.
let _ = damusState.profiles.lookup(id: pubkey)
}
}
override func tearDown() {
keypair = nil
}
func testSearch() throws {
let keypair = try XCTUnwrap(keypair)
XCTAssertEqual(damusState.user_search_cache.search(key: "tyiu"), [keypair.pubkey])
XCTAssertEqual(damusState.user_search_cache.search(key: "ty"), [keypair.pubkey])
XCTAssertEqual(damusState.user_search_cache.search(key: "terry yiu"), [keypair.pubkey])
XCTAssertEqual(damusState.user_search_cache.search(key: "rry"), [keypair.pubkey])
XCTAssertEqual(damusState.user_search_cache.search(key: "somedomain"), [keypair.pubkey])
XCTAssertEqual(damusState.user_search_cache.search(key: "dom"), [keypair.pubkey])
XCTAssertEqual(damusState.user_search_cache.search(key: "i"), [keypair.pubkey])
}
func testUpdateProfile() throws {
let keypair = try XCTUnwrap(keypair)
let newNip05 = "_@other.xyz"
damusState.profiles.validated[keypair.pubkey] = NIP05.parse(newNip05)
let newProfile = Profile(name: "whoami", display_name: "T-DAWG", about: nil, picture: nil, banner: nil, website: nil, lud06: nil, lud16: nil, nip05: newNip05, damus_donation: nil)
let newTimestampedProfile = TimestampedProfile(profile: newProfile, timestamp: 1000, event: test_event)
damusState.profiles.add(id: keypair.pubkey, profile: newTimestampedProfile)
// Lookup to synchronize access on profiles dictionary to avoid race conditions.
let _ = damusState.profiles.lookup(id: keypair.pubkey)
// Old profile attributes are removed from cache.
XCTAssertEqual(damusState.user_search_cache.search(key: "tyiu"), [])
XCTAssertEqual(damusState.user_search_cache.search(key: "ty"), [])
XCTAssertEqual(damusState.user_search_cache.search(key: "Terry Yiu"), [])
XCTAssertEqual(damusState.user_search_cache.search(key: "rry"), [])
XCTAssertEqual(damusState.user_search_cache.search(key: "somedomain"), [])
XCTAssertEqual(damusState.user_search_cache.search(key: "dom"), [])
// New profile attributes are added to cache.
XCTAssertEqual(damusState.user_search_cache.search(key: "whoami"), [keypair.pubkey])
XCTAssertEqual(damusState.user_search_cache.search(key: "hoa"), [keypair.pubkey])
XCTAssertEqual(damusState.user_search_cache.search(key: "t-dawg"), [keypair.pubkey])
XCTAssertEqual(damusState.user_search_cache.search(key: "daw"), [keypair.pubkey])
XCTAssertEqual(damusState.user_search_cache.search(key: "other"), [keypair.pubkey])
XCTAssertEqual(damusState.user_search_cache.search(key: "xyz"), [keypair.pubkey])
XCTAssertEqual(damusState.user_search_cache.search(key: "the"), [keypair.pubkey])
XCTAssertEqual(damusState.user_search_cache.search(key: "y"), [keypair.pubkey])
}
func testUpdateOwnContactsPetnames() throws {
let keypair = try XCTUnwrap(keypair)
let damus = "3efdaebb1d8923ebd99c9e7ace3b4194ab45512e2be79c1b7d68d9243e0d2681"
let jb55 = "32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245"
var pubkeysToPetnames = [String: String]()
pubkeysToPetnames[damus] = "damus"
pubkeysToPetnames[jb55] = "jb55"
let contactsEvent = try createContactsEventWithPetnames(pubkeysToPetnames: pubkeysToPetnames)
// Initial own contacts event caching on searchable petnames.
damusState.user_search_cache.updateOwnContactsPetnames(id: keypair.pubkey, oldEvent: nil, newEvent: contactsEvent)
XCTAssertEqual(damusState.user_search_cache.search(key: "damus"), [damus])
XCTAssertEqual(damusState.user_search_cache.search(key: "jb55"), [jb55])
XCTAssertEqual(damusState.user_search_cache.search(key: "5"), [jb55])
// Replace one of the petnames and verify if the cache updates accordingly.
pubkeysToPetnames.removeValue(forKey: jb55)
pubkeysToPetnames[jb55] = "bill"
let newContactsEvent = try createContactsEventWithPetnames(pubkeysToPetnames: pubkeysToPetnames)
damusState.user_search_cache.updateOwnContactsPetnames(id: keypair.pubkey, oldEvent: contactsEvent, newEvent: newContactsEvent)
XCTAssertEqual(damusState.user_search_cache.search(key: "damus"), [damus])
XCTAssertEqual(damusState.user_search_cache.search(key: "jb55"), [])
XCTAssertEqual(damusState.user_search_cache.search(key: "5"), [])
XCTAssertEqual(damusState.user_search_cache.search(key: "bill"), [jb55])
XCTAssertEqual(damusState.user_search_cache.search(key: "l"), [jb55])
}
private func createContactsEventWithPetnames(pubkeysToPetnames: [String: String]) throws -> NostrEvent {
let keypair = try XCTUnwrap(keypair)
let privkey = try XCTUnwrap(keypair.privkey)
let bootstrapRelays = load_bootstrap_relays(pubkey: keypair.pubkey)
let relayInfo = RelayInfo(read: true, write: true)
var relays: [String: RelayInfo] = [:]
for relay in bootstrapRelays {
relays[relay] = relayInfo
}
let relayJson = encode_json(relays)!
let tags = pubkeysToPetnames.enumerated().map {
["p", $0.element.key, "", $0.element.value]
}
let ev = NostrEvent(content: relayJson,
pubkey: keypair.pubkey,
kind: NostrKind.contacts.rawValue,
tags: tags)
ev.calculate_id()
ev.sign(privkey: privkey)
return ev
}
}

View File

@@ -69,7 +69,7 @@ final class ZapTests: XCTestCase {
XCTAssertEqual(zap.target, ZapTarget.profile("32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245"))
XCTAssertEqual(zap_notification_title(zap), "Zap")
XCTAssertEqual(zap_notification_body(profiles: Profiles(), zap: zap), "You received 1k sats from 107jk7ht:2qlu3nfm")
XCTAssertEqual(zap_notification_body(profiles: Profiles(user_search_cache: UserSearchCache()), zap: zap), "You received 1k sats from 107jk7ht:2qlu3nfm")
}
}