stakwork / sphinx-ios

Client app for communication over the lightning network.
MIT License
18 stars 11 forks source link

Manage App Storage #218

Closed tomastiminskas closed 1 year ago

tomastiminskas commented 1 year ago

We need a way to allow user to inspect and manage media storage on the app.

  1. Add a max storage limit field on Profile in GB: start deleting old items from local storage as new onces are created when the limit is reached. 2.

  2. Build UI interface to manage storage: Here are some screenshots from WhatsApp on how it handles it and some ideas on what we could implement to improve this on Sphinx.

Total space used by Sphinx: IMG_1672

List of chats with media on each chat: IMG_1673

Details of media on each chat with ability to delete items: IMG_1675

uncleJim21 commented 1 year ago

this looks good. The only thing I'd add is that maybe it makes sense to also manage ongoing downloads and have the ability to cancel/remove from queue. What do you think @tomastiminskas @Antanasijevic ?

tomastiminskas commented 1 year ago

@jimBeaux27 makes sense. Also ability to disable auto download of media content on messages render event

uncleJim21 commented 1 year ago

leaving this here since it's related & we will prob consolidate: https://github.com/stakwork/sphinx-ios/issues/112

uncleJim21 commented 1 year ago

As of today @Antanasijevic came to the conclusion that really the big items that will take up space are:

  1. Chat media
  2. Downloaded podcasts
  3. Keeping in mind for future dev, downloading video which is on the roadmap

There are a few ways to break down the media sections:

  1. We could break it down by media type (audio, video, images)
  2. We could break it down by in app category (sections that already exist in the app) Podcast, Video, Chat
uncleJim21 commented 1 year ago

@tomastiminskas @pitoi

@Antanasijevic and I met and we walk away with the following conclusions:

Ideal Long Term Goal: On the profile page, the user has a way to manage storage. There will be a bar indicating storage usage with the button labeled "manage".

When that Manage Page opens:

  1. It shows more details on what media is taking up how much space
  2. It shows a bar at the top that allows users to adjust their storage limit
  3. Indicate how much is storage is used by media type (images, audio, video)
  4. Option to delete all images/video from one place (bulk delete)
  5. Two buttons Chats & Downloaded Episodes
  6. For chat button -> Show the list of contacts and show how much media each chat takes, option to delete for each individual person.
  7. For episodes button -> show all downloaded episodes with amount and leave option to delete.

Phases We think there are a few phases/levels to this:

  1. High Level Overview - that lets the user select the storage limit and see at a high level how much storage they are using, how it is broken down by media type, bulk delete, set the max media storage limit (items 1 2 3 4 above)
  2. Fine grain management - letting users manage down to the detail (items 6 7 above)
tomastiminskas commented 1 year ago

@jimBeaux27 it sounds good to me. The only thing that I would add is the ability to enable/disable auto download on chats. Right now when you receive a media message (image, video, audio), it will download automatically when rendered in the chat view. Disabling that will just show the image/video placeholder and a button will allow user to download it and access it.

I think this can be done in the initial phase of the feature development.

uncleJim21 commented 1 year ago

Some follow up questions @tomastiminskas :

  1. What should trigger "garbage cleanup" where we decide to go delete items? I am thinking maybe whenever a new item comes in we could check this
  2. What should be the criteria for deletion? Just age of the item or something else?
  3. What should trigger the scanning/loading of memory data? I am thinking we could just scan upon startup in the background and just save it to a shared singleton I am calling StorageManager. It would store the key metadata of each item and keep it "at the ready" for whenever the user decides to inspect memory/change something or we need to do garbage cleanup
tomastiminskas commented 1 year ago

@jimBeaux27

  1. Definitely when a new item comes in, we should trigger garbage cleanup if the storage exceeds the maximum set by the user
  2. The criteria should be age as you mentioned. Oldest items should be removed until being under the storage limit again
  3. You can try and decide on that. If the process is not that long we could do it directly when the user wants to inspect (I think WhatsApp does it that way) and show a loading wheel while it loads. Or when user sets the storage maximum on Profile (show a popup up with a loading wheel and some text letting the user know a needed scanning process is being done). But your call
