yuya373 / emacs-slack

slack client for emacs
1.11k stars 117 forks source link

emacs-slack doesn't mark user as "active" #506

Open nicklan opened 4 years ago

nicklan commented 4 years ago

Describe the bug When using emacs-slack I don't appear as "active" to other users. I can confirm this by manually curling the api. For example, I just typed a message to someone and then do: curl -H "Authorization: Bearer TOKEN" "https://slack.com/api/users.getPresence?user=MYID" and I get:

{
  "ok": true,
  "presence": "away",
  "online": true,
  "auto_away": true,
  "manual_away": false,
  "connection_count": 1,
  "last_activity": 1584118427
}

However, if I open the official client then for 30 minutes it'll return:

{
  "ok": true,
  "presence": "active",
  "online": true,
  "auto_away": false,
  "manual_away": false,
  "connection_count": 2,
  "last_activity": 1584142902
}

To Reproduce Steps to reproduce the behavior:

  1. Have no other client other than emacs-slack open for at least 30 minutes
  2. Curl as: curl -H "Authorization: Bearer TOKEN" "https://slack.com/api/users.getPresence?user=MYID"
  3. Note that your presence is "away"
  4. Open an official client
  5. recurl
  6. note you are "active"

Expected behavior A bit hard to define. Maybe at least that after sending a message I should be "active" for a while. According to the slack docs: "A user is active if they have at least one client connected to Slack, and they are not marked as "away"." so if possible emacs-slack should just do whatever it needs to to keep the user "active" as long as it's running, and probably also add a method to mark oneself as "away"

yuya373 commented 4 years ago

Thanks for the detailed reproduction steps. I can reproduce the issue. I checked the official client, but there was no special API or websocket message, so the official client seems to be treated specially. I ’ll try to find out if there ’s any other way

ghost commented 4 years ago

Does this not allow you to set the presence? https://api.slack.com/methods/users.setPresence

There's some more information here as well https://api.slack.com/docs/presence-and-status

Feel free to Ignore this if you've already looked into these.

yuya373 commented 4 years ago

after calling the api, the response does not change

call [2020-05-18 00:34:31] [trace] REQUEST FINISHED. URL: "https://slack.com/api/users.setPresence", PARAMS: (("presence" . "auto")), DATA: (:ok t) - emacs-slack

response from user.getPresence:

{
  "ok": true,
  "presence": "away",
  "online": true,
  "auto_away": true,
  "manual_away": false,
  "connection_count": 2,
  "last_activity": 1589726425
}

call [2020-05-18 00:36:06] [trace] REQUEST FINISHED. URL: "https://slack.com/api/users.setPresence", PARAMS: (("presence" . "away")), DATA: (:ok t) - emacs-slack

response:

 {
   "ok": true,
   "presence": "away",
   "online": true,
   "auto_away": true,
   "manual_away": true,
   "connection_count": 2,
   "last_activity": 1589726425
 }

call [2020-05-18 00:36:50] [trace] REQUEST FINISHED. URL: "https://slack.com/api/users.setPresence", PARAMS: (("presence" . "auto")), DATA: (:ok t) - emacs-slack

response:

{
  "ok": true,
  "presence": "away",
  "online": true,
  "auto_away": true,
  "manual_away": false,
  "connection_count": 2,
  "last_activity": 1589726425
}
stonekyx commented 3 years ago

Also having this problem.

Looks like reconnecting ws will mark user as active again, so I'm using an ugly hack to keep myself as active: Set a timer to reconnect ws with slack-ws--reconnect, and call something like slack-im-list-update to refresh my status 🤕

ghost commented 3 years ago

@stonekyx do you know what the interval is for getting set to away by any chance?

stonekyx commented 3 years ago

Slack API doc says it's 30 minutes. Anyway, this feels like a problem in Slack API, unless emacs-slack didn't actually send the request (which I suppose is unlikely the case).

erichlf commented 3 years ago

Also having this problem.

Looks like reconnecting ws will mark user as active again, so I'm using an ugly hack to keep myself as active: Set a timer to reconnect ws with slack-ws--reconnect, and call something like slack-im-list-update to refresh my status

I don't seem to have access to a slack-ws--reconnect command. I have been running slack-start, which is really annoying when it runs when I am writing a message. Could you give some more details on your hack?

stonekyx commented 3 years ago

It's something like this:

(run-with-timer 0 (* 25 60)
                (lambda ()
                  (slack-ws--reconnect (oref slack-current-team :id) t)
                  (slack-im-list-update)))

Maybe the last slack-im-list-update is not necessary though, I just kept it there to be safe.