Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set retro list per room #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ gem "lita-retro"

Throughout the week, team members may think of things they'd like to discuss at the next team retro. They can store their topic ideas with Lita and Lita will list all the topics when it comes time to meet and discuss them. Topics can be classified as good, bad, or neutral, signified by a happy face, a sad face, or a straight face, respectively.

Now it's possible each team to have the lita retro at your channel/room

```
Carl: Lita retro :) Our new documentation was super useful!
Lita: Good topic added!
Expand Down
21 changes: 12 additions & 9 deletions lib/lita/handlers/retro.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,23 @@ def add_neutral(response)

def list(response)
topics = [
list_type("good"),
list_type("bad"),
list_type("neutral")
list_type("good",response.room.id),
list_type("bad",response.room.id),
list_type("neutral",response.room.id)
].compact

if topics.empty?
response.reply(t("no_topics"))
elsif topics.inspect == "[" + '"' + '"' + "]"
response.reply(t("no_topics"))
else
response.reply(topics.join("\n"))
end
end

def clear(response)
%w(good bad neutral).map do |type|
redis.smembers(type).each { |id| redis.del("#{type}:#{id}") }
redis.smembers("#{type}:#{response.room.id}").each { |id| redis.del("#{type}:#{response.room.id}:#{id}") }
redis.del(type)
end

Expand All @@ -59,13 +61,14 @@ def clear(response)
private

def add_type(type, response)
redis.sadd("#{type}:#{response.user.id}", response.matches[0][0])
redis.sadd("#{type}", response.user.id)
redis.sadd("#{type}:#{response.room.id}:#{response.user.id}", response.matches[0][0])
redis.sadd("#{type}:#{response.room.id}", response.user.id)
redis.sadd("#{type}", response.room.id)
response.reply(t("added", type: type))
end

def list_type(type)
user_ids = redis.smembers(type)
def list_type(type,room)
user_ids = redis.smembers("#{type}:#{room}")
return if user_ids.empty?

topics = []
Expand All @@ -74,7 +77,7 @@ def list_type(type)
user = User.find_by_id(user_id)
next unless user

redis.smembers("#{type}:#{user.id}").each do |topic|
redis.smembers("#{type}:#{room}:#{user.id}").each do |topic|
topics << t("topic", type: type.capitalize, name: user.name, topic: topic)
end
end
Expand Down