{"action":"created","issue":{"url":"https://api.github.com/repos/SafeSlingerProject/SafeSlinger-iOS/issues/4","labels_url":"https://api.github.com/repos/SafeSlingerProject/SafeSlinger-iOS/issues/4/labels{/name}","comments_url":"https://api.github.com/repos/SafeSlingerProject/SafeSlinger-iOS/issues/4/comments","events_url":"https://api.github.com/repos/SafeSlingerProject/SafeSlinger-iOS/issues/4/events","html_url":"https://github.com/SafeSlingerProject/SafeSlinger-iOS/issues/4","id":38114454,"number":4,"title":"add auto-decryption of messages","user":{"login":"mwfarb","id":215994,"avatar_url":"https://avatars.githubusercontent.com/u/215994?v=3","gravatar_id":"","url":"https://api.github.com/users/mwfarb","html_url":"https://github.com/mwfarb","followers_url":"https://api.github.com/users/mwfarb/followers","following_url":"https://api.github.com/users/mwfarb/following{/other_user}","gists_url":"https://api.github.com/users/mwfarb/gists{/gist_id}","starred_url":"https://api.github.com/users/mwfarb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mwfarb/subscriptions","organizations_url":"https://api.github.com/users/mwfarb/orgs","repos_url":"https://api.github.com/users/mwfarb/repos","events_url":"https://api.github.com/users/mwfarb/events{/privacy}","received_events_url":"https://api.github.com/users/mwfarb/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/SafeSlingerProject/SafeSlinger-iOS/labels/cross-platform","name":"cross-platform","color":"bfe5bf"},{"url":"https://api.github.com/repos/SafeSlingerProject/SafeSlinger-iOS/labels/enhancement","name":"enhancement","color":"84b6eb"}],"state":"open","locked":false,"assignee":{"login":"brnunes","id":1976718,"avatar_url":"https://avatars.githubusercontent.com/u/1976718?v=3","gravatar_id":"","url":"https://api.github.com/users/brnunes","html_url":"https://github.com/brnunes","followers_url":"https://api.github.com/users/brnunes/followers","following_url":"https://api.github.com/users/brnunes/following{/other_user}","gists_url":"https://api.github.com/users/brnunes/gists{/gist_id}","starred_url":"https://api.github.com/users/brnunes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brnunes/subscriptions","organizations_url":"https://api.github.com/users/brnunes/orgs","repos_url":"https://api.github.com/users/brnunes/repos","events_url":"https://api.github.com/users/brnunes/events{/privacy}","received_events_url":"https://api.github.com/users/brnunes/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/SafeSlingerProject/SafeSlinger-iOS/milestones/2","html_url":"https://github.com/SafeSlingerProject/SafeSlinger-iOS/milestones/Messenger%20iOS%201.8.2","labels_url":"https://api.github.com/repos/SafeSlingerProject/SafeSlinger-iOS/milestones/2/labels","id":824045,"number":2,"title":"Messenger iOS 1.8.2","description":"","creator":{"login":"mwfarb","id":215994,"avatar_url":"https://avatars.githubusercontent.com/u/215994?v=3","gravatar_id":"","url":"https://api.github.com/users/mwfarb","html_url":"https://github.com/mwfarb","followers_url":"https://api.github.com/users/mwfarb/followers","following_url":"https://api.github.com/users/mwfarb/following{/other_user}","gists_url":"https://api.github.com/users/mwfarb/gists{/gist_id}","starred_url":"https://api.github.com/users/mwfarb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mwfarb/subscriptions","organizations_url":"https://api.github.com/users/mwfarb/orgs","repos_url":"https://api.github.com/users/mwfarb/repos","events_url":"https://api.github.com/users/mwfarb/events{/privacy}","received_events_url":"https://api.github.com/users/mwfarb/received_events","type":"User","site_admin":false},"open_issues":2,"closed_issues":13,"state":"open","created_at":"2014-10-13T15:02:26Z","updated_at":"2015-05-18T16:45:40Z","due_on":null,"closed_at":null},"comments":1,"created_at":"2014-07-17T19:05:44Z","updated_at":"2015-05-23T04:57:50Z","closed_at":null,"body":"Version 1.7.0. Messages are not currently automatically decrypted when users are logged in. Provide a an auto-decrypt setting users can configure which defaults to true. When the passphrase is cached, messages should decrypt without having to press \"tap to decrypt\". Similarly, the moment a user successfully logs in, a background job should seek out encrypted messages and attempt to automatically decrypt them."},"comment":{"url":"https://api.github.com/repos/SafeSlingerProject/SafeSlinger-iOS/issues/comments/104845201","html_url":"https://github.com/SafeSlingerProject/SafeSlinger-iOS/issues/4#issuecomment-104845201","issue_url":"https://api.github.com/repos/SafeSlingerProject/SafeSlinger-iOS/issues/4","id":104845201,"user":{"login":"brnunes","id":1976718,"avatar_url":"https://avatars.githubusercontent.com/u/1976718?v=3","gravatar_id":"","url":"https://api.github.com/users/brnunes","html_url":"https://github.com/brnunes","followers_url":"https://api.github.com/users/brnunes/followers","following_url":"https://api.github.com/users/brnunes/following{/other_user}","gists_url":"https://api.github.com/users/brnunes/gists{/gist_id}","starred_url":"https://api.github.com/users/brnunes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brnunes/subscriptions","organizations_url":"https://api.github.com/users/brnunes/orgs","repos_url":"https://api.github.com/users/brnunes/repos","events_url":"https://api.github.com/users/brnunes/events{/privacy}","received_events_url":"https://api.github.com/users/brnunes/received_events","type":"User","site_admin":false},"created_at":"2015-05-23T04:57:50Z","updated_at":"2015-05-23T04:57:50Z","body":"I finished the auto decryption and everything seems to be working fine. I tested with multiple accounts on the same device, checking and unchecking the auto-decryption, and everything worked as expected.\r\nI had to add a new column to the `msgtable` to indicate if a message has been already read or not, since now we can't differentiate them just by being encrypted/decrypted. The patch will be executed if the user is running the version 1.8.1 or prior, but will not be executed if the version is already the 1.8.2 (not yet released). In order to test, you will have to reinstall the app, or change the logic [here](https://github.com/SafeSlingerProject/SafeSlinger-iOS/blob/3b9ba83d8f9a46817d6c43e1592386bee549fd64/safeslingermessager/safeslingermessager/SafeSlingerDB.m#L138-L154), and call the `patchForUnreadMessagesFlag` method.\r\n\r\nA few notes on some problems that are not directly related to this task but I noticed while working on it:\r\n\r\n- If the user created more than one public/private key pair, he will receive all the messages when logged in with any key pair. If the message was sent to a key that is not the currently logged in, the messages will show up but he won't be able to decrypt. I think we have already talked about this issue. It happens because the only destination identification is the push token, which is the same for accounts created on the same device.\r\nA possible solution for this, when auto-decryption is enabled, is to just not show any messages that we could not decrypt when the user logged in or when the message arrived. That's an indicator that the message was addressed to another key pair.\r\n\r\n- When the nonce for a new message is received, it is first inserted in the `ciphertable` with the `keyid` \"UNDEFINED\". Then the encrypted message is downloaded from the server and the `ciphertable` is updated with the correct `keyid` and `ciphertext`. If for some reason the download of the encrypted message fails, the message will stay in the `ciphertable` with the `keyid` \"UNKNOWN\" and will be shown as \"Message expired\". We never try to download that message again.\r\nAlso, if multiple messages arrive in a short period of time and the user is in the screen where the list of conversation threads is shown, we might reload the threads while one message is temporarily stored in the `ciphertable` with `keyid` \"UNKNOWN\". That will appear as a conversation with an unknown contact. Then, when that message is downloaded and decrypted, we will again reload the threads and the conversation will disappear because that message has been downloaded, decrypted and is now in the `msgtable`.\r\nOne solution for this problem would be to store the nonces in a different table. We could also just not show messages that have keyid \"UNKNOWN\" since the user won't be able to decrypt them anyway. Regardless, we should always check if we have nonces for messages that were still not downloaded, and try to download them.\r\n"}}