AsamK / signal-cli

signal-cli provides an unofficial commandline, JSON-RPC and dbus interface for the Signal messenger.
GNU General Public License v3.0
3.17k stars 299 forks source link

Cannot set username with discriminator via updateAccount RPC #1535

Closed kareldonk closed 4 months ago

kareldonk commented 4 months ago

I was tring to change the username via the RPC deamon by sending the following message:

{
    "jsonrpc": "2.0",
    "method": "updateAccount",
    "params": {
        "username": "user.111"
    },
    "id": "THIS_ID"
}

That failed with response:

{
    "jsonrpc": "2.0",
    "error": {
        "code": -3,
        "message": "Failed to set username: StatusCode: 409",
        "data": null
    },
    "id": "THIS_ID"
}

But if I do a request WITHOUT a discriminator (so just user for example), that works, and the server specifies a discriminator in the response.

According to the docs, sending a discriminator should also work:

-u NAME --username NAME Specify a username that can then be used to contact this account. This can either be just the nickname (e.g. test) or the complete > username with discriminator (e.g. test.000). Returns the new username with discriminator and the username link.

On the command line I also got the same response.

Is this a bug or am I doing something wrong? Perhaps the names were already taken but I tried a number of different discriminators and would still get response 409.

AsamK commented 4 months ago

409 is indeed the status code for an already taken username. You can check if a given username already exists with getUserStatus --username user.111

kareldonk commented 4 months ago

I tried via the RPC http endpoint with the following:

{
    "jsonrpc": "2.0",
    "method": "getUserStatus",
    "params": {
        "username": ["name"]
    },
    "id": "THIS_ID"
}

And got this:

{
    "jsonrpc": "2.0",
    "error": {
        "code": -32603,
        "message": "Cannot invoke \"java.util.Collection.size()\" because \"c\" is null",
        "data": null
    },
    "id": "THIS_ID"
}

I also tried specifying just one username (and not an array) like "username": "name" but get the same error. Am I using the wrong syntax?

AsamK commented 4 months ago

There's a bug in the command when no recipients are given, as a workaround you can add an empty recipient array:

{
    "jsonrpc": "2.0",
    "method": "getUserStatus",
    "params": {
        "username": ["name"],
        "recipient":[]
    },
    "id": "THIS_ID"
}
kareldonk commented 4 months ago

Thank you very much