Skip to content
This repository has been archived by the owner on Apr 8, 2019. It is now read-only.

Rich Presence not updating when state and details not set #14

Open
echebbi opened this issue Apr 22, 2018 · 1 comment
Open

Rich Presence not updating when state and details not set #14

echebbi opened this issue Apr 22, 2018 · 1 comment

Comments

@echebbi
Copy link

echebbi commented Apr 22, 2018

Hi !

Calling DiscordRpc.updatePresence(DiscordRichPresence) on a presence that has neither details nor state has no effect. Indeed, if these properties are not set (or empty) then Discord is not updated.

Since Discord's developer documentation seems to indicate that all fields are optional when updating a presence, I assume that it is a bug related to this implementation.

I can reproduce the bug by taking the example SimpleGame.java and commenting one of the lines that set the details or the state (on lines 91, 92).

Does someone have an idea about how to resolve this issue ? I'm on Windows, by the way.

@echebbi echebbi changed the title Rich Presence not updating when date and details not set Rich Presence not updating when state and details not set Apr 22, 2018
@echebbi
Copy link
Author

echebbi commented Apr 22, 2018

I think that I've found why !

Currently, the JSON sent to Discord contains the state and details fields, even when they are empty. For instance, the following presence:

discordRichPresence.setState("Doing something");
discordRichPresence.setStartTimestamp(System.currentTimeMillis() / 1000);
discordRpc.updatePresence(discordRichPresence);

leads to the following JSON:

{
   "nonce":"1",
   "cmd":"SET_ACTIVITY",
   "args":{
      "pid":15228,
      "activity":{
         "state":"Doing something",
         "details":"",
         "timestamps":{
            "start":1524398662
         },
         "instance":false
      }
   }
}

and Discord displays neither the state nor the elapsed time.

However, if we avoid empty unspecified fields and generate the JSON as follows:

{
   "nonce":"1",
   "cmd":"SET_ACTIVITY",
   "args":{
      "pid":968,
      "activity":{
         "state":"Doing something",
         "timestamps":{
            "start":1524398370
         },
         "instance":false
      }
   }
}

then Discord shows the state and the elapsed time as expected.

That's kind of strange: I would expect Discord to handle empty fields. I'll do further tests and will submit a PR if this fix works well.

echebbi added a commit to echebbi/discord-rpc-java that referenced this issue Apr 22, 2018
…er#14

Ensure that state and details are not empty strings before adding them to the JSON.
Discord won't update itself if one of them is empty.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant