Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • ITI/foreman_notification_send
1 result
Show changes
Commits on Source (2)
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
module ForemanNotificationSend module ForemanNotificationSend
class SenderBase class SenderBase
def self.create_sender(backend:, **args) def self.create_sender(backend:, **args)
return SenderMatrix.new(args) if backend == :matrix return SenderMatrix.new(**args) if backend == :matrix
raise NotImplementedError, 'Only Matrix backend implemented at the moment' raise NotImplementedError, 'Only Matrix backend implemented at the moment'
end end
......
# frozen_string_literal: true # frozen_string_literal: true
require 'matrix_sdk/api' require 'matrix_sdk'
module ForemanNotificationSend module ForemanNotificationSend
class SenderMatrix < SenderBase class SenderMatrix < SenderBase
def initialize(hs_url:, access_token:, room:, msgtype: 'm.notice') def initialize(hs_url:, access_token:, room:, msgtype: 'm.notice')
super()
room = MatrixSdk::MXID.new room unless room.is_a?(MatrixSdk::MXID) room = MatrixSdk::MXID.new room unless room.is_a?(MatrixSdk::MXID)
raise ArgumentError, 'room must be a Matrix room ID/Alias' unless room.room? raise ArgumentError, 'room must be a Matrix room ID/Alias' unless room.room?
...@@ -12,12 +14,10 @@ module ForemanNotificationSend ...@@ -12,12 +14,10 @@ module ForemanNotificationSend
@access_token = access_token @access_token = access_token
@room_id = room @room_id = room
@msgtype = msgtype @msgtype = msgtype
super
end end
def send_notification(notification) def send_notification(notification)
room.send_html(notification.to_html, notification.to_body, msgtype: @msgtype) room.send_html(notification.to_html, notification.to_markdown, msgtype: @msgtype)
end end
private private
...@@ -28,9 +28,9 @@ module ForemanNotificationSend ...@@ -28,9 +28,9 @@ module ForemanNotificationSend
def room def room
@room ||= if @room_id.room_id? @room ||= if @room_id.room_id?
@client.ensure_room(@room_id) client.ensure_room(@room_id)
else else
@client.fetch_room(@room_id) || @client.join_room(@room_id) client.fetch_room(@room_id) || client.join_room(@room_id)
end end
end end
end end
......
# frozen_string_literal: true # frozen_string_literal: true
module ForemanNotificationSend module ForemanNotificationSend
VERSION = '0.2.0' VERSION = '0.3.0'
end end