Skip to content

Commit 01842a1

Browse files
Merge pull request #94 from Julien-Mialon/feature/DelayedPushSupport
Implement support to send delayed push notification using .NET SDK.
2 parents 16d59f8 + 48dcd54 commit 01842a1

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

Parse/Internal/Push/Coder/ParsePushEncoder.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ public IDictionary<string, object> Encode(IPushState state) {
3636
} else if (state.ExpirationInterval.HasValue) {
3737
payload["expiration_interval"] = state.ExpirationInterval.Value.TotalSeconds;
3838
}
39+
if (state.PushTime.HasValue) {
40+
payload["push_time"] = state.PushTime.Value.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ");
41+
}
3942

4043
return payload;
4144
}

Parse/Internal/Push/State/IPushState.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ internal interface IPushState {
99
IEnumerable<string> Channels { get; }
1010
DateTime? Expiration { get; }
1111
TimeSpan? ExpirationInterval { get; }
12+
DateTime? PushTime { get; }
1213
IDictionary<string, object> Data { get; }
1314
String Alert { get; }
1415

Parse/Internal/Push/State/MutablePushState.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ internal class MutablePushState : IPushState {
1010
public IEnumerable<string> Channels { get; set; }
1111
public DateTime? Expiration { get; set; }
1212
public TimeSpan? ExpirationInterval { get; set; }
13+
public DateTime? PushTime { get; set; }
1314
public IDictionary<string, object> Data { get; set; }
1415
public String Alert { get; set; }
1516

@@ -25,6 +26,7 @@ protected virtual MutablePushState MutableClone() {
2526
Channels = Channels == null ? null: new List<string>(Channels),
2627
Expiration = Expiration,
2728
ExpirationInterval = ExpirationInterval,
29+
PushTime = PushTime,
2830
Data = Data == null ? null : new Dictionary<string, object>(Data),
2931
Alert = Alert
3032
};
@@ -40,6 +42,7 @@ public override bool Equals(object obj) {
4042
this.Channels.CollectionsEqual(other.Channels) &&
4143
Object.Equals(this.Expiration, other.Expiration) &&
4244
Object.Equals(this.ExpirationInterval, other.ExpirationInterval) &&
45+
Object.Equals(this.PushTime, other.PushTime) &&
4346
this.Data.CollectionsEqual(other.Data) &&
4447
Object.Equals(this.Alert, other.Alert);
4548
}

Parse/ParsePush.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,19 @@ public DateTime? Expiration {
8282
}
8383
}
8484

85+
public DateTime? PushTime {
86+
get { return state.PushTime; }
87+
set {
88+
MutateState(s => {
89+
DateTime now = DateTime.Now;
90+
if (value < now || value > now.AddDays(14)) {
91+
throw new InvalidOperationException("Cannot set PushTime in the past or more than two weeks later than now");
92+
}
93+
s.PushTime = value;
94+
});
95+
}
96+
}
97+
8598
/// <summary>
8699
/// The time from initial schedul when this push will expire. This should not be used in tandem with Expiration.
87100
/// </summary>

0 commit comments

Comments
 (0)