@@ -11,6 +11,8 @@ _msgsubtopic = 'stream-room-messages' # 'messages'
1111_msgsublimit = 10 # this is not actually used right now
1212_messageCollection = ' stream-room-messages'
1313
14+ _methodExists = {}
15+
1416# room id cache
1517_roomCacheSize = parseInt (process .env .ROOM_ID_CACHE_SIZE ) || 10
1618_directMessageRoomCacheSize = parseInt (process .env .DM_ROOM_ID_CACHE_SIZE ) || 100
@@ -46,6 +48,28 @@ class RocketChatDriver
4648 getDirectMessageRoomId : (username ) =>
4749 @ tryCache _directMessageRoomIdCache, ' createDirectMessage' , username, ' DM Room ID'
4850
51+ checkMethodExists : (method ) =>
52+ if ! _methodExists[method]?
53+ @logger .info " Checking to see if method: #{ method} exists"
54+ r = @asteroid .call (method, " " )
55+ r .result .then ((res ) =>
56+ _methodExists[method] = true
57+ return Q ()
58+ ).catch ((err ) =>
59+ if err .error == 404
60+ _methodExists[method] = false
61+ @logger .info " Method: #{ method} does not exist"
62+ return Q .reject (" Method: #{ method} does not exist" )
63+ else
64+ _methodExists[method] = true
65+ return Q ()
66+ )
67+ else
68+ if _methodExists[method]
69+ return Q ()
70+ else
71+ return Q .reject ()
72+
4973 tryCache : (cacheArray , method , key , name ) =>
5074 name ?= method
5175 cached = cacheArray .get key
@@ -55,9 +79,10 @@ class RocketChatDriver
5579 else
5680 @logger .info " Looking up #{ name} for: #{ key} "
5781 r = @asteroid .call method, key
58- return r .result .then (res) =>
82+ return r .result .then ( (res ) =>
5983 cacheArray .set key, res
6084 return Q (res)
85+ )
6186
6287 joinRoom : (userid , uname , roomid , cb ) =>
6388 @logger .info " Joining Room: #{ roomid} "
0 commit comments