Skip to content

Commit a143adf

Browse files
committed
gather all notification related stuff in one class
1 parent e76e0a7 commit a143adf

File tree

6 files changed

+28
-43
lines changed

6 files changed

+28
-43
lines changed

Signal-Windows.Lib/Signal-Windows.Lib.csproj

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
<ItemGroup>
109109
<Compile Include="Events\SignalMessageEventArgs.cs" />
110110
<Compile Include="IncomingMessages.cs" />
111-
<Compile Include="LibUtils.cs" />
111+
<Compile Include="Util\LibUtils.cs" />
112112
<Compile Include="Migrations\LibsignalDB\20170806145530_ls1.cs" />
113113
<Compile Include="Migrations\LibsignalDB\20170806145530_ls1.Designer.cs">
114114
<DependentUpon>20170806145530_ls1.cs</DependentUpon>
@@ -156,6 +156,7 @@
156156
<Compile Include="SignalMessageContainer.cs" />
157157
<Compile Include="Storage\DB.cs" />
158158
<Compile Include="Storage\Store.cs" />
159+
<Compile Include="Util\SignalNotificationsUtils.cs" />
159160
<EmbeddedResource Include="Properties\Signal_Windows.Lib.rd.xml" />
160161
</ItemGroup>
161162
<ItemGroup>
@@ -175,7 +176,7 @@
175176
<Version>1.1.4</Version>
176177
</PackageReference>
177178
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
178-
<Version>6.0.1</Version>
179+
<Version>6.0.4</Version>
179180
</PackageReference>
180181
<PackageReference Include="Microsoft.Toolkit.Uwp.Notifications">
181182
<Version>2.1.1</Version>
@@ -184,6 +185,11 @@
184185
<Version>4.4.0</Version>
185186
</PackageReference>
186187
</ItemGroup>
188+
<ItemGroup>
189+
<SDKReference Include="WindowsMobile, Version=10.0.16299.0">
190+
<Name>Windows Mobile Extensions for the UWP</Name>
191+
</SDKReference>
192+
</ItemGroup>
187193
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '14.0' ">
188194
<VisualStudioVersion>14.0</VisualStudioVersion>
189195
</PropertyGroup>

Signal-Windows.Lib/Util/LibUtils.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Text;
99
using System.Threading;
1010
using System.Threading.Tasks;
11+
using Windows.Foundation.Metadata;
1112
using Windows.Networking.BackgroundTransfer;
1213
using Windows.Storage;
1314
using Windows.UI.Core;

Signal-Windows/SignalNotifications.cs renamed to Signal-Windows.Lib/Util/NotificationsUtils.cs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,25 @@
88
using Windows.Foundation.Metadata;
99
using Windows.UI.Notifications;
1010

11-
namespace Signal_Windows
11+
namespace Signal_Windows.Lib
1212
{
13-
class SignalNotifications
13+
public class NotificationsUtils
1414
{
15+
public static void Notify(SignalMessage message)
16+
{
17+
TryVibrate(true);
18+
SendMessageNotification(message);
19+
SendTileNotification(message);
20+
}
21+
22+
public static void TryVibrate(bool quick)
23+
{
24+
if (ApiInformation.IsTypePresent("Windows.Phone.Devices.Notification.VibrationDevice"))
25+
{
26+
Windows.Phone.Devices.Notification.VibrationDevice.GetDefault().Vibrate(TimeSpan.FromMilliseconds(quick ? 100 : 500));
27+
}
28+
}
29+
1530
public static void SendMessageNotification(SignalMessage message)
1631
{
1732
// notification tags can only be 16 chars (64 after creators update)
@@ -69,14 +84,6 @@ private static IList<AdaptiveText> GetNotificationText(SignalMessage message)
6984
return text;
7085
}
7186

72-
public static void TryVibrate(bool quick)
73-
{
74-
if (ApiInformation.IsTypePresent("Windows.Phone.Devices.Notification.VibrationDevice"))
75-
{
76-
Windows.Phone.Devices.Notification.VibrationDevice.GetDefault().Vibrate(TimeSpan.FromMilliseconds(quick ? 100 : 500));
77-
}
78-
}
79-
8087
public static void SendTileNotification(SignalMessage message)
8188
{
8289
TileBindingContentAdaptive tileBindingContent = new TileBindingContentAdaptive()

Signal-Windows.RC/SignalBackgroundTask.cs

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -81,33 +81,7 @@ private void Handle_SignalMessageEvent(object sender, SignalMessageEventArgs e)
8181
{
8282
if (e.MessageType == Lib.Events.SignalMessageType.NormalMessage)
8383
{
84-
string notificationId = e.Message.ThreadId;
85-
ToastBindingGeneric toastBinding = new ToastBindingGeneric();
86-
87-
var notificationText = GetNotificationText(e.Message.Author.ThreadDisplayName, e.Message.Content.Content);
88-
foreach (var item in notificationText)
89-
{
90-
toastBinding.Children.Add(item);
91-
}
92-
93-
ToastContent toastContent = new ToastContent()
94-
{
95-
Launch = notificationId,
96-
Visual = new ToastVisual()
97-
{
98-
BindingGeneric = toastBinding
99-
},
100-
DisplayTimestamp = DateTimeOffset.FromUnixTimeMilliseconds(e.Message.ReceivedTimestamp)
101-
};
102-
103-
ToastNotification toastNotification = new ToastNotification(toastContent.GetXml());
104-
uint expiresIn = e.Message.ExpiresAt;
105-
if (expiresIn > 0)
106-
{
107-
toastNotification.ExpirationTime = DateTime.Now.Add(TimeSpan.FromSeconds(expiresIn));
108-
}
109-
toastNotification.Tag = notificationId;
110-
ToastNotifier.Show(toastNotification);
84+
NotificationsUtils.Notify(e.Message);
11185
}
11286
else if (e.MessageType == Lib.Events.SignalMessageType.PipeEmptyMessage)
11387
{

Signal-Windows/Signal-Windows.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,6 @@
168168
<Compile Include="Controls\Welcome.xaml.cs">
169169
<DependentUpon>Welcome.xaml</DependentUpon>
170170
</Compile>
171-
<Compile Include="SignalNotifications.cs" />
172171
<Compile Include="SignalWindowsFrontend.cs" />
173172
<Compile Include="Utils.cs" />
174173
<Compile Include="ViewModels\AddContactPageViewModel.cs" />

Signal-Windows/SignalWindowsFrontend.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,7 @@ public void HandleUnreadMessage(SignalMessage message)
8686
{
8787
if (message.Author != null)
8888
{
89-
SignalNotifications.TryVibrate(true);
90-
SignalNotifications.SendMessageNotification(message);
91-
SignalNotifications.SendTileNotification(message);
89+
NotificationsUtils.Notify(message);
9290
}
9391
}
9492
}

0 commit comments

Comments
 (0)