-my $sub = AnyEvent::Redis->new( host => $ENV{REDIS_HOST}, port => $ENV{REDIS_PORT}, on_error => sub { confess @_ } );
-
-our $contacts = { $room => 1 };
-
-$sub->psubscribe( 'channel *', sub {
- my ( $message, $from ) = @_;
- return unless $from !~ m/\Q$jid\E/; # skip our messages
- Encode::_utf8_on($message);
- warn "#Q<< ", dump( $from, $message );
- my ( undef, $channel, $user ) = split(/ /,$from,3);
-warn "# contacts ",dump($contacts);
- foreach my $contact ( keys %$contacts ) {
- next if $from =~ m/\Q$contact\E/;
- warn "# $jid [$from] -> [$contact] | $message\n";
- $cl->send_message( join(' ',$channel, $user, $message), $contact => $jid, 'chat' );
+warn "# jid:$jid root:$room subscribe:$subscribe\n";
+
+our $contacts;
+our $muc_rooms;
+
+sub publish;
+
+MQR::Redis->redis->psubscribe( "MSG $subscribe", sub {
+ my ( $body, $channel ) = @_;
+ warn "<<<< ", dump( $channel, $body );
+ Encode::_utf8_on($body);
+
+ my ( undef, $gw, $room, $user, $from ) = split(/\s/,$channel);
+
+ return if $from eq $jid; # FIXME skip own
+
+ foreach my $to ( keys %$contacts, keys %$muc_rooms ) {
+ next if $from =~ m/\Q$to\E/; # FIXME
+ my $type = defined $muc_rooms->{$from} ? 'groupchat' : 'chat';
+ publish "SEND $jid $type $user $to" => $body;