mirror of
https://github.com/bitwarden/android.git
synced 2024-10-31 07:05:35 +03:00
[PM-7631] Handle new FCMv1 format (#3176)
* handle new FCMv1 format * optimizations * restore formatting * revert formatting * revert formatting --------- Co-authored-by: Kyle Spearrin <kyle.spearrin@gmail.com>
This commit is contained in:
parent
c847449db8
commit
3c1105b35d
1 changed files with 26 additions and 5 deletions
|
@ -1,8 +1,9 @@
|
|||
#if !FDROID
|
||||
#if !FDROID
|
||||
using System;
|
||||
using Android.App;
|
||||
using Bit.App.Abstractions;
|
||||
using Bit.Core.Abstractions;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Services;
|
||||
using Bit.Core.Utilities;
|
||||
using Firebase.Messaging;
|
||||
|
@ -20,7 +21,7 @@ namespace Bit.Droid.Push
|
|||
try {
|
||||
var stateService = ServiceContainer.Resolve<IStateService>("stateService");
|
||||
var pushNotificationService = ServiceContainer.Resolve<IPushNotificationService>("pushNotificationService");
|
||||
|
||||
|
||||
await stateService.SetPushRegisteredTokenAsync(token);
|
||||
await pushNotificationService.RegisterAsync();
|
||||
}
|
||||
|
@ -38,13 +39,33 @@ namespace Bit.Droid.Push
|
|||
{
|
||||
return;
|
||||
}
|
||||
var data = message.Data.ContainsKey("data") ? message.Data["data"] : null;
|
||||
if (data == null)
|
||||
|
||||
JObject obj = null;
|
||||
if (message.Data.TryGetValue("data", out var data))
|
||||
{
|
||||
// Legacy GCM format
|
||||
obj = JObject.Parse(data);
|
||||
}
|
||||
else if (message.Data.TryGetValue("type", out var typeData) &&
|
||||
Enum.TryParse(typeData, out NotificationType type))
|
||||
{
|
||||
// New FCMv1 format
|
||||
obj = new JObject
|
||||
{
|
||||
{ "type", (int)type }
|
||||
};
|
||||
|
||||
if (message.Data.TryGetValue("payload", out var payloadData))
|
||||
{
|
||||
obj.Add("payload", payloadData);
|
||||
}
|
||||
}
|
||||
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var obj = JObject.Parse(data);
|
||||
var listener = ServiceContainer.Resolve<IPushNotificationListenerService>(
|
||||
"pushNotificationListenerService");
|
||||
await listener.OnMessageAsync(obj, Device.Android);
|
||||
|
|
Loading…
Reference in a new issue