Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implemented draft feature, including attatchments #225

Merged
merged 6 commits into from
Mar 10, 2021

Conversation

clemensott
Copy link
Contributor

@clemensott clemensott commented Feb 27, 2021

Implemented the saving and loading of drafts including the attatchemnt file.
Fixed the saving of color from conversation.

I'm not sure if my migration is correct, because I just copied m6 by hand and renamed it to m7 and added the new property DraftFileTokens.

@clemensott clemensott marked this pull request as ready for review February 27, 2021 12:48
}
}

public static void InsertOrUpdateConversationsLocked(IEnumerable<SignalConversation> conversations)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this function to improve the performance when saving all conversations on suspending.

Signal-Windows.Lib/Storage/DB.cs Outdated Show resolved Hide resolved
* because on mobile app gets supended during file picking and
* the new conversation does not have the DraftFileTokens
*/
if (conversationThreadIdChanged)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought the best approach to solve this issue is to just keep the current draft if its the same thread id and set the kept draft in the new conversation.

Task.Run(() =>
{
SignalDBContext.InsertOrUpdateConversationLocked(SignalConversation);
});
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the token is not saved in the database right away it could happen, that StorageApplicationPermissions and database get out of sync when the app crashes or gets in other way suspended without saving.

await Task.Run(() =>
{
SignalDBContext.InsertOrUpdateConversationsLocked(Views.Values.SelectMany(view => view.Locator.MainPageInstance.Conversations));
});
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this is the best position to save the current state of all conversations. Maybe within Handle.Release()? But I think in Handle.Release() is no nice way to access the conversations.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A question I have is what in the conversation state isn't saved when the app shuts down. You're already saving the attachment state in the DB immediately after selection. The draft text may be a little harder as we wouldn't want to save to the DB on every keystroke. I could see that being saved in App_Suspending

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this code in App.xaml.cs everything is saved in the conversation state on App_Suspending. In Conversation.xaml.cs the state is only saved, so that no files are saved in the FutureAccessList, which then might not be saved in the state or database, because the app crashes or similar.

I think I have better idea now. We could save the selected file in FutureAccessList and the state of the current conversation in the database on SaveDraftInCurrentConversation(). With this approch saving the state of all conversations in App_Suspending is not needed, because the only conversation that has to be saved is the current and this gets done by Handle.Release().

@golf1052
Copy link
Member

golf1052 commented Mar 5, 2021

I'm not sure if my migration is correct, because I just copied m6 by hand and renamed it to m7 and added the new property DraftFileTokens.

If you used the Add-Migration command in the Package Manager Console in Visual Studio you did the migration correctly. I should add documentation to the repo on doing DB migrations.

@clemensott
Copy link
Contributor Author

I tried the Add-Migration command (Add-Migration m7 -Context SignalDBContext) but I get an error:
Startup project 'Signal-Windows.Lib' is a class library. Select a Universal Windows Platform app as your startup project and try again.

@clemensott
Copy link
Contributor Author

I think I found the problem. I nedded to select the project Signal-Windows and add -Project Signal-Windows.Lib the command. I created an PR to fix the documentation.

I updated/fixed the migration of this PR.

await Task.Run(() =>
{
SignalDBContext.InsertOrUpdateConversationsLocked(Views.Values.SelectMany(view => view.Locator.MainPageInstance.Conversations));
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A question I have is what in the conversation state isn't saved when the app shuts down. You're already saving the attachment state in the DB immediately after selection. The draft text may be a little harder as we wouldn't want to save to the DB on every keystroke. I could see that being saved in App_Suspending

}
catch (Exception e)
{
Logger.LogError("SetSelectedFile() failed: {0}\n{1}", e.Message, e.StackTrace);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did this fail for you while testing? Does it make sense to fail to save the selected file in the StorageApplicationPermissions and the DB but still show it in the UI?

Copy link
Contributor Author

@clemensott clemensott Mar 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually no, I just like to put everything that has to do with IO in a try catch. I change it.

Comment on lines 588 to 596
if (SelectedFile == null)
{
AddedAttachmentDisplay.HideAttachment();
}
else
{
AddedAttachmentDisplay.ShowAttachment(SelectedFile.Name);
}
UpdateSendButtonIcon();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like this should be split out into a separate method called SetSelectedFileInUI. Then the only two places where the argument save is set to false could just directly call the new method and the save argument could be removed.

Copy link
Contributor Author

@clemensott clemensott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed when the conversations and it's draft get saved. It's now saved in SaveCurrentConversationInDatabase(), which is call on change of conversation and shutdown of app. SelectedFile gets save in FutureAccessList there aswell.

Obviously the draft of the current conversation is not saved when the app crashes but I think this is acceptable, as long as the DraftFileTokens in the database don't get out of sync with FutureAccessList, which is case.

await Task.Run(() =>
{
SignalDBContext.InsertOrUpdateConversationsLocked(Views.Values.SelectMany(view => view.Locator.MainPageInstance.Conversations));
});
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this code in App.xaml.cs everything is saved in the conversation state on App_Suspending. In Conversation.xaml.cs the state is only saved, so that no files are saved in the FutureAccessList, which then might not be saved in the state or database, because the app crashes or similar.

I think I have better idea now. We could save the selected file in FutureAccessList and the state of the current conversation in the database on SaveDraftInCurrentConversation(). With this approch saving the state of all conversations in App_Suspending is not needed, because the only conversation that has to be saved is the current and this gets done by Handle.Release().

@clemensott clemensott requested a review from golf1052 March 9, 2021 13:09
@golf1052 golf1052 merged commit ce75302 into signal-csharp:master Mar 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants