Skip to content

Commit

Permalink
VCST-1334: Use Firebase Cloud Messaging (FCM) (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
artem-dudarev authored Jun 13, 2024
1 parent a75fe91 commit c6d2be9
Show file tree
Hide file tree
Showing 48 changed files with 1,835 additions and 20 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,31 +45,32 @@ subscription pushMessageCreated {
```js
{
pushMessages (unreadOnly: true, cultureName: "en-Us") {
unreadCount
totalCount
items {
id
shortMessage
createdDate
isRead
isHidden
}
}
}
```
### Mutations
```js
mutation clearAllPushMessages{
mutation clearAllPushMessages {
clearAllPushMessages
}
```

```js
mutation markAllPushMessagesRead{
mutation markAllPushMessagesRead {
markAllPushMessagesRead
}
```

```js
mutation markAllPushMessagesUnread{
mutation markAllPushMessagesUnread {
markAllPushMessagesUnread
}
```
Expand Down
3 changes: 2 additions & 1 deletion VirtoCommerce.PushMessages.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateConstants/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateStaticReadonly/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/UserRules/=15b5b1f1_002D457c_002D4ca6_002Db278_002D5615aedc07d3/@EntryIndexedValue">&lt;Policy&gt;&lt;Descriptor Staticness="Static" AccessRightKinds="Private" Description="Static readonly fields (private)"&gt;&lt;ElementKinds&gt;&lt;Kind Name="READONLY_FIELD" /&gt;&lt;/ElementKinds&gt;&lt;/Descriptor&gt;&lt;Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" /&gt;&lt;/Policy&gt;</s:String>
Expand All @@ -8,4 +8,5 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=pomelo/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=postgre/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=virto/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=xapi/@EntryIndexedValue">True</s:Boolean>
</wpf:ResourceDictionary>
13 changes: 13 additions & 0 deletions src/VirtoCommerce.PushMessages.Core/Events/FcmTokenChangedEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Collections.Generic;
using VirtoCommerce.Platform.Core.Events;
using VirtoCommerce.PushMessages.Core.Models;

namespace VirtoCommerce.PushMessages.Core.Events;

public class FcmTokenChangedEvent : GenericChangedEntryEvent<FcmToken>
{
public FcmTokenChangedEvent(IEnumerable<GenericChangedEntry<FcmToken>> changedEntries)
: base(changedEntries)
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Collections.Generic;
using VirtoCommerce.Platform.Core.Events;
using VirtoCommerce.PushMessages.Core.Models;

namespace VirtoCommerce.PushMessages.Core.Events;

public class FcmTokenChangingEvent : GenericChangedEntryEvent<FcmToken>
{
public FcmTokenChangingEvent(IEnumerable<GenericChangedEntry<FcmToken>> changedEntries)
: base(changedEntries)
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Collections.Generic;
using System.Linq;

namespace VirtoCommerce.PushMessages.Core.Extensions;

public static class EnumerableExtensions
{
public static IList<T> ToIList<T>(this IEnumerable<T> enumerable)
{
return enumerable.ToList();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Collections.Generic;
using System.Linq;
using VirtoCommerce.Platform.Core.Common;
using VirtoCommerce.PushMessages.Core.Events;
using VirtoCommerce.PushMessages.Core.Models;

namespace VirtoCommerce.PushMessages.Core.Extensions;

public static class PushMessageRecipientChangedEventExtensions
{
public static IDictionary<string, IList<PushMessageRecipient>> GetMessageIdsAndRecipients(this PushMessageRecipientChangedEvent @event)
{
return @event.ChangedEntries
.Where(x => x.EntryState == EntryState.Added)
.GroupBy(x => x.NewEntry.MessageId)
.ToDictionary(g => g.Key, g => g.Select(x => x.NewEntry).ToIList());
}
}
12 changes: 12 additions & 0 deletions src/VirtoCommerce.PushMessages.Core/Models/FcmReceiverOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace VirtoCommerce.PushMessages.Core.Models;

public class FcmReceiverOptions
{
public string ApiKey { get; set; }
public string AuthDomain { get; set; }
public string ProjectId { get; set; }
public string StorageBucket { get; set; }
public string MessagingSenderId { get; set; }
public string AppId { get; set; }
public string VapidKey { get; set; }
}
39 changes: 39 additions & 0 deletions src/VirtoCommerce.PushMessages.Core/Models/FcmSenderOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using Newtonsoft.Json;

namespace VirtoCommerce.PushMessages.Core.Models;

public class FcmSenderOptions
{
[JsonProperty("type")]
public string Type { get; set; }

[JsonProperty("project_id")]
public string ProjectId { get; set; }

[JsonProperty("private_key_id")]
public string PrivateKeyId { get; set; }

[JsonProperty("private_key")]
public string PrivateKey { get; set; }

[JsonProperty("client_email")]
public string ClientEmail { get; set; }

[JsonProperty("client_id")]
public string ClientId { get; set; }

[JsonProperty("auth_uri")]
public string AuthUri { get; set; }

[JsonProperty("token_uri")]
public string TokenUri { get; set; }

[JsonProperty("auth_provider_x509_cert_url")]
public string AuthProviderX509CertUrl { get; set; }

[JsonProperty("client_x509_cert_url")]
public string ClientX509CertUrl { get; set; }

[JsonProperty("universe_domain")]
public string UniverseDomain { get; set; }
}
16 changes: 16 additions & 0 deletions src/VirtoCommerce.PushMessages.Core/Models/FcmToken.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using VirtoCommerce.Platform.Core.Common;

namespace VirtoCommerce.PushMessages.Core.Models;

public class FcmToken : AuditableEntity, ICloneable
{
public string Token { get; set; }

public string UserId { get; set; }

public object Clone()
{
return MemberwiseClone();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Collections.Generic;
using VirtoCommerce.Platform.Core.Common;

namespace VirtoCommerce.PushMessages.Core.Models;

public class FcmTokenSearchCriteria : SearchCriteriaBase
{
public string Token { get; set; }

public IList<string> UserIds { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using VirtoCommerce.Platform.Core.Common;

namespace VirtoCommerce.PushMessages.Core.Models;

public class FcmTokenSearchResult : GenericSearchResult<FcmToken>
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace VirtoCommerce.PushMessages.Core.Models;

public class PushMessageOptions
{
public bool UseFirebaseCloudMessaging { get; set; }
public FcmSenderOptions FcmSenderOptions { get; set; }
public FcmReceiverOptions FcmReceiverOptions { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using VirtoCommerce.Platform.Core.GenericCrud;
using VirtoCommerce.PushMessages.Core.Models;

namespace VirtoCommerce.PushMessages.Core.Services;

public interface IFcmTokenSearchService : ISearchService<FcmTokenSearchCriteria, FcmTokenSearchResult, FcmToken>
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using VirtoCommerce.Platform.Core.GenericCrud;
using VirtoCommerce.PushMessages.Core.Models;

namespace VirtoCommerce.PushMessages.Core.Services;

public interface IFcmTokenService : ICrudService<FcmToken>
{
}
Loading

0 comments on commit c6d2be9

Please sign in to comment.