aboutsummaryrefslogtreecommitdiffstats
path: root/slack/slack_workspace.py
Commit message (Collapse)AuthorAgeFilesLines
* Update user info for open IM conversations when using session tokensTrygve Aaberge2024-04-181-6/+17
| | | | | | | | | | | | | | | | | | | | | | | When using session tokens we apparently don't get any user_status_changed events, so when a user updated their status the title in an IM with them wasn't updated. If we specify the query param slack_client=desktop when connecting to the websocket we at least get a user_invalidated event when the user info changes. This doesn't include any info though, so we have to make a request to get the updated user info. On workspaces with a lot of users, we may get user_invalidated very often, so we can't fetch new user info every time we get it, otherwise we would make a lot of requests. So at least for now, only update the user info if we have an open IM with the user. This ensures the status in the IM title is kept up to date at least. In other words, nick changes are not picked up and updated. This is also the case when using OAuth tokens, as we only listen for user_status_changed events, and not the other user updated events. Handling nick changes is also a bit more complex, so I'll leave that for later.
* Retry fetching users with fewer users on errorsTrygve Aaberge2024-03-291-0/+1
| | | | | | | | | | | | | | Apparently it varies how many users can be fetched in one request with the users.info method. I have had successful requests with 4096 users, while some people have reported getting HTTP 500 when fetching 1000 users and one person got an error response with error `too_many_users` when fetching 500 users. So when we get either of those errors, reduce the number of users we fetch in one request and try again until it works or the number of users has been reduced to 1. Fixes #924
* Use enterprise id in edgeapi path if it existsTrygve Aaberge2024-03-291-0/+1
| | | | | | | It seems like for enterprise workspaces you have to use the enterprise id (if the token is a workspace level token, `enterprise_id/workspace_id` can also be used, but isn't necessary), while for non-enterprise workspaces the workspace id should be used.
* Add command `/slack linkarchive`Trygve Aaberge2024-02-201-0/+2
|
* Add command `/slack part`Trygve Aaberge2024-02-181-1/+1
|
* Don't call conversations.leave when closed from serverTrygve Aaberge2024-02-181-1/+1
|
* Unset _connect_task after cancelling itTrygve Aaberge2024-02-181-0/+1
| | | | | | | If _connect_task remains set, the connect command won't allow you to connect again because it thinks it's still connecting. This caused a problem where if you disconnect while connecting (or after connecting has crashed), it wasn't possible to connect again afterwards.
* Set buffer_pointer to None when buffer doesn't existTrygve Aaberge2024-02-181-1/+2
| | | | | | This enforces us to check that buffer_pointer is set, so we don't accidentally operate on the core buffer, which is what is done when buffer_pointer is an empty string.
* Check enterprise_user when determining if a user is externalTrygve Aaberge2024-02-181-0/+7
| | | | | | | The team id in the profile may be either the enterprise id or the workspace id depending on the token used and the workspace the user belongs to, so if the user has enterprise_user set, check the enterprise_id too.
* Only open channels for the current sub workspaceTrygve Aaberge2024-02-181-1/+23
| | | | | | | | | | | | | | | | | | | | | It's possible to have a token that's only for one workspace in an enterprise grid. For me with such a token, it returns channels in all workspaces in client.userBoot, but only channels in the tokens workspace in client.counts. This meant that we didn't get last_read for all channels we opened, and additionally some methods like conversations.members would fail with "channel_not_found" for those channels. This filters the channels from client.userBoot by checking that the channel is in the current sub workspace, if the token we're using is not an org level (for all workspaces the user is in) token. Additionally it raises an error if any of the channels to open isn't included in the response from client.counts to prevent missing last_read for any channels if there are other channels that isn't included. I could have filtered the list of channels to open by the channels included from client.counts, but I don't want any channels to just silently be ignored.
* URL encode cookies if not encodedTrygve Aaberge2024-02-181-2/+2
| | | | | The cookies need to be encoded for the Slack API to accept them, so this makes it work if the config is set with cookies that are not encoded.
* Support API restricted workspacesTrygve Aaberge2024-02-181-31/+114
| | | | | | | | | | | | | | | | | | Some enterprise workspaces are restricted in which API methods they can use, so we have to use some of the APIs the official web client uses (which can't be used by OAuth tokens) instead (mainly to initialize the workspace with client.userBoot and client.counts, and to connect to the websocket). This also has the benefit of being more performant, as the API methods the web client uses are more suited for creating a client than the official API methods. I think which API methods are restricted may be configured by the workspace admins, so it may not be the same for different workspaces, but for me it seems to be at least rtm.connect, users.conversations, conversations.list and conversations.members, so these are the ones I've changed to be conditional on the token type.
* Don't return sort_key from _conversation_if_should_openTrygve Aaberge2024-02-181-2/+4
| | | | | This originally had to be returned here because it was an async function, but now that it's a sync function this can be simplified.
* Remove logging of some known unhandled websocket message typesTrygve Aaberge2024-02-181-1/+7
|
* Fix ruff lint errorsTrygve Aaberge2024-02-181-2/+2
|
* Add completion of emoji namesTrygve Aaberge2024-02-181-0/+4
|
* Make SlackConversation constructor asyncTrygve Aaberge2024-02-181-1/+1
| | | | | | This is perhaps a bit hacky, but it makes the type checker enforce that we complete the async initialization of SlackConversation instead of getting a runtime exception.
* Make conversations.name not asyncTrygve Aaberge2024-02-181-12/+13
| | | | | This means a lot of methods don't have to be async. It's especially useful for the next commit adding conversations completions.
* Support open/close/joined/left conversation eventsTrygve Aaberge2024-02-181-2/+22
|
* Open closed IM/MPIM buffers on new messagesTrygve Aaberge2024-02-181-5/+11
|
* Show user status in DM buffer titleTrygve Aaberge2024-02-181-0/+7
|
* Check if closed IMs/MPIMs have unread messages on startTrygve Aaberge2024-02-181-3/+15
| | | | | Sometimes an IM/MPIM can have unread messages even when is_open is false, so we have to check the history if there are any unread messages.
* Show conversation topic in buffer titleTrygve Aaberge2024-02-181-0/+3
|
* Handle when some items are missing from the responseTrygve Aaberge2024-02-181-1/+4
|
* Log connected/disconnected from workspaceTrygve Aaberge2024-02-181-0/+3
| | | | | We should create a server buffer for each workspace, but print to the core buffer for now.
* Log unknown websocket messages to debug buffer instead of coreTrygve Aaberge2024-02-181-5/+14
| | | | | This just logs that a message is unknown/unhandled. The contents of the message will be printed on the line above.
* Print error when loosing connection, for debuggingTrygve Aaberge2024-02-181-2/+2
|
* Use one debug buffer for all debug loggingTrygve Aaberge2024-02-181-44/+3
| | | | | I will implement filtering like the /server raw buffer, instead of having multiple debug buffers.
* Support sending messagesTrygve Aaberge2024-02-181-8/+1
|
* Support muted conversations configTrygve Aaberge2024-02-181-0/+15
|
* Add some repr methods for useful debug printingTrygve Aaberge2024-02-181-1/+1
|
* Update message when subscribed/unsubscribedTrygve Aaberge2024-02-181-2/+13
| | | | | | Pyright doesn't allow me to set subscribed/last_read in _message_json since some of the _message_json types don't have them, so had to use separate attributes.
* Reload conversations on reconnectTrygve Aaberge2024-02-181-1/+1
|
* Add unread buffers to hotlist on connectTrygve Aaberge2024-02-181-0/+4
|
* Mark as read when switching away from bufferTrygve Aaberge2024-02-181-0/+10
|
* Mark buffer as read when conversation/thread is markedTrygve Aaberge2024-02-181-0/+21
|
* Open conversations in sorted order by nameTrygve Aaberge2024-02-181-3/+17
|
* Include cookie when making the websocket connectionTrygve Aaberge2024-02-181-0/+1
| | | | Slack began to require this for xoxc tokens today.
* Support typing notices for thread buffersTrygve Aaberge2024-02-181-1/+1
|
* Support opening a debug buffer with all ws messagesTrygve Aaberge2024-02-181-1/+45
|
* Support thread buffersTrygve Aaberge2024-02-181-2/+17
|
* Fetch usergroups at startup if edgeapi isn't availableTrygve Aaberge2024-02-181-0/+7
|
* Split edgeapi out to separate classTrygve Aaberge2024-02-181-1/+3
| | | | | Since this isn't available for OAuth tokens it's good to have an easy way to see where it's used.
* Render thread suffix in messagesTrygve Aaberge2024-02-181-1/+1
|
* Support rendering huddlesTrygve Aaberge2024-02-181-0/+4
|
* Rename add_message and add some TODOsTrygve Aaberge2024-02-181-1/+1
|
* Render reactions after messagesTrygve Aaberge2024-02-181-7/+29
|
* Remove async modifier from initialize_items functionTrygve Aaberge2024-02-181-2/+2
|
* Support rendering message edits and deletionsTrygve Aaberge2024-02-181-9/+7
|
* Support sending and receiving typingTrygve Aaberge2024-02-181-3/+18
| | | | | | This does not support globally showing typing from direct messages, like the old wee-slack did, because that's not supported by WeeChats typing plugin. It only shows typing in the current buffer.