π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Handle deleted Space post references
Anand Baburajanc47a53c35556
diff --git a/rust/bindings/wasm/ente-wasm/src/space.rs b/rust/bindings/wasm/ente-wasm/src/space.rsindex abba5d23c7..89822958ce 100644--- a/rust/bindings/wasm/ente-wasm/src/space.rs+++ b/rust/bindings/wasm/ente-wasm/src/space.rs@@ -170,6 +170,7 @@ struct MessageJs {recipient_space_id: String,text: String,reply_post_id: Option<i64>,+ reply_post_deleted: bool,reply_message_id: Option<String>,liked: bool,viewer_liked: bool,@@ -197,6 +198,7 @@ struct MessageConversationActivityJs {text: Option<String>,post_id: Option<i64>,post_space_id: Option<String>,+ post_deleted: bool,}#[derive(Serialize)]@@ -446,6 +448,7 @@ async fn account_message_to_js(recipient_space_id: message.recipient_space_id,text: decrypted.payload.text,reply_post_id: message.reply_post_id,+ reply_post_deleted: message.reply_post_deleted,reply_message_id: message.reply_message_id,liked: message.liked,viewer_liked: message.viewer_liked,@@ -472,6 +475,7 @@ async fn account_message_response_to_js(recipient_space_id: message.recipient_space_id,text: message.text,reply_post_id: message.reply_post_id,+ reply_post_deleted: message.reply_post_deleted,reply_message_id: message.reply_message_id,liked: message.liked,viewer_liked: message.viewer_liked,@@ -506,6 +510,7 @@ async fn message_conversation_activity_text(encrypted_message_key: activity.encrypted_message_key.clone(),text: String::new(),reply_post_id: activity.post_id,+ reply_post_deleted: activity.post_deleted,reply_message_id: activity.reply_message_id.clone(),liked: false,viewer_liked: false,@@ -532,6 +537,7 @@ async fn message_conversation_activity_to_js(text,post_id: activity.post_id,post_space_id: activity.post_space_id,+ post_deleted: activity.post_deleted,})}diff --git a/rust/space/src/client/tests.rs b/rust/space/src/client/tests.rsindex 1c9de4f93f..32d3619c40 100644--- a/rust/space/src/client/tests.rs+++ b/rust/space/src/client/tests.rs@@ -1450,18 +1450,8 @@ async fn message_actions_use_message_endpoints() {json!({"messageId": "wmsg_reply","kind": "regular",- "sender": {- "spaceId": "space_owner_main",- "spaceSlug": "owner-main",- "publicKey": encode_b64(&test_public_key(&ctx)),- "keyVersion": 3- },- "recipient": {- "spaceId": "space_friend",- "spaceSlug": "friend",- "publicKey": encode_b64(&friend_public_key),- "keyVersion": 2- },+ "senderSpaceId": "space_owner_main",+ "recipientSpaceId": "space_friend","messageCipher": "cipher","encryptedMessageKey": "key","replyMessageId": "wmsg_parent",diff --git a/rust/space/src/transport.rs b/rust/space/src/transport.rsindex 3072434b50..b7e86dbb06 100644--- a/rust/space/src/transport.rs+++ b/rust/space/src/transport.rs@@ -152,6 +152,8 @@ pub struct MessageResponse {#[serde(default)]pub reply_post_id: Option<i64>,#[serde(default)]+ pub reply_post_deleted: bool,+ #[serde(default)]pub reply_message_id: Option<String>,#[serde(default)]pub liked: bool,@@ -198,6 +200,8 @@ pub struct MessageConversationActivity {pub post_id: Option<i64>,#[serde(default)]pub post_space_id: Option<String>,+ #[serde(default)]+ pub post_deleted: bool,}#[derive(Debug, Clone, Serialize, Deserialize)]diff --git a/server/space/controller/messages.go b/server/space/controller/messages.goindex 5b0571eec0..1fb74d9c3b 100644--- a/server/space/controller/messages.go+++ b/server/space/controller/messages.go@@ -340,6 +340,7 @@ func toMessageResponse(message repo.SpaceMessageRecord) *models.MessageResponseif message.ReplyPostID.Valid {replyPostID := message.ReplyPostID.Int64resp.ReplyPostID = &replyPostID+ resp.ReplyPostDeleted = message.ReplyPostDeleted}if message.ReplyMessageID.Valid {replyMessageID := message.ReplyMessageID.String@@ -381,6 +382,7 @@ func toMessageConversationActivityResponse(activity repo.SpaceMessageConversatioif activity.PostID.Valid {postID := activity.PostID.Int64resp.PostID = &postID+ resp.PostDeleted = activity.PostDeletedif activity.PostSpaceID.Valid {resp.PostSpaceID = activity.PostSpaceID.String}diff --git a/server/space/models/models.go b/server/space/models/models.goindex 89a48a5da8..691555d149 100644--- a/server/space/models/models.go+++ b/server/space/models/models.go@@ -293,6 +293,7 @@ type MessageResponse struct {EncryptedMessageKey string `json:"encryptedMessageKey,omitempty"`Text string `json:"text,omitempty"`ReplyPostID *int64 `json:"replyPostId,omitempty"`+ ReplyPostDeleted bool `json:"replyPostDeleted,omitempty"`ReplyMessageID *string `json:"replyMessageId,omitempty"`Liked bool `json:"liked"`ViewerLiked bool `json:"viewerLiked"`@@ -320,6 +321,7 @@ type MessageConversationActivityResponse struct {ReplyMessageID *string `json:"replyMessageId,omitempty"`PostID *int64 `json:"postId,omitempty"`PostSpaceID string `json:"postSpaceId,omitempty"`+ PostDeleted bool `json:"postDeleted,omitempty"`}type ConversationChatSummaryResponse struct {diff --git a/server/space/repo/messages.go b/server/space/repo/messages.goindex eb02d59190..d2adc92d21 100644--- a/server/space/repo/messages.go+++ b/server/space/repo/messages.go@@ -20,6 +20,13 @@ const spaceMessageBaseSelectColumns = `COALESCE(m.message_cipher, '\x'::bytea),%[2]s AS encrypted_message_key,m.reply_post_id,+ (+ m.reply_post_id IS NOT NULL+ AND EXISTS (+ SELECT 1 FROM space_posts p+ WHERE p.post_id = m.reply_post_id AND p.is_deleted = TRUE+ )+ ) AS reply_post_deleted,m.reply_message_id,(m.recipient_liked_at IS NOT NULL) AS liked,(m.recipient_liked_at IS NOT NULL AND m.recipient_space_id = %[1]s) AS viewer_liked,@@ -81,6 +88,7 @@ SELECTmessage_id,post_id,post_space_id,+ post_deleted,message_kind,sender_space_id,recipient_space_id,@@ -110,6 +118,13 @@ FROM (CASE WHEN m.kind = 'post_like' THEN NULL::text ELSE m.message_id END AS message_id,m.reply_post_id AS post_id,m.recipient_space_id AS post_space_id,+ (+ m.reply_post_id IS NOT NULL+ AND EXISTS (+ SELECT 1 FROM space_posts p+ WHERE p.post_id = m.reply_post_id AND p.is_deleted = TRUE+ )+ ) AS post_deleted,m.kind AS message_kind,m.sender_space_id,m.recipient_space_id,@@ -140,6 +155,7 @@ FROM (m.message_id,NULL::bigint AS post_id,NULL::text AS post_space_id,+ FALSE AS post_deleted,m.kind AS message_kind,m.sender_space_id,m.recipient_space_id,@@ -377,6 +393,7 @@ func scanMessageRecord(scanner interface{ Scan(dest ...any) error }) (*SpaceMess&rec.MessageCipher,&rec.EncryptedMessageKey,&rec.ReplyPostID,+ &rec.ReplyPostDeleted,&rec.ReplyMessageID,&rec.Liked,&rec.ViewerLiked,@@ -413,6 +430,7 @@ func conversationActivityScanDest(activity *SpaceMessageConversationActivityReco&activity.MessageID,&activity.PostID,&activity.PostSpaceID,+ &activity.PostDeleted,&activity.Kind,&activity.SenderSpaceID,&activity.RecipientSpaceID,diff --git a/server/space/repo/module.go b/server/space/repo/module.goindex 84802a0832..71f36b4f3f 100644--- a/server/space/repo/module.go+++ b/server/space/repo/module.go@@ -125,6 +125,7 @@ type SpaceMessageRecord struct {MessageCipher []byteEncryptedMessageKey []byteReplyPostID sql.NullInt64+ ReplyPostDeleted boolReplyMessageID sql.NullStringLiked boolViewerLiked bool@@ -154,6 +155,7 @@ type SpaceMessageConversationActivityRecord struct {ReplyMessageID sql.NullStringPostID sql.NullInt64PostSpaceID sql.NullString+ PostDeleted bool}type CreateSpaceMessageRecord struct {diff --git a/server/space/repo/module_test.go b/server/space/repo/module_test.goindex 5b594910b5..cd1f704864 100644--- a/server/space/repo/module_test.go+++ b/server/space/repo/module_test.go@@ -610,6 +610,7 @@ func TestSpaceMessageConversationsUseLatestActivity(t *testing.T) {require.Equal(t, "post_like", conversations[0].LatestActivity.Type)require.True(t, conversations[0].LatestActivity.PostID.Valid)require.Equal(t, postID, conversations[0].LatestActivity.PostID.Int64)+ require.False(t, conversations[0].LatestActivity.PostDeleted)postReply, err := module.Messages.CreateMessage(ctx, CreateSpaceMessageRecord{Kind: "post_reply",@@ -629,6 +630,7 @@ func TestSpaceMessageConversationsUseLatestActivity(t *testing.T) {require.True(t, conversations[0].LatestActivity.MessageID.Valid)require.Equal(t, postReply.MessageID, conversations[0].LatestActivity.MessageID.String)require.Equal(t, postID, conversations[0].LatestActivity.PostID.Int64)+ require.False(t, conversations[0].LatestActivity.PostDeleted)replyOnlyPostID, err := testCreatePost(ctx, module, aliceID, aliceSpace.SpaceID, "reply-only-post-key", nil, aliceSpace.CurrentVersion, nil)require.NoError(t, err)@@ -650,6 +652,7 @@ func TestSpaceMessageConversationsUseLatestActivity(t *testing.T) {require.True(t, conversations[0].LatestActivity.MessageID.Valid)require.Equal(t, replyOnly.MessageID, conversations[0].LatestActivity.MessageID.String)require.Equal(t, replyOnlyPostID, conversations[0].LatestActivity.PostID.Int64)+ require.False(t, conversations[0].LatestActivity.PostDeleted)require.NoError(t, module.Posts.DeletePost(ctx, replyOnlyPostID, aliceSpace.SpaceID))@@ -660,6 +663,11 @@ func TestSpaceMessageConversationsUseLatestActivity(t *testing.T) {require.Equal(t, replyOnly.MessageID, conversations[0].LatestActivity.MessageID.String)require.True(t, conversations[0].LatestActivity.PostID.Valid)require.Equal(t, replyOnlyPostID, conversations[0].LatestActivity.PostID.Int64)+ require.True(t, conversations[0].LatestActivity.PostDeleted)+ thread, _, err := module.Messages.ListThread(ctx, aliceSpace.SpaceID, bobSpace.SpaceID, "", 10)+ require.NoError(t, err)+ require.Equal(t, replyOnly.MessageID, thread[0].MessageID)+ require.True(t, thread[0].ReplyPostDeleted)latestActivityAt, err := module.Read.GetLatestConversationActivityAt(ctx, aliceSpace.SpaceID, bobSpace.SpaceID)require.NoError(t, err)require.Equal(t, int64(5500), latestActivityAt)diff --git a/web/apps/space/src/services/space.ts b/web/apps/space/src/services/space.tsindex 6f687e9b9a..c04d157838 100644--- a/web/apps/space/src/services/space.ts+++ b/web/apps/space/src/services/space.ts@@ -92,6 +92,7 @@ interface SpaceMessageConversationActivity {messageId?: string;outgoing?: boolean;postId?: number;+ postDeleted?: boolean;postSpaceId?: string;text?: string;type: SpaceMessageConversationActivityType;@@ -119,6 +120,7 @@ interface SpaceMessageResponse {recipientSpaceId: string;replyMessageId?: string;replyPostId?: number;+ replyPostDeleted?: boolean;senderSpaceId: string;text: string;viewerLiked?: boolean;@@ -646,6 +648,9 @@ const messageQuoteFromReplyPost = async (postId: message.replyPostId,spaceId: message.recipientSpaceId,};+ if (message.replyPostDeleted) {+ return { ...fallbackQuote, isUnavailable: true };+ }if (!includeImage) return fallbackQuote;try {@@ -716,7 +721,11 @@ const messageActivityPostFromActivity = (if (typeof activity.postId != "number" || !activity.postSpaceId) {return undefined;}- return { postId: activity.postId, spaceId: activity.postSpaceId };+ return {+ isDeleted: Boolean(activity.postDeleted),+ postId: activity.postId,+ spaceId: activity.postSpaceId,+ };};export const loadCurrentMessageActivityPostPreview = async (diff --git a/web/apps/space/src/services/spaceProfile.ts b/web/apps/space/src/services/spaceProfile.tsindex 1a199b5db9..7f42c53742 100644--- a/web/apps/space/src/services/spaceProfile.ts+++ b/web/apps/space/src/services/spaceProfile.ts@@ -131,8 +131,17 @@ let currentSpaceContext:let pendingCurrentSpaceContext:| { cacheKey: string; promise: Promise<SpaceAccountCtxHandle> }| undefined;+let currentSpaceProfile:+ | { cacheKey: string; profile: SetupProfile | null }+ | undefined;+let pendingCurrentSpaceProfile:+ | { cacheKey: string; promise: Promise<SetupProfile | null> }+ | undefined;let currentSpaceContextGeneration = 0;+const cloneSetupProfile = (profile: SetupProfile | null) =>+ profile ? { ...profile } : null;+export const openCurrentSpaceContext = async () => {const config = await currentSpaceContextConfig();if (!config) return undefined;@@ -146,6 +155,8 @@ export const clearCurrentSpaceContext = () => {currentSpaceContextGeneration += 1;currentSpaceContext = undefined;pendingCurrentSpaceContext = undefined;+ currentSpaceProfile = undefined;+ pendingCurrentSpaceProfile = undefined;cached?.ctx.free();};@@ -245,19 +256,45 @@ const profileFromDecryptedSpaceProfile = (};};-export const loadExistingSpaceProfile = async () => {- if (!(await currentSpaceContextConfig())) return null;+export const loadExistingSpaceProfile = async (options?: {+ force?: boolean;+}) => {+ const config = await currentSpaceContextConfig();+ if (!config) return null;++ if (pendingCurrentSpaceProfile?.cacheKey == config.cacheKey) {+ return cloneSetupProfile(await pendingCurrentSpaceProfile.promise);+ }+ if (!options?.force && currentSpaceProfile?.cacheKey == config.cacheKey) {+ return cloneSetupProfile(currentSpaceProfile.profile);+ }- const ctx = await ensureCurrentSpaceContext();- const spaces = (await ctx.list_owned_spaces()) as OwnedSpace[];- const space = defaultOwnedSpace(spaces);- if (!space) return null;-- const spaceProfile = (await ctx.get_space_profile(- space.spaceId,- space.spaceId,- )) as DecryptedSpaceProfile;- return profileFromDecryptedSpaceProfile(spaceProfile);+ const promise = (async () => {+ const ctx = await ensureCurrentSpaceContext();+ const spaces = (await ctx.list_owned_spaces()) as OwnedSpace[];+ const space = defaultOwnedSpace(spaces);+ if (!space) return null;++ const spaceProfile = (await ctx.get_space_profile(+ space.spaceId,+ space.spaceId,+ )) as DecryptedSpaceProfile;+ return profileFromDecryptedSpaceProfile(spaceProfile);+ })();++ const pendingProfile = { cacheKey: config.cacheKey, promise };+ pendingCurrentSpaceProfile = pendingProfile;+ try {+ const profile = await promise;+ if (pendingCurrentSpaceProfile == pendingProfile) {+ currentSpaceProfile = { cacheKey: config.cacheKey, profile };+ }+ return cloneSetupProfile(profile);+ } finally {+ if (pendingCurrentSpaceProfile == pendingProfile) {+ pendingCurrentSpaceProfile = undefined;+ }+ }};export const loadExistingSpaceAvatar = async (@@ -405,7 +442,7 @@ export const saveSpaceProfile = async ()) as UpdateSpaceProfileResponse;}- return {+ const savedProfile = {avatarObjectID:updateResponse?.avatar?.objectID ?? profile.avatarObjectID,avatarUpdatedAt:@@ -421,6 +458,9 @@ export const saveSpaceProfile = async (spaceId,spaceSlug,};+ currentSpaceProfile = undefined;+ pendingCurrentSpaceProfile = undefined;+ return savedProfile;} catch (error) {if (spaceHTTPStatus(error) == 409) {throw new Error("This username is already taken.", {diff --git a/web/apps/space/src/state/SpaceAppStateProvider.tsx b/web/apps/space/src/state/SpaceAppStateProvider.tsxindex 119d17dcca..60aaf4a374 100644--- a/web/apps/space/src/state/SpaceAppStateProvider.tsx+++ b/web/apps/space/src/state/SpaceAppStateProvider.tsx@@ -160,7 +160,9 @@ export const SpaceAppStateProvider: React.FC<React.PropsWithChildren> = ({setProfileLoadStatus("loading");try {- const nextProfile = await loadExistingSpaceProfile();+ const nextProfile = await loadExistingSpaceProfile({+ force: true,+ });if (profileLoadGenerationRef.current == generation) {setProfileLoadError(undefined);applyProfile(nextProfile);