Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
PetitionPeerReviewViewModel.cs
1using CommunityToolkit.Mvvm.ComponentModel;
2using CommunityToolkit.Mvvm.Input;
9using System.Collections.ObjectModel;
13
15{
20 {
21 private readonly PhotosLoader photosLoader;
22 private readonly string? requestorFullJid;
23 private readonly string? requestedIdentityId;
24 private readonly string? petitionId;
25 private readonly string? bareJid;
26
31 public PetitionPeerReviewViewModel(PetitionPeerReviewNavigationArgs? Args)
32 {
33 this.photosLoader = new PhotosLoader(this.Photos);
34
35 if (Args is not null)
36 {
37 this.RequestorIdentity = Args.RequestorIdentity;
38 this.requestorFullJid = Args.RequestorFullJid;
39 this.requestedIdentityId = Args.RequestedIdentityId;
40 this.petitionId = Args.PetitionId;
41 this.Purpose = Args.Purpose;
42 this.ContentToSign = Args.ContentToSign;
43
44 if (!string.IsNullOrEmpty(this.requestorFullJid))
45 this.bareJid = XmppClient.GetBareJID(this.requestorFullJid);
46 else if (Args.RequestorIdentity is not null)
47 this.bareJid = Args.RequestorIdentity.GetJid();
48 else
49 this.bareJid = string.Empty;
50 }
51 }
52
56 public void AddView(ReviewStep Step, BaseContentView View)
57 {
58 View.BindingContext = this;
59 this.stepViews[Step] = View;
60 }
61
65 [ObservableProperty]
66 private ReviewStep currentStep = ReviewStep.Photo;
67
71 private readonly SortedDictionary<ReviewStep, BaseContentView> stepViews = [];
72
74 protected override async Task OnInitialize()
75 {
76 await base.OnInitialize();
77
78 if (!string.IsNullOrEmpty(this.bareJid))
79 {
80 ContactInfo Info = await ContactInfo.FindByBareJid(this.bareJid);
81
82 if (this.RequestorIdentity is not null &&
83 Info is not null &&
84 (Info.LegalIdentity is null || (
85 Info.LegalId != this.RequestorIdentity?.Id &&
86 Info.LegalIdentity is not null &&
87 Info.LegalIdentity.Created < this.RequestorIdentity!.Created &&
88 this.RequestorIdentity.State == IdentityState.Approved)))
89 {
90 Info.LegalId = this.LegalId;
91 Info.LegalIdentity = this.RequestorIdentity;
92 Info.FriendlyName = ContactInfo.GetFriendlyName(this.RequestorIdentity);
93
94 await Database.Update(Info);
95 await Database.Provider.Flush();
96 }
97
98 this.ThirdPartyInContacts = Info is not null;
99 }
100
101 this.AssignProperties();
102 this.NotifyCommandsCanExecuteChanged();
103
104 this.ReloadPhotos();
105 }
106
107 private async void ReloadPhotos()
108 {
109 try
110 {
111 this.photosLoader.CancelLoadPhotos();
112
113 Attachment[]? Attachments = this.RequestorIdentity?.Attachments;
114 Photo? First;
115
116 if (Attachments is not null)
117 {
118 First = await this.photosLoader.LoadPhotos(Attachments, SignWith.LatestApprovedId);
119
120 this.FirstPhotoSource = First?.Source;
121 this.FirstPhotoRotation = First?.Rotation ?? 0;
122 }
123
124 Attachments = ServiceRef.TagProfile.LegalIdentity?.Attachments;
125
126 if (Attachments is not null)
127 {
128 First = await this.photosLoader.LoadPhotos(Attachments, SignWith.LatestApprovedId);
129
130 this.MyFirstPhotoSource = First?.Source;
131 this.MyFirstPhotoRotation = First?.Rotation ?? 0;
132 }
133 }
134 catch (Exception ex)
135 {
136 ServiceRef.LogService.LogException(ex);
137 }
138 }
139
141 protected override async Task OnDispose()
142 {
143 this.photosLoader.CancelLoadPhotos();
144
145 await base.OnDispose();
146 }
147
151 public ObservableCollection<Photo> Photos { get; } = [];
152
156 public LegalIdentity? RequestorIdentity { get; private set; }
157
159 protected override Task XmppService_ConnectionStateChanged(object? Sender, XmppState NewState)
160 {
161 return MainThread.InvokeOnMainThreadAsync(async () =>
162 {
163 await base.XmppService_ConnectionStateChanged(Sender, NewState);
164
165 this.NotifyCommandsCanExecuteChanged();
166 });
167 }
168
169 public override void SetIsBusy(bool IsBusy)
170 {
171 base.SetIsBusy(IsBusy);
172 this.NotifyCommandsCanExecuteChanged();
173 }
174
175 private void NotifyCommandsCanExecuteChanged()
176 {
177 this.AcceptCommand.NotifyCanExecuteChanged();
178 this.DeclineCommand.NotifyCanExecuteChanged();
179 this.AuthenticateReviewerCommand.NotifyCanExecuteChanged();
180 }
181
185 public bool CanAccept
186 {
187 get
188 {
189 if (!this.IsConnected || this.IsBusy || this.ContentToSign is null)
190 return false;
191
192 if (this.HasPhoto && !this.IsPhotoOk)
193 return false;
194
195 if (this.HasName && !this.IsNameOk)
196 return false;
197
198 if (this.HasPersonalNumber && !this.IsPnrOk)
199 return false;
200
201 if (this.HasNationality && !this.IsNationalityOk)
202 return false;
203
204 if (this.HasBirthDate && !this.IsBirthDateOk)
205 return false;
206
207 if (this.HasGender && !this.IsGenderOk)
208 return false;
209
210 if (this.HasPersonalAddressInfo && !this.IsPersonalAddressInfoOk)
211 return false;
212
213 if (this.HasOrganizationalInfo && !this.IsOrganizationalInfoOk)
214 return false;
215
216 if (!this.AcknowledgeResponsibility || !this.ConsentProcessing || !this.ConfirmCorrect)
217 return false;
218
219 return true;
220 }
221 }
222
223 [RelayCommand(CanExecute = nameof(CanAccept))]
224 private Task Accept()
225 {
226 return this.Accept(true);
227 }
228
229 private async Task Accept(bool GoBackIfOk)
230 {
231 if (this.ContentToSign is null || !await App.AuthenticateUser(AuthenticationPurpose.AcceptPeerReview))
232 return;
233
234 bool Succeeded = await ServiceRef.NetworkService.TryRequest(async () =>
235 {
236 byte[] Signature = await ServiceRef.XmppService.Sign(this.ContentToSign!, SignWith.LatestApprovedId);
237
238 await ServiceRef.XmppService.SendPetitionSignatureResponse(this.requestedIdentityId, this.ContentToSign, Signature,
239 this.petitionId!, this.requestorFullJid!, true);
240 });
241
242 if (Succeeded && GoBackIfOk)
243 await base.GoBack();
244 }
245
249 public bool CanDecline => this.IsConnected && !this.IsBusy && this.ContentToSign is not null;
250
251 [RelayCommand(CanExecute = nameof(CanDecline))]
252 private Task Decline()
253 {
254 return this.Decline(true);
255 }
256
257 private async Task Decline(bool GoBackIfOk)
258 {
259 if (this.ContentToSign is null || !await App.AuthenticateUser(AuthenticationPurpose.DeclinePeerReview))
260 return;
261
262 bool Succeeded = await ServiceRef.NetworkService.TryRequest(async () =>
263 {
264 byte[] Signature = await ServiceRef.XmppService.Sign(this.ContentToSign!, SignWith.LatestApprovedId);
265
266 await ServiceRef.XmppService.SendPetitionSignatureResponse(this.requestedIdentityId, this.ContentToSign, Signature,
267 this.petitionId!, this.requestorFullJid!, false);
268 });
269
270 if (Succeeded && GoBackIfOk)
271 await base.GoBack();
272 }
273
274 [RelayCommand]
275 private async Task Ignore()
276 {
277 await base.GoBack();
278 }
279
280 [RelayCommand(CanExecute = nameof(IsPhotoOk))]
281 private void AcceptPhoto()
282 {
283 if (this.IsPhotoOk)
284 this.NextPage();
285 }
286
287 [RelayCommand(CanExecute = nameof(IsNameOk))]
288 private void AcceptName()
289 {
290 if (this.IsNameOk)
291 this.NextPage();
292 }
293
294 [RelayCommand(CanExecute = nameof(IsPnrOk))]
295 private void AcceptPnr()
296 {
297 if (this.IsPnrOk)
298 this.NextPage();
299 }
300
301 [RelayCommand(CanExecute = nameof(IsNationalityOk))]
302 private void AcceptNationality()
303 {
304 if (this.IsNationalityOk)
305 this.NextPage();
306 }
307
308 [RelayCommand(CanExecute = nameof(IsBirthDateOk))]
309 private void AcceptBirthDate()
310 {
311 if (this.IsBirthDateOk)
312 this.NextPage();
313 }
314
315 [RelayCommand(CanExecute = nameof(IsGenderOk))]
316 private void AcceptGender()
317 {
318 if (this.IsGenderOk)
319 this.NextPage();
320 }
321
322 [RelayCommand(CanExecute = nameof(IsPersonalAddressInfoOk))]
323 private void AcceptPersonalAddressInfo()
324 {
325 if (this.IsPersonalAddressInfoOk)
326 this.NextPage();
327 }
328
329 [RelayCommand(CanExecute = nameof(IsOrganizationalInfoOk))]
330 private void AcceptOrganizationalInfo()
331 {
332 if (this.IsOrganizationalInfoOk)
333 this.NextPage();
334 }
335
336 [RelayCommand(CanExecute = nameof(IsConsentOk))]
337 private void AcceptConsent()
338 {
339 if (this.IsConsentOk)
340 this.NextPage();
341 }
342
343 private void NextPage()
344 {
345 ReviewStep Current = this.CurrentStep;
346 bool IsVisible;
347
348 do
349 {
350 Current++;
351 IsVisible = Current switch
352 {
353 ReviewStep.Photo => this.HasPhoto,
354 ReviewStep.Name => this.HasName,
355 ReviewStep.Pnr => this.HasPersonalNumber,
356 ReviewStep.Nationality => this.HasNationality,
357 ReviewStep.BirthDate => this.HasBirthDate,
358 ReviewStep.Gender => this.HasGender,
359 ReviewStep.PersonalAddressInfo => this.HasPersonalAddressInfo,
360 ReviewStep.OrganizationalInfo => this.HasOrganizationalInfo,
361 _ => true,
362 };
363 }
364 while (!IsVisible);
365
366 this.CurrentStep = Current;
367 }
368
369 private bool PrevPage()
370 {
371 ReviewStep Current = this.CurrentStep;
372 bool IsVisible;
373
374 do
375 {
376 if (Current == 0)
377 return false;
378
379 Current--;
380 IsVisible = Current switch
381 {
382 ReviewStep.Photo => this.HasPhoto,
383 ReviewStep.Name => this.HasName,
384 ReviewStep.Pnr => this.HasPersonalNumber,
385 ReviewStep.Nationality => this.HasNationality,
386 ReviewStep.BirthDate => this.HasBirthDate,
387 ReviewStep.Gender => this.HasGender,
388 ReviewStep.PersonalAddressInfo => this.HasPersonalAddressInfo,
389 ReviewStep.OrganizationalInfo => this.HasOrganizationalInfo,
390 _ => true,
391 };
392 }
393 while (!IsVisible);
394
395 this.CurrentStep = Current;
396
397 return true;
398 }
399
403 public bool HasPhoto => this.FirstPhotoSource is not null;
404
408 public bool HasName => !string.IsNullOrEmpty(this.FullName);
409
413 public bool HasPersonalNumber => !string.IsNullOrEmpty(this.PersonalNumber);
414
418 public bool HasNationality => !string.IsNullOrEmpty(this.NationalityCode);
419
423 public bool HasBirthDate => this.BirthDate is not null;
424
428 public bool HasGender => !string.IsNullOrEmpty(this.Gender);
429
434 {
435 get
436 {
437 return
438 !string.IsNullOrEmpty(this.Address) ||
439 !string.IsNullOrEmpty(this.Address2) ||
440 !string.IsNullOrEmpty(this.Area) ||
441 !string.IsNullOrEmpty(this.City) ||
442 !string.IsNullOrEmpty(this.Region) ||
443 !string.IsNullOrEmpty(this.CountryCode);
444 }
445 }
446
451 {
452 get
453 {
454 return
455 !string.IsNullOrEmpty(this.OrgName) ||
456 !string.IsNullOrEmpty(this.OrgNumber) ||
457 !string.IsNullOrEmpty(this.OrgDepartment) ||
458 !string.IsNullOrEmpty(this.OrgRole) ||
459 !string.IsNullOrEmpty(this.OrgAddress) ||
460 !string.IsNullOrEmpty(this.OrgAddress2) ||
461 !string.IsNullOrEmpty(this.OrgArea) ||
462 !string.IsNullOrEmpty(this.OrgCity) ||
463 !string.IsNullOrEmpty(this.OrgRegion) ||
464 !string.IsNullOrEmpty(this.OrgCountryCode);
465 }
466 }
467
468 #region Properties
469
473 [ObservableProperty]
474 private DateTime created;
475
479 [ObservableProperty]
480 private DateTime? updated;
481
485 [ObservableProperty]
486 private string? legalId;
487
491 [ObservableProperty]
492 private IdentityState state;
493
497 [ObservableProperty]
498 private DateTime? from;
499
503 [ObservableProperty]
504 private DateTime? to;
505
509 [ObservableProperty]
510 [NotifyPropertyChangedFor(nameof(FullName))]
511 [NotifyPropertyChangedFor(nameof(PhotoReviewText))]
512 [NotifyPropertyChangedFor(nameof(PeerReviewConfirmCorrectText))]
513 [NotifyPropertyChangedFor(nameof(PeerReviewAuthenticationText))]
514 [NotifyPropertyChangedFor(nameof(ReviewApproved))]
515 private string? firstName;
516
520 [ObservableProperty]
521 [NotifyPropertyChangedFor(nameof(FullName))]
522 [NotifyPropertyChangedFor(nameof(PhotoReviewText))]
523 [NotifyPropertyChangedFor(nameof(PeerReviewConfirmCorrectText))]
524 [NotifyPropertyChangedFor(nameof(PeerReviewAuthenticationText))]
525 [NotifyPropertyChangedFor(nameof(ReviewApproved))]
526 private string? middleNames;
527
531 [ObservableProperty]
532 [NotifyPropertyChangedFor(nameof(FullName))]
533 [NotifyPropertyChangedFor(nameof(PhotoReviewText))]
534 [NotifyPropertyChangedFor(nameof(PeerReviewConfirmCorrectText))]
535 [NotifyPropertyChangedFor(nameof(PeerReviewAuthenticationText))]
536 [NotifyPropertyChangedFor(nameof(ReviewApproved))]
537 private string? lastNames;
538
542 [ObservableProperty]
543 [NotifyPropertyChangedFor(nameof(PersonalNumberWithFlag))]
544 private string? personalNumber;
545
550 {
551 get
552 {
553 if (string.IsNullOrEmpty(this.CountryCode) ||
554 !ISO_3166_1.TryGetCountryByCode(this.CountryCode, out ISO_3166_Country? Country) ||
555 Country is null)
556 {
557 return this.PersonalNumber;
558 }
559
560 return Country.EmojiInfo.Unicode + "\t" + this.PersonalNumber;
561 }
562 }
563
567 [System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1822:Mark members as static",
568 Justification = "Must be instance property for view binding to work.")]
570 {
571 get
572 {
573 if (ServiceRef.TagProfile.LegalIdentity is null)
574 return null;
575
576 string? MyCountryCode = ServiceRef.TagProfile.LegalIdentity[Constants.XmppProperties.Country];
577 string? MyPersonalNumber = ServiceRef.TagProfile.LegalIdentity[Constants.XmppProperties.PersonalNumber];
578
579 if (string.IsNullOrEmpty(MyCountryCode) ||
580 !ISO_3166_1.TryGetCountryByCode(MyCountryCode, out ISO_3166_Country? MyCountry) ||
581 MyCountry is null)
582 {
583 return MyPersonalNumber;
584 }
585
586 return MyCountry.EmojiInfo.Unicode + "\t" + MyPersonalNumber;
587 }
588 }
589
593 [ObservableProperty]
594 private string? address;
595
599 [ObservableProperty]
600 private string? address2;
601
605 [ObservableProperty]
606 private string? zipCode;
607
611 [ObservableProperty]
612 private string? area;
613
617 [ObservableProperty]
618 private string? city;
619
623 [ObservableProperty]
624 private string? region;
625
629 [ObservableProperty]
630 [NotifyPropertyChangedFor(nameof(PersonalNumberWithFlag))]
631 private string? countryCode;
632
636 [ObservableProperty]
637 [NotifyPropertyChangedFor(nameof(NationalityWithFlag))]
638 private string? nationalityCode;
639
643 public string? NationalityWithFlag
644 {
645 get
646 {
647 if (string.IsNullOrEmpty(this.NationalityCode) ||
648 !ISO_3166_1.TryGetCountryByCode(this.NationalityCode, out ISO_3166_Country? Country) ||
649 Country is null)
650 {
651 return this.NationalityCode;
652 }
653
654 return Country.EmojiInfo.Unicode + "\t" + Country.Name;
655 }
656 }
657
661 [ObservableProperty]
662 [NotifyPropertyChangedFor(nameof(GenderWithSymbol))]
663 private string? gender;
664
668 public string? GenderWithSymbol
669 {
670 get
671 {
672 if (string.IsNullOrEmpty(this.Gender) ||
673 !ISO_5218.LetterToGender(this.Gender, out ISO_5218_Gender? Gender) ||
674 Gender is null)
675 {
676 return this.Gender;
677 }
678
679 return Gender.Unicode + "\t" + ServiceRef.Localizer[Gender.LocalizedNameId];
680 }
681 }
682
686 [ObservableProperty]
687 private DateTime? birthDate;
688
692 [ObservableProperty]
693 private string? orgName;
694
698 [ObservableProperty]
699 private string? orgNumber;
700
704 [ObservableProperty]
705 private string? orgDepartment;
706
710 [ObservableProperty]
711 private string? orgRole;
712
716 [ObservableProperty]
717 private string? orgAddress;
718
722 [ObservableProperty]
723 private string? orgAddress2;
724
728 [ObservableProperty]
729 private string? orgZipCode;
730
734 [ObservableProperty]
735 private string? orgArea;
736
740 [ObservableProperty]
741 private string? orgCity;
742
746 [ObservableProperty]
747 private string? orgRegion;
748
752 [ObservableProperty]
753 private string? orgCountryCode;
754
758 [ObservableProperty]
759 [NotifyPropertyChangedFor(nameof(OrgRowHeight))]
760 private bool hasOrg;
761
765 public GridLength OrgRowHeight => this.HasOrg ? GridLength.Auto : new GridLength(0, GridUnitType.Absolute);
766
770 [ObservableProperty]
771 private string? phoneNr;
772
776 [ObservableProperty]
777 private string? eMail;
778
782 [ObservableProperty]
783 private string? deviceId;
784
788 [ObservableProperty]
789 private bool isApproved;
790
794 [ObservableProperty]
795 private string? purpose;
796
800 [ObservableProperty]
801 private byte[]? contentToSign;
802
806 [ObservableProperty]
807 private bool thirdPartyInContacts;
808
812 [ObservableProperty]
813 private ImageSource? firstPhotoSource;
814
818 [ObservableProperty]
819 private int firstPhotoRotation;
820
824 [ObservableProperty]
825 private ImageSource? myFirstPhotoSource;
826
830 [ObservableProperty]
831 private int myFirstPhotoRotation;
832
833 // Full name of requesting entity.
834 public string FullName => ContactInfo.GetFullName(this.FirstName, this.MiddleNames, this.LastNames);
835
836 // Full name of reviewer.
837 [System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1822:Mark members as static",
838 Justification = "Must be instance property for view binding to work.")]
839 public string MyFullName => ContactInfo.GetFullName(ServiceRef.TagProfile.LegalIdentity);
840
844 [ObservableProperty]
845 [NotifyCanExecuteChangedFor(nameof(AcceptPhotoCommand))]
846 private bool isPhotoOk;
847
851 [ObservableProperty]
852 [NotifyCanExecuteChangedFor(nameof(AcceptNameCommand))]
853 private bool isNameOk;
854
858 [ObservableProperty]
859 [NotifyCanExecuteChangedFor(nameof(AcceptPnrCommand))]
860 private bool isPnrOk;
861
865 [ObservableProperty]
866 [NotifyCanExecuteChangedFor(nameof(AcceptNationalityCommand))]
867 private bool isNationalityOk;
868
872 [ObservableProperty]
873 [NotifyCanExecuteChangedFor(nameof(AcceptBirthDateCommand))]
874 private bool isBirthDateOk;
875
879 [ObservableProperty]
880 [NotifyCanExecuteChangedFor(nameof(AcceptGenderCommand))]
881 private bool isGenderOk;
882
886 [ObservableProperty]
887 [NotifyCanExecuteChangedFor(nameof(AcceptPersonalAddressInfoCommand))]
888 private bool isPersonalAddressInfoOk;
889
893 [ObservableProperty]
894 [NotifyCanExecuteChangedFor(nameof(AcceptOrganizationalInfoCommand))]
895 private bool isOrganizationalInfoOk;
896
900 [ObservableProperty]
901 [NotifyCanExecuteChangedFor(nameof(AcceptConsentCommand))]
902 [NotifyPropertyChangedFor(nameof(IsConsentOk))]
903 private bool acknowledgeResponsibility;
904
908 [ObservableProperty]
909 [NotifyCanExecuteChangedFor(nameof(AcceptConsentCommand))]
910 [NotifyPropertyChangedFor(nameof(IsConsentOk))]
911 private bool consentProcessing;
912
916 [ObservableProperty]
917 [NotifyCanExecuteChangedFor(nameof(AcceptConsentCommand))]
918 [NotifyPropertyChangedFor(nameof(IsConsentOk))]
919 private bool confirmCorrect;
920
924 [ObservableProperty]
925 private bool showDetails;
926
930 public bool IsConsentOk => this.AcknowledgeResponsibility && this.ConsentProcessing && this.ConfirmCorrect;
931
935 public string PhotoReviewText => ServiceRef.Localizer[nameof(AppResources.PeerReviewPhotoText), this.FullName];
936
940 public string PeerReviewConfirmCorrectText => ServiceRef.Localizer[nameof(AppResources.PeerReviewConfirmCorrectText), this.FullName];
941
945 public string PeerReviewAuthenticationText => ServiceRef.Localizer[nameof(AppResources.PeerReviewAuthenticationText), this.FullName];
946
950 public string ReviewApproved => ServiceRef.Localizer[nameof(AppResources.ReviewApproved), this.FullName];
951
955 [RelayCommand]
956 public void ToggleIsPhotoOk()
957 {
958 this.IsPhotoOk = !this.IsPhotoOk;
959 }
960
964 [RelayCommand]
965 public void ToggleIsNameOk()
966 {
967 this.IsNameOk = !this.IsNameOk;
968 }
969
973 [RelayCommand]
974 public void ToggleIsPnrOk()
975 {
976 this.IsPnrOk = !this.IsPnrOk;
977 }
978
982 [RelayCommand]
984 {
985 this.IsNationalityOk = !this.IsNationalityOk;
986 }
987
991 [RelayCommand]
993 {
994 this.IsBirthDateOk = !this.IsBirthDateOk;
995 }
996
1000 [RelayCommand]
1001 public void ToggleIsGenderOk()
1002 {
1003 this.IsGenderOk = !this.IsGenderOk;
1004 }
1005
1009 [RelayCommand]
1011 {
1012 this.IsPersonalAddressInfoOk = !this.IsPersonalAddressInfoOk;
1013 }
1014
1018 [RelayCommand]
1020 {
1021 this.IsOrganizationalInfoOk = !this.IsOrganizationalInfoOk;
1022 }
1023
1027 [RelayCommand]
1029 {
1030 this.AcknowledgeResponsibility = !this.AcknowledgeResponsibility;
1031 }
1032
1036 [RelayCommand]
1038 {
1039 this.ConsentProcessing = !this.ConsentProcessing;
1040 }
1041
1045 [RelayCommand]
1047 {
1048 this.ConfirmCorrect = !this.ConfirmCorrect;
1049 }
1050
1054 [RelayCommand]
1055 public void ToggleShowDetails()
1056 {
1057 this.ShowDetails = !this.ShowDetails;
1058 }
1059
1060 #endregion
1061
1062 private void AssignProperties()
1063 {
1064 if (this.RequestorIdentity is not null)
1065 {
1066 this.Created = this.RequestorIdentity.Created;
1067 this.Updated = this.RequestorIdentity.Updated.GetDateOrNullIfMinValue();
1068 this.LegalId = this.RequestorIdentity.Id;
1069 this.State = this.RequestorIdentity.State;
1070 this.From = this.RequestorIdentity.From.GetDateOrNullIfMinValue();
1071 this.To = this.RequestorIdentity.To.GetDateOrNullIfMinValue();
1072 this.FirstName = this.RequestorIdentity[Constants.XmppProperties.FirstName];
1073 this.MiddleNames = this.RequestorIdentity[Constants.XmppProperties.MiddleNames];
1074 this.LastNames = this.RequestorIdentity[Constants.XmppProperties.LastNames];
1075 this.PersonalNumber = this.RequestorIdentity[Constants.XmppProperties.PersonalNumber];
1077 this.Address2 = this.RequestorIdentity[Constants.XmppProperties.Address2];
1082 this.CountryCode = this.RequestorIdentity[Constants.XmppProperties.Country];
1083 this.NationalityCode = this.RequestorIdentity[Constants.XmppProperties.Nationality];
1085
1086 string BirthDayStr = this.RequestorIdentity[Constants.XmppProperties.BirthDay];
1087 string BirthMonthStr = this.RequestorIdentity[Constants.XmppProperties.BirthMonth];
1088 string BirthYearStr = this.RequestorIdentity[Constants.XmppProperties.BirthYear];
1089
1090 if (!string.IsNullOrEmpty(BirthDayStr) && int.TryParse(BirthDayStr, out int BirthDay) &&
1091 !string.IsNullOrEmpty(BirthMonthStr) && int.TryParse(BirthMonthStr, out int BirthMonth) &&
1092 !string.IsNullOrEmpty(BirthYearStr) && int.TryParse(BirthYearStr, out int BirthYear))
1093 {
1094 try
1095 {
1096 this.BirthDate = new DateTime(BirthYear, BirthMonth, BirthDay);
1097 }
1098 catch (Exception ex)
1099 {
1100 ServiceRef.LogService.LogException(ex);
1101 this.BirthDate = null;
1102 }
1103 }
1104
1106 this.OrgNumber = this.RequestorIdentity[Constants.XmppProperties.OrgNumber];
1107 this.OrgDepartment = this.RequestorIdentity[Constants.XmppProperties.OrgDepartment];
1109 this.OrgAddress = this.RequestorIdentity[Constants.XmppProperties.OrgAddress];
1110 this.OrgAddress2 = this.RequestorIdentity[Constants.XmppProperties.OrgAddress2];
1111 this.OrgZipCode = this.RequestorIdentity[Constants.XmppProperties.OrgZipCode];
1114 this.OrgRegion = this.RequestorIdentity[Constants.XmppProperties.OrgRegion];
1115 this.OrgCountryCode = this.RequestorIdentity[Constants.XmppProperties.OrgCountry];
1116 this.HasOrg =
1117 !string.IsNullOrEmpty(this.OrgName) ||
1118 !string.IsNullOrEmpty(this.OrgNumber) ||
1119 !string.IsNullOrEmpty(this.OrgDepartment) ||
1120 !string.IsNullOrEmpty(this.OrgRole) ||
1121 !string.IsNullOrEmpty(this.OrgAddress) ||
1122 !string.IsNullOrEmpty(this.OrgAddress2) ||
1123 !string.IsNullOrEmpty(this.OrgZipCode) ||
1124 !string.IsNullOrEmpty(this.OrgArea) ||
1125 !string.IsNullOrEmpty(this.OrgCity) ||
1126 !string.IsNullOrEmpty(this.OrgRegion) ||
1127 !string.IsNullOrEmpty(this.OrgCountryCode);
1128 this.PhoneNr = this.RequestorIdentity[Constants.XmppProperties.Phone];
1130 this.DeviceId = this.RequestorIdentity[Constants.XmppProperties.DeviceId];
1131 this.IsApproved = this.RequestorIdentity.State == IdentityState.Approved;
1132 }
1133 else
1134 {
1135 this.Created = DateTime.MinValue;
1136 this.Updated = null;
1137 this.LegalId = Constants.NotAvailableValue;
1138 this.State = IdentityState.Compromised;
1139 this.From = null;
1140 this.To = null;
1141 this.FirstName = Constants.NotAvailableValue;
1142 this.MiddleNames = Constants.NotAvailableValue;
1143 this.LastNames = Constants.NotAvailableValue;
1144 this.PersonalNumber = Constants.NotAvailableValue;
1145 this.Address = Constants.NotAvailableValue;
1146 this.Address2 = Constants.NotAvailableValue;
1147 this.ZipCode = Constants.NotAvailableValue;
1148 this.Area = Constants.NotAvailableValue;
1149 this.City = Constants.NotAvailableValue;
1150 this.Region = Constants.NotAvailableValue;
1151 this.CountryCode = Constants.NotAvailableValue;
1152 this.NationalityCode = Constants.NotAvailableValue;
1153 this.Gender = Constants.NotAvailableValue;
1154 this.BirthDate = null;
1155 this.OrgName = Constants.NotAvailableValue;
1156 this.OrgNumber = Constants.NotAvailableValue;
1157 this.OrgDepartment = Constants.NotAvailableValue;
1158 this.OrgRole = Constants.NotAvailableValue;
1159 this.OrgAddress = Constants.NotAvailableValue;
1160 this.OrgAddress2 = Constants.NotAvailableValue;
1161 this.OrgZipCode = Constants.NotAvailableValue;
1162 this.OrgArea = Constants.NotAvailableValue;
1163 this.OrgCity = Constants.NotAvailableValue;
1164 this.OrgRegion = Constants.NotAvailableValue;
1165 this.OrgCountryCode = Constants.NotAvailableValue;
1166 this.HasOrg = false;
1167 this.PhoneNr = Constants.NotAvailableValue;
1168 this.EMail = Constants.NotAvailableValue;
1169 this.DeviceId = Constants.NotAvailableValue;
1170 this.IsApproved = false;
1171 }
1172 }
1173
1174 [RelayCommand(CanExecute = nameof(CanAccept))]
1175 private async Task AuthenticateReviewer()
1176 {
1177 try
1178 {
1179 if (await App.AuthenticateUser(AuthenticationPurpose.AuthenticateReviewer, true))
1180 {
1181 await this.Accept(false);
1182 this.NextPage();
1183 }
1184 }
1185 catch (Exception ex)
1186 {
1187 ServiceRef.LogService.LogException(ex);
1188
1189 await ServiceRef.UiService.DisplayAlert(
1190 ServiceRef.Localizer[nameof(AppResources.ErrorTitle)],
1191 ServiceRef.Localizer[nameof(AppResources.UnableToSignReview)]);
1192 }
1193 }
1194
1196 public override async Task GoBack()
1197 {
1198 if (!this.PrevPage())
1199 await base.GoBack();
1200 }
1201
1205 [RelayCommand]
1206 public Task Close()
1207 {
1208 return base.GoBack();
1209 }
1210
1211 #region ILinkableView
1212
1216 public override Task<string> Title => Task.FromResult(ContactInfo.GetFriendlyName(this.RequestorIdentity!));
1217
1218 #endregion
1219 }
1220}
The Application class, representing an instance of the Neuro-Access app.
Definition: App.xaml.cs:69
static Task< bool > AuthenticateUser(AuthenticationPurpose Purpose, bool Force=false)
Authenticates the user using the configured authentication method.
Definition: App.xaml.cs:981
const string PersonalNumber
Personal number
Definition: Constants.cs:284
const string OrgAddress2
Organization Address line 2
Definition: Constants.cs:364
const string OrgArea
Organization Area
Definition: Constants.cs:369
const string OrgRegion
Organization Region
Definition: Constants.cs:384
const string Nationality
Nationality
Definition: Constants.cs:324
const string BirthYear
Birth Year
Definition: Constants.cs:344
const string OrgCity
Organization City
Definition: Constants.cs:374
const string OrgRole
Organization Role
Definition: Constants.cs:399
const string Phone
Phone number
Definition: Constants.cs:414
const string EMail
e-Mail address
Definition: Constants.cs:419
const string OrgZipCode
Organization Zip Code
Definition: Constants.cs:379
const string MiddleNames
Middle names
Definition: Constants.cs:274
const string OrgCountry
Organization Country
Definition: Constants.cs:389
const string OrgDepartment
Organization Department
Definition: Constants.cs:394
const string Address2
Address line 2
Definition: Constants.cs:294
const string OrgAddress
Organization Address line 1
Definition: Constants.cs:359
const string Address
Address line 1
Definition: Constants.cs:289
const string LastNames
Last names
Definition: Constants.cs:279
const string OrgNumber
Organization number
Definition: Constants.cs:354
const string BirthMonth
Birth Month
Definition: Constants.cs:339
const string FirstName
First name
Definition: Constants.cs:269
const string OrgName
Organization name
Definition: Constants.cs:349
A set of never changing property constants and helpful values.
Definition: Constants.cs:7
const string NotAvailableValue
A generic "no value available" string.
Definition: Constants.cs:11
Contains information about a contact.
Definition: ContactInfo.cs:21
static async Task< string > GetFriendlyName(CaseInsensitiveString RemoteId)
Gets the friendly name of a remote identity (Legal ID or Bare JID).
Definition: ContactInfo.cs:257
LegalIdentity? LegalIdentity
Legal Identity object.
Definition: ContactInfo.cs:81
static string GetFullName(LegalIdentity? Identity)
Gets the full name of a person.
Definition: ContactInfo.cs:577
static Task< ContactInfo > FindByBareJid(string BareJid)
Finds information about a contact, given its Bare JID.
Definition: ContactInfo.cs:220
CaseInsensitiveString LegalId
Legal ID of contact.
Definition: ContactInfo.cs:71
Conversion between Country Names and ISO-3166-1 country codes.
Definition: ISO_3166_1.cs:10
static bool TryGetCountryByCode(string? CountryCode, [NotNullWhen(true)] out ISO_3166_Country? Country)
Tries to get the country, given its country code.
Definition: ISO_3166_1.cs:71
Static class containing ISO 5218 gender codes
Definition: ISO_5218.cs:9
static bool LetterToGender(string Letter, out ISO_5218_Gender? Gender)
Tries to get the gender label corresponding to an ISO 5218 gender code.
Definition: ISO_5218.cs:40
Base class that references services in the app.
Definition: ServiceRef.cs:31
static ILogService LogService
Log service.
Definition: ServiceRef.cs:91
static INetworkService NetworkService
Network service.
Definition: ServiceRef.cs:103
static IUiService UiService
Service serializing and managing UI-related tasks.
Definition: ServiceRef.cs:55
static ITagProfile TagProfile
TAG Profile service.
Definition: ServiceRef.cs:79
static IStringLocalizer Localizer
Localization service
Definition: ServiceRef.cs:235
static IXmppService XmppService
The XMPP service for XMPP communication.
Definition: ServiceRef.cs:67
The view model to bind to when displaying petitioning of an identity in a view or page.
string PeerReviewConfirmCorrectText
Instruction to reviewer when confirming reviewed information is correct.
override async Task OnDispose()
Method called when the view is disposed, and will not be used more. Use this method to unregister eve...
override async Task OnInitialize()
Method called when view is initialized for the first time. Use this method to implement registration ...
string PeerReviewAuthenticationText
Instruction to reviewer when accepting peer review.
void AddView(ReviewStep Step, BaseContentView View)
Adds a view to the wizard dialog.
PetitionPeerReviewViewModel(PetitionPeerReviewNavigationArgs? Args)
Creates a new instance of the PetitionPeerReviewViewModel class.
override async Task GoBack()
Method called when user wants to navigate to the previous screen.
override Task XmppService_ConnectionStateChanged(object? Sender, XmppState NewState)
Listens to connection state changes from the XMPP server.
ObservableCollection< Photo > Photos
The list of photos related to the identity being petitioned.
A view model that holds the XMPP state.
Contains a reference to an attachment assigned to a legal object.
Definition: Attachment.cs:9
Abstract base class of signatures
Definition: Signature.cs:10
Manages an XMPP client connection. Implements XMPP, as defined in https://tools.ietf....
Definition: XmppClient.cs:59
static string GetBareJID(string JID)
Gets the Bare JID from a JID, which may be a Full JID.
Definition: XmppClient.cs:6901
Static interface for database persistence. In order to work, a database provider has to be assigned t...
Definition: Database.cs:19
static IDatabaseProvider Provider
Registered database provider.
Definition: Database.cs:57
static async Task Update(object Object)
Updates an object in the database.
Definition: Database.cs:626
Task Flush()
Persists any pending changes.
class ISO_3166_Country(string Name, string Alpha2, string Alpha3, int NumericCode, string DialCode, EmojiInfo? EmojiInfo=null)
Representation of an ISO3166-1 Country
class ISO_5218_Gender(string Gender, int Code, string Letter, string LocalizedNameId, char Unicode)
Contains one record of the ISO 5218 data set.
class Photo(byte[] Binary, int Rotation)
Class containing information about a photo.
Definition: Photo.cs:8
ReviewStep
Steps in the peer-review process
Definition: ReviewStep.cs:7
AuthenticationPurpose
Purpose for requesting the user to authenticate itself.
IdentityState
Lists recognized legal identity states.
SignWith
Options on what keys to use when signing data.
Definition: Enumerations.cs:84
XmppState
State of XMPP connection.
Definition: XmppState.cs:7