uncleJim21 commented 1 year ago

Re #2: How do you determine age for each media type:

  1. Content: Video/podcast (don't think newsletter applies?)
  2. Messages

For messages it's more obvious. In the case of podcasts less so. Do you delete based on publish date? Based on date last consumed?

For me anecdotally I'd be mad if there's a really old podcast I'm digging back into and I can't see it b/c garbage cleanup is fighting me :)

tomastiminskas commented 1 year ago

I would apply the age criteria for messages media content first, since those are downloaded automatically to the device right now. I wouldn't apply that for podcast/video in the first phase since those items are downloaded manually and intentionally by the user and deleting them sounds invasive. Something to think about, but maybe if video/podcasts are taking more than 75% of the max storage set, we could throw an alert to the user inviting him to manage those manually from Profile

Antanasijevic commented 1 year ago

@jimBeaux27 @tomastiminskas Guys, here is a mock-up and a video preview of features we discussed. This sample should be used as a starting point so we can discuss details. Please let me know what you think.

image

https://github.com/stakwork/sphinx-ios/assets/13258550/9d355e48-01e4-4d41-870d-e4e73039d82c

uncleJim21 commented 1 year ago

Thanks @Antanasijevic this looks really good and it's cool to see your vision come to life.

@tomastiminskas one issue I think we may have is that based on what I see, all of the images stored in the SDImageCache are effectively in the same "bucket". We don't actually seem to have a way to relate the images themselves to a given chat as it stands (correct me if I'm wrong but the cache is just one big array basically). We would either have to:

  1. Change this so that going forward they have some kind of join/relationship to the chat ID. This would still leave previous values unassigned so we would either have to accept this or find a clever way to create chat ID relationships in some kind of bulk migration process.
  2. Abandon the concept of breaking them down by chat and instead show them in bulk

Let me know your thoughts. You can check what I've done so far specifically the StorageManager and its getImageCacheItems/getImageCacheSize methods. I set it up so that it runs in the background when all tribes loads as a way to experiment.

uncleJim21 commented 1 year ago

Other point worthy of note: The cache from the images for me only takes up about 120MB and I use it almost every day since about December. There are methods that actually allow you to set the max cache size if that becomes a problem.

In comparison, I have about 4 GB worth of podcasts downloaded which clearly takes up the lion's share of space. I think that may also be a factor in the way we think about this. Downloaded media is going to take up way more space than the passively downloaded chat media as far as I can tell.

tomastiminskas commented 1 year ago

@jimBeaux27 definitely let's change the way Cache is stored so we can have a way to relate each item to the specific chat it belongs. We can take care later of a migration process for backward compatibility.

uncleJim21 commented 1 year ago

Ok I think I have most of the fundamental issues resolved and the core business logic written. Now it's a matter of implementing the UI. I think there shouldn't be too many major issues implementing the design as is.

@Antanasijevic Do we consider this UI approved or are we still tweaking it?

uncleJim21 commented 1 year ago

@Antanasijevic couple details I noticed:

  1. There’s nothing that tells the user what their actual storage limit for Sphinx is
  2. it’s unclear whether the podcasts do/should be broken down by episode or by feed. I think it makes sense to break down by feed then fan out into the specfic episodes but up to you
Antanasijevic commented 1 year ago

@tomastiminskas @jimBeaux27 @pitoi Here is a video recording of updated managing storage flow. It contains all features we discussed. Please, check it out so we can go over it once again before i post final version.

Few notes:

https://github.com/stakwork/sphinx-ios/assets/13258550/bbe0bbfc-883c-4e18-a8d2-abd8aa913079

Antanasijevic commented 1 year ago

@pitoi @tomastiminskas @jimBeaux27 In addition to main screens, i have created delete notifications. I suggest we make a difference between bulk delete (delete all images/podcasts..) and delete selected images/videos. Please, check out this video and let me know what you think.

Few notes:

https://github.com/stakwork/sphinx-ios/assets/13258550/d13b0d68-3387-4e8d-831a-ab1a22f4fc28