diff --git a/docs/releases.md b/docs/releases.md index 4bbd306b..ad149246 100644 --- a/docs/releases.md +++ b/docs/releases.md @@ -77,7 +77,7 @@ going. It'll only make ntfy better. **Special thanks:** A big Thank-you goes to everyone who tested the user account and payments work. I very much appreciate all the feedback, -suggestions, and bug reports. Thank you, @nwithan8, @deadcade, @xenrox, @cmeis, and the others who I forgot. +suggestions, and bug reports. Thank you, @nwithan8, @deadcade, @xenrox, @cmeis, @wunter8 and the others who I forgot. ## ntfy server v1.31.0 Released February 14, 2023 diff --git a/docs/subscribe/api.md b/docs/subscribe/api.md index b9d72b41..58da9752 100644 --- a/docs/subscribe/api.md +++ b/docs/subscribe/api.md @@ -319,7 +319,7 @@ format of the message. It's very straight forward: |--------------|----------|---------------------------------------------------|-------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------| | `id` | ✔️ | *string* | `hwQ2YpKdmg` | Randomly chosen message identifier | | `time` | ✔️ | *number* | `1635528741` | Message date time, as Unix time stamp | -| `expires` | ✔️ | *number* | `1673542291` | Unix time stamp indicating when the message will be deleted | +| `expires` | (✔)️ | *number* | `1673542291` | Unix time stamp indicating when the message will be deleted, not set if `Cache: no` is sent | | `event` | ✔️ | `open`, `keepalive`, `message`, or `poll_request` | `message` | Message type, typically you'd be only interested in `message` | | `topic` | ✔️ | *string* | `topic1,topic2` | Comma-separated list of topics the message is associated with; only one for all `message` events, but may be a list in `open` events | | `message` | - | *string* | `Some message` | Message body; always present in `message` events | diff --git a/server/server.go b/server/server.go index 4853dabd..1890f179 100644 --- a/server/server.go +++ b/server/server.go @@ -589,7 +589,9 @@ func (s *Server) handlePublishWithoutResponse(r *http.Request, v *visitor) (*mes } m.Sender = v.IP() m.User = v.MaybeUserID() - m.Expires = time.Unix(m.Time, 0).Add(v.Limits().MessageExpiryDuration).Unix() + if cache { + m.Expires = time.Unix(m.Time, 0).Add(v.Limits().MessageExpiryDuration).Unix() + } if err := s.handlePublishBody(r, v, m, body, unifiedpush); err != nil { return nil, err } diff --git a/server/server_test.go b/server/server_test.go index f183f088..e2bbf4c9 100644 --- a/server/server_test.go +++ b/server/server_test.go @@ -149,6 +149,8 @@ func TestServer_PublishAndSubscribe(t *testing.T) { require.Equal(t, "", messages[1].Title) require.Equal(t, 0, messages[1].Priority) require.Nil(t, messages[1].Tags) + require.True(t, time.Now().Add(12*time.Hour-5*time.Second).Unix() < messages[1].Expires) + require.True(t, time.Now().Add(12*time.Hour+5*time.Second).Unix() > messages[1].Expires) require.Equal(t, messageEvent, messages[2].Event) require.Equal(t, "mytopic", messages[2].Topic) @@ -287,6 +289,7 @@ func TestServer_PublishNoCache(t *testing.T) { msg := toMessage(t, response.Body.String()) require.NotEmpty(t, msg.ID) require.Equal(t, "this message is not cached", msg.Message) + require.Equal(t, 0, msg.Expires) response = request(t, s, "GET", "/mytopic/json?poll=1", "", nil) messages := toMessages(t, response.Body.String())