-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #141 from RightToAskOrg/plaintext-votes-2
Plaintext votes 2
- Loading branch information
Showing
20 changed files
with
448 additions
and
295 deletions.
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
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() | ||
{ | ||
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.