1
0
mirror of git://jb55.com/damus synced 2024-09-07 05:43:42 +00:00
Commit Graph

2848 Commits

Author SHA1 Message Date
William Casarin
cc385d3c3f nostrdb: add migration to fix local japanese profile names 2023-11-02 14:17:17 +09:00
ericholguin
2895c374c0 fix: relay filter button fix
Closes: https://github.com/damus-io/damus/pull/1678
Tested-by: William Casarin <jb55@jb55.com>
Signed-off-by: William Casarin <jb55@jb55.com>
2023-11-02 13:21:19 +09:00
William Casarin
6863e74c0f nostrdb: fix japanese profile names not loading
update flatcc, including the patch that fixes japanese usenames

Changelog-Fixed: Fix japanese profiles names not loading
2023-11-02 10:20:40 +09:00
William Casarin
280d889f25 v1.6 (25) changelog 2023-10-31 10:27:55 +09:00
William Casarin
d1d830fca1 v1.6 (25) 2023-10-31 10:26:12 +09:00
Daniel D’Aquino
d2bb013db7 relays: automatically load extra regional bootstrap relays
Depending on user's locale. currently only supported for Japanese users.

This change allows Japanese users to automatically connect with popular
Japanese regional relays during account creation, thus allowing Japanese
users to better connect with the Japanese Nostr community.

More specifically, 3 Japanese regional relays will be automatically
added to the user's relay list (on top of the usual relays) under the
following conditions:

1. User's region (As configured in iOS settings) is Japan, AND
2. The user is creating a new Nostr account through Damus.

