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;
10using System.Collections.ObjectModel;
14
16{
21 {
22 private readonly IAuthenticationService authenticationService = ServiceRef.Provider.GetRequiredService<IAuthenticationService>();
23
24 private readonly PhotosLoader photosLoader;
25 private readonly string? requestorFullJid;
26 private readonly string? requestedIdentityId;
27 private readonly string? petitionId;
28 private readonly string? bareJid;
29
34 public PetitionPeerReviewViewModel(PetitionPeerReviewNavigationArgs? Args)
35 {
36 this.photosLoader = new PhotosLoader(this.Photos);
37
38 if (Args is not null)
39 {
40 this.RequestorIdentity = Args.RequestorIdentity;
41 this.requestorFullJid = Args.RequestorFullJid;
42 this.requestedIdentityId = Args.RequestedIdentityId;
43 this.petitionId = Args.PetitionId;
44 this.Purpose = Args.Purpose;
45 this.ContentToSign = Args.ContentToSign;
46
47 if (!string.IsNullOrEmpty(this.requestorFullJid))
48 this.bareJid = XmppClient.GetBareJID(this.requestorFullJid);
49 else if (Args.RequestorIdentity is not null)
50 this.bareJid = Args.RequestorIdentity.GetJid();
51 else
52 this.bareJid = string.Empty;
53 }
54 }
55
59 public void AddView(ReviewStep Step, BaseContentView View)
60 {
61 View.BindingContext = this;
62 this.stepViews[Step] = View;
63 }
64
68 [ObservableProperty]
69 private ReviewStep currentStep = ReviewStep.Photo;
70
74 private readonly SortedDictionary<ReviewStep, BaseContentView> stepViews = [];
75
77 public override async Task OnInitializeAsync()
78 {
79 await base.OnInitializeAsync();
80
81 if (!string.IsNullOrEmpty(this.bareJid))
82 {
83 ContactInfo Info = await ContactInfo.FindByBareJid(this.bareJid);
84
85 if (this.RequestorIdentity is not null &&
86 Info is not null &&
87 (Info.LegalIdentity is null || (
88 Info.LegalId != this.RequestorIdentity?.Id &&
89 Info.LegalIdentity is not null &&
90 Info.LegalIdentity.Created < this.RequestorIdentity!.Created &&
91 this.RequestorIdentity.State == IdentityState.Approved)))
92 {
93 Info.LegalId = this.LegalId;
94 Info.LegalIdentity = this.RequestorIdentity;
95 Info.FriendlyName = ContactInfo.GetFriendlyName(this.RequestorIdentity);
96
97 await Database.Update(Info);
98 await Database.Provider.Flush();
99 }
100
101 this.ThirdPartyInContacts = Info is not null;
102 }
103
104 this.AssignProperties();
105 this.NotifyCommandsCanExecuteChanged();
106
107 this.ReloadPhotos();
108 }
109
110 private async void ReloadPhotos()
111 {
112 try
113 {
114 this.photosLoader.CancelLoadPhotos();
115
116 Attachment[]? Attachments = this.RequestorIdentity?.Attachments;
117 Photo? First;
118
119 if (Attachments is not null)
120 {
121 First = await this.photosLoader.LoadPhotos(Attachments, SignWith.LatestApprovedId);
122
123 this.FirstPhotoSource = First?.Source;
124 this.FirstPhotoRotation = First?.Rotation ?? 0;
125 }
126
127 Attachments = ServiceRef.TagProfile.LegalIdentity?.Attachments;
128
129 if (Attachments is not null)
130 {
131 First = await this.photosLoader.LoadPhotos(Attachments, SignWith.LatestApprovedId);
132
133 this.MyFirstPhotoSource = First?.Source;
134 this.MyFirstPhotoRotation = First?.Rotation ?? 0;
135 }
136 }
137 catch (Exception ex)
138 {
139 ServiceRef.LogService.LogException(ex);
140 }
141 }
142
144 public override async Task OnDisposeAsync()
145 {
146 this.photosLoader.CancelLoadPhotos();
147
148 await base.OnDisposeAsync();
149 }
150
154 public ObservableCollection<Photo> Photos { get; } = [];
155
159 public LegalIdentity? RequestorIdentity { get; private set; }
160
162 protected override Task XmppService_ConnectionStateChanged(object? Sender, XmppState NewState)
163 {
164 return MainThread.InvokeOnMainThreadAsync(async () =>
165 {
166 await base.XmppService_ConnectionStateChanged(Sender, NewState);
167
168 this.NotifyCommandsCanExecuteChanged();
169 });
170 }
171
172 public override void SetIsBusy(bool IsBusy)
173 {
174 base.SetIsBusy(IsBusy);
175 this.NotifyCommandsCanExecuteChanged();
176 }
177
178 private void NotifyCommandsCanExecuteChanged()
179 {
180 this.AcceptCommand.NotifyCanExecuteChanged();
181 this.DeclineCommand.NotifyCanExecuteChanged();
182 this.AuthenticateReviewerCommand.NotifyCanExecuteChanged();
183 }
184
188 public bool CanAccept
189 {
190 get
191 {
192 if (!this.IsConnected || this.IsBusy || this.ContentToSign is null)
193 return false;
194
195 if (this.HasPhoto && !this.IsPhotoOk)
196 return false;
197
198 if (this.HasName && !this.IsNameOk)
199 return false;
200
201 if (this.HasPersonalNumber && !this.IsPnrOk)
202 return false;
203
204 if (this.HasNationality && !this.IsNationalityOk)
205 return false;
206
207 if (this.HasBirthDate && !this.IsBirthDateOk)
208 return false;
209
210 if (this.HasGender && !this.IsGenderOk)
211 return false;
212
213 if (this.HasPersonalAddressInfo && !this.IsPersonalAddressInfoOk)
214 return false;
215
216 if (this.HasOrganizationalInfo && !this.IsOrganizationalInfoOk)
217 return false;
218
219 if (!this.AcknowledgeResponsibility || !this.ConsentProcessing || !this.ConfirmCorrect)
220 return false;
221
222 return true;
223 }
224 }
225
226 [RelayCommand(CanExecute = nameof(CanAccept))]
227 private Task Accept()
228 {
229 return this.Accept(true);
230 }
231
232 private async Task Accept(bool GoBackIfOk)
233 {
234 if (this.ContentToSign is null || !await this.authenticationService.AuthenticateUserAsync(AuthenticationPurpose.AcceptPeerReview))
235 return;
236
237 bool Succeeded = await ServiceRef.NetworkService.TryRequest(async () =>
238 {
239 byte[] Signature = await ServiceRef.XmppService.Sign(this.ContentToSign!, SignWith.LatestApprovedId);
240
241 await ServiceRef.XmppService.SendPetitionSignatureResponse(this.requestedIdentityId, this.ContentToSign, Signature,
242 this.petitionId!, this.requestorFullJid!, true);
243 });
244
245 if (Succeeded && GoBackIfOk)
246 await base.GoBack();
247 }
248
252 public bool CanDecline => this.IsConnected && !this.IsBusy && this.ContentToSign is not null;
253
254 [RelayCommand(CanExecute = nameof(CanDecline))]
255 private Task Decline()
256 {
257 return this.Decline(true);
258 }
259
260 private async Task Decline(bool GoBackIfOk)
261 {
262 if (this.ContentToSign is null || !await this.authenticationService.AuthenticateUserAsync(AuthenticationPurpose.DeclinePeerReview))
263 return;
264
265 bool Succeeded = await ServiceRef.NetworkService.TryRequest(async () =>
266 {
267 byte[] Signature = await ServiceRef.XmppService.Sign(this.ContentToSign!, SignWith.LatestApprovedId);
268
269 await ServiceRef.XmppService.SendPetitionSignatureResponse(this.requestedIdentityId, this.ContentToSign, Signature,
270 this.petitionId!, this.requestorFullJid!, false);
271 });
272
273 if (Succeeded && GoBackIfOk)
274 await base.GoBack();
275 }
276
277 [RelayCommand]
278 private async Task Ignore()
279 {
280 await base.GoBack();
281 }
282
283 [RelayCommand(CanExecute = nameof(IsPhotoOk))]
284 private void AcceptPhoto()
285 {
286 if (this.IsPhotoOk)
287 this.NextPage();
288 }
289
290 [RelayCommand(CanExecute = nameof(IsNameOk))]
291 private void AcceptName()
292 {
293 if (this.IsNameOk)
294 this.NextPage();
295 }
296
297 [RelayCommand(CanExecute = nameof(IsPnrOk))]
298 private void AcceptPnr()
299 {
300 if (this.IsPnrOk)
301 this.NextPage();
302 }
303
304 [RelayCommand(CanExecute = nameof(IsNationalityOk))]
305 private void AcceptNationality()
306 {
307 if (this.IsNationalityOk)
308 this.NextPage();
309 }
310
311 [RelayCommand(CanExecute = nameof(IsBirthDateOk))]
312 private void AcceptBirthDate()
313 {
314 if (this.IsBirthDateOk)
315 this.NextPage();
316 }
317
318 [RelayCommand(CanExecute = nameof(IsGenderOk))]
319 private void AcceptGender()
320 {
321 if (this.IsGenderOk)
322 this.NextPage();
323 }
324
325 [RelayCommand(CanExecute = nameof(IsPersonalAddressInfoOk))]
326 private void AcceptPersonalAddressInfo()
327 {
328 if (this.IsPersonalAddressInfoOk)
329 this.NextPage();
330 }
331
332 [RelayCommand(CanExecute = nameof(IsOrganizationalInfoOk))]
333 private void AcceptOrganizationalInfo()
334 {
335 if (this.IsOrganizationalInfoOk)
336 this.NextPage();
337 }
338
339 [RelayCommand(CanExecute = nameof(IsConsentOk))]
340 private void AcceptConsent()
341 {
342 if (this.IsConsentOk)
343 this.NextPage();
344 }
345
346 private void NextPage()
347 {
348 ReviewStep Current = this.CurrentStep;
349 bool IsVisible;
350
351 do
352 {
353 Current++;
354 IsVisible = Current switch
355 {
356 ReviewStep.Photo => this.HasPhoto,
357 ReviewStep.Name => this.HasName,
358 ReviewStep.Pnr => this.HasPersonalNumber,
359 ReviewStep.Nationality => this.HasNationality,
360 ReviewStep.BirthDate => this.HasBirthDate,
361 ReviewStep.Gender => this.HasGender,
362 ReviewStep.PersonalAddressInfo => this.HasPersonalAddressInfo,
363 ReviewStep.OrganizationalInfo => this.HasOrganizationalInfo,
364 _ => true,
365 };
366 }
367 while (!IsVisible);
368
369 this.CurrentStep = Current;
370 }
371
372 private bool PrevPage()
373 {
374 ReviewStep Current = this.CurrentStep;
375 bool IsVisible;
376
377 do
378 {
379 if (Current == 0)
380 return false;
381
382 Current--;
383 IsVisible = Current switch
384 {
385 ReviewStep.Photo => this.HasPhoto,
386 ReviewStep.Name => this.HasName,
387 ReviewStep.Pnr => this.HasPersonalNumber,
388 ReviewStep.Nationality => this.HasNationality,
389 ReviewStep.BirthDate => this.HasBirthDate,
390 ReviewStep.Gender => this.HasGender,
391 ReviewStep.PersonalAddressInfo => this.HasPersonalAddressInfo,
392 ReviewStep.OrganizationalInfo => this.HasOrganizationalInfo,
393 _ => true,
394 };
395 }
396 while (!IsVisible);
397
398 this.CurrentStep = Current;
399
400 return true;
401 }
402
406 public bool HasPhoto => this.FirstPhotoSource is not null;
407
411 public bool HasName => !string.IsNullOrEmpty(this.FullName);
412
416 public bool HasPersonalNumber => !string.IsNullOrEmpty(this.PersonalNumber);
417
421 public bool HasNationality => !string.IsNullOrEmpty(this.NationalityCode);
422
426 public bool HasBirthDate => this.BirthDate is not null;
427
431 public bool HasGender => !string.IsNullOrEmpty(this.Gender);
432
437 {
438 get
439 {
440 return
441 !string.IsNullOrEmpty(this.Address) ||
442 !string.IsNullOrEmpty(this.Address2) ||
443 !string.IsNullOrEmpty(this.Area) ||
444 !string.IsNullOrEmpty(this.City) ||
445 !string.IsNullOrEmpty(this.Region) ||
446 !string.IsNullOrEmpty(this.CountryCode);
447 }
448 }
449
454 {
455 get
456 {
457 return
458 !string.IsNullOrEmpty(this.OrgName) ||
459 !string.IsNullOrEmpty(this.OrgNumber) ||
460 !string.IsNullOrEmpty(this.OrgDepartment) ||
461 !string.IsNullOrEmpty(this.OrgRole) ||
462 !string.IsNullOrEmpty(this.OrgAddress) ||
463 !string.IsNullOrEmpty(this.OrgAddress2) ||
464 !string.IsNullOrEmpty(this.OrgArea) ||
465 !string.IsNullOrEmpty(this.OrgCity) ||
466 !string.IsNullOrEmpty(this.OrgRegion) ||
467 !string.IsNullOrEmpty(this.OrgCountryCode);
468 }
469 }
470
471 #region Properties
472
476 [ObservableProperty]
477 private DateTime created;
478
482 [ObservableProperty]
483 private DateTime? updated;
484
488 [ObservableProperty]
489 private string? legalId;
490
494 [ObservableProperty]
495 private IdentityState state;
496
500 [ObservableProperty]
501 private DateTime? from;
502
506 [ObservableProperty]
507 private DateTime? to;
508
512 [ObservableProperty]
513 [NotifyPropertyChangedFor(nameof(FullName))]
514 [NotifyPropertyChangedFor(nameof(PhotoReviewText))]
515 [NotifyPropertyChangedFor(nameof(PeerReviewConfirmCorrectText))]
516 [NotifyPropertyChangedFor(nameof(PeerReviewAuthenticationText))]
517 [NotifyPropertyChangedFor(nameof(ReviewApproved))]
518 private string? firstName;
519
523 [ObservableProperty]
524 [NotifyPropertyChangedFor(nameof(FullName))]
525 [NotifyPropertyChangedFor(nameof(PhotoReviewText))]
526 [NotifyPropertyChangedFor(nameof(PeerReviewConfirmCorrectText))]
527 [NotifyPropertyChangedFor(nameof(PeerReviewAuthenticationText))]
528 [NotifyPropertyChangedFor(nameof(ReviewApproved))]
529 private string? middleNames;
530
534 [ObservableProperty]
535 [NotifyPropertyChangedFor(nameof(FullName))]
536 [NotifyPropertyChangedFor(nameof(PhotoReviewText))]
537 [NotifyPropertyChangedFor(nameof(PeerReviewConfirmCorrectText))]
538 [NotifyPropertyChangedFor(nameof(PeerReviewAuthenticationText))]
539 [NotifyPropertyChangedFor(nameof(ReviewApproved))]
540 private string? lastNames;
541
545 [ObservableProperty]
546 [NotifyPropertyChangedFor(nameof(PersonalNumberWithFlag))]
547 private string? personalNumber;
548
553 {
554 get
555 {
556 if (string.IsNullOrEmpty(this.CountryCode) ||
557 !ISO_3166_1.TryGetCountryByCode(this.CountryCode, out ISO_3166_Country? Country) ||
558 Country is null)
559 {
560 return this.PersonalNumber;
561 }
562
563 return Country.EmojiInfo.Unicode + "\t" + this.PersonalNumber;
564 }
565 }
566
570 [System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1822:Mark members as static",
571 Justification = "Must be instance property for view binding to work.")]
573 {
574 get
575 {
576 if (ServiceRef.TagProfile.LegalIdentity is null)
577 return null;
578
579 string? MyCountryCode = ServiceRef.TagProfile.LegalIdentity[Constants.XmppProperties.Country];
580 string? MyPersonalNumber = ServiceRef.TagProfile.LegalIdentity[Constants.XmppProperties.PersonalNumber];
581
582 if (string.IsNullOrEmpty(MyCountryCode) ||
583 !ISO_3166_1.TryGetCountryByCode(MyCountryCode, out ISO_3166_Country? MyCountry) ||
584 MyCountry is null)
585 {
586 return MyPersonalNumber;
587 }
588
589 return MyCountry.EmojiInfo.Unicode + "\t" + MyPersonalNumber;
590 }
591 }
592
596 [ObservableProperty]
597 private string? address;
598
602 [ObservableProperty]
603 private string? address2;
604
608 [ObservableProperty]
609 private string? zipCode;
610
614 [ObservableProperty]
615 private string? area;
616
620 [ObservableProperty]
621 private string? city;
622
626 [ObservableProperty]
627 private string? region;
628
632 [ObservableProperty]
633 [NotifyPropertyChangedFor(nameof(PersonalNumberWithFlag))]
634 private string? countryCode;
635
639 [ObservableProperty]
640 [NotifyPropertyChangedFor(nameof(NationalityWithFlag))]
641 private string? nationalityCode;
642
646 public string? NationalityWithFlag
647 {
648 get
649 {
650 if (string.IsNullOrEmpty(this.NationalityCode) ||
651 !ISO_3166_1.TryGetCountryByCode(this.NationalityCode, out ISO_3166_Country? Country) ||
652 Country is null)
653 {
654 return this.NationalityCode;
655 }
656
657 return Country.EmojiInfo.Unicode + "\t" + Country.Name;
658 }
659 }
660
664 [ObservableProperty]
665 [NotifyPropertyChangedFor(nameof(GenderWithSymbol))]
666 private string? gender;
667
671 public string? GenderWithSymbol
672 {
673 get
674 {
675 if (string.IsNullOrEmpty(this.Gender) ||
676 !ISO_5218.LetterToGender(this.Gender, out ISO_5218_Gender? Gender) ||
677 Gender is null)
678 {
679 return this.Gender;
680 }
681
682 return Gender.Unicode + "\t" + ServiceRef.Localizer[Gender.LocalizedNameId];
683 }
684 }
685
689 [ObservableProperty]
690 private DateTime? birthDate;
691
695 [ObservableProperty]
696 private string? orgName;
697
701 [ObservableProperty]
702 private string? orgNumber;
703
707 [ObservableProperty]
708 private string? orgDepartment;
709
713 [ObservableProperty]
714 private string? orgRole;
715
719 [ObservableProperty]
720 private string? orgAddress;
721
725 [ObservableProperty]
726 private string? orgAddress2;
727
731 [ObservableProperty]
732 private string? orgZipCode;
733
737 [ObservableProperty]
738 private string? orgArea;
739
743 [ObservableProperty]
744 private string? orgCity;
745
749 [ObservableProperty]
750 private string? orgRegion;
751
755 [ObservableProperty]
756 private string? orgCountryCode;
757
761 [ObservableProperty]
762 [NotifyPropertyChangedFor(nameof(OrgRowHeight))]
763 private bool hasOrg;
764
768 public GridLength OrgRowHeight => this.HasOrg ? GridLength.Auto : new GridLength(0, GridUnitType.Absolute);
769
773 [ObservableProperty]
774 private string? phoneNr;
775
779 [ObservableProperty]
780 private string? eMail;
781
785 [ObservableProperty]
786 private string? deviceId;
787
791 [ObservableProperty]
792 private bool isApproved;
793
797 [ObservableProperty]
798 private string? purpose;
799
803 [ObservableProperty]
804 private byte[]? contentToSign;
805
809 [ObservableProperty]
810 private bool thirdPartyInContacts;
811
815 [ObservableProperty]
816 private ImageSource? firstPhotoSource;
817
821 [ObservableProperty]
822 private int firstPhotoRotation;
823
827 [ObservableProperty]
828 private ImageSource? myFirstPhotoSource;
829
833 [ObservableProperty]
834 private int myFirstPhotoRotation;
835
836 // Full name of requesting entity.
837 public string FullName => ContactInfo.GetFullName(this.FirstName, this.MiddleNames, this.LastNames);
838
839 // Full name of reviewer.
840 [System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1822:Mark members as static",
841 Justification = "Must be instance property for view binding to work.")]
842 public string MyFullName => ContactInfo.GetFullName(ServiceRef.TagProfile.LegalIdentity);
843
847 [ObservableProperty]
848 [NotifyCanExecuteChangedFor(nameof(AcceptPhotoCommand))]
849 private bool isPhotoOk;
850
854 [ObservableProperty]
855 [NotifyCanExecuteChangedFor(nameof(AcceptNameCommand))]
856 private bool isNameOk;
857
861 [ObservableProperty]
862 [NotifyCanExecuteChangedFor(nameof(AcceptPnrCommand))]
863 private bool isPnrOk;
864
868 [ObservableProperty]
869 [NotifyCanExecuteChangedFor(nameof(AcceptNationalityCommand))]
870 private bool isNationalityOk;
871
875 [ObservableProperty]
876 [NotifyCanExecuteChangedFor(nameof(AcceptBirthDateCommand))]
877 private bool isBirthDateOk;
878
882 [ObservableProperty]
883 [NotifyCanExecuteChangedFor(nameof(AcceptGenderCommand))]
884 private bool isGenderOk;
885
889 [ObservableProperty]
890 [NotifyCanExecuteChangedFor(nameof(AcceptPersonalAddressInfoCommand))]
891 private bool isPersonalAddressInfoOk;
892
896 [ObservableProperty]
897 [NotifyCanExecuteChangedFor(nameof(AcceptOrganizationalInfoCommand))]
898 private bool isOrganizationalInfoOk;
899
903 [ObservableProperty]
904 [NotifyCanExecuteChangedFor(nameof(AcceptConsentCommand))]
905 [NotifyPropertyChangedFor(nameof(IsConsentOk))]
906 private bool acknowledgeResponsibility;
907
911 [ObservableProperty]
912 [NotifyCanExecuteChangedFor(nameof(AcceptConsentCommand))]
913 [NotifyPropertyChangedFor(nameof(IsConsentOk))]
914 private bool consentProcessing;
915
919 [ObservableProperty]
920 [NotifyCanExecuteChangedFor(nameof(AcceptConsentCommand))]
921 [NotifyPropertyChangedFor(nameof(IsConsentOk))]
922 private bool confirmCorrect;
923
927 [ObservableProperty]
928 private bool showDetails;
929
933 public bool IsConsentOk => this.AcknowledgeResponsibility && this.ConsentProcessing && this.ConfirmCorrect;
934
938 public string PhotoReviewText => ServiceRef.Localizer[nameof(AppResources.PeerReviewPhotoText), this.FullName];
939
944
949
953 public string ReviewApproved => ServiceRef.Localizer[nameof(AppResources.ReviewApproved), this.FullName];
954
958 [RelayCommand]
959 public void ToggleIsPhotoOk()
960 {
961 this.IsPhotoOk = !this.IsPhotoOk;
962 }
963
967 [RelayCommand]
968 public void ToggleIsNameOk()
969 {
970 this.IsNameOk = !this.IsNameOk;
971 }
972
976 [RelayCommand]
977 public void ToggleIsPnrOk()
978 {
979 this.IsPnrOk = !this.IsPnrOk;
980 }
981
985 [RelayCommand]
987 {
988 this.IsNationalityOk = !this.IsNationalityOk;
989 }
990
994 [RelayCommand]
996 {
997 this.IsBirthDateOk = !this.IsBirthDateOk;
998 }
999
1003 [RelayCommand]
1004 public void ToggleIsGenderOk()
1005 {
1006 this.IsGenderOk = !this.IsGenderOk;
1007 }
1008
1012 [RelayCommand]
1014 {
1015 this.IsPersonalAddressInfoOk = !this.IsPersonalAddressInfoOk;
1016 }
1017
1021 [RelayCommand]
1023 {
1024 this.IsOrganizationalInfoOk = !this.IsOrganizationalInfoOk;
1025 }
1026
1030 [RelayCommand]
1032 {
1033 this.AcknowledgeResponsibility = !this.AcknowledgeResponsibility;
1034 }
1035
1039 [RelayCommand]
1041 {
1042 this.ConsentProcessing = !this.ConsentProcessing;
1043 }
1044
1048 [RelayCommand]
1050 {
1051 this.ConfirmCorrect = !this.ConfirmCorrect;
1052 }
1053
1057 [RelayCommand]
1058 public void ToggleShowDetails()
1059 {
1060 this.ShowDetails = !this.ShowDetails;
1061 }
1062
1063 #endregion
1064
1065 private void AssignProperties()
1066 {
1067 if (this.RequestorIdentity is not null)
1068 {
1069 this.Created = this.RequestorIdentity.Created;
1070 this.Updated = this.RequestorIdentity.Updated.GetDateOrNullIfMinValue();
1071 this.LegalId = this.RequestorIdentity.Id;
1072 this.State = this.RequestorIdentity.State;
1073 this.From = this.RequestorIdentity.From.GetDateOrNullIfMinValue();
1074 this.To = this.RequestorIdentity.To.GetDateOrNullIfMinValue();
1075 this.FirstName = this.RequestorIdentity[Constants.XmppProperties.FirstName];
1076 this.MiddleNames = this.RequestorIdentity[Constants.XmppProperties.MiddleNames];
1077 this.LastNames = this.RequestorIdentity[Constants.XmppProperties.LastNames];
1078 this.PersonalNumber = this.RequestorIdentity[Constants.XmppProperties.PersonalNumber];
1080 this.Address2 = this.RequestorIdentity[Constants.XmppProperties.Address2];
1085 this.CountryCode = this.RequestorIdentity[Constants.XmppProperties.Country];
1086 this.NationalityCode = this.RequestorIdentity[Constants.XmppProperties.Nationality];
1088
1089 string BirthDayStr = this.RequestorIdentity[Constants.XmppProperties.BirthDay];
1090 string BirthMonthStr = this.RequestorIdentity[Constants.XmppProperties.BirthMonth];
1091 string BirthYearStr = this.RequestorIdentity[Constants.XmppProperties.BirthYear];
1092
1093 if (!string.IsNullOrEmpty(BirthDayStr) && int.TryParse(BirthDayStr, out int BirthDay) &&
1094 !string.IsNullOrEmpty(BirthMonthStr) && int.TryParse(BirthMonthStr, out int BirthMonth) &&
1095 !string.IsNullOrEmpty(BirthYearStr) && int.TryParse(BirthYearStr, out int BirthYear))
1096 {
1097 try
1098 {
1099 this.BirthDate = new DateTime(BirthYear, BirthMonth, BirthDay);
1100 }
1101 catch (Exception ex)
1102 {
1103 ServiceRef.LogService.LogException(ex);
1104 this.BirthDate = null;
1105 }
1106 }
1107
1109 this.OrgNumber = this.RequestorIdentity[Constants.XmppProperties.OrgNumber];
1110 this.OrgDepartment = this.RequestorIdentity[Constants.XmppProperties.OrgDepartment];
1112 this.OrgAddress = this.RequestorIdentity[Constants.XmppProperties.OrgAddress];
1113 this.OrgAddress2 = this.RequestorIdentity[Constants.XmppProperties.OrgAddress2];
1114 this.OrgZipCode = this.RequestorIdentity[Constants.XmppProperties.OrgZipCode];
1117 this.OrgRegion = this.RequestorIdentity[Constants.XmppProperties.OrgRegion];
1118 this.OrgCountryCode = this.RequestorIdentity[Constants.XmppProperties.OrgCountry];
1119 this.HasOrg =
1120 !string.IsNullOrEmpty(this.OrgName) ||
1121 !string.IsNullOrEmpty(this.OrgNumber) ||
1122 !string.IsNullOrEmpty(this.OrgDepartment) ||
1123 !string.IsNullOrEmpty(this.OrgRole) ||
1124 !string.IsNullOrEmpty(this.OrgAddress) ||
1125 !string.IsNullOrEmpty(this.OrgAddress2) ||
1126 !string.IsNullOrEmpty(this.OrgZipCode) ||
1127 !string.IsNullOrEmpty(this.OrgArea) ||
1128 !string.IsNullOrEmpty(this.OrgCity) ||
1129 !string.IsNullOrEmpty(this.OrgRegion) ||
1130 !string.IsNullOrEmpty(this.OrgCountryCode);
1131 this.PhoneNr = this.RequestorIdentity[Constants.XmppProperties.Phone];
1133 this.DeviceId = this.RequestorIdentity[Constants.XmppProperties.DeviceId];
1134 this.IsApproved = this.RequestorIdentity.State == IdentityState.Approved;
1135 }
1136 else
1137 {
1138 this.Created = DateTime.MinValue;
1139 this.Updated = null;
1140 this.LegalId = Constants.NotAvailableValue;
1141 this.State = IdentityState.Compromised;
1142 this.From = null;
1143 this.To = null;
1144 this.FirstName = Constants.NotAvailableValue;
1145 this.MiddleNames = Constants.NotAvailableValue;
1146 this.LastNames = Constants.NotAvailableValue;
1147 this.PersonalNumber = Constants.NotAvailableValue;
1148 this.Address = Constants.NotAvailableValue;
1149 this.Address2 = Constants.NotAvailableValue;
1150 this.ZipCode = Constants.NotAvailableValue;
1151 this.Area = Constants.NotAvailableValue;
1152 this.City = Constants.NotAvailableValue;
1153 this.Region = Constants.NotAvailableValue;
1154 this.CountryCode = Constants.NotAvailableValue;
1155 this.NationalityCode = Constants.NotAvailableValue;
1156 this.Gender = Constants.NotAvailableValue;
1157 this.BirthDate = null;
1158 this.OrgName = Constants.NotAvailableValue;
1159 this.OrgNumber = Constants.NotAvailableValue;
1160 this.OrgDepartment = Constants.NotAvailableValue;
1161 this.OrgRole = Constants.NotAvailableValue;
1162 this.OrgAddress = Constants.NotAvailableValue;
1163 this.OrgAddress2 = Constants.NotAvailableValue;
1164 this.OrgZipCode = Constants.NotAvailableValue;
1165 this.OrgArea = Constants.NotAvailableValue;
1166 this.OrgCity = Constants.NotAvailableValue;
1167 this.OrgRegion = Constants.NotAvailableValue;
1168 this.OrgCountryCode = Constants.NotAvailableValue;
1169 this.HasOrg = false;
1170 this.PhoneNr = Constants.NotAvailableValue;
1171 this.EMail = Constants.NotAvailableValue;
1172 this.DeviceId = Constants.NotAvailableValue;
1173 this.IsApproved = false;
1174 }
1175 }
1176
1177 [RelayCommand(CanExecute = nameof(CanAccept))]
1178 private async Task AuthenticateReviewer()
1179 {
1180 try
1181 {
1182 if (await this.authenticationService.AuthenticateUserAsync(AuthenticationPurpose.AuthenticateReviewer, true))
1183 {
1184 await this.Accept(false);
1185 this.NextPage();
1186 }
1187 }
1188 catch (Exception ex)
1189 {
1190 ServiceRef.LogService.LogException(ex);
1191
1192 await ServiceRef.UiService.DisplayAlert(
1195 }
1196 }
1197
1199 public override async Task GoBack()
1200 {
1201 if (!this.PrevPage())
1202 await base.GoBack();
1203 }
1204
1208 [RelayCommand]
1209 public Task Close()
1210 {
1211 return base.GoBack();
1212 }
1213
1214 #region ILinkableView
1215
1219 public override Task<string> Title => Task.FromResult(ContactInfo.GetFriendlyName(this.RequestorIdentity!));
1220
1221 #endregion
1222 }
1223}
const string PersonalNumber
Personal number
Definition: Constants.cs:394
const string OrgAddress2
Organization Address line 2
Definition: Constants.cs:474
const string OrgArea
Organization Area
Definition: Constants.cs:479
const string OrgRegion
Organization Region
Definition: Constants.cs:494
const string Nationality
Nationality
Definition: Constants.cs:434
const string BirthYear
Birth Year
Definition: Constants.cs:454
const string OrgCity
Organization City
Definition: Constants.cs:484
const string OrgRole
Organization Role
Definition: Constants.cs:509
const string Phone
Phone number
Definition: Constants.cs:524
const string EMail
e-Mail address
Definition: Constants.cs:529
const string OrgZipCode
Organization Zip Code
Definition: Constants.cs:489
const string MiddleNames
Middle names
Definition: Constants.cs:379
const string OrgCountry
Organization Country
Definition: Constants.cs:499
const string OrgDepartment
Organization Department
Definition: Constants.cs:504
const string Address2
Address line 2
Definition: Constants.cs:404
const string OrgAddress
Organization Address line 1
Definition: Constants.cs:469
const string Address
Address line 1
Definition: Constants.cs:399
const string LastNames
Last names
Definition: Constants.cs:384
const string OrgNumber
Organization number
Definition: Constants.cs:464
const string BirthMonth
Birth Month
Definition: Constants.cs:449
const string FirstName
First name
Definition: Constants.cs:374
const string OrgName
Organization name
Definition: Constants.cs:459
A set of never changing property constants and helpful values.
Definition: Constants.cs:24
const string NotAvailableValue
A generic "no value available" string.
Definition: Constants.cs:28
A strongly-typed resource class, for looking up localized strings, etc.
static string UnableToSignReview
Looks up a localized string similar to Unable to sign the review..
static string PeerReviewConfirmCorrectText
Looks up a localized string similar to I confirm that the information provided by {0} is correct....
static string PeerReviewPhotoText
Looks up a localized string similar to The photo clearly represents {0}..
static string ReviewApproved
Looks up a localized string similar to You have now approved the information provided by {0}....
static string PeerReviewAuthenticationText
Looks up a localized string similar to By authenticating myself and signing the review,...
static string ErrorTitle
Looks up a localized string similar to An error has occurred.
Contains information about a contact.
Definition: ContactInfo.cs:22
static async Task< string > GetFriendlyName(CaseInsensitiveString RemoteId)
Gets the friendly name of a remote identity (Legal ID or Bare JID).
Definition: ContactInfo.cs:258
LegalIdentity? LegalIdentity
Legal Identity object.
Definition: ContactInfo.cs:82
static string GetFullName(LegalIdentity? Identity)
Gets the full name of a person.
Definition: ContactInfo.cs:578
static Task< ContactInfo > FindByBareJid(string BareJid)
Finds information about a contact, given its Bare JID.
Definition: ContactInfo.cs:221
CaseInsensitiveString LegalId
Legal ID of contact.
Definition: ContactInfo.cs:72
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:43
static IServiceProvider Provider
The service provider for the app. This is set before the app is started, and will be used to resolve ...
Definition: ServiceRef.cs:48
static ILogService LogService
Log service.
Definition: ServiceRef.cs:214
static INetworkService NetworkService
Network service.
Definition: ServiceRef.cs:226
static IUiService UiService
Service serializing and managing UI-related tasks.
Definition: ServiceRef.cs:130
static ITagProfile TagProfile
TAG Profile service.
Definition: ServiceRef.cs:202
static IReportingStringLocalizer Localizer
Localization service
Definition: ServiceRef.cs:370
static IXmppService XmppService
The XMPP service for XMPP communication.
Definition: ServiceRef.cs:190
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.
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 async Task OnDisposeAsync()
Method called when the view is disposed, and will not be used more. Use this method to unregister eve...
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.
override async Task OnInitializeAsync()
Method called when view is initialized for the first time. Use this method to implement registration ...
A view model that holds the XMPP state.
Contains a reference to an attachment assigned to a legal object.
Definition: Attachment.cs:10
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:58
static string GetBareJID(string JID)
Gets the Bare JID from a JID, which may be a Full JID.
Definition: XmppClient.cs:6958
Static interface for database persistence. In order to work, a database provider has to be assigned t...
Definition: Database.cs:21
static IDatabaseProvider Provider
Registered database provider.
Definition: Database.cs:59
static async Task Update(object Object)
Updates an object in the database.
Definition: Database.cs:1211
Task Flush()
Persists any pending changes.
Definition: ImplTypes.g.cs:58
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, Attachment? Attachment)
Class containing information about a photo.
Definition: Photo.cs:10
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:82
Gender
Gender classification in a legal ID.
Definition: Gender.cs:7
XmppState
State of XMPP connection.
Definition: XmppState.cs:7