Skip to content

Commit

Permalink
Merge pull request #24 from southbridgeio/develop
Browse files Browse the repository at this point in the history
Release 0.3.2
  • Loading branch information
vladislav-yashin authored Jan 10, 2020
2 parents 163ae6d + e352393 commit a65464d
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 11 deletions.
12 changes: 9 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
language: ruby
rvm:
- 2.3.8
- 2.6.0
- 2.4.9
- 2.6.5
- 2.7.0

branches:
only:
Expand All @@ -13,7 +14,12 @@ addons:

env:
- REDMINE_VER=3.4-stable
- REDMINE_VER=4.0-stable
- REDMINE_VER=4.1-stable

matrix:
exclude:
- env: REDMINE_VER=3.4-stable
rvm: 2.7.0

install: "echo skip bundle install"

Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# 0.3.2

* Handle supergroup upgrade error
* Fix toggle admin command
* Fix remove_keyboard error
* Don’t respond to locked members commands
* Handle "Administrators editing is disabled" errors

# 0.3.1

* Fix Rails 4 support
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ Please help us make this plugin better telling us of any [issues](https://github

### Requirements

* **Ruby 2.3+**
* Configured [redmine_bots](https://github.com/southbridgeio/redmine_bots)
* **Ruby 2.4+**
* Configured [redmine_bots](https://github.com/centosadmin/redmine_bots) (version 0.4.0 or higher)
* You need to use utf8mb4 encoding if you're using mysql database

Standard plugin installation:
Expand Down
4 changes: 2 additions & 2 deletions init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@
name 'Redmine 2Chat'
url 'https://github.com/southbridgeio/redmine_2chat'
description 'This is a plugin for Redmine which adds group chats to Redmine issues on different chat platforms such as Slack and Telegram.'
version '0.3.1'
version '0.3.2'
author 'Southbridge'
author_url 'https://github.com/southbridgeio'

requires_redmine_plugin :redmine_bots, '0.2.0'
requires_redmine_plugin :redmine_bots, '0.4.0'

settings(default: {
'daily_report' => '1',
Expand Down
15 changes: 14 additions & 1 deletion lib/redmine2chat/platforms/telegram.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ module Redmine2chat::Platforms
class Telegram
include Dry::Monads::Result::Mixin

class ChatUpgradedError
def self.===(e)
e.is_a?(::Telegram::Bot::Exceptions::ResponseError) && e.message.include?('group chat was upgraded to a supergroup chat')
end
end

def icon_path
'/plugin_assets/redmine_2chat/images/telegram-icon.png'
end
Expand Down Expand Up @@ -42,7 +48,14 @@ def send_message(im_id, message, params = {})
bot_token: RedmineBots::Telegram.bot_token
}.merge(params)

RedmineBots::Telegram::Bot::MessageSender.call(message_params)
begin
RedmineBots::Telegram::Bot::MessageSender.call(message_params)
rescue ChatUpgradedError => e
new_chat_id = e.send(:data).dig('parameters', 'migrate_to_chat_id')
issue_chat = IssueChat.find_by(im_id: im_id, platform_name: 'telegram')
new_chat_id && issue_chat&.update!(im_id: new_chat_id) || raise(e)
message_params.merge!(chat_id: new_chat_id) && retry
end
end

private
Expand Down
10 changes: 9 additions & 1 deletion lib/redmine2chat/telegram/bot/group_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ module GroupCommand
include ActionView::Helpers::TagHelper
include ERB::Util

class AdminEditingDisabledError
def self.===(e)
e.is_a?(TD::Error) && e.message.include?('Administrators editing is disabled')
end
end

private

def group_common_commands
Expand Down Expand Up @@ -134,7 +140,9 @@ def can_manage_chat?(telegram_user)

def edit_group_admin(telegram_user, is_admin = true)
return unless issue.active_chat
RedmineBots::Telegram::Tdlib::ToggleChatAdmin.(issue.active_chat.im_id, telegram_user.id, is_admin)
RedmineBots::Telegram::Tdlib::ToggleChatAdmin.(issue.active_chat.im_id, telegram_user.id, is_admin).wait!
rescue AdminEditingDisabledError
# skip
end

def left_chat_member
Expand Down
2 changes: 1 addition & 1 deletion lib/redmine2chat/telegram/commands/base_bot_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def account
@account ||=
begin
account = TelegramAccount.find_by!(telegram_id: command.from.id)
if account.user
if account.user && !account.user.locked?
account
else
send_message(I18n.t('redmine_2chat.bot.account_not_connected'))
Expand Down
2 changes: 1 addition & 1 deletion lib/redmine2chat/telegram/commands/edit_issue_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def finish_with_error
executing_command.destroy
send_message(
locale('incorrect_value'),
reply_markup: Telegram::Bot::Types::ReplyKeyboardRemove.new(hide_keyboard: true).to_json)
reply_markup: Telegram::Bot::Types::ReplyKeyboardRemove.new(remove_keyboard: true).to_json)
end

def executing_command
Expand Down

0 comments on commit a65464d

Please sign in to comment.