Commit 59e6fc48 authored by Mo Firouz's avatar Mo Firouz
Browse files

Allow custom notification expiry to be set from Runtime.

parent c42f0af3
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -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 {
+2 −4
Original line number Diff line number Diff line
@@ -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)
@@ -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
	}
+15 −1
Original line number Diff line number Diff line
@@ -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":
@@ -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