Skip to content

Commit

Permalink
Merge pull request #47 from southbridgeio/fix-kick-locked-users
Browse files Browse the repository at this point in the history
fix kick locked users
  • Loading branch information
nevrfl authored Sep 9, 2024
2 parents ead4233 + efff56f commit f0f97df
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.4.3

* Fix kick locked users

# 0.4.2

* Fix set admin permissions
Expand Down
16 changes: 8 additions & 8 deletions lib/redmine2chat/telegram/tdlib/kick_locked_users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

0 comments on commit f0f97df

Please sign in to comment.