-
Notifications
You must be signed in to change notification settings - Fork 12
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
Add JsonFileSessionStore #18
Conversation
Laiteux
commented
Sep 14, 2020
Let me know what you think. |
Note that you have to add
This might be annoying. After a few Google searches, I tend to believe the issue is due to the fact we recently migrated to .NET Standard 2.0 or .NET Core: https://stackoverflow.com/a/48043024/12753809 |
who is 'we'? I don't understand this sentence, can you clarify |
"we" = TgSharp. Nevermind tho, I used the master branch and it wasn't migrated to .NET Standard 2.0 yet. Forget about that. |
So you mean the System.IO.FileNotFoundException problem will only happen when we change TgSharp to .NETStandard? |
No, it currently is happening. I thought that was because we migrated to .NET Standard but I was wrong. Maybe migrating will fix the issue? |
I see, ok. BTW you haven't said why is this JsonFileSessionStore useful at all? Why did you include it? What benefit does it bring to you? |
I mean, it's always better to have a human-readable JSON file than an unreadable DAT one containing bytes. You can see what the session file contains, what it is all about. Also, it prevents the file from getting corrupted. Happened to me a few times in the past using And it's just way better in general for storing data, in my opinion. For example, I currently store a lot of sessions in a SQL database, and doing it with bytes would have been a pain. I believe a JSON session file is just better in general. |
I agree, thanks for the explanation. I'll be reviewing this PR today. |
2 questions:
|
|
Ah, do you actually mind to not use this operator please? I find it quite unreadable.
Imagine some software developer uses TgSharp current master branch, and in the future he upgrades to a version that has this feature merged. If we merge this PR as is, what I guess will happen is that his program won't try to open the .dat file, instead it will try to open a saved JSON store file, it will not find it, and create a new one. However, what should happen is that it should be backwards compatible: TgSharp should see the existence of the .dat file (and no existence of JSON store file), then it should convert the .dat file to JSON, and afterwards, load the session from that JSON file. |
Ok, sure. Should I then revert 306dc8f8b76c8490e5f92eaf6eb288760d073bf4 too?
Got it, will write that tomorrow. |
Yup because it's not needed anymore. We will upgrade C# when we really need it. |
Tested & working 👌 |
Cool thanks! BTW, are you good at rebasing, separating commits et al? |
Never done that. Honestly this is one of my first "serious" pull requests, I'm still a bit of a beginner with git. |
So if I ask you to separate your last commit in 2 commits (one that removes the ??= operator, and one that introduces the migration), will you know how to do it? |
I have no idea if I did it the way you wanted, but here we go |
There's a merge commit, so no :( you should have used interactive rebase |
I have no idea of how to do that, sorry |
If you give me access to your fork I'll remove the merge commit |
@Laiteux see how I reordered commits, squashed some of them and adjusted commit messages (thanks to the magic of |
Looks cool! |
Thanks. By the way I've just realised there may be a couple more improvements to make, I'm going to point them out now, but be careful, given that I pushed with |
(Otherwise, you may get conflicts, or git merge commits, if you pull.) |
However, that would mean it STILL would be included in the binary session file, and others. JsonIgnoreAttribute will only affect the JsonSerializer/JsonConvert. Let me know what you think |
We don't want the binary session file to store different things than the JSON session file. |
So what should we do? 😕 |
Consumer could still get TLUser using MakeAuthAsync and store it himself if really needed. |
So, you meant to answer "no" to Anders' below question?:
|
Yes, this is what I meant. |
Ye, I just added the id from TLUser to the Session persisting (1 line in session and 1 line in client on auth) - the other (TLUser) values are flux anyways - but the user id is nice to know. |
Sorry, what do you mean by that? I don't understand
|
Nevermind, got it. Would you mind contributing to this PR? |
@Laiteux In my code to make it work.. I just added |
@Laiteux Yes, but I'm so so bad at git/github - I always f'up something :P .. But was just this to TelegramClient.cs + added the prop to
|
That's fine, I'll add it then rebase. Ok for you @knocte? |
yes sounds fine; note you may have problems injecting that change in the 2nd commit because the 3rd commit changes stuff around that too (if this is the case, you can just merge the 2nd and 3rd commits into 1, copy+pasting the text from the commit message from the 3rd) |
No problem if you guys want to remove TLUser but you have to have a GetMe function to get the TLUser object ( if user == null (can be overruled with a force_update arg) ) |
what do you mean with the above @aarani ? |
|
I rebased this PR in this branch: https://github.com/nblockchain/TgSharp/commits/wip/jsonSessionStore , can you review @aarani ? (Note: CI might be broken in the last commit, I just have to replace the .dat file with a new .json file, I'll do that tomorrow.) |
LGTM but it probably needs more testing |
It's always better to have a human-readable JSON file than an unreadable DAT one containing bytes. You can see what the session file contains, what it is all about. Also, it prevents the file from getting corrupted. Happened to me a few times in the past using FileSessionStore, had to delete the session file and reconnect/auth. And it's just way better in general for storing data. For example, I currently store a lot of sessions in a SQL database, and doing it with bytes would have been a pain. JSON session file is just better in general. NOTE: Reason for migrating to .NET4.6.2 is to be able to reference .NETStandard2.0 (needed for System.Text.Json). Co-authored-by: Andres G. Aragoneses <[email protected]>
what is still missing to finish this pull request? |
Nothing I believe, iirc it works well but we wanted to do some more tests before merging, which we never ended up doing |
Is there anything I can help with? I really like to use this feature in the official NuGet |
Please test the feature on your side and let us know if everything works fine. If so, @knocte will most likely merge it |
@omerjacobi you wanna contribute? tell me your username in telegram and I'll add you to a group where we can chat |
@knocte I send it to your gmail |