use lib get_info 'xchatdir';
use Xchat::XPI;
use Xchat::XPI::Events qw<delay>;
+use Xchat::XPI::Utils qw<save_context local_context>;
use constant {
JOIN_DELAY => 1000,
return EAT_NONE if $fetched{$serv}{$chan};
- my $oldctxt = get_context;
- set_context $chan, $serv or return EAT_NONE;
- fetch $serv, $chan;
- scan $serv, $chan;
- set_context $oldctxt;
+ local_context $chan, $serv => sub {
+ fetch $serv, $chan;
+ scan $serv, $chan;
+ };
return EAT_NONE;
};
my $chan = lc substr $_[0][2], 1; # starts with colon
my $clones = add $nick, host($userhost), $serv, $chan;
- if ($clones > 0) {
- my $oldctxt = get_context;
- if (set_context $chan, $serv) {
- print $ph clone_enter_str $userhost, $nick, $clones;
- set_context $oldctxt;
- } else {
- delay JOIN_DELAY, sub {
- my $oldctxt = get_context;
- return unless set_context $chan, $serv;
+ return EAT_NONE unless $clones > 0;
+
+ local_context $chan, $serv => sub {
+ print $ph clone_enter_str $userhost, $nick, $clones;
+ 1
+ } or do {
+ delay JOIN_DELAY, sub {
+ local_context $chan, $serv => sub {
print $ph clone_enter_str $userhost, $nick, $clones;
- set_context $oldctxt;
- };
+ }
}
- }
+ };
return EAT_NONE;
};
get_list 'channels';
if (nickcmp get_info('nick'), $nick) {
- my $oldctxt = get_context;
- my $host = host $userhost;
+ my $guard = save_context;
+ my $host = host $userhost;
for (@chans) {
my $clones = remove $nick, $host, $serv, $_->[0];
if ($clones > 0) {
print $ph clone_leave_str $userhost, $nick, $clones;
}
}
- set_context $oldctxt;
} else {
flush $serv, $_->[0] for @chans;
}