Skip to content

Commit

Permalink
Allow custom notification expiry to be set from Runtime.
Browse files Browse the repository at this point in the history
  • Loading branch information
mofirouz committed Mar 29, 2018
1 parent c42f0af commit 59e6fc4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
1 change: 0 additions & 1 deletion server/core_friend.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ func friendAdd(logger *zap.Logger, db *sql.DB, ns *NotificationService, userID s
if e, ok := err.(*pq.Error); ok && e.Code == "23505" {
// Ignore error if it is dbErrorUniqueViolation,
// which is the case if we are adding users that already have a relationship.
logger.Warn("CODE", zap.Any("code", e.Code), zap.String("msg", e.Message))
err = nil
}
} else {
Expand Down
6 changes: 2 additions & 4 deletions server/core_notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,6 @@ func (n *NotificationService) NotificationsRemove(userID string, notificationIDs
}

func (n *NotificationService) notificationsSave(notifications []*NNotification) error {
createdAt := nowMs()
expiresAt := createdAt + n.expiryMs

statements := make([]string, 0)
params := make([]interface{}, 0)
Expand All @@ -231,8 +229,8 @@ func (n *NotificationService) notificationsSave(notifications []*NNotification)
params = append(params, no.Content)
params = append(params, no.Code)
params = append(params, no.SenderID)
params = append(params, createdAt)
params = append(params, expiresAt)
params = append(params, no.CreatedAt)
params = append(params, no.ExpiresAt)

counter = counter + 8
}
Expand Down
16 changes: 15 additions & 1 deletion server/runtime_nakama_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -1910,6 +1910,8 @@ func (n *NakamaModule) notificationsSendId(l *lua.LState) int {
}

notification := &NNotification{}
notification.CreatedAt = nowMs()
notification.ExpiresAt = n.notificationService.expiryMs + notification.CreatedAt
notificationTable.ForEach(func(k lua.LValue, v lua.LValue) {
switch k.String() {
case "Persistent":
Expand Down Expand Up @@ -1950,10 +1952,22 @@ func (n *NakamaModule) notificationsSendId(l *lua.LState) int {
}
number := int64(lua.LVAsNumber(v))
if number <= 100 {
l.ArgError(1, "expects Code to number above 100")
l.ArgError(1, "expects Code to be above 100")
return
}
notification.Code = int64(number)
case "ExpiresAt":
if v.Type() != lua.LTNumber {
conversionError = true
l.ArgError(1, "expects ExpiresAt to be number")
return
}
number := int64(lua.LVAsNumber(v))
if number <= 0 {
l.ArgError(1, "expects ExpiresAt to be above 100")
return
}
notification.ExpiresAt = notification.CreatedAt + int64(number)
case "UserId":
if v.Type() != lua.LTString {
conversionError = true
Expand Down

0 comments on commit 59e6fc4

Please sign in to comment.