In the case the Nostr account is not new, Damus will not add any
regional relays (It will respect the user's relay list).

Testing
-------

PASS

Device: iPhone 15 Pro (Simulator)
iOS: 17.0.1
Damus: This commit
Test steps:

1. With the US region set, install Damus
2. Go through onboarding and create a new account.
3. Once the onboarding is complete, look at the connected relays. Should only be connected with popular international relays. PASS
4. Uninstall Damus
5. On iOS settings, go to Location & Region settings and change the region to Japan.
6. Install Damus
7. Go through onboarding and create a new account.
8. Once the onboarding is complete, look at the connected relays. User should be connected with intl relays as well as Japanese relays. PASS
9. Quit Damus and restart
10. Ensure the Japanese relays are still on the list. PASS
11. Quit Damus
12. Change region back to US
13. Restart Damus and check the relay list. Relay list should not be affected. PASS
14. Reinstall Damus
15. Check relay list. Only intl relays should be shown. PASS
16. Change region to Japan (JP)
17. Restart Damus and check the relay list. Relay list should not be affected. PASS
18. Reinstall Damus
19. This time, login with a pre-existing account (One that is not connected to Japanese relays).
20. After onboarding, check relay list. The relay list should be unaffected (i.e. Japanese relays should not have been added since this account is pre-existing). PASS

Note: The actual network connection with some of the Japanese relays
failed, but that is likely due to the Geo-based IP restrictions imposed
by some of those Japanese relays. The relay list has been copied
verbatim from @mattn's suggestions.

Reference ticket: https://github.com/damus-io/damus/issues/1447

Changelog-Changed: Automatically load extra regional Japanese relays during account creation if user's region is set to Japan.
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
Signed-off-by: William Casarin <jb55@jb55.com>
2023-10-31 10:03:13 +09:00
ericholguin
c437a05ec0 ux: add long press to profile to navigate to profile page
Closes: https://github.com/damus-io/damus/pull/1665
Reviewed-by: William Casarin <jb55@jb55.com>
Signed-off-by: William Casarin <jb55@jb55.com>
2023-10-30 11:59:13 +09:00
ericholguin
a2fdb61013 ui: change post view background to be all black
Closes: https://github.com/damus-io/damus/pull/1666
Reviewed-by: William Casarin <jb55@jb55.com>
Signed-off-by: William Casarin <jb55@jb55.com>
2023-10-30 11:59:10 +09:00
ericholguin
4dd800e6b9 ui: make qrcode view font color white
Currently when in light mode the font is black which blends into the background
Changelog-Fixed: use white font color in qrcode view

Closes: https://github.com/damus-io/damus/pull/1653
Reviewed-by: William Casarin <jb55@jb55.com>
Signed-off-by: William Casarin <jb55@jb55.com>
2023-10-30 11:59:07 +09:00
ericholguin
34c0728f21 ui: update the customize zap view
This PR updates the customize zap view by:

- replacing the old gradient button to the pink style
- show cursor on text field
- show textfield by default
- change custom zap grid to 4x2 instead of 3x3

Changelog-Changed: Updated customize zap view
Closes: https://github.com/damus-io/damus/pull/1656
Signed-off-by: William Casarin <jb55@jb55.com>
2023-10-30 11:58:36 +09:00
ericholguin
ec604664d8 ui: status view fixes for smaller screen devices
Changelog-Added: Tap to dismiss keyboard on user status view
Closes: https://github.com/damus-io/damus/pull/1652
Reviewed-by: William Casarin <jb55@jb55.com>
Signed-off-by: William Casarin <jb55@jb55.com>
2023-10-27 09:21:43 +08:00
William Casarin
7710839261 noting: users are now notified when you quote repost them
Changelog-Changed: Users are now notified when you quote repost them
2023-10-27 09:02:05 +08:00
William Casarin
4389cc2128 load_profiles: add context for debugging
This is useful to see where the load_profiles request is coming from

We may need to switch to a central dispatch for profile loading, I
suspect there is a lot of redundancy between requests.
2023-10-24 13:02:41 +08:00
William Casarin
76508dbbfd perf: don't continuously attempt to fetch old profiles
Changelog-Changed: Save bandwidth by only fetching new profiles after a certain amount of time
2023-10-24 13:02:41 +08:00
Daniel D’Aquino
bbccc27a26 ui: Add setting that allows users to optionally disable profile action sheets.
Tested on iOS 17.0.1 on an iPhone 15 Pro simulator.

Closes: https://github.com/damus-io/damus/issues/1641
Changelog-Added: Add setting that allows users to optionally disable the new profile action sheet feature
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
Reviewed-by: William Casarin <jb55@jb55.com>
Signed-off-by: William Casarin <jb55@jb55.com>
2023-10-24 12:18:20 +08:00
Daniel D’Aquino
9969e70b5f ui: Add follow button to profile action sheet
Testing: Tested on iPhone 15 Pro simulator with iOS 17.0.1

Closes: https://github.com/damus-io/damus/issues/1636
Changelog-Added: Add follow button to profile action sheet
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
Reviewed-by: William Casarin <jb55@jb55.com>
Signed-off-by: William Casarin <jb55@jb55.com>
2023-10-24 12:18:20 +08:00
Daniel D’Aquino
692d29942b zaps: Implement single-tap zap on profile action sheet and fix zap fallthrough on default settings
This commit implements a single-tap zap on the profile action sheet and fixes an issue where zapping would silently fail on default settings if the user had no lightning wallet installed in their system.

Testing
-------

Configurations:
- iPhone 13 Mini (physical device) on iOS 17.0.2 with NWC wallet attached
- iPhone 15 Pro (simulator) on iOS 17.0.1 with no lightning wallet nor NWC

Damus: This commit

Coverage:
- Zapping using NWC connected wallet: PASS (Zaps and shows UX feedback of the completed action)
- Zapping under default settings and no lightning wallet: PASS (Shows the wallet selector invoice view)
- Long press on zap button brings custom zap view

Regression testing
------------------

Preconditions: iPhone 15 Pro (simulator) on iOS 17.0.1 with no lightning wallet nor NWC

Coverage:
- Zapping user on their full profile shows wallet selector. PASS
- On-post invoice shows wallet selector. PASS

Closes: https://github.com/damus-io/damus/issues/1634
Changelog-Changed: Zap button on profile action sheet now zaps with a single click, while a long press brings custom zap view
Changelog-Fixed: Fixed an issue where zapping would silently fail on default settings if the user does not have a lightning wallet preinstalled on their device.
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
Reviewed-by: William Casarin <jb55@jb55.com>
Signed-off-by: William Casarin <jb55@jb55.com>
2023-10-24 12:18:20 +08:00
Daniel D’Aquino
139df33cb7 Rename ZapButton to NoteZapButton and ZapButtonView to ProfileZapLinkView (no-op)
This is a non-functional refactor to rename two views with similar names, to avoid confusion.

Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
Reviewed-by: William Casarin <jb55@jb55.com>
Signed-off-by: William Casarin <jb55@jb55.com>
2023-10-24 12:18:20 +08:00
William Casarin
a324523b85 ndb: new methods for profile fetched_at
This adds a few methods to Ndb for reading and writing fetched_at stats.
These are a way of tracking when we last tried to fetch profiles so that
we don't need to keep fetching them.
2023-10-23 10:44:54 +08:00
William Casarin
1cf898e0b2 ndb: update nostrdb
This includes the new profile fetched_at logic and reaction stats.

When receiving new profiles, nostrdb will record when it was last
received in a new database. This database is a mapping from Pubkey to
timestamp.

You can manually read/write to this table using:

ndb_read_last_profile_fetch
ndb_write_last_profile_fetch

This patch also includes the new reaction counting metadata table. It is
not used yet (but reactions are still counted!)

Changelog-Added: Added reaction counters to nostrdb
Changelog-Added: Record when profile is last fetched in nostrdb
2023-10-23 10:40:11 +08:00
William Casarin
502ceee6d4 ndb: update bindings
This adds new bindings from nostrdb related to tracking reaction stats.
We aren't using this yet but it's a part of the latest nostrdb update.
2023-10-23 10:39:27 +08:00
William Casarin
4f628ec733 Merge remote-tracking branch 'github/translations' 2023-10-23 09:18:45 +08:00
William Casarin
29915159db v1.6 (24) changelog 2023-10-22 14:27:56 +08:00
William Casarin
2b102671e5 smol fix 2023-10-22 10:41:36 +08:00
Daniel D’Aquino
e70f270c5c zaps: Improve discoverability of profile zaps
via zappability badges and profile action sheets

This commit improves discoverability of zaps with the following changes:

1. New zap icon appears on profile pictures of events where the author of such event has zaps setup
2. Clicking on a profile picture from an event shows an action sheet that makes it easier to see a preview of their profile, and a zap button

Testing
-------

Devices:
- iPhone 14 Pro simulator
- iPad 10 simulator

iOS:
- 17.0.1
- 16.4

Damus: This commit

Coverage:
1. Checked that zap icon appears on profile pictures on events in different feeds and threads
2. Checked that this zap icon only appears for profiles that have zaps enabled
3. Checked that profile action sheet looks good on both light mode and dark mode
4. Checked that long descriptions are truncated and the "see more" "see less" buttons work
5. Checked that clicking "see more" or "see less" adapts the size of the action sheet (on iPhone)
6. Checked that action sheet looks good whether or not the user has a website link setup
7. Checked that long presses on the zap button in the action sheet bring the same options as the normal profile view
8. Checked all the buttons in the action sheet take the user to the expected place
9. Checked that the original profile view looks good (on both light and dark mode)

Notes:
- Action sheet cannot be resized on iPad.
- Could not test on Mac Catalyst because there seems to be a crash on the creation of a new account

Reference ticket: https://github.com/damus-io/damus/issues/1596

Changelog-Added: Improve discoverability of profile zaps with zappability badges and profile action sheets
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
Signed-off-by: William Casarin <jb55@jb55.com>
2023-10-22 10:40:31 +08:00
William Casarin
4ed79ff3c3 ui: reduce size of event menu hitbox
Changelog-Fixed: Reduce size of event menu hitbox
2023-10-22 10:40:29 +08:00
William Casarin
17331301da Clarified camera and mic usage strings
Fixes: https://github.com/damus-io/damus/issues/1628
2023-10-22 10:25:03 +08:00
Davide De Rosa
45904e1bf2 nav: compare searches for navigation decisions
In 7c98489, routes are compared to the stack top before push.
Problem is, search comparison is not looking at the NostrFilter.

Instead, hash value involves two UUID-based fields (sub_id,
profiles_subid), so equality will always fail and result in a
"duplicated push".

As I do not know the context of such fields to deliberately
drop them, this patch is sent as a draft.

The basic idea is using the filter for comparison, so I added
a Hashable extension to NostrFilter where the subject of the
comparison may be fine-tuned.

Adding `hashtag` resolves #1367 but it's only a starting point.

Signed-off-by: Davide De Rosa <keeshux@gmail.com>
Reviewed-by: William Casarin <jb55@jb55.com>
Signed-off-by: William Casarin <jb55@jb55.com>
2023-10-22 08:56:42 +08:00
Daniel D’Aquino
7ae66b8490 ui: Add suggested hashtags to universe view
This commit adds a suggested hashtag section to the universe view tab. The method for suggesting hashtags is currently simple:
1. It contains a list of many possible hashtags that we could recommend
2. It calculates how many users have been talking about it in the events fetched by the Universe tab
3. It selects the Top-N most mentioned suggested hashtags in the Universe tab

This has the following properties:
1. It has some spam resistance as it ranks by unique users mentioning the tag (instead of events)
2. It is a simple way to curate good hashtags
3. It shows the ones with the most amount of people talking about it among the notes fecthed in the Universe view

Testing
-------

PASS

Device: iPhone 14 Pro simulator
iOS: 17.0
Damus: This commit
Coverage:

1. Suggested hashtags are displayed
2. Layout looks similar to Figma
3. User count goes up (does not stay at zero)
4. Clicking on a suggested hashtag takes you to that hashtag view
5. Only the top 5 hashtags are displayed

Notes: The counts seem low, probably because there are not enough notes loaded in Universe View

Changelog-Added: Add suggested hashtags to universe view
Closes: https://github.com/damus-io/damus/issues/1569
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
Signed-off-by: William Casarin <jb55@jb55.com>
2023-10-21 08:42:00 +08:00
Daniel D’Aquino
bf43842590 onboarding: Suggest first post during onboarding
Testing of standard flow
------------------------

PASS

Device: iPhone 14 Pro simulator
iOS: 17.0
Damus: This commit
Steps:
1. Delete and reinstall Damus
2. Go through onboarding until suggested users appear
3. Click "continue". Should slide into the post view. PASS
4. Post view should look similar to the Figma design file, but with examples as placeholders. PASS
5. Examples should switch every 3 seconds. PASS
6. Typing a first character causes the #introductions hashtag to be automatically added. PASS
7. Uploading an image makes progress view show up and not break layout. PASS
8. Clicking on "post" should post this note and dismiss onboarding view. PASS

Testing of other flows
----------------------

PASS

Device: iPhone 14 Pro simulator
iOS: 17.0
Damus: This commit
Special remark: Made local change to always show the onboarding suggestions, and speed up testing
Coverage:

1. Clicking "skip" on suggested users view will skip into the post view. PASS
2. Clicking "cancel" on post view and then going to the normal post view reveals a blank draft. PASS
3. Clicking "cancel" dismisses onboarding view and does not post anything. PASS
4. Normal post view looks normal (not broken). PASS
5. Changing initial suggested post during onboarding, cancelling the post, and then re-entering normal post view reveals the draft with user modifications. PASS

Changelog-Added: Suggest first post during onboarding
Closes: https://github.com/damus-io/damus/issues/1338
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
Signed-off-by: William Casarin <jb55@jb55.com>
2023-10-21 08:42:00 +08:00
Davide De Rosa
7c98489904 nav: fix pushing duplicate routes
Skip push if matches top route.

Fixes: https://github.com/damus-io/damus/issues/104
Closes: https://github.com/damus-io/damus/pull/1625
Reviewed-by: William Casarin <jb55@jb55.com>
Signed-off-by: William Casarin <jb55@jb55.com>
2023-10-20 12:41:53 +08:00
transifex-integration[bot]
0277303da7
Translate Localizable.stringsdict in pl_PL
100% translated source file: 'Localizable.stringsdict'
on 'pl_PL'.
2023-10-19 19:16:26 +00:00
transifex-integration[bot]
63fee80c53
Translate Localizable.stringsdict in pl_PL
100% translated source file: 'Localizable.stringsdict'
on 'pl_PL'.
2023-10-19 19:16:15 +00:00
transifex-integration[bot]
2aaedd077e
Translate Localizable.stringsdict in pl_PL
100% translated source file: 'Localizable.stringsdict'
on 'pl_PL'.
2023-10-19 19:16:01 +00:00
Daniel D’Aquino
06eb9d4a0e dm: Do not show DMs from muted users
This commits causes DMs from muted users to be filtered out. It also fixes an issue where the DM list would appear completely blank in certain scenarios.

Testing
-------

CONDITIONAL PASS

Device: iPhone 14 Pro simulator
iOS: 17.0
Damus: This commit
Setup:
- Three test accounts (A, B, and C). "A" will be the account running on the device under test.
- Account "A" should start with no DMs

1. Send a direct message from "B" to "A", and reply from "A".
2. Go to DMs -> DMs tab. Conversation with "B" should appear. PASS
3. Mute user "B" (I did it via profiles page).
4. Go back to DMs view via back button. DMs from "B" should not appear. PASS
5. Since there are no DMs, the screen should display "Nothing to see here". PASS
5. Close Damus app via iOS app switcher and reopen Damus
6. Check DMs list. Should only show "Nothing to see here". PASS
7. Send a DM from account "C" to "A" and reply.
8. Go back to DMs -> DMs tab. Only the message from account "C" should appear.
9. Unmute user "B"
10. Go back to DMs. Messages from "B" and "C" should appear. PASS

Notes:
- There was one instance when the first DM from account "C" appeared in the "DMs" tab (Not "requests") momentarily. After a bit it went into requests as expected.
- When unmuting user "B", I had to refresh the DM list by switching tabs, meaning that the view did not immediately update.

Upon inspection, the two behaviors above are not caused by this change, so this is a conditional pass.

Closes: https://github.com/damus-io/damus/issues/1350
Changelog-Fixed: Do not show DMs from muted users
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
Reviewed-by: William Casarin <jb55@jb55.com>
Signed-off-by: William Casarin <jb55@jb55.com>
2023-10-18 07:04:17 +08:00
Daniel D’Aquino
3b76fcb743 test: Add basic snapshot test coverage for EventView
This commit adds a basic snapshot test for EventView, and also adds some testing infrastructure to help with mocking NostrDB behavior.

Test
----

PASS

Device: iOS 17.0 Simulator
iOS: 17.0
Damus: This commit
Steps: Run `EventViewTests`
Results: Snapshot matches baseline reference added
2023-10-16 03:13:28 +02:00
Daniel D’Aquino
edb23e4e70 ui: prefix username with @ character, fix spacing
Closes: https://github.com/damus-io/damus/issues/1559
Changelog-Fixed: Add more spacing between display name and username, and prefix username with `@` character
2023-10-16 03:13:28 +02:00
Daniel D’Aquino
82fba88cc4 storage: set disk cache expiry dates for images
This commit adds expiry dates for images added to the Kingfisher cache.
The expiry date depends on the context of the image:

- Images from notes expire after a week
- Images from profile banners expire after two weeks
- Profile pictures never expire.

Test
----

Device: iPhone 14 Pro (Simulator), iOS: 17.0
Special remarks: Requires minor local mods and debugger connection
Steps:

1. Locally change the note image expiry to 5 seconds
2. Set a breakpoint in `removeExpiredValues` function in `DiskStorage.swift` in Kingfisher
3. Disable breakpoints for now
4. Start Damus and go to the profile feed of someone new
5. Scroll down through the images for about a minute
6. Turn on breakpoints
7. Switch to a different app in the simulator (Make Damus go to background mode)
8. Wait for a few seconds. Debugger should hit the breakpoint set. PASS
9. Take note of the fileURLs of the images being deleted
10. Go to that directory where the fileURLs are in via Finder
11. Look at some of the images being deleted. Perhaps save a copy for comparison.
12. Turn off breakpoints, resume execution and go back to Damus
13. Scroll back up. Some images there should match the images being automatically deleted from the cache. PASS

Closes: https://github.com/damus-io/damus/issues/1565
Changelog-Added: Add expiry date for images in cache to be auto-deleted after a preset time to save space on storage
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
Reviewed-by: William Casarin <jb55@jb55.com>
Signed-off-by: William Casarin <jb55@jb55.com>
2023-10-16 03:13:28 +02:00
Jericho Hasselbush
439f9974c5 login: add nsec qr-scanning
- Allow scanning of QR codes, and if detects a nsec, will provide it to
  the login prompt.

- If nsec is found, provides option to keep nsec in keychain; default is
  to not store

- User stays logged in until they logout, or app is force-quit if nsec
  is not stored.

damusApp.swift:
  Obtains keypair from the notification generated to allow login.

LoginView.swift:
  New views allowing for adding and logic handling the QR reader in
  QRScanNSECView.swift to enable QR scan for nsec.

QRScanNSECView.swift:
  New view to scan for QR code. The sparkling magnifying glass is enabled
  if the view calling the QR view changes the privKeyFound bound variable.

Tipjar: npub1el277q4kesp8vhs7rq6qkwnhpxfp345u7tnuxykwr67d9wg0wvyslam5n0
Closes: https://github.com/damus-io/damus/issues/1291
Changelog-Added: Add QR scan nsec logins.
Signed-off-by: Jericho Hasselbush <jericho@sal-et-lucem.com>
Reviewed-by: William Casarin <jb55@jb55.com>
Signed-off-by: William Casarin <jb55@jb55.com>
2023-10-16 03:12:53 +02:00
ericholguin
cf243e39c9 ui: improve status view
Changelog-Changed: Improved status view design
Closes: https://github.com/damus-io/damus/pull/1606
2023-10-16 02:51:07 +02:00
ericholguin
76f6ed0f86 colors: add an adapatable white color 2023-10-16 02:50:25 +02:00
transifex-integration[bot]
ef035b6300
Translate Localizable.stringsdict in lv_LV
100% translated source file: 'Localizable.stringsdict'
on 'lv_LV'.
2023-10-11 17:28:36 +00:00
transifex-integration[bot]
769f03943c
Translate Localizable.strings in lv_LV
100% translated source file: 'Localizable.strings'
on 'lv_LV'.
2023-10-11 17:19:54 +00:00
transifex-integration[bot]
6cdf2dca53
Translate InfoPlist.strings in lv_LV
100% translated source file: 'InfoPlist.strings'
on 'lv_LV'.
2023-10-11 16:19:17 +00:00
ericholguin
05dee129b5 relays: allow users to hide the recommended relay view
Closes: https://github.com/damus-io/damus/pull/1587
Signed-off-by: William Casarin <jb55@jb55.com>
2023-10-10 22:07:57 -07:00
Daniel D’Aquino
7bed47c919 test: Setup Snapshot testing library and add a snapshot test (testTextWrapperViewWillWrapText)
This change adds `https://github.com/pointfreeco/swift-snapshot-testing` as a package dependency and links it to the `damusTests` target.
It also adds one snapshot test to demonstrate its usefulness, by adding coverage to one particular aspect that we have never been able to test before: Whether or not the post text editor will wrap the text once the text gets long.

Testing of the test
-------------------

PASS

iOS: 17.0
Device: Simulator
Damus: This commit
Test steps:

1. Run `testTextWrapperViewWillWrapText`. PASS
2. Change TextViewWrapper.swift and remove this line:
```
textView.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
```
3. Rerun. It fails. PASS (This is expected)

Closes: https://github.com/damus-io/damus/issues/1562
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
Signed-off-by: William Casarin <jb55@jb55.com>
2023-10-10 22:05:45 -07:00
transifex-integration[bot]
7f5707294c
Translate Localizable.stringsdict in pl_PL
100% translated source file: 'Localizable.stringsdict'
on 'pl_PL'.
2023-10-08 13:47:07 +00:00
William Casarin
7a6a6dffbc camera: actually add CameraPreview to project 2023-10-07 17:00:25 -07:00
Suhail Saqan
472f81b311 add CameraModel and CameraService for interacting with the camera 2023-10-07 16:52:38 -07:00
Daniel D’Aquino
7744787c51 storage: Improve clear cache functionality
This patch improves clear cache functionality by:
- Reducing kingfisher cache removal to one command (The two commands running async was leading to warning logs. One was a subset of the other)
- Removing all files under the cache folder where not currently used by other processes

Full Functionality test
-----------------------

PASS

Device: iPhone 13 mini (Physical device)
iOS: 17.0.3
Damus: This commit
Special remarks:
- I had to locally delete other unit tests to be able to build the test target
- Unit test run on an earlier version of the patch. Test coverage should still apply since this newer patch is a subset of the previous.

Setup: Run Damus with debugger connection to Xcode

Test steps:

1. Follow multiple active accounts (Skip if local Damus is already filled up with GBs of data)
2. Scroll down on the feed for a couple of minutes (or until you have seen at least a few images, a few videos, and link previews) (Skip if local Damus is filled up with GBs of data)
3. In Xcode, download a storage container (Window > Devices and Simulators > Select the device > Select Damus > click on (...) > Download container)
    - Note: Even though you see the file, it does not download instantly. Monitor the file size until it roughly reaches the size reported in iOS storage settings, as the download may still be in progress. This may take a few minutes in some cases.
    - Also take note of storage usage in iOS settings
4. Open the app data package using terminal
5. Run `du -h . | sort -hr`
6. Clear cache and check logs. Logs should indicate the caches being cleared, and there should be no storage-related warning/error logs. PASS
7. Download a new storage container. Remember to wait until it completes download.
8. Run `du -h . | sort -hr` on it.
9. Compare. There should be much less data. Also check iOS settings storage usage. PASS
10. Go back to the home feed and start scrolling, browsing, follow some other people, etc. Look at your own profile as well. Everything should appear to be working as expected with no crashes or important data loss
11. Check bookmarks are still present. PASS
12. Run `DamusCacheManagerTests`. Should pass. PASS* (*See special remarks)

Results:
- Storage usage goes from 3.9GB to 394.7MB
- Damus works as normal after clearing cache, and after restarting the app as well. It becomes slower for a moment, but after a bit it loads as normal again.
- No warning or error logs pertaining to clearing cache
- Unit test passes

My storage container disk usage stats after clearing cache:
```
% du -h | sort -hr
359M	./AppData
359M	.
336M	./AppData/Documents
 23M	./AppData/Library
 20M	./AppData/Library/Caches
7.9M	./AppData/Library/Caches/com.jb55.damus2
2.4M	./AppData/Library/SplashBoard/Snapshots
2.4M	./AppData/Library/SplashBoard
1.8M	./AppData/Library/SplashBoard/Snapshots/com.jb55.damus2 - {DEFAULT GROUP}
1.6M	./AppData/Library/Caches/com.jb55.damus2/fsCachedData
636K	./AppData/Library/SplashBoard/Snapshots/sceneID:com.jb55.damus2-ecc156b1-eb9c-4439-b219-e1eebf2b4c36
596K	./AppData/Library/Caches/com.apple.WebKit.GPU/com.apple.metal
596K	./AppData/Library/Caches/com.apple.WebKit.GPU
452K	./AppData/Library/Caches/com.jb55.damus2/com.apple.metal
296K	./AppData/Library/SplashBoard/Snapshots/sceneID:com.jb55.damus2-ecc156b1-eb9c-4439-b219-e1eebf2b4c36/downscaled
224K	./AppData/Library/HTTPStorages/com.jb55.damus2
224K	./AppData/Library/HTTPStorages
164K	./AppData/Library/Caches/com.onevcat.Kingfisher.ImageCache.default
156K	./AppData/Library/Caches/RelayLogs
112K	./AppData/Library/Caches/com.apple.dyld
 92K	./AppData/Library/Preferences
 60K	./AppData/Library/Caches/com.jb55.damus2/com.apple.metal/archiveUsage.db
 12K	./AppData/Library/Saved Application State/com.jb55.damus2.savedState
 12K	./AppData/Library/Saved Application State
8.0K	./AppData/StoreKit
8.0K	./AppData/Library/Saved Application State/com.jb55.damus2.savedState/ecc156b1-eb9c-4439-b219-e1eebf2b4c36
4.0K	./AppData/Library/Saved Application State/com.jb55.damus2.savedState/KnownSceneSessions
4.0K	./AppData/Library/LanguageModeling/en-dynamic.lm
4.0K	./AppData/Library/LanguageModeling
4.0K	./AppData/Library/Cookies
  0B	./AppData/SystemData/com.apple.SafariViewService/Library/WebKit/WebsiteData
  0B	./AppData/SystemData/com.apple.SafariViewService/Library/WebKit
  0B	./AppData/SystemData/com.apple.SafariViewService/Library
  0B	./AppData/SystemData/com.apple.SafariViewService
```

Biggest storage used remaining is in the Documents folder where NostrDB is stored. However, we do not want to clear NostrDB, so this is expected behavior.

Changelog-Changed: Improve clear cache functionality
Closes: https://github.com/damus-io/damus/issues/1472
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
Signed-off-by: William Casarin <jb55@jb55.com>
2023-10-07 16:42:08 -07:00