There's an interesting implementation in https://github.com/slackhq/node-slack-client/blob/master/src/client.coffee that caches users, channels, ims and groups.
for k of data.users
u = data.users[k]
@users[u.id] = new User @, u
It then does a lot of bookkeeping for you listening to well-known slack events.
when "team_join", "user_change"
u = message.user
@emit 'userChange', u
@users[u.id] = new User @, u
Slack::RealTime::Client should implement similar behavior, possibly optionally.
The 2.0 branch does this even better with a clearly defined local store abstracted away.
We want to start with a local store
module Slack
module RealTime
module Store
class Memory
attr_accessor :users
attr_accessor :channels
attr_accessor :dms
attr_accessor :groups
attr_accessor :bots
attr_accessor :teams
def initialize
@users = {}
@channels = {}
@dms = {}
@groups = {}
@bots = {}
@teams = {}
end
end
end
end
end
And implement a set of handlers like https://github.com/slackhq/node-slack-client/tree/2.0.0-beta/lib/data-store/message-handlers that manipulate the store.
There's an interesting implementation in https://github.com/slackhq/node-slack-client/blob/master/src/client.coffee that caches users, channels, ims and groups.
It then does a lot of bookkeeping for you listening to well-known slack events.
Slack::RealTime::Clientshould implement similar behavior, possibly optionally.The 2.0 branch does this even better with a clearly defined local store abstracted away.
We want to start with a local store
And implement a set of handlers like https://github.com/slackhq/node-slack-client/tree/2.0.0-beta/lib/data-store/message-handlers that manipulate the store.