π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
server: track collection share timestamp in shared diff
Neeraj Guptaa8d8b864b390
diff --git a/server/ente/collection.go b/server/ente/collection.goindex 3fe50c1e68..7420e222a0 100644--- a/server/ente/collection.go+++ b/server/ente/collection.go@@ -23,6 +23,7 @@ type Collection struct {Sharees []CollectionUser `json:"sharees"`PublicURLs []PublicURL `json:"publicURLs"`UpdationTime int64 `json:"updationTime"`+ SharedAt *int64 `json:"sharedAt,omitempty"`IsDeleted bool `json:"isDeleted,omitempty"`MagicMetadata *MagicMetadata `json:"magicMetadata,omitempty"`App string `json:"app"`diff --git a/server/migrations/115_add_shared_at_collection_shares.down.sql b/server/migrations/115_add_shared_at_collection_shares.down.sqlnew file mode 100644index 0000000000..ae3b368de8--- /dev/null+++ b/server/migrations/115_add_shared_at_collection_shares.down.sql@@ -0,0 +1,2 @@+ALTER TABLE collection_shares+ DROP COLUMN IF EXISTS shared_at;diff --git a/server/migrations/115_add_shared_at_collection_shares.up.sql b/server/migrations/115_add_shared_at_collection_shares.up.sqlnew file mode 100644index 0000000000..431789ed31--- /dev/null+++ b/server/migrations/115_add_shared_at_collection_shares.up.sql@@ -0,0 +1,2 @@+ALTER TABLE collection_shares+ ADD COLUMN IF NOT EXISTS shared_at BIGINT;diff --git a/server/pkg/repo/collection.go b/server/pkg/repo/collection.goindex df14122327..f12a392fc5 100644--- a/server/pkg/repo/collection.go+++ b/server/pkg/repo/collection.go@@ -258,7 +258,7 @@ pct.access_token, pct.valid_till, pct.device_limit, pct.created_at, pct.updated_// with a userfunc (repo *CollectionRepository) GetCollectionsSharedWithUser(userID int64, updationTime int64, app ente.App, limit *int64) ([]ente.Collection, error) {query := `- SELECT collections.collection_id, collections.owner_id, users.encrypted_email, users.email_decryption_nonce, collection_shares.encrypted_key, collections.name, collections.encrypted_name, collections.name_decryption_nonce, collections.type, collections.app, collections.pub_magic_metadata, collection_shares.magic_metadata, collections.updation_time, collection_shares.is_deleted, collection_shares.role_type+ SELECT collections.collection_id, collections.owner_id, users.encrypted_email, users.email_decryption_nonce, collection_shares.encrypted_key, collections.name, collections.encrypted_name, collections.name_decryption_nonce, collections.type, collections.app, collections.pub_magic_metadata, collection_shares.magic_metadata, collections.updation_time, collection_shares.is_deleted, collection_shares.role_type, collection_shares.shared_atFROM collectionsINNER JOIN usersON collections.owner_id = users.user_id@@ -283,9 +283,14 @@ func (repo *CollectionRepository) GetCollectionsSharedWithUser(userID int64, updvar collectionName, encryptedName, nameDecryptionNonce sql.NullStringvar encryptedEmail, emailDecryptionNonce []bytevar roleType sql.NullString- if err := rows.Scan(&c.ID, &c.Owner.ID, &encryptedEmail, &emailDecryptionNonce, &c.EncryptedKey, &collectionName, &encryptedName, &nameDecryptionNonce, &c.Type, &c.App, &c.PublicMagicMetadata, &c.SharedMagicMetadata, &c.UpdationTime, &c.IsDeleted, &roleType); err != nil {+ var sharedAt sql.NullInt64+ if err := rows.Scan(&c.ID, &c.Owner.ID, &encryptedEmail, &emailDecryptionNonce, &c.EncryptedKey, &collectionName, &encryptedName, &nameDecryptionNonce, &c.Type, &c.App, &c.PublicMagicMetadata, &c.SharedMagicMetadata, &c.UpdationTime, &c.IsDeleted, &roleType, &sharedAt); err != nil {return collections, stacktrace.Propagate(err, "")}+ if sharedAt.Valid {+ sharedAtValue := sharedAt.Int64+ c.SharedAt = &sharedAtValue+ }if collectionName.Valid && len(collectionName.String) > 0 {c.Name = collectionName.String} else {@@ -507,10 +512,17 @@ func (repo *CollectionRepository) Share(err = fmt.Errorf("invalid role %s", string(role))return stacktrace.Propagate(err, "")}- _, err = tx.ExecContext(context, `INSERT INTO collection_shares(collection_id, from_user_id, to_user_id, encrypted_key, updation_time, role_type) VALUES($1, $2, $3, $4, $5, $6)- ON CONFLICT (collection_id, from_user_id, to_user_id)- DO UPDATE SET(is_deleted, updation_time, role_type) = (FALSE, $5, $6)`,- collectionID, fromUserID, toUserID, encryptedKey, updationTime, role)+ _, err = tx.ExecContext(context, `INSERT INTO collection_shares(collection_id, from_user_id, to_user_id, encrypted_key, updation_time, role_type, shared_at) VALUES($1, $2, $3, $4, $5, $6, $7)+ ON CONFLICT (collection_id, from_user_id, to_user_id)+ DO UPDATE SET+ is_deleted = FALSE,+ updation_time = $5,+ role_type = $6,+ shared_at = CASE+ WHEN collection_shares.is_deleted = TRUE THEN $7+ ELSE collection_shares.shared_at+ END`,+ collectionID, fromUserID, toUserID, encryptedKey, updationTime, role, updationTime)if err != nil {tx.Rollback()return stacktrace.Propagate(err, "")