LearnersGuild / echo

learning management system
MIT License
3 stars 31 forks source link

Fix channelId being undefined when setting channel topic. #1071

Closed ian-deans closed 7 years ago

ian-deans commented 7 years ago

Fixes #950 .

Overview

Echo is using a 3rd party tool, cache-manager, to wrap a Map containing the channel names and IDs that is built from data received from the Slack API. It then uses this cached Map to serve the channel IDs to setChannelTopic().

It seemed that the cache-manager would keep the Map in cache, and if there was no Map, it would then call the function that queries Slack API and returns the Map. But when attempting to pull and ID from the Map using a channel name that is not in it, the Map would simply return undefined and not update the data from Slack. This is what was causing errors to be thrown when attempting to set the channel topic.

getChannelId now sets the channel values by using memoryCache.set() and returns the desired id directly from memoryCache. If the channel name is not found it refreshes it's data from Slack.

Data Model / DB Schema Changes

none

Environment / Configuration Changes

none

Notes

For this scenario ( setting a channel topic for a channel just created during project initialization ) it seems like the cached list will never have the desired channel data since each channel is created as needed. If the project belongs to a Slack channel that already exists, setChannelTopic is never called. It is only called when creating a new channel that is needed by the project currently being initialized, and the list will always need to be updated.