From 30c15df673c3ec3ac859179c49ec4c2a549b7960 Mon Sep 17 00:00:00 2001
From: Alexander Olofsson <alexander.olofsson@liu.se>
Date: Tue, 17 Aug 2021 10:41:44 +0200
Subject: [PATCH] Fixup notification sending

---
 .../foreman_notification_send/notification_extensions.rb    | 6 ++++--
 app/services/foreman_notification_send/sender_matrix.rb     | 3 ++-
 foreman_notification_send.gemspec                           | 2 +-
 3 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/app/models/concerns/foreman_notification_send/notification_extensions.rb b/app/models/concerns/foreman_notification_send/notification_extensions.rb
index 0faa833..a573562 100644
--- a/app/models/concerns/foreman_notification_send/notification_extensions.rb
+++ b/app/models/concerns/foreman_notification_send/notification_extensions.rb
@@ -18,8 +18,10 @@ module ForemanNotificationSend
         sender.send_notification(self)
       end
 
-      NotificationTarget.select { |target| target.should_send?(self) }
-                        .each { |target| target.send(self) }
+      #NotificationTarget.select { |target| target.should_send?(self) }
+      #                  .each { |target| target.send(self) }
+    rescue StandardError => ex
+      Foreman::Logging.exception "Failed to send notification #{self}", ex
     end
 
     def level_to_symbol
diff --git a/app/services/foreman_notification_send/sender_matrix.rb b/app/services/foreman_notification_send/sender_matrix.rb
index 453f1f5..65f7247 100644
--- a/app/services/foreman_notification_send/sender_matrix.rb
+++ b/app/services/foreman_notification_send/sender_matrix.rb
@@ -4,7 +4,8 @@ require 'matrix_sdk/api'
 module ForemanNotificationSend
   class SenderMatrix < SenderBase
     def initialize(hs_url:, access_token:, room:, msgtype: 'm.notice')
-      raise ArgumentError, 'access_token must be a Matrix room ID/Alias' unless access_token.is_a?(MXID) && access_token.room?
+      room = MatrixSdk::MXID.new room unless room.is_a?(MatrixSdk::MXID) 
+      raise ArgumentError, 'room must be a Matrix room ID/Alias' unless room.room?
 
       @hs_url = hs_url
       @access_token = access_token
diff --git a/foreman_notification_send.gemspec b/foreman_notification_send.gemspec
index 579f92e..c45eec8 100644
--- a/foreman_notification_send.gemspec
+++ b/foreman_notification_send.gemspec
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
   s.executables   = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
   s.require_paths = ['lib']
 
-  s.add_dependency 'matrix_sdk', '~> 1'
+  s.add_dependency 'matrix_sdk', '~> 2'
 
   s.add_development_dependency 'bundler', '~> 1.16'
   s.add_development_dependency 'minitest', '~> 5.0'
-- 
GitLab