@@ -32,6 +32,13 @@ export class Proof {
3232 */
3333 caption = '' ;
3434
35+ /**
36+ * The timestamp when the asset is uploaded to the backend, in the format "2023-12-21T01:15:17Z".
37+ * By default, it is undefined. Once the asset is successfully uploaded, the uploadedAt property
38+ * will be set to the timestamp provided by the backend.
39+ */
40+ uploadedAt ?: string = undefined ;
41+
3542 isCollected = false ;
3643
3744 signatures : Signatures = { } ;
@@ -47,6 +54,32 @@ export class Proof {
4754 */
4855 cameraSource : CameraSource = CameraSource . Camera ;
4956
57+ /**
58+ * Used to sort the assets in the VERIFIED tab either by timestamp or uploadedAt (if available).
59+ */
60+ get uploadedAtOrTimestamp ( ) {
61+ const MILLISECONDS_PER_SECOND = 1000 ;
62+ const LENGTH_IN_MILLISECONDS = 13 ;
63+
64+ // convert timestamp to milliseconds if needed
65+ const proofTimestampInMilliseconds =
66+ this . timestamp . toString ( ) . length === LENGTH_IN_MILLISECONDS
67+ ? this . timestamp
68+ : this . timestamp * MILLISECONDS_PER_SECOND ;
69+
70+ const serverTimestampInMilliseconds = Date . parse ( this . uploadedAt ?? '' ) ;
71+ return serverTimestampInMilliseconds || proofTimestampInMilliseconds ;
72+ }
73+
74+ /**
75+ * The timestamp when the proof was first created or captured. Different from uploadedAt
76+ * The timestamp is generated using Date.now() and is represented in milliseconds.
77+ *
78+ * Note: After restoring or syncing with the backend assets, the timestamp will be in seconds.
79+ * For more details, refer to https://github.com/numbersprotocol/storage-backend/issues/976
80+ *
81+ * Note: Milliseconds are 13 digits long, while seconds are 10 digits long.
82+ */
5083 get timestamp ( ) {
5184 return this . truth . timestamp ;
5285 }
@@ -127,6 +160,7 @@ export class Proof {
127160 proof . setIndexedAssets ( indexedProofView . indexedAssets ) ;
128161 proof . diaBackendAssetId = indexedProofView . diaBackendAssetId ;
129162 proof . caption = indexedProofView . caption ?? '' ;
163+ proof . uploadedAt = indexedProofView . uploadedAt ;
130164 proof . isCollected = indexedProofView . isCollected ?? false ;
131165 proof . signatureVersion = indexedProofView . signatureVersion ;
132166 proof . integritySha = indexedProofView . integritySha ;
@@ -298,6 +332,7 @@ export class Proof {
298332 signatureVersion : this . signatureVersion ,
299333 diaBackendAssetId : this . diaBackendAssetId ,
300334 caption : this . caption ,
335+ uploadedAt : this . uploadedAt ,
301336 isCollected : this . isCollected ,
302337 integritySha : this . integritySha ,
303338 cameraSource : this . cameraSource ,
@@ -433,6 +468,7 @@ export interface IndexedProofView extends Tuple {
433468 readonly signatureVersion ?: string ;
434469 readonly diaBackendAssetId ?: string ;
435470 readonly caption ?: string ;
471+ readonly uploadedAt ?: string ;
436472 readonly isCollected ?: boolean ;
437473 readonly integritySha ?: string ;
438474 readonly cameraSource : CameraSource ;
0 commit comments