2024-06-28 10:34:57 +00:00
|
|
|
{.push raises: [].}
|
2022-11-22 18:40:24 +00:00
|
|
|
|
2024-07-12 16:19:12 +00:00
|
|
|
import stew/byteutils
|
|
|
|
import ../../../waku_core
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
type Index* = object
|
|
|
|
## This type contains the description of an Index used in the pagination of WakuMessages
|
2024-07-12 16:19:12 +00:00
|
|
|
time*: Timestamp # the time at which the message is generated
|
2024-03-12 11:51:03 +00:00
|
|
|
hash*: WakuMessageHash
|
2024-07-12 16:19:12 +00:00
|
|
|
pubsubTopic*: PubsubTopic
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
proc `==`*(x, y: Index): bool =
|
2024-07-12 16:19:12 +00:00
|
|
|
return x.hash == y.hash
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
proc cmp*(x, y: Index): int =
|
|
|
|
## compares x and y
|
|
|
|
## returns 0 if they are equal
|
|
|
|
## returns -1 if x < y
|
|
|
|
## returns 1 if x > y
|
|
|
|
##
|
|
|
|
## Default sorting order priority is:
|
2024-07-12 16:19:12 +00:00
|
|
|
## 1. time
|
|
|
|
## 2. hash
|
2022-11-22 18:40:24 +00:00
|
|
|
|
2024-07-12 16:19:12 +00:00
|
|
|
let timeCMP = cmp(x.time, y.time)
|
|
|
|
if timeCMP != 0:
|
|
|
|
return timeCMP
|
2022-11-22 18:40:24 +00:00
|
|
|
|
2024-07-12 16:19:12 +00:00
|
|
|
return cmp(x.hash, y.hash)
|