Skip to content

Add rsChats/getAvatar and rsChats/getOwnAvatar to the JSON API - #350

Open
jolavillette wants to merge 1 commit into
RetroShare:masterfrom
jolavillette:feature/jsonapi-chat-avatar
Open

Add rsChats/getAvatar and rsChats/getOwnAvatar to the JSON API#350
jolavillette wants to merge 1 commit into
RetroShare:masterfrom
jolavillette:feature/jsonapi-chat-avatar

Conversation

@jolavillette

Copy link
Copy Markdown
Contributor

Add rsChats/getAvatar and rsChats/getOwnAvatar to the JSON API.

Supersedes #341 and #321, which encoded base64 by hand inside
p3ChatService.

Both methods return the avatar as an RsGxsImage, the container already
used to carry identity avatars over the JSON API. Its serial_process()
goes through RsTypeSerializer::RawMemoryWrapper, so the base64 wrapping
of the binary payload is produced by the serialization layer itself
rather than by the service, as requested in #1977. The resulting
representation is the one API clients already handle for identity
avatars:

$ curl -u $API_TOKEN -d '{"pid":"<ssl id>"}' \
    $API_BASE_URL/rsChats/getAvatar
{"avatar":{"mData":{"base64":"/9j/4AAQSkZJRgABAQ..."}},"retval":true}

When the avatar of a peer is not known yet, getAvatar() returns false
and asks the peer for it, so a later call may succeed.

The existing getAvatarData() is kept as is for its existing callers: it
hands out a raw malloc'ed buffer and an int size, which is neither
serializable nor usable from the JSON API, and the GUI still relies on
it. Its "create bookkeeping entry then ask the peer, at most once a
minute" part is factored out into locked_requestAvatar() and shared
with the new getAvatar(), and its out parameters are now explicitly
cleared when no avatar is available.

@defnax

defnax commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

@G10h4ck review?

@jolavillette
jolavillette force-pushed the feature/jsonapi-chat-avatar branch 5 times, most recently from 15ba816 to 45d75b2 Compare August 3, 2026 15:20
@jolavillette
jolavillette force-pushed the feature/jsonapi-chat-avatar branch from 45d75b2 to 178ebd9 Compare August 4, 2026 18:29
Add rsChats/getAvatar and rsChats/getOwnAvatar to the JSON API.

Both return the avatar as a RsGxsImage, which is the container already
used to carry identity avatars over the JSON API. Its serial_process()
goes through RsTypeSerializer::RawMemoryWrapper, so the base64 wrapping
of the binary payload is produced by the serialization layer itself
rather than by the service, and the resulting representation
({"mData": {"base64": "..."}}) is the same one API clients already
handle for identity avatars.

The existing getAvatarData() is left untouched: it hands out a raw
malloc'ed buffer and an int size, which is neither serializable nor
usable from the JSON API, and the GUI still relies on it. Its
"create bookkeeping entry then ask the peer, at most once a minute"
part is factored out into locked_requestAvatar() and shared with the
new getAvatar(), and its out parameters are now explicitly cleared when
no avatar is available.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@jolavillette
jolavillette force-pushed the feature/jsonapi-chat-avatar branch from 178ebd9 to 5e600a5 Compare August 6, 2026 23:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants