[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,8 +1,9 @@
|
||||||
#if !FDROID
|
#if !FDROID
|
||||||
using System;
|
using System;
|
||||||
using Android.App;
|
using Android.App;
|
||||||
using Bit.App.Abstractions;
|
using Bit.App.Abstractions;
|
||||||
using Bit.Core.Abstractions;
|
using Bit.Core.Abstractions;
|
||||||
|
using Bit.Core.Enums;
|
||||||
using Bit.Core.Services;
|
using Bit.Core.Services;
|
||||||
using Bit.Core.Utilities;
|
using Bit.Core.Utilities;
|
||||||
using Firebase.Messaging;
|
using Firebase.Messaging;
|
||||||
|
@ -20,7 +21,7 @@ namespace Bit.Droid.Push
|
||||||
try {
|
try {
|
||||||
var stateService = ServiceContainer.Resolve<IStateService>("stateService");
|
var stateService = ServiceContainer.Resolve<IStateService>("stateService");
|
||||||
var pushNotificationService = ServiceContainer.Resolve<IPushNotificationService>("pushNotificationService");
|
var pushNotificationService = ServiceContainer.Resolve<IPushNotificationService>("pushNotificationService");
|
||||||
|
|
||||||
await stateService.SetPushRegisteredTokenAsync(token);
|
await stateService.SetPushRegisteredTokenAsync(token);
|
||||||
await pushNotificationService.RegisterAsync();
|
await pushNotificationService.RegisterAsync();
|
||||||
}
|
}
|
||||||
|
@ -38,13 +39,33 @@ namespace Bit.Droid.Push
|
||||||
{
|
{
|
||||||
return;
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var obj = JObject.Parse(data);
|
|
||||||
var listener = ServiceContainer.Resolve<IPushNotificationListenerService>(
|
var listener = ServiceContainer.Resolve<IPushNotificationListenerService>(
|
||||||
"pushNotificationListenerService");
|
"pushNotificationListenerService");
|
||||||
await listener.OnMessageAsync(obj, Device.Android);
|
await listener.OnMessageAsync(obj, Device.Android);
|
||||||
|
|
Loading…
Reference in New Issue