Skip to content

Implement support to send delayed push notification using .NET SDK. #94

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Parse/Internal/Push/Coder/ParsePushEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public IDictionary<string, object> Encode(IPushState state) {
} else if (state.ExpirationInterval.HasValue) {
payload["expiration_interval"] = state.ExpirationInterval.Value.TotalSeconds;
}
if (state.PushTime.HasValue) {
payload["push_time"] = state.PushTime.Value.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ");
}

return payload;
}
Expand Down
1 change: 1 addition & 0 deletions Parse/Internal/Push/State/IPushState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ internal interface IPushState {
IEnumerable<string> Channels { get; }
DateTime? Expiration { get; }
TimeSpan? ExpirationInterval { get; }
DateTime? PushTime { get; }
IDictionary<string, object> Data { get; }
String Alert { get; }

Expand Down
3 changes: 3 additions & 0 deletions Parse/Internal/Push/State/MutablePushState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ internal class MutablePushState : IPushState {
public IEnumerable<string> Channels { get; set; }
public DateTime? Expiration { get; set; }
public TimeSpan? ExpirationInterval { get; set; }
public DateTime? PushTime { get; set; }
public IDictionary<string, object> Data { get; set; }
public String Alert { get; set; }

Expand All @@ -25,6 +26,7 @@ protected virtual MutablePushState MutableClone() {
Channels = Channels == null ? null: new List<string>(Channels),
Expiration = Expiration,
ExpirationInterval = ExpirationInterval,
PushTime = PushTime,
Data = Data == null ? null : new Dictionary<string, object>(Data),
Alert = Alert
};
Expand All @@ -40,6 +42,7 @@ public override bool Equals(object obj) {
this.Channels.CollectionsEqual(other.Channels) &&
Object.Equals(this.Expiration, other.Expiration) &&
Object.Equals(this.ExpirationInterval, other.ExpirationInterval) &&
Object.Equals(this.PushTime, other.PushTime) &&
this.Data.CollectionsEqual(other.Data) &&
Object.Equals(this.Alert, other.Alert);
}
Expand Down
13 changes: 13 additions & 0 deletions Parse/ParsePush.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,19 @@ public DateTime? Expiration {
}
}

public DateTime? PushTime {
get { return state.PushTime; }
set {
MutateState(s => {
DateTime now = DateTime.Now;
if (value < now || value > now.AddDays(14)) {
throw new InvalidOperationException("Cannot set PushTime in the past or more than two weeks later than now");
}
s.PushTime = value;
});
}
}

/// <summary>
/// The time from initial schedul when this push will expire. This should not be used in tandem with Expiration.
/// </summary>
Expand Down