From 60c580036867a638c94b8ceff4dff5e4c40bead1 Mon Sep 17 00:00:00 2001 From: Ralph Ronnquist Date: Wed, 25 Aug 2021 21:04:28 +1000 Subject: [PATCH] handle conversations member list --- slirc.pl | 77 +++++++++++++++++++++++++++++++------------------------- 1 file changed, 43 insertions(+), 34 deletions(-) diff --git a/slirc.pl b/slirc.pl index e744e73..bfa7f3d 100755 --- a/slirc.pl +++ b/slirc.pl @@ -689,7 +689,8 @@ my %irc_command = ( irc_broadcast_part $self_id, $chan->{Id} if rtm_update_part $self_id, $chan->{Id}; } else { - rtm_apicall "channels.leave", { channel => $chan->{Id} }; + #rtm_apicall "channels.leave", { channel => $chan->{Id} }; + rtm_apicall "conersations.leave", { channel => $chan->{Id} }; } } } @@ -926,6 +927,7 @@ sub irc_do_message { sub irc_privmsg { my ($id, $subtype, $msg) = @_; + print "id = $id\n"; irc_do_message $id, $users{$id}->{Name}, $subtype, $msg; } @@ -1182,41 +1184,48 @@ sub rtm_record_unknown_uid { sub rtm_update_channel { my ($type, $c) = @_; - my $id = $c->{id}; - my $mhash = {}; - my $name = $c->{name}; - - $name = "+$name" if $type eq "G"; - - # Cross-reference users/channels - foreach my $u (@{$c->{members}}) { - rtm_record_unknown_uid $u; - # Filter ourselves out of the membership list if this is a - # closed group chat. - next if $type eq 'G' && $u eq $self_id && !$c->{is_open}; - $mhash->{$u} = 1; - $users{$u}->{Channels}->{$id} = 1; - } - if (exists $channels{$id}) { - my $chan = $channels{$id}; - $chan->{Members} = $mhash; - $chan->{Topic} = $c->{topic}->{value}; - $chan->{Type} = $type; - } else { - my $name = irc_pick_name($name, \%channels_by_name); - my $chan = { - Id => $c->{id}, - Members => $mhash, - Name => $name, - Type => $type, - Topic => $c->{topic}->{value} - }; + rtm_apicall "conversations.members", { channel => $id }, sub { - $channels{$c->{id}} = $chan; - $channels_by_name{irc_lcase($name)} = $chan; - } + my $id = $c->{id}; + my $data = shift; + my $mhash = {}; + my $name = $c->{name}; + + $c->{members} = $data->{'members'}; + + $name = "+$name" if $type eq "G"; + + # Cross-reference users/channels + foreach my $u (@{$c->{members}}) { + rtm_record_unknown_uid $u; + # Filter ourselves out of the membership list if this is a + # closed group chat. + next if $type eq 'G' && $u eq $self_id && !$c->{is_open}; + $mhash->{$u} = 1; + $users{$u}->{Channels}->{$id} = 1; + } + + if (exists $channels{$id}) { + my $chan = $channels{$id}; + $chan->{Members} = $mhash; + $chan->{Topic} = $c->{topic}->{value}; + $chan->{Type} = $type; + } else { + my $name = irc_pick_name($name, \%channels_by_name); + my $chan = { + Id => $c->{id}, + Members => $mhash, + Name => $name, + Type => $type, + Topic => $c->{topic}->{value} + }; + + $channels{$c->{id}} = $chan; + $channels_by_name{irc_lcase($name)} = $chan; + } + }; } sub rtm_delete_channel { @@ -1242,7 +1251,7 @@ sub rtm_mark_channel { unless (defined $rtm_mark_timer) { $rtm_mark_timer = AnyEvent->timer(after => 5, cb => sub { for my $chid (keys %rtm_mark_queue ) { - rtm_apicall "channels.mark", { + rtm_apicall "conversations.mark", { channel => $chid, ts => $rtm_mark_queue{$chid} }; -- 2.39.2