Sha256: 3477e155a87e34fb1c2f5eb3bd6fdc4de000a7bc05eb79f7bf231eccc048c519

Contents?: true

Size: 1.34 KB

Versions: 1

Compression:

Stored size: 1.34 KB

Contents

module MatrixQQ
  class Matrix
    # send matrix massage to other
    class Forward
      class << self
        attr_accessor :send_to
      end
      self.send_to = Hash.new { |h, k| h[k] = [] }

      def initialize(dbus, qq, info)
        @dbus = dbus
        @info = info
        @qq = qq
      end

      def run
        return unless @info.is_a? Hash
        @info.each_pair do |room, value|
          tunnel = Config[:tunnel][room]
          next if tunnel.nil?
          next unless tunnel[:type] == 'matrix'
          each_event value['timeline']['events'], tunnel
        end
      end

      def each_event(events, tunnel)
        events.each do |event|
          next unless event['type'] == 'm.room.message'
          next if exist @info['event_id']
          tunnel[:to].each_pair do |to_room, type|
            call_module(event, to_room, type)
          end
        end
      end

      def call_module(event, room, type)
        Forward.send_to[type.to_s].each do |func|
          puts "Start #{func.name}" if $VERBOSE
          func.new(@dbus, @qq, event, room).run
          puts "End #{func.name}" if $VERBOSE
        end
      end

      def exist(event_id)
        MatrixQQ::Matrix::Send.ignore_lock.synchronize do
          MatrixQQ::Matrix::Send.ignore.delete(event_id)
        end
      end
    end # Forward

    Matrix.join << Forward
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
matrix_qq-0.2.1 lib/matrix_qq/matrix/forward/main.rb