π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Show unfriend events in social notifications
Anand Baburajana6f6e0bb38e6
diff --git a/rust/wall/src/client.rs b/rust/wall/src/client.rsindex eaa097e254..a4ef86889b 100644--- a/rust/wall/src/client.rs+++ b/rust/wall/src/client.rs@@ -2643,28 +2643,38 @@ mod tests {.with_status(200).with_body(json!({- "items": [{- "id": "post_like:42:9",- "type": "likedPost",- "createdAt": "2026-04-16T00:00:00Z",- "actor": {- "userId": 9,- "username": "mira",- "wallId": "wall_mira",- "wallSlug": "mira"- },- "post": {- "postId": 42,- "wallId": "wall_owner_gallery",- "wallSlug": "owner-gallery",- "ownerUserId": 7,- "author": {- "userId": 7,+ "items": [+ {+ "id": "post_like:42:9",+ "type": "likedPost",+ "createdAt": "2026-04-16T00:00:00Z",+ "actor": {+ "userId": 9,+ "username": "mira",+ "wallId": "wall_mira",+ "wallSlug": "mira"+ },+ "post": {+ "postId": 42,"wallId": "wall_owner_gallery",- "wallSlug": "owner-gallery"+ "wallSlug": "owner-gallery",+ "ownerUserId": 7,+ "author": {+ "userId": 7,+ "wallId": "wall_owner_gallery",+ "wallSlug": "owner-gallery"+ }+ }+ },+ {+ "id": "friend_remove:12",+ "type": "removedYouAsFriend",+ "createdAt": "2026-04-17T00:00:00Z",+ "actor": {+ "wallSlug": "mira"}}- }],+ ],"nextCursor": "cursor-2"}).to_string(),@@ -2677,11 +2687,15 @@ mod tests {.await.expect("notifications should load");- assert_eq!(page.items.len(), 1);+ assert_eq!(page.items.len(), 2);assert_eq!(page.items[0].notification_type,crate::transport::WallNotificationType::LikedPost);+ assert_eq!(+ page.items[1].notification_type,+ crate::transport::WallNotificationType::RemovedYouAsFriend+ );assert_eq!(page.items[0].actor.wall_slug, "mira");assert_eq!(page.next_cursor, "cursor-2");notifications.assert_async().await;diff --git a/rust/wall/src/transport.rs b/rust/wall/src/transport.rsindex 0834b6f94c..ce2f09cbf2 100644--- a/rust/wall/src/transport.rs+++ b/rust/wall/src/transport.rs@@ -168,6 +168,7 @@ pub struct PostPage {pub enum WallNotificationType {LikedPost,AddedYouAsFriend,+ RemovedYouAsFriend,}#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]diff --git a/server/migrations/121_wall.up.sql b/server/migrations/121_wall.up.sqlindex 96976b5346..348079d32a 100644--- a/server/migrations/121_wall.up.sql+++ b/server/migrations/121_wall.up.sql@@ -132,17 +132,22 @@ EXECUTE PROCEDURE trigger_updated_at_microseconds_column();CREATE TABLE IF NOT EXISTS wall_friend_events (event_id BIGSERIAL PRIMARY KEY,+ event_type TEXT NOT NULL DEFAULT 'friend_add',actor_id BIGINT NOT NULL REFERENCES users (user_id) ON DELETE CASCADE,actor_wall_id TEXT NOT NULL REFERENCES walls (wall_id) ON DELETE CASCADE,target_id BIGINT NOT NULL REFERENCES users (user_id) ON DELETE CASCADE,target_wall_id TEXT NOT NULL REFERENCES walls (wall_id) ON DELETE CASCADE,created_at BIGINT NOT NULL DEFAULT now_utc_micro_seconds(),- CONSTRAINT chk_wall_friend_events_distinct_users CHECK (actor_id <> target_id)+ CONSTRAINT chk_wall_friend_events_distinct_users CHECK (actor_id <> target_id),+ CONSTRAINT chk_wall_friend_events_type CHECK (event_type IN ('friend_add', 'friend_remove')));CREATE INDEX IF NOT EXISTS idx_wall_friend_events_target_createdON wall_friend_events (target_id, created_at DESC);+CREATE INDEX IF NOT EXISTS idx_wall_friend_events_target_type_created+ ON wall_friend_events (target_id, event_type, created_at DESC);+CREATE TABLE IF NOT EXISTS wall_links (wall_id TEXT PRIMARY KEY REFERENCES walls (wall_id) ON DELETE CASCADE,auth_key_hash BYTEA NOT NULL UNIQUE,diff --git a/server/wall/repo/friends.go b/server/wall/repo/friends.goindex 29fc21b0ff..5e6fa8c723 100644--- a/server/wall/repo/friends.go+++ b/server/wall/repo/friends.go@@ -86,8 +86,8 @@ func (r *FriendsRepository) AddFriend(ctx context.Context, requesterID int64, reif !alreadyFriends {if _, err := tx.ExecContext(ctx, `- INSERT INTO wall_friend_events (actor_id, actor_wall_id, target_id, target_wall_id)- VALUES ($1, $2, $3, $4)+ INSERT INTO wall_friend_events (event_type, actor_id, actor_wall_id, target_id, target_wall_id)+ VALUES ('friend_add', $1, $2, $3, $4)`, requesterID, requesterWallID, targetOwnerID, targetWallID); err != nil {return stacktrace.Propagate(err, "")}@@ -165,23 +165,42 @@ func (r *FriendsRepository) DeleteFriendship(ctx context.Context, userID int64,defer tx.Rollback()var targetOwnerID int64- if err := tx.QueryRowContext(ctx, `SELECT owner_id FROM walls WHERE wall_id = $1`, targetWallID).Scan(&targetOwnerID); err != nil {+ var actorWallID string+ if err := tx.QueryRowContext(ctx, `+ SELECT target_wall.owner_id, actor_wall.wall_id+ FROM walls target_wall+ JOIN walls actor_wall ON actor_wall.owner_id = $2+ WHERE target_wall.wall_id = $1+ `, targetWallID, userID).Scan(&targetOwnerID, &actorWallID); err != nil {return stacktrace.Propagate(err, "")}if targetOwnerID == userID {return nil}- if _, err := tx.ExecContext(ctx, `+ res, err := tx.ExecContext(ctx, `DELETE FROM wall_friend_sharesWHERE (wall_id = $1 AND friend_id = $2)OR (friend_id = $3AND wall_id IN (SELECT wall_id FROM walls WHERE owner_id = $2))- `, targetWallID, userID, targetOwnerID); err != nil {+ `, targetWallID, userID, targetOwnerID)+ if err != nil {+ return stacktrace.Propagate(err, "")+ }+ affected, err := res.RowsAffected()+ if err != nil {return stacktrace.Propagate(err, "")}+ if affected > 0 {+ if _, err := tx.ExecContext(ctx, `+ INSERT INTO wall_friend_events (event_type, actor_id, actor_wall_id, target_id, target_wall_id)+ VALUES ('friend_remove', $1, $2, $3, $4)+ `, userID, actorWallID, targetOwnerID, targetWallID); err != nil {+ return stacktrace.Propagate(err, "")+ }+ }return stacktrace.Propagate(tx.Commit(), "")}diff --git a/server/wall/repo/module_test.go b/server/wall/repo/module_test.goindex 386e257c16..781e0cbc35 100644--- a/server/wall/repo/module_test.go+++ b/server/wall/repo/module_test.go@@ -346,7 +346,7 @@ func TestAddFriendCreatesReciprocalSharesAndEvent(t *testing.T) {require.Equal(t, bobWall.CurrentVersion, reciprocalShare.KeyVersion)var eventCount int- err = module.Friends.DB.QueryRow(`SELECT COUNT(*) FROM wall_friend_events WHERE actor_id = $1 AND target_id = $2`, bobID, aliceID).Scan(&eventCount)+ err = module.Friends.DB.QueryRow(`SELECT COUNT(*) FROM wall_friend_events WHERE event_type = 'friend_add' AND actor_id = $1 AND target_id = $2`, bobID, aliceID).Scan(&eventCount)require.NoError(t, err)require.Equal(t, 1, eventCount)}@@ -371,7 +371,7 @@ func TestAddFriendIsIdempotentForExistingFriends(t *testing.T) {require.NoError(t, err)require.Equal(t, "alice-share-key-v2", share.EncryptedWallKey)var eventCount int- err = module.Friends.DB.QueryRow(`SELECT COUNT(*) FROM wall_friend_events WHERE actor_id = $1 AND target_id = $2`, bobID, aliceID).Scan(&eventCount)+ err = module.Friends.DB.QueryRow(`SELECT COUNT(*) FROM wall_friend_events WHERE event_type = 'friend_add' AND actor_id = $1 AND target_id = $2`, bobID, aliceID).Scan(&eventCount)require.NoError(t, err)require.Equal(t, 1, eventCount)}@@ -415,6 +415,31 @@ func TestDeleteFriendshipRemovesReciprocalShares(t *testing.T) {relationship, err := module.Friends.GetRelationship(ctx, aliceID, bobID, bobWall.WallID)require.NoError(t, err)require.Empty(t, relationship)++ var removeEventCount int+ err = module.Friends.DB.QueryRow(`+ SELECT COUNT(*)+ FROM wall_friend_events+ WHERE event_type = 'friend_remove'+ AND actor_id = $1+ AND actor_wall_id = $2+ AND target_id = $3+ AND target_wall_id = $4+ `, aliceID, aliceWall.WallID, bobID, bobWall.WallID).Scan(&removeEventCount)+ require.NoError(t, err)+ require.Equal(t, 1, removeEventCount)++ err = module.Friends.DeleteFriendship(ctx, aliceID, bobWall.WallID)+ require.NoError(t, err)+ err = module.Friends.DB.QueryRow(`+ SELECT COUNT(*)+ FROM wall_friend_events+ WHERE event_type = 'friend_remove'+ AND actor_id = $1+ AND target_id = $2+ `, aliceID, bobID).Scan(&removeEventCount)+ require.NoError(t, err)+ require.Equal(t, 1, removeEventCount)}func TestUpdateShareOnlyRefreshesExistingShares(t *testing.T) {@@ -777,7 +802,7 @@ func TestNotificationsIncludeWallSocialEvents(t *testing.T) {err = module.Friends.AddFriend(ctx, bobID, bobWall.WallID, aliceWall.WallID, "alice-share-key", aliceWall.CurrentVersion, "bob-share-key", bobWall.CurrentVersion)require.NoError(t, err)- setFriendEventCreatedAt(t, module, 3000, bobID, aliceID)+ setFriendEventCreatedAt(t, module, 3000, "friend_add", bobID, aliceID)page, nextCursor, err := module.Notifications.List(ctx, aliceID, "", 3)require.NoError(t, err)@@ -785,6 +810,17 @@ func TestNotificationsIncludeWallSocialEvents(t *testing.T) {require.Equal(t, "addedYouAsFriend", page[0].Type)require.Equal(t, "likedPost", page[1].Type)require.Empty(t, nextCursor)++ err = module.Friends.DeleteFriendship(ctx, aliceID, bobWall.WallID)+ require.NoError(t, err)+ setFriendEventCreatedAt(t, module, 4000, "friend_remove", aliceID, bobID)++ page, nextCursor, err = module.Notifications.List(ctx, bobID, "", 3)+ require.NoError(t, err)+ require.Len(t, page, 1)+ require.Equal(t, "removedYouAsFriend", page[0].Type)+ require.Equal(t, aliceID, page[0].Actor.UserID)+ require.Empty(t, nextCursor)}func TestListPostLikersPaginates(t *testing.T) {@@ -863,8 +899,8 @@ func setPostLikeCreatedAt(t *testing.T, module *Module, createdAt, postID, userIrequire.NoError(t, err)}-func setFriendEventCreatedAt(t *testing.T, module *Module, createdAt, actorID, targetID int64) {+func setFriendEventCreatedAt(t *testing.T, module *Module, createdAt int64, eventType string, actorID, targetID int64) {t.Helper()- _, err := module.Friends.DB.Exec(`UPDATE wall_friend_events SET created_at = $1 WHERE actor_id = $2 AND target_id = $3`, createdAt, actorID, targetID)+ _, err := module.Friends.DB.Exec(`UPDATE wall_friend_events SET created_at = $1 WHERE event_type = $2 AND actor_id = $3 AND target_id = $4`, createdAt, eventType, actorID, targetID)require.NoError(t, err)}diff --git a/server/wall/repo/notifications.go b/server/wall/repo/notifications.goindex 27b2e906e2..152cd6dacd 100644--- a/server/wall/repo/notifications.go+++ b/server/wall/repo/notifications.go@@ -56,8 +56,14 @@ const wallNotificationRows = `UNION ALLSELECT- 'friend_add:' || fe.event_id::text AS notification_id,- 'addedYouAsFriend' AS notification_type,+ CASE fe.event_type+ WHEN 'friend_remove' THEN 'friend_remove:'+ ELSE 'friend_add:'+ END || fe.event_id::text AS notification_id,+ CASE fe.event_type+ WHEN 'friend_remove' THEN 'removedYouAsFriend'+ ELSE 'addedYouAsFriend'+ END AS notification_type,fe.created_at,actor_wall.owner_id, actor_wall.wall_id, actor_wall.wall_slug, actor_ka.public_key,actor_wall.current_version, actor_wall.encrypted_profile, actor_wall.avatar_object_key,diff --git a/web/apps/social/src/screens/NotificationsScreen.tsx b/web/apps/social/src/screens/NotificationsScreen.tsxindex ebb44e0372..37181585d6 100644--- a/web/apps/social/src/screens/NotificationsScreen.tsx+++ b/web/apps/social/src/screens/NotificationsScreen.tsx@@ -1,4 +1,8 @@-import { ArrowLeft02Icon, UserAdd01Icon } from "@hugeicons/core-free-icons";+import {+ ArrowLeft02Icon,+ UserAdd01Icon,+ UserRemove01Icon,+} from "@hugeicons/core-free-icons";import { HugeiconsIcon } from "@hugeicons/react";import { Box } from "@mui/material";import {@@ -28,7 +32,7 @@ const timelineLineTop = iconCircleTopOffset + iconCircleSize;const timelineListInset = "12px";const thumbnailRightInset = "16px";-type NotificationType = "liked-post" | "added-friend";+type NotificationType = "liked-post" | "added-friend" | "removed-friend";interface SocialNotification {actor: Pick<FriendProfile, "avatarUrl" | "fullName" | "id" | "username">;@@ -80,6 +84,10 @@ const UserAddNotificationIcon: React.FC = () => (<HugeiconsIcon icon={UserAdd01Icon} size={17} strokeWidth={1.8} />);+const UserRemoveNotificationIcon: React.FC = () => (+ <HugeiconsIcon icon={UserRemove01Icon} size={17} strokeWidth={1.8} />+);+const actionForNotification = (type: NotificationType,): { icon: React.ReactNode; label: string } => {@@ -91,6 +99,11 @@ const actionForNotification = (icon: <UserAddNotificationIcon />,label: "added you as a friend",};+ case "removed-friend":+ return {+ icon: <UserRemoveNotificationIcon />,+ label: "removed you as a friend",+ };}};@@ -535,7 +548,7 @@ export const NotificationsScreen: React.FC<NotificationsScreenProps> = ({maxWidth: 240,}}>- Likes, replies and new friends will appear here.+ Likes and friend updates will appear here.</Box></Box>)}diff --git a/web/apps/social/src/services/socialWall.ts b/web/apps/social/src/services/socialWall.tsindex f42eb9aa6f..bededc8565 100644--- a/web/apps/social/src/services/socialWall.ts+++ b/web/apps/social/src/services/socialWall.ts@@ -1,8 +1,8 @@+import type { FriendProfile } from "data/friends";import { clientPackageName, desktopAppVersion, isDesktop } from "ente-base/app";import { apiOrigin } from "ente-base/origins";import type { WallAccountCtxHandle, WallLinkCtxHandle } from "ente-wasm";import { loadEnteWasm } from "ente-wasm/load";-import type { FriendProfile } from "data/friends";import type { PendingSocialInvite } from "services/socialInvite";import { socialInviteURL } from "services/socialInvite";import { ensureCurrentWallContext } from "services/socialProfile";@@ -80,7 +80,7 @@ interface WallNotification {wallId: string;wallSlug: string;};- type: "likedPost" | "addedYouAsFriend";+ type: "likedPost" | "addedYouAsFriend" | "removedYouAsFriend";}interface WallNotificationPage {@@ -118,7 +118,7 @@ export interface SocialWallNotification {id: string;post?: SocialWallPost;timestampMs: number;- type: "added-friend" | "liked-post";+ type: "added-friend" | "liked-post" | "removed-friend";}export interface SocialWallNotificationPage {@@ -519,7 +519,9 @@ export const loadCurrentNotificationsPage =const notificationType: SocialWallNotification["type"] =notification.type == "addedYouAsFriend"? "added-friend"- : "liked-post";+ : notification.type == "removedYouAsFriend"+ ? "removed-friend"+ : "liked-post";return {actor,id: notification.id,@@ -550,7 +552,8 @@ export const loadPublicSocialInvite = async ({wallUsername,});try {- const wallProfile = (await ctx.get_wall_profile()) as WallProfileResponse;+ const wallProfile =+ (await ctx.get_wall_profile()) as WallProfileResponse;const profile = profileFromWallProfile(wallProfile);profile.avatarUrl = await linkAvatarURL(ctx, wallProfile.avatar);const posts = await postPageFromLinkPage(