muke1908 / chat-e2ee

End-to-end encrypted disposable chat sessions, exchange sensitive information with peer safely and securely.
https://chat-e2ee-2.azurewebsites.net/
Apache License 2.0
323 stars 198 forks source link

Store messages in session storage #299

Closed iHDeveloper closed 1 year ago

iHDeveloper commented 1 year ago

This PR is aimed to resolve #114. The patch is ready and haven't test it yet. I was sick and couldn't touch my computer easily during the last 3 days. Alhamdullilah I'm okay. I would like to point out that the patch is over-simplified to require a full on test. But that's not up to me.

I have provided very simple functionlities to the storage utility for in case the conversation goes beyond 5MB of size to be mitigation solutions later.

I would like to point out an important note that the messages are stored without encryption. This is mostly due to the storage limitations of the Session Storage see here.

Sorry for being late. Testing was very buggy to deal with for me to finish it in the promised time sadly.

Thank you for giving me the time and the chance to resolve #144.

muke1908 commented 1 year ago

@iHDeveloper thanks for your PR! Feel free to create issues that you faced during the test so that we can work for a better dev experience.

sonarcloud[bot] commented 1 year ago

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

hfdem commented 3 months ago

Is the purpose of this PR to prevent chat content from disappearing after refreshing the page? I tried https://chat-e2ee-2.azurewebsites.net, but found messages were still not restored. @iHDeveloper @muke1908

muke1908 commented 1 month ago

Hi @hfdem , yes, it is the purpose. However, note that the behavior is not by-default. In order to enable it, you'll have to set a flag in localStorage like localStorage.setItem('store-chat-messages', 'true')

hfdem commented 1 month ago

Hi @hfdem , yes, it is the purpose. However, note that the behavior is not by-default. In order to enable it, you'll have to set a flag in localStorage like localStorage.setItem('store-chat-messages', 'true')

I discovered an issue that causes the functionality to break. When refreshing the page, the messages stored in SS get reset. My current solution is:

  useEffect(() => {
    if (LS.get('store-chat-messages') && messages.length > 0) {
      SS.set(`chat#${channelID}`, messages);
    }
  }, [channelID, messages]);

So that it doesn't trigger useEffect to overwrite when the messages are empty (entering the chat after page refresh). This fix has been tested and works as expected. Do you have a better solution for this? If possible, I can submit a pull request with this fix.

Additionally, storing messages in plaintext is indeed not secure. I hope there is a better solution for this.

muke1908 commented 1 month ago

Thanks! sure, create a PR