diff --git a/apps/lists/CHANGELOG.md b/apps/lists/CHANGELOG.md index c6d615c37..8d30dc9e0 100644 --- a/apps/lists/CHANGELOG.md +++ b/apps/lists/CHANGELOG.md @@ -4,7 +4,7 @@ - Lists are chips that wrap onto more rows; pull the items down to show or hide finished ones. - List settings, from the gear on the selected list: its name, who has access, invitations with a role, and Delete after a question. -- A shared list names its people under the lists; items are edited in their own row. +- A shared list names its people under the lists, with their profile pictures; items are edited in their own row. ## [1.1.10] - 2026-10-23 diff --git a/apps/lists/lists_view.zi b/apps/lists/lists_view.zi index e8af58b7f..d7203b71b 100644 --- a/apps/lists/lists_view.zi +++ b/apps/lists/lists_view.zi @@ -33,6 +33,8 @@ #import "drawing_props" #import "tree" #import "icon" +#import "image_props" +#import "image_widget" EditIcon :: #import "mingcute/mingcute_regular_edit_2"; SettingsIcon :: #import "mingcute/mingcute_regular_settings_3"; BackIcon :: #import "mingcute/mingcute_regular_arrow_left"; @@ -117,8 +119,15 @@ AvatarFill :: (place: s32) -> Color { return Color.{58, 110, 165, 255} } -// A round avatar with the first letter of a name. -Avatar :: (key: u64, name: string, place: s32, x: s32, y: s32, size: s32) { +// A person's profile picture, or a round avatar with the first letter of +// their name when they have not chosen one. +Avatar :: (key: u64, name: string, place: s32, x: s32, y: s32, size: s32, icon: s32) { + if (icon >= 41 && icon <= 65) || (icon >= 124 && icon <= 126) { + picture := ImageForIcon(icon, Bounds(x, y, size, size), name) + picture.key = key + Image(frame.session, picture) + return + } Box(frame.session, BoxProps.{.key = key, .bounds = Bounds(x, y, size, size), .fill = AvatarFill(place), .radius = cast(float32)size / 2.0}) letter_end: s64 = 1 @@ -475,7 +484,8 @@ MemberRow :: (row: ListsUiPerson, place: s32, x: s32, y: s32, width: s32, manage shown = BuilderFinish(invited) } avatar := Scale(36) - Avatar(cast(u64)(7900 + place), shown, place, x, y + (Scale(MEMBER_ROW) - avatar) / 2, avatar) + icon := ifx row.target == frame.public_id then frame.profile_icon else row.profile_icon + Avatar(cast(u64)(7900 + place), shown, place, x, y + (Scale(MEMBER_ROW) - avatar) / 2, avatar, icon) role_width := Scale(140) name_x := x + avatar + Scale(12) Text(frame.session, TextProps.{.bounds = Bounds(name_x, y, x + width - role_width - Scale(8) - name_x, Scale(MEMBER_ROW)), @@ -876,8 +886,8 @@ ListSettingsPage :: () { if !shared || owner_id == frame.public_id { owner_name = ListsLocaleHost("elist_you") } - MemberRow(ListsUiPerson.{.target = owner_id, .target_alias = owner_name, .access = "owner"}, - 0, x, cy, inner, false, true, blocked) + MemberRow(ListsUiPerson.{.target = owner_id, .target_alias = owner_name, .access = "owner", + .profile_icon = FriendIcon(owner_id)}, 0, x, cy, inner, false, true, blocked) cy += Scale(MEMBER_ROW) place: s32 = 1 for index: cast(s32)0..frame.invitation_count - 1 { @@ -945,43 +955,65 @@ ListSettingsPage :: () { } } +// A friend's profile picture, or this account's own; 0 when unknown. +FriendIcon :: (id: string) -> s32 { + if id == frame.public_id { + return frame.profile_icon + } + for index: cast(s32)0..frame.friend_count - 1 { + friend := ReadListsSharingRowHost(index, false) + if friend.id == id { + return friend.profile_icon + } + } + return 0 +} + // Under the chips, a shared list shows who has it, as a document does: -// avatars and names, invited people marked. A tap opens List settings. +// pictures and names, invited people marked. A tap opens List settings. SharedLine :: (current: ListsUiRow, x: s32, y: s32, width: s32) -> bool { - people := Copied(current.people) - invited := ifx current.owner then Copied(current.invited) else "" - invited_label := Copied(ListsLocaleHost("elist_invited")) + list_id := Copied(current.id) + owner_id := Copied(current.owner_id) + owner_name := Copied(ifx current.owner_alias.count > 0 then current.owner_alias else current.people) + owns := current.owner title := Copied(current.title) + invited_label := Copied(ListsLocaleHost("elist_invited")) text: Vec(u8) - initials: [3]string + names: [3]string + icons: [3]s32 count: s32 = 0 - for group: cast(s32)0..1 { - source := ifx group == 0 then people else invited - start: s64 = 0 - at: s64 = 0 - while at <= source.count { - separator := at + 1 < source.count && source[at] == cast(u8)44 && source[at + 1] == cast(u8)32 - if at == source.count || separator { - name := source[start:at] - if name.count > 0 { - if text.count > 0 { - BuilderPrint(*text, " · ") - } - if group == 0 { - BuilderPrint(*text, "%", name) - } else { - BuilderPrint(*text, "% (%)", name, invited_label) - } - if count < 3 { - initials[count] = name - } - count += 1 - } - start = at + 2 - at += 2 - } else { - at += 1 + if !owns { + BuilderPrint(*text, "%", owner_name) + names[0] = owner_name + icons[0] = FriendIcon(owner_id) + count = 1 + } + // People who joined come first, then those still invited. + for pass: cast(s32)0..1 { + if !owns { + break + } + for index: cast(s32)0..frame.invitation_count - 1 { + row := ReadListsSharingRowHost(index, true) + if !SharingMemberShown(row, list_id) || (row.status == "pending") != (pass == 1) { + continue } + icon := row.profile_icon + name := Copied(ifx row.target_alias.count > 0 then row.target_alias else + row.target[:ifx row.target.count > 8 then 8 else row.target.count]) + if text.count > 0 { + BuilderPrint(*text, " · ") + } + if pass == 0 { + BuilderPrint(*text, "%", name) + } else { + BuilderPrint(*text, "% (%)", name, invited_label) + } + if count < 3 { + names[count] = name + icons[count] = icon + } + count += 1 } } if count == 0 { @@ -991,7 +1023,7 @@ SharedLine :: (current: ListsUiRow, x: s32, y: s32, width: s32) -> bool { step := Scale(22) shown := ifx count > 3 then 3 else count for place: cast(s32)0..shown - 1 { - Avatar(cast(u64)(7950 + place), initials[place], place, x + place * step, y + Scale(4), size) + Avatar(cast(u64)(7950 + place), names[place], place, x + place * step, y + Scale(4), size, icons[place]) } text_x := x + (shown - 1) * step + size + Scale(10) if Button(frame.session, ButtonProps.{.key = cast(u64)6508, diff --git a/src/app/app_sync.zi b/src/app/app_sync.zi index 1a4df80c8..01bd0ecb8 100644 --- a/src/app/app_sync.zi +++ b/src/app/app_sync.zi @@ -62,6 +62,7 @@ GetTime :: () -> float64 #foreign c; #import, file "app_notifications.zi"; #import, file "../screens/profile_social.zi"; #import, file "sync_retry.zi"; +#import, file "profile_icon_publish.zi"; #import, file "../app/text_buffers.zi"; #import, file "locale.zi"; @@ -1376,6 +1377,7 @@ app_sync_pump :: (app: *InnerBreeze) { app_clear_disconnected_sync_work() return } + ProfileIconPublishPump(app.profile_picture_icon, AppTextFromCString(*url[0], 256), now) last_result := SettingsReadInt("sync_last_result", SYNC_OK) if !app_sync_retry_ready(last_result, now) { return diff --git a/src/app/profile_icon_publish.zi b/src/app/profile_icon_publish.zi new file mode 100644 index 000000000..682d750a9 --- /dev/null +++ b/src/app/profile_icon_publish.zi @@ -0,0 +1,55 @@ +// The profile picture chosen in Inner Breeze goes to the account's node, so +// friends see it in Lists and wherever the node shows people. It is sent in +// the background once per new choice; a failed attempt waits ten minutes, +// and nothing here ever holds up the app. +#import "text" +#import "vec" +#import "text_buffer" +#import "auth" +#import, file "../storage/sync_state.zi"; +#import, file "../storage/delegate_store.zi"; +#import, file "../storage/sync_async.zi"; +#import, file "../storage/storage_settings.zi"; +#import, file "../platform/network_transport.zi"; + +profile_icon_operation: StoredOperation; +profile_icon_transfer: NetworkTransfer; +profile_icon_response: [1024]u8; +// The picture on its way, saved as sent once the node accepts it. +profile_icon_sending: s32; +profile_icon_retry_at: float64; + +ProfileIconPublishPump :: (picture: s32, server: string, now: float64) { + if profile_icon_operation.active { + if !PollStoredOperation(*profile_icon_operation) { + return + } + if profile_icon_operation.result == cast(s32)AuthResult.AUTH_OK { + storage_set_setting_int("profile_icon_published", profile_icon_sending) + } else { + profile_icon_retry_at = now + 600.0 + } + return + } + if picture <= 0 || now < profile_icon_retry_at || server.count == 0 { + return + } + if storage_get_setting_int("profile_icon_published", 0) == picture { + return + } + if storage_has_sync_account() == 0 || StoredAccountMode() == AccountModeDelegate { + return + } + body: Vec(u8) + BuilderPrint(*body, "{\"user_id_hash\":\"%\",\"profile_icon\":%}", + storage_get_setting_text("sync_public_id"), picture) + request := BuilderFinish(body) + profile_icon_response = .{} + if !BeginStoredRequest(*profile_icon_operation, server, + NetworkTransport(*profile_icon_transfer), "POST", "/api/v1/account/profile-icon", + request, profile_icon_response[:], true) { + profile_icon_retry_at = now + 600.0 + return + } + profile_icon_sending = picture +} diff --git a/src/cells/app_codec.zi b/src/cells/app_codec.zi index 0debc591b..92d311555 100644 --- a/src/cells/app_codec.zi +++ b/src/cells/app_codec.zi @@ -786,7 +786,7 @@ WidgetValidInbeUiFrame :: (value: HostValue) -> bool { } WidgetListsUiFrameCodec :: struct { - fields: [25]HostField + fields: [26]HostField session: WidgetSessionCodec input: WidgetTextFieldInputCodec } @@ -796,7 +796,7 @@ WidgetEncodeListsUiFrame :: (data: ListsUiFrame, codec: *WidgetListsUiFrameCodec value.kind = cast(s32)HostRecord value.type_name = HostTextData("ListsUiFrame") value.fields = *codec.fields[0] - value.field_count = 25 + value.field_count = 26 codec.fields[0].name = HostTextData("session") codec.fields[0].value = WidgetEncodeSession(data.session, *codec.session) codec.fields[1].name = HostTextData("width") @@ -847,6 +847,8 @@ WidgetEncodeListsUiFrame :: (data: ListsUiFrame, codec: *WidgetListsUiFrameCodec codec.fields[23].value = HostValue.{.kind = cast(s32)HostString, .type_name = HostTextData("string"), .data = HostTextData(data.pending_count_text), .length = cast(usize)data.pending_count_text.count} codec.fields[24].name = HostTextData("next_id") codec.fields[24].value = HostValue.{.kind = cast(s32)HostString, .type_name = HostTextData("string"), .data = HostTextData(data.next_id), .length = cast(usize)data.next_id.count} + codec.fields[25].name = HostTextData("profile_icon") + codec.fields[25].value = HostScalar("s32", cast(s64)data.profile_icon) return value } @@ -1002,6 +1004,12 @@ WidgetDecodeListsUiFrame :: (value: HostValue, codec: *WidgetListsUiFrameCodec) data.next_id = TextFromBytes(BytesFromPointer(value.fields[field_at].value.data, cast(u64)value.fields[field_at].value.length)) } } + { + field_at := HostFieldAt(value, 25, "profile_icon") + if field_at >= 0 { + data.profile_icon = cast(s32)value.fields[field_at].value.integer + } + } return data } @@ -1159,6 +1167,12 @@ WidgetValidListsUiFrame :: (value: HostValue) -> bool { if !HostScalarValid(value.fields[field_at].value, "string", cast(s32)HostString) { return false } } } + { + field_at := HostFieldAt(value, 25, "profile_icon") + if field_at >= 0 { + if !HostScalarValid(value.fields[field_at].value, "s32", cast(s32)HostInteger) { return false } + } + } return true } @@ -1399,7 +1413,7 @@ WidgetValidListsUiRow :: (value: HostValue) -> bool { } WidgetListsUiPersonCodec :: struct { - fields: [9]HostField + fields: [10]HostField } WidgetEncodeListsUiPerson :: (data: ListsUiPerson, codec: *WidgetListsUiPersonCodec) -> HostValue { @@ -1407,7 +1421,7 @@ WidgetEncodeListsUiPerson :: (data: ListsUiPerson, codec: *WidgetListsUiPersonCo value.kind = cast(s32)HostRecord value.type_name = HostTextData("ListsUiPerson") value.fields = *codec.fields[0] - value.field_count = 9 + value.field_count = 10 codec.fields[0].name = HostTextData("id") codec.fields[0].value = HostValue.{.kind = cast(s32)HostString, .type_name = HostTextData("string"), .data = HostTextData(data.id), .length = cast(usize)data.id.count} codec.fields[1].name = HostTextData("alias") @@ -1426,6 +1440,8 @@ WidgetEncodeListsUiPerson :: (data: ListsUiPerson, codec: *WidgetListsUiPersonCo codec.fields[7].value = HostValue.{.kind = cast(s32)HostString, .type_name = HostTextData("string"), .data = HostTextData(data.target_alias), .length = cast(usize)data.target_alias.count} codec.fields[8].name = HostTextData("access") codec.fields[8].value = HostValue.{.kind = cast(s32)HostString, .type_name = HostTextData("string"), .data = HostTextData(data.access), .length = cast(usize)data.access.count} + codec.fields[9].name = HostTextData("profile_icon") + codec.fields[9].value = HostScalar("s32", cast(s64)data.profile_icon) return value } @@ -1486,6 +1502,12 @@ WidgetDecodeListsUiPerson :: (value: HostValue, codec: *WidgetListsUiPersonCodec data.access = TextFromBytes(BytesFromPointer(value.fields[field_at].value.data, cast(u64)value.fields[field_at].value.length)) } } + { + field_at := HostFieldAt(value, 9, "profile_icon") + if field_at >= 0 { + data.profile_icon = cast(s32)value.fields[field_at].value.integer + } + } return data } @@ -1547,6 +1569,12 @@ WidgetValidListsUiPerson :: (value: HostValue) -> bool { if !HostScalarValid(value.fields[field_at].value, "string", cast(s32)HostString) { return false } } } + { + field_at := HostFieldAt(value, 9, "profile_icon") + if field_at >= 0 { + if !HostScalarValid(value.fields[field_at].value, "s32", cast(s32)HostInteger) { return false } + } + } return true } diff --git a/src/cells/lists_ui_types.zi b/src/cells/lists_ui_types.zi index 83c8cc94f..653fa8d92 100644 --- a/src/cells/lists_ui_types.zi +++ b/src/cells/lists_ui_types.zi @@ -27,6 +27,8 @@ ListsUiFrame :: struct { invitation_count: s32 pending_count_text: string next_id: string + // This account's profile picture, an icon number; 0 when none is set. + profile_icon: s32 } ListsUiRow :: struct { @@ -61,6 +63,9 @@ ListsUiPerson :: struct { status: string target_alias: string access: string + // The profile picture of the friend, or of the invited person or the + // list's owner; 0 when it is not known. + profile_icon: s32 } ListsUiRequest :: struct { diff --git a/src/screens/elist_screen.zi b/src/screens/elist_screen.zi index d577aa3fc..88d6be5b3 100644 --- a/src/screens/elist_screen.zi +++ b/src/screens/elist_screen.zi @@ -27,6 +27,7 @@ app_auto_sync :: (app: *InnerBreeze) -> s32 #foreign c; #import, file "../screens/elist_types.zi"; #import, file "../app/metrics.zi"; +#import, file "../app/profile_picture_policy.zi"; elist_ids_equal :: (first: *u8, second: *u8) -> bool { if first == null || second == null { @@ -308,6 +309,14 @@ ListsUiCall :: (context: *void, module: *u8, function: *u8, row.status = AppTextFromCString(*lists_person_text[6][0], 512) row.target_alias = AppTextFromCString(*lists_person_text[7][0], 512) row.access = AppTextFromCString(*lists_person_text[8][0], 512) + if !invitation { + row.profile_icon = ListsProfileIcon(source, object) + } else { + // An invitation shows the other person: whoever it went to, + // or the owner when it came to this account. + person := ifx row.target == storage_get_setting_text("sync_public_id") then row.owner else row.target + row.profile_icon = ListsFriendIcon(AppTextFromCString(*lists_friends[0], 8192), person) + } } result.* = WidgetEncodeListsUiPerson(row, *lists_person_codec) return 1 @@ -323,6 +332,38 @@ ListsUiCall :: (context: *void, module: *u8, function: *u8, return 0 } +// A friend's profile picture as Kryon's icon number. The node still keeps +// pictures chosen in older clients by their own numbers 1 to 11; those map +// to the same pictures. +ListsProfileIcon :: (friends: string, friend: s32) -> s32 { + at := FieldAt(friends, friend, "profile_icon") + if at < 0 { + return 0 + } + icon := cast(s32)ReadNumber(friends, at).value + legacy: [12]s32 = .[0, 42, 43, 46, 53, 54, 55, 62, 63, 64, 65, 65] + if icon >= 0 && icon <= 11 { + return legacy[icon] + } + return ifx ProfilePictureValid(icon) then icon else 0 +} + +ListsFriendIcon :: (friends: string, id: string) -> s32 { + if id.count == 0 { + return 0 + } + array := FieldAt(friends, 0, "friends") + for index: cast(s32)0..ArrayCount(friends, array) - 1 { + friend := ElementAt(friends, array, index) + user: [65]u8 + ListsCopyJson(friends, friend, "user_id_hash", user[:]) + if AppTextFromCString(*user[0], 65) == id { + return ListsProfileIcon(friends, friend) + } + } + return 0 +} + draw_elist_screen :: (app: *InnerBreeze) { ListsNetworkContext() if app.elist.loaded == 0 { @@ -369,7 +410,7 @@ draw_elist_screen :: (app: *InnerBreeze) { FieldAt(AppTextFromCString(*lists_friends[0], 8192), 0, "friends")), .invitation_count = lists_invitation_count, .pending_count_text = AppTextFromCString(*lists_pending_number[0], 24), - .next_id = next_id} + .next_id = next_id, .profile_icon = app.profile_picture_icon} message := elist_message_for(*app.elist, LISTS_FRAME, -1) message.now = GetTime() WidgetHostBegin(app.ui.session, HostedAssetAllowed) diff --git a/tests/lists_ui_test.py b/tests/lists_ui_test.py index c2dec5679..4d4cd4e1a 100644 --- a/tests/lists_ui_test.py +++ b/tests/lists_ui_test.py @@ -333,9 +333,14 @@ with contextlib.ExitStack() as stack: user = db.execute("SELECT id FROM users LIMIT 1").fetchone()[0] db.execute("INSERT OR REPLACE INTO social_snapshots VALUES(?,?,?,1)", (user, "friends.list", json.dumps({"friends": [ - {"user_id_hash": "a" * 64, "alias": "Alice"}, {"user_id_hash": "c" * 64, "alias": "Cedar"}, + {"user_id_hash": "a" * 64, "alias": "Alice", "profile_icon": 55}, + {"user_id_hash": "c" * 64, "alias": "Cedar", "profile_icon": 0}, {"user_id_hash": "d" * 64, "alias": "Dana"}, {"user_id_hash": "e" * 64, "alias": "Emerald"}]}))) time.sleep(.5) + # People show their own profile picture; someone without one keeps the + # first letter of their name. + driver.wait(label="Alice", role="image") + assert not driver.find(label="Cedar (Invited)", role="image"), "a person without a picture got one" driver.press(label="Alice · Cedar (Invited)", role="button") driver.wait(label="List settings") time.sleep(1.0) @@ -346,6 +351,8 @@ with contextlib.ExitStack() as stack: assert "Dana" not in names and "Emerald" not in names, names assert "Owner" in names and "Read only" in names, names assert "Refresh" not in names, names + driver.wait(label="Alice", role="image") + driver.wait(label="You", role="image") # Escape leaves List settings and stays on this list. driver.press(key=6540) subprocess.run(["xdotool", "windowfocus", find_window()], check=True)