Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Update user Public desc by grpc

63 views
Skip to first unread message

Saman Sami

unread,
Feb 6, 2025, 1:30:34 AMFeb 6
to Tinode General
I can create a new user as root with below object and gprc method
```
const msg: ClientMsg = {
  acc: {
    id: '106042',
    userId: 'new',
    authLevel: 20,
    desc: {
      defaultAcs: {
        auth: 'JRWPS',
        anon: 'N',
      },
      public: new TextEncoder().encode(
        JSON.stringify({
          userId,
          fn: fullName, // "John Doe",
          photo: profileImage
            ? {
                type: getMimeType(profile_image).replace('image/', ''),
                ref: profile_image,
              }
            : undefined,
        }),
      ),
      trusted: new TextEncoder().encode(
        JSON.stringify({
          verified: true,
        }),
      ),
    },
    tags: username ? [`user_id:${userId}`] : [],
    scheme: 'basic',
    secret: secret,
    login: false,
    token: new Uint8Array(0),
    state: 'ok',
    tmpScheme: '',
    tmpSecret: new Uint8Array(0),
    cred: [],
  },
  extra: {
    authLevel: 30,
  },
};
```
but how can I update the current user's "Public" features
I tried these objects But neither of these worked.

```
const msg: ClientMsg = {
  acc: {
    id: '106042',
    userId: tinodeUserId,
    authLevel: 20,
    desc: {
      defaultAcs: undefined,
      public: new TextEncoder().encode(
        JSON.stringify({
          userId,
          fn: fullName,
          photo: profileImage
            ? {
                type: getMimeType(profile_image).replace('image/', ''),
                ref: profile_image,
              }
            : undefined,
        }),
      ),
    },
  },
  extra: {
onBehalfOf: tinodeUserId,
    authLevel: 30,
  },
}

```
```
const msg: ClientMsg = {
  set: {
    id: '462482',
    topic: 'me',
    query: {
      desc: {
        public: new TextEncoder().encode(
          JSON.stringify({
            userId,
            fn: fullName,
            photo: profileImage
              ? {
                  type: getMimeType(profile_image).replace('image/', ''),
                  ref: profile_image,
                }
              : undefined,
          }),
        ),
      },
    },
  },
  extra: {
    onBehalfOf: tinodeUserId,
    authLevel: 30,
  },
}; ```

Gene

unread,
Feb 6, 2025, 3:30:48 AMFeb 6
to Tinode General
Please show the logs.

Gene

unread,
Feb 6, 2025, 3:33:22 AMFeb 6
to Tinode General
Each of the messages you showed is wrong. Try

{"set":{"id":"12345","topic":"me","desc":{"public":{"fn":"This is my new name"}}}}

Just look at the console logs of the web app.

Saman Sami

unread,
Feb 6, 2025, 4:02:21 AMFeb 6
to Tinode General

Your suggested object is not for grpc
this is the Tinode grpc proto-model
```
message ClientSet {
string id = 1;
string topic = 2;
SetQuery query = 3;
}
message SetQuery {
// Topic metadata, new topic & new subscriptions only
SetDesc desc = 1;
// Subscription parameters
SetSub sub = 2;
// Indexable tags
repeated string tags = 3;
// Credential being updated.
ClientCred cred = 4;
}
message SetDesc {
DefaultAcsMode default_acs = 1;
bytes public = 2;
bytes private = 3;
bytes trusted = 4;
}
```
```
and as I said it works for the new account creation
but it doesn't work for updating.
this is updating the server log
I2025/02/06 12:24:11 grpc in: set:{id:"462482"  topic:"me"  query:{desc:{public:"{\"userId\":719,\"fn\":\"saman khan\",\"photo\":{\"type\":\"application/octet-stream\",\"ref\":\"https://cdn.example.com/static/profile/general/avatar-008.svg?id=4ddc5db671dbf43966bd8ab0079dbfd6\"}}"}}}  extra:{on_behalf_of:"usryzDacHJKbtE"  auth_level:ROOT} bqJtzqDS_Yg

Gene

unread,
Feb 6, 2025, 5:11:57 AMFeb 6
to Tinode General
Please show the logs.

Gene

unread,
Feb 6, 2025, 5:37:12 AMFeb 6
to Tinode General
You have to subscribe to topic before issuing {set}. 

Saman Sami

unread,
Feb 6, 2025, 2:04:06 PMFeb 6
to Tinode General
Thanks for your reply
it works, but it's not the best practice
as a root user (system user) I should subscribe to each user before updating its profile
Can we do this without a subscription for the root user?

Gene

unread,
Feb 7, 2025, 12:44:34 AMFeb 7
to Tinode General
On Thursday, February 6, 2025 at 10:04:06 PM UTC+3 Saman Sami wrote:
Thanks for your reply
it works, but it's not the best practice
as a root user (system user) I should subscribe to each user before updating its profile

Looking forward to your PR.
 
Can we do this without a subscription for the root user?

Yes.

Saman Sami

unread,
Feb 8, 2025, 10:44:29 AMFeb 8
to Tinode General
Can the root user subscribe to multiple users' "me" topics simultaneously?
Reply all
Reply to author
Forward
0 new messages