Skip to content

Commit

Permalink
Merge pull request #11 from ApollosProject/fix-12.4
Browse files Browse the repository at this point in the history
Recompile the One Signal DLL for Rock v12.4
  • Loading branch information
richarddubay authored Aug 12, 2021
2 parents 485ac1d + 0c2238c commit 69b38cf
Show file tree
Hide file tree
Showing 22 changed files with 565 additions and 80 deletions.
113 changes: 58 additions & 55 deletions Rock/Communication/Transport/OneSignal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,74 +168,77 @@ public override void Send( Model.Communication communication, int mediumEntityTy
{
if (ValidRecipient(recipient, communication.IsBulkCommunication))
{
try
if ( recipient.PersonAliasId.HasValue )
{
var mergeObjects = recipient.CommunicationMergeValues(mergeFields);
var message = ResolveText(communication.PushMessage, currentPerson, communication.EnabledLavaCommands, mergeObjects, publicAppRoot);
var title = ResolveText(communication.PushTitle, currentPerson, communication.EnabledLavaCommands, mergeObjects, publicAppRoot);
var sound = ResolveText( communication.PushSound, currentPerson, communication.EnabledLavaCommands, mergeObjects, publicAppRoot );
var data = ResolveText(communication.PushData, currentPerson, communication.EnabledLavaCommands, mergeFields, publicAppRoot);
var jsonData = Newtonsoft.Json.JsonConvert.DeserializeObject<PushData>(data);
var url = jsonData.Url;
string appId = GetAttributeValue("AppId");
string restApiKey = GetAttributeValue("RestAPIKey");
OneSignalClient client = new OneSignalClient(restApiKey);

var options = new NotificationCreateOptions
try
{
AppId = new Guid(appId),
IncludeExternalUserIds = new List<string> { recipient.PersonAliasId.ToString() }
};
var mergeObjects = recipient.CommunicationMergeValues(mergeFields);
var message = ResolveText(communication.PushMessage, currentPerson, communication.EnabledLavaCommands, mergeObjects, publicAppRoot);
var title = ResolveText(communication.PushTitle, currentPerson, communication.EnabledLavaCommands, mergeObjects, publicAppRoot);
var sound = ResolveText( communication.PushSound, currentPerson, communication.EnabledLavaCommands, mergeObjects, publicAppRoot );
var data = ResolveText(communication.PushData, currentPerson, communication.EnabledLavaCommands, mergeFields, publicAppRoot);
var jsonData = Newtonsoft.Json.JsonConvert.DeserializeObject<PushData>(data);
var url = jsonData.Url;
string appId = GetAttributeValue("AppId");
string restApiKey = GetAttributeValue("RestAPIKey");
OneSignalClient client = new OneSignalClient(restApiKey);

options.Headings.Add(LanguageCodes.English, title);
options.Contents.Add(LanguageCodes.English, message);
options.Url = url;
NotificationCreateResult response = client.Notifications.Create(options);
var options = new NotificationCreateOptions
{
AppId = new Guid(appId),
IncludeExternalUserIds = new List<string> { recipient.PersonAliasId.ToString() }
};

bool failed = !string.IsNullOrWhiteSpace(response.Error);
options.Headings.Add(LanguageCodes.English, title);
options.Contents.Add(LanguageCodes.English, message);
options.Url = url;
NotificationCreateResult response = client.Notifications.Create(options);

var status = failed ? CommunicationRecipientStatus.Failed : CommunicationRecipientStatus.Delivered;
bool failed = !string.IsNullOrWhiteSpace(response.Error);

if (failed)
{
recipient.StatusNote = "OneSignal failed to notify devices";
}
else
{
recipient.SendDateTime = RockDateTime.Now;
}
var status = failed ? CommunicationRecipientStatus.Failed : CommunicationRecipientStatus.Delivered;

recipient.Status = status;
recipient.TransportEntityTypeName = this.GetType().FullName;
recipient.UniqueMessageId = response.Id;
if (failed)
{
recipient.StatusNote = "OneSignal failed to notify devices";
}
else
{
recipient.SendDateTime = RockDateTime.Now;
}

try
{
var historyService = new HistoryService(recipientRockContext);
historyService.Add(new History
recipient.Status = status;
recipient.TransportEntityTypeName = this.GetType().FullName;
recipient.UniqueMessageId = response.Id;

try
{
var historyService = new HistoryService(recipientRockContext);
historyService.Add(new History
{
CreatedByPersonAliasId = communication.SenderPersonAliasId,
EntityTypeId = personEntityTypeId,
CategoryId = communicationCategoryId,
EntityId = recipient.PersonAlias.PersonId,
Verb = History.HistoryVerb.Sent.ConvertToString().ToUpper(),
ChangeType = History.HistoryChangeType.Record.ToString(),
ValueName = "Push Notification",
Caption = message.Truncate(200),
RelatedEntityTypeId = communicationEntityTypeId,
RelatedEntityId = communication.Id
});
}
catch (Exception ex)
{
CreatedByPersonAliasId = communication.SenderPersonAliasId,
EntityTypeId = personEntityTypeId,
CategoryId = communicationCategoryId,
EntityId = recipient.PersonAlias.PersonId,
Verb = History.HistoryVerb.Sent.ConvertToString().ToUpper(),
ChangeType = History.HistoryChangeType.Record.ToString(),
ValueName = "Push Notification",
Caption = message.Truncate(200),
RelatedEntityTypeId = communicationEntityTypeId,
RelatedEntityId = communication.Id
});
ExceptionLogService.LogException(ex, null);
}

}
catch (Exception ex)
{
ExceptionLogService.LogException(ex, null);
recipient.Status = CommunicationRecipientStatus.Failed;
recipient.StatusNote = "OneSignal Exception: " + ex.Message;
}

}
catch (Exception ex)
{
recipient.Status = CommunicationRecipientStatus.Failed;
recipient.StatusNote = "OneSignal Exception: " + ex.Message;
}
}

Expand Down
Binary file modified Versions/12.0/apollosProject.OneSignal.dll
Binary file not shown.
6 changes: 3 additions & 3 deletions apollosProject.OneSignal.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@
<Reference Include="RestSharp, Version=105.2.3.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>.\packages\RestSharp.105.2.3\lib\net452\RestSharp.dll</HintPath>
</Reference>
<Reference Include="Rock, Version=1.9.0.9, Culture=neutral, processorArchitecture=MSIL">
<Reference Include="Rock, Version=1.11.0.3, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\RockWeb\Bin\Rock.dll</HintPath>
<HintPath>..\Rock\RockWeb\Bin\Rock.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.Composition" />
Expand Down Expand Up @@ -76,4 +76,4 @@
xcopy /Y /R "$(ProjectDir)bin\Apollos.OneSignal.RestAPIv3.Client.dll" "$(SolutionDir)RockWeb\bin"
xcopy /Y /I /E "$(ProjectDir)Communication\Transport\*.*" "$(SolutionDir)Rock\Communication\Transport"</PostBuildEvent>
</PropertyGroup>
</Project>
</Project>
Binary file modified bin/DotLiquid.dll
Binary file not shown.
Binary file modified bin/DotLiquid.pdb
Binary file not shown.
Binary file modified bin/Microsoft.IdentityModel.Logging.dll
Binary file not shown.
Binary file modified bin/Microsoft.IdentityModel.Tokens.dll
Binary file not shown.
Loading

0 comments on commit 69b38cf

Please sign in to comment.