-
Notifications
You must be signed in to change notification settings - Fork 2
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
Plaintext votes 2 #141
Merged
Merged
Plaintext votes 2 #141
Changes from 19 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
2e6f639
Create data structures necessary for plaintext voting.
vteague 002cbcf
Added command and correct URL
vteague 5eb629e
Shifting some of the commands into the QuestionViewModel or QuestionD…
vteague 2339874
QuestionDisplayCards now displaying properly with new view model.
vteague fef1d9a
Remove SelectedQuestion from ReadingPage
vteague 4a406f4
Merge remote-tracking branch 'origin/main' into plaintext-votes-2
vteague bf3013a
Only test now failing is the UpvoteQuestion test.
vteague a53b7b5
Added & modified some Question and QuestionViewModel tests.
vteague cdf3c90
Reformatted QuestionDisplayCard.xaml to fit upvote / total data.
vteague c31b3d8
Slightly better-spaced QuestionDisplayCard.xaml.
vteague 099111f
Minimal plaintext up-voting working, but without keeping track of whi…
vteague 3a78cf8
Explicit passing of question responses compiling but not implemented.
vteague d25eb15
Plaintext up-voting now working, but not Dismissing or down-voting. T…
vteague 4e00ddd
Both plaintex up-voting and dismissing now working.
vteague a76c021
Both plaintext upvoting and vote-dismissing mostly working.
vteague b07d615
Slight refactor of some of the things that should be in QuestionViewM…
vteague 270a5a9
Corrections to plaintext upvotes. Now seems to be working correctly, …
vteague de4ab96
Wrapped QuestionResponseRecords.cs Init in a test to see if it's alre…
vteague 11df564
Preceded some more uploads with a check that you're already registere…
vteague 5475eca
Remove commented-out code.
vteague File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
RightToAskClient/RightToAskClient/RightToAskClient/Helpers/Exceptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System; | ||
|
||
public class TriedToUploadWhileNotRegisteredException : Exception | ||
{ | ||
public TriedToUploadWhileNotRegisteredException() | ||
{ | ||
} | ||
|
||
public TriedToUploadWhileNotRegisteredException(string message) | ||
: base(message) | ||
{ | ||
} | ||
|
||
public TriedToUploadWhileNotRegisteredException(string message, Exception inner) | ||
: base(message, inner) | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
RightToAskClient/RightToAskClient/RightToAskClient/Models/QuestionResponseRecords.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using System.Text.Json; | ||
using RightToAskClient.Helpers; | ||
using Xamarin.Forms; | ||
|
||
namespace RightToAskClient.Models | ||
{ | ||
/* | ||
* Stores information about this user's responses to questions: which ones | ||
* they've up-voted, down-voted, dismissed, flagged. | ||
*/ | ||
public class QuestionResponseRecords | ||
{ | ||
private HashSet<string> _upvotedQuestionIDs; | ||
private HashSet<string> _downvotedQuestionIDs; | ||
private HashSet<string> _reportedQuestionIDs; | ||
private HashSet<string> _dismissedQuestionIDs; | ||
private bool _isInitialised; | ||
|
||
public void Init() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indentation seems strange in this file, are the methods meant to be indented that far? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't worry about this |
||
{ | ||
if (!_isInitialised) | ||
{ | ||
// Retrieve from preferences. | ||
_upvotedQuestionIDs = retrieveHashSetFromPreferences(Constants.UpvotedQuestions); | ||
_downvotedQuestionIDs = retrieveHashSetFromPreferences(Constants.DownvotedQuestions); | ||
_dismissedQuestionIDs = retrieveHashSetFromPreferences(Constants.DismissedQuestions); | ||
_reportedQuestionIDs = retrieveHashSetFromPreferences(Constants.ReportedQuestions); | ||
_isInitialised = true; | ||
} | ||
} | ||
|
||
|
||
public void AddDownvotedQuestion(string questionID) | ||
{ | ||
_downvotedQuestionIDs.Add(questionID); | ||
storeHashSetInPreferences(Constants.DownvotedQuestions, _downvotedQuestionIDs); | ||
} | ||
|
||
public bool IsAlreadyDownvoted(string questionID) => _downvotedQuestionIDs.Contains(questionID); | ||
|
||
public void AddUpvotedQuestion(string questionID) | ||
{ | ||
_upvotedQuestionIDs.Add(questionID); | ||
storeHashSetInPreferences(Constants.UpvotedQuestions, _upvotedQuestionIDs); | ||
} | ||
|
||
public bool IsAlreadyUpvoted(string questionID) => _upvotedQuestionIDs.Contains(questionID); | ||
|
||
public void AddReportedQuestion(string questionID) | ||
{ | ||
_reportedQuestionIDs.Add(questionID); | ||
storeHashSetInPreferences(Constants.ReportedQuestions, _reportedQuestionIDs); | ||
} | ||
|
||
public bool IsAlreadyReported(string questionID) => _reportedQuestionIDs.Contains(questionID); | ||
|
||
public void AddDismissedQuestion(string questionID) | ||
{ | ||
_dismissedQuestionIDs.Add(questionID); | ||
storeHashSetInPreferences(Constants.DismissedQuestions, _dismissedQuestionIDs); | ||
} | ||
|
||
public bool IsAlreadyDismissed(string questionID) => _dismissedQuestionIDs.Contains(questionID); | ||
|
||
private void storeHashSetInPreferences(string key, HashSet<string> hashSet) | ||
{ | ||
try | ||
{ | ||
var hashSetString = JsonSerializer.Serialize(hashSet); | ||
XamarinPreferences.shared.Set(key, hashSetString); | ||
} | ||
catch (Exception e) | ||
{ | ||
Debug.WriteLine("Error storing "+key+" to preferences: "+e.Message); | ||
} | ||
} | ||
private HashSet<string> retrieveHashSetFromPreferences(string key) | ||
{ | ||
var retrievedSet = new HashSet<string>(); | ||
|
||
var retrievedString = XamarinPreferences.shared.Get(key, ""); | ||
if (!String.IsNullOrEmpty(retrievedString)) | ||
{ | ||
try | ||
{ | ||
retrievedSet = JsonSerializer.Deserialize<HashSet<string>>(retrievedString); | ||
} | ||
catch (Exception e) | ||
{ | ||
Debug.WriteLine("Error deserialising "+key+":"+e.Message); | ||
} | ||
} | ||
|
||
return retrievedSet ?? new HashSet<string>();; | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...ightToAskClient/RightToAskClient/Models/ServerCommsData/PlainTextVoteOnQuestionCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace RightToAskClient.Models.ServerCommsData | ||
{ | ||
public class PlainTextVoteOnQuestionCommand | ||
{ | ||
|
||
[JsonPropertyName("question_id")] | ||
public string question_id { get; set; } | ||
|
||
[JsonPropertyName("up")] | ||
public bool up { get; set; } | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...ToAskClient/Models/ServerCommsData/PlaintextVoteOnQuestionCommandPostedToBulletinBoard.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace RightToAskClient.Models.ServerCommsData | ||
{ | ||
public class PlaintextVoteOnQuestionCommandPostedToBulletinBoard | ||
{ | ||
[JsonPropertyName("command")] | ||
public ClientSignedUnparsed command { get; set; } | ||
|
||
|
||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would like some more tests for this. For example try and test what happens when you try to add something in the hashset