diff --git a/CHANGELOG.md b/CHANGELOG.md index 14fc855..b697947 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.4.3 + +* Fix kick locked users + # 0.4.2 * Fix set admin permissions diff --git a/lib/redmine2chat/telegram/tdlib/kick_locked_users.rb b/lib/redmine2chat/telegram/tdlib/kick_locked_users.rb index 9f02834..6dccb5a 100644 --- a/lib/redmine2chat/telegram/tdlib/kick_locked_users.rb +++ b/lib/redmine2chat/telegram/tdlib/kick_locked_users.rb @@ -10,14 +10,18 @@ def call .where(users: { status: Principal::STATUS_LOCKED }) .to_a + message_senders = telegram_accounts.map do |telegram_account| + TD::Types::MessageSender::User.new(user_id: telegram_account.telegram_id) + end + promises = IssueChat.active.where(platform_name: 'telegram').where.not(im_id: nil).map do |group| client.get_chat(chat_id: group.im_id).then do |chat| client.get_basic_group_full_info(basic_group_id: chat.type.basic_group_id) end.flat.rescue { nil }.then do |group_info| next Promises.fulfilled_future(true) if group_info.blank? - accounts = telegram_accounts.select { |account| account.telegram_id.in?(group_info.members.map(&:user_id)) } - Promises.zip(*accounts.map { |account| kick_member(group.im_id, account.telegram_id) }) + accounts = message_senders.select { |account| account.in?(group_info.members.map(&:member_id)) } + Promises.zip(*accounts.map { |account| kick_member(group.im_id, account) }) end.flat end @@ -27,12 +31,8 @@ def call private - def kick_member(chat_id, user_id) - client.set_chat_member_status(chat_id: chat_id, member_id: message_sender(user_id), status: ChatMemberStatus::Left.new).rescue { nil } - end - - def message_sender(user_id) - TD::Types::MessageSender::User.new(user_id: user_id) + def kick_member(chat_id, member_id) + client.set_chat_member_status(chat_id: chat_id, member_id: member_id, status: ChatMemberStatus::Left.new).rescue { nil } end end end