nips/34asc.md

35 lines
817 B
Markdown
Raw Normal View History

2023-06-27 10:15:05 -04:00
NIP-34asc
=========
2023-06-02 13:40:46 -04:00
2023-06-27 10:15:05 -04:00
Ascending
---------
2023-06-02 13:40:46 -04:00
`draft` `optional` `author:arthurfranca`
Events with older `created_at` are retrieved first.
2023-06-27 11:10:35 -04:00
## Motivation
For thread building it may better showing first comments at top to make it easier to understand
the context of newer comments.
2023-06-02 13:40:46 -04:00
## Implementation
2023-06-27 10:15:05 -04:00
`Relay` computes `nip34asc` field once upon receiving the event.
2023-06-02 13:40:46 -04:00
2023-06-27 10:15:05 -04:00
The lower the `created_at`, the higher `nip34asc` will be.
2023-06-02 13:40:46 -04:00
### Javascript
```js
function getNip34asc (createdAt) {
const maxDateNowSeconds = 8640000000000 // 8.64e15 ms / 1000
2023-06-02 13:40:46 -04:00
// Make it lower the greater the ts is (the newer the createdAt is)
// maxDateNowSeconds - -maxDateNowSeconds equals 17280000000000 and is lower than Number.MAX_SAFE_INTEGER
return maxDateNowSeconds - createdAt
2023-06-02 13:40:46 -04:00
}
event.nip34asc = getNip34asc(event.created_at)
2023-06-02 13:40:46 -04:00
```