From 7ca96edc69fe5e800d3854441f7a86975d3865e8 Mon Sep 17 00:00:00 2001 From: Hyodo Date: Thu, 9 Nov 2017 22:22:57 -0200 Subject: [PATCH 1/2] [Set Retro List Per Room] From 7e04987583840a54f9f32bb15017163258e7f44c Mon Sep 17 00:00:00 2001 From: Hyodo Date: Thu, 9 Nov 2017 22:37:19 -0200 Subject: [PATCH 2/2] Alter the redis methos, so it is possible for each room to have your own list for retro, so more then one team can usa the lita retro at the same time --- README.md | 2 ++ lib/lita/handlers/retro.rb | 21 ++++++++++++--------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index caaf9af..818fd10 100644 --- a/README.md +++ b/README.md @@ -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! diff --git a/lib/lita/handlers/retro.rb b/lib/lita/handlers/retro.rb index 60e4eaa..b9e34c7 100644 --- a/lib/lita/handlers/retro.rb +++ b/lib/lita/handlers/retro.rb @@ -35,13 +35,15 @@ 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 @@ -49,7 +51,7 @@ def list(response) 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 @@ -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 = [] @@ -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