2024-06-28 16:04:57 +05:30
|
|
|
{.push raises: [].}
|
2022-11-22 19:40:24 +01:00
|
|
|
|
2024-07-12 12:19:12 -04:00
|
|
|
import stew/byteutils
|
|
|
|
import ../../../waku_core
|
2022-11-22 19:40:24 +01:00
|
|
|
|
|
|
|
type Index* = object
|
|
|
|
## This type contains the description of an Index used in the pagination of WakuMessages
|
2024-07-12 12:19:12 -04:00
|
|
|
time*: Timestamp # the time at which the message is generated
|
2024-03-12 07:51:03 -04:00
|
|
|
hash*: WakuMessageHash
|
2024-07-12 12:19:12 -04:00
|
|
|
pubsubTopic*: PubsubTopic
|
2022-11-22 19:40:24 +01:00
|
|
|
|
|
|
|
proc `==`*(x, y: Index): bool =
|
2024-07-12 12:19:12 -04:00
|
|
|
return x.hash == y.hash
|
2022-11-22 19:40:24 +01: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 12:19:12 -04:00
|
|
|
## 1. time
|
|
|
|
## 2. hash
|
2022-11-22 19:40:24 +01:00
|
|
|
|
2024-07-12 12:19:12 -04:00
|
|
|
let timeCMP = cmp(x.time, y.time)
|
|
|
|
if timeCMP != 0:
|
|
|
|
return timeCMP
|
2022-11-22 19:40:24 +01:00
|
|
|
|
2024-07-12 12:19:12 -04:00
|
|
|
return cmp(x.hash, y.hash)
|