diff --git a/Data_Manager2/Classes/Toast/ToastHelper.cs b/Data_Manager2/Classes/Toast/ToastHelper.cs index a58a3f0d4..e18aebaea 100644 --- a/Data_Manager2/Classes/Toast/ToastHelper.cs +++ b/Data_Manager2/Classes/Toast/ToastHelper.cs @@ -5,7 +5,6 @@ using Microsoft.Toolkit.Uwp.Notifications; using Shared.Classes; using Windows.Data.Xml.Dom; -using Windows.Phone.Devices.Notification; using Windows.UI.Notifications; namespace Data_Manager2.Classes.Toast @@ -230,7 +229,7 @@ private static void popToastReduced() // Vibrate: if (DeviceFamilyHelper.SupportsVibration() && !Settings.getSettingBoolean(SettingsConsts.DISABLE_VIBRATION_FOR_NEW_CHAT_MESSAGES)) { - VibrationDevice.GetDefault().Vibrate(VIBRATE_TS); + SharedUtils.VibratePress(VIBRATE_TS); } // Play sound: diff --git a/Shared/Classes/SharedUtils.cs b/Shared/Classes/SharedUtils.cs index 72beee7ae..963b30752 100644 --- a/Shared/Classes/SharedUtils.cs +++ b/Shared/Classes/SharedUtils.cs @@ -4,6 +4,7 @@ using Windows.ApplicationModel.Core; using Windows.Media.Core; using Windows.Media.Playback; +using Windows.Phone.Devices.Notification; using Windows.UI.Core; namespace Shared.Classes @@ -89,7 +90,7 @@ public static void RetryOnException(Action action, int retryCount) /// The return value of the given function. public static T RetryOnException(Func funct) { - return RetryOnException(funct, 1); + return RetryOnException(funct, 1); } /// @@ -137,6 +138,19 @@ public static MediaPlayer PlaySoundFromUri(string uri) return player; } + /// + /// Vibrates the device for the given timespan if the device supports phone vibration. + /// + /// How long should the vibration persist. Max 5 seconds. + public static void VibratePress(TimeSpan duration) + { + if (DeviceFamilyHelper.SupportsVibration()) + { + VibrationDevice.GetDefault().Vibrate(duration); + } + Logger.Debug("Vibration not supported."); + } + #endregion #region --Misc Methods (Private)-- diff --git a/Shared/Shared.csproj b/Shared/Shared.csproj index 0742676bb..180a7a003 100644 --- a/Shared/Shared.csproj +++ b/Shared/Shared.csproj @@ -166,6 +166,11 @@ Logging + + + Windows Mobile Extensions for the UWP + + 14.0 diff --git a/UWPX_UI/Controls/OMEMO/OmemoTrustFingerprintControl.xaml b/UWPX_UI/Controls/OMEMO/OmemoTrustFingerprintControl.xaml index 96c5910b2..a348f6a1b 100644 --- a/UWPX_UI/Controls/OMEMO/OmemoTrustFingerprintControl.xaml +++ b/UWPX_UI/Controls/OMEMO/OmemoTrustFingerprintControl.xaml @@ -25,7 +25,7 @@ - /// TODO: Not done yet. + /// [WIP] + /// Parses XMPP IRIs and URIs based on RFC 5122 and returns the result. /// - /// - /// - public static AbstractUriAction parse(Uri uri) + /// The URI or IRI that should get parsed. + /// The URI or IRI result or null if an error occurred. + public static IUriAction parse(Uri uri) { if (!string.IsNullOrEmpty(uri?.OriginalString)) { - string tmp = uri.OriginalString; - - // 1. 'xmpp:' - if (tmp.StartsWith("xmpp:")) + if (string.Equals(uri.Scheme.ToLowerInvariant(), "xmpp")) { + string tmp = uri.OriginalString; + + // 1. remove 'xmpp:' tmp = tmp.Substring(5); // 2. Authority @@ -124,11 +129,37 @@ public static AbstractUriAction parse(Uri uri) } } - // 3. + // Check if is OMEMO fingerprint URI: + WwwFormUrlDecoder query = parseUriQuery(uri); + IWwwFormUrlDecoderEntry entry = query.FirstOrDefault(x => x.Name.StartsWith("omemo-sid-")); + if (!(entry is null)) + { + ECPublicKey pubKey = null; + try + { + byte[] fingerprintBytes = CryptoUtils.hexStringToByteArray(entry.Value); + pubKey = Curve.decodePoint(fingerprintBytes, 0); + } + catch (Exception e) + { + Logger.Error("Failed to parse XMPP URI. Parsing fingerprint failed: " + entry.Value, e); + return null; + } + + if (uint.TryParse(entry.Name.Replace("omemo-sid-", "").Trim(), out uint deviceId)) + { + SignalProtocolAddress address = new SignalProtocolAddress(uri.LocalPath, deviceId); + return new OmemoFingerprintUriAction(new OmemoFingerprint(pubKey, address)); + } + else + { + Logger.Warn("Failed to parse XMPP URI. Invalid device ID: " + entry.Name); + } + } } else { - Logger.Warn("Unable to parse XMPP URI - 'xmpp:' missing."); + Logger.Warn("Failed to parse XMPP URI. No 'xmpp' scheme."); } } return null; diff --git a/XMPP_API/XMPP_API.csproj b/XMPP_API/XMPP_API.csproj index cfcdc0299..154a728d2 100644 --- a/XMPP_API/XMPP_API.csproj +++ b/XMPP_API/XMPP_API.csproj @@ -339,8 +339,9 @@ + - +