line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Weixin::Client::Chatroom; |
2
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
3
|
1
|
|
|
1
|
|
4
|
use List::Util qw(first); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
46
|
|
4
|
1
|
|
|
1
|
|
632
|
use Weixin::Client::Private::_update_chatroom_member; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
5
|
1
|
|
|
1
|
|
617
|
use Weixin::Client::Private::_get_chatroom; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
649
|
|
6
|
|
|
|
|
|
|
sub add_chatroom{ |
7
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
8
|
0
|
|
|
|
|
|
my $chatroom = shift; |
9
|
0
|
|
0
|
|
|
|
my $is_update_member = shift || 0; |
10
|
0
|
0
|
0
|
|
|
|
$self->update_chatroom_member($chatroom) if ($is_update_member and $chatroom->{MemberCount}!=0); |
11
|
0
|
0
|
|
|
|
|
$chatroom->{ChatRoomName} = $self->get_default_chatroomname($chatroom) if $chatroom->{ChatRoomName} eq ""; |
12
|
0
|
|
|
0
|
|
|
my $c = first {$chatroom->{ChatRoomId} eq $_->{ChatRoomId}} @{$self->{_data}{chatroom}} ; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
13
|
0
|
0
|
|
|
|
|
defined $c?($c = $chatroom):(push @{$self->{_data}{chatroom}},$chatroom); |
|
0
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
sub del_chatroom{ |
16
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
17
|
0
|
|
|
|
|
|
my $chatroom_id = shift; |
18
|
0
|
|
|
|
|
|
for(my $i = 0;$i<@{$self->{_data}{chatroom}};$i++){ |
|
0
|
|
|
|
|
|
|
19
|
0
|
0
|
|
|
|
|
if($self->{_data}{chatroom}[$i]{ChatRoomId} eq $chatroom_id){ |
20
|
0
|
|
|
|
|
|
splice @{$self->{_data}{chatroom}},$i,1; |
|
0
|
|
|
|
|
|
|
21
|
0
|
|
|
|
|
|
return 1; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
} |
24
|
0
|
|
|
|
|
|
return 0; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub search_chatroom { |
28
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
29
|
0
|
|
|
|
|
|
my %p = @_; |
30
|
0
|
0
|
|
|
|
|
if(wantarray){ |
31
|
0
|
0
|
|
0
|
|
|
return grep {my $c = $_;(first {$p{$_} ne $c->{$_}} keys %p) ? 0 : 1;} @{$self->{_data}{chatroom}} ; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
else{ |
34
|
0
|
0
|
|
0
|
|
|
return first {my $c = $_;(first {$p{$_} ne $c->{$_}} keys %p) ? 0 : 1;} @{$self->{_data}{chatroom}} ; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
sub search_chatroom_member{ |
38
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
39
|
0
|
|
|
|
|
|
my %p = @_; |
40
|
0
|
|
|
|
|
|
my @member; |
41
|
0
|
|
|
|
|
|
for(@{$self->{_data}{chatroom}}){ |
|
0
|
|
|
|
|
|
|
42
|
0
|
0
|
|
|
|
|
next if $_->{MemberCount}== 0; |
43
|
0
|
|
|
|
|
|
push @member, @{$_->{Member}}; |
|
0
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
} |
45
|
0
|
0
|
|
|
|
|
if(wantarray){ |
46
|
0
|
0
|
|
0
|
|
|
return grep {my $m = $_;(first {$p{$_} ne $m->{$_}} keys %p) ? 0 : 1;} @member ; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
else{ |
49
|
0
|
0
|
|
0
|
|
|
return first {my $m = $_;(first {$p{$_} ne $m->{$_}} keys %p) ? 0 : 1;} @member ; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
sub add_chatroom_member{ |
53
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
54
|
0
|
|
|
|
|
|
my $chatroom_id = shift; |
55
|
0
|
|
|
|
|
|
my $member = shift; |
56
|
0
|
|
|
0
|
|
|
my $c = first {$chatroom_id eq $_->{ChatRoomId}} @{$self->{_data}{chatroom}} ; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
57
|
0
|
0
|
|
|
|
|
return unless defined $c; |
58
|
0
|
|
|
0
|
|
|
my $m = first {$member->{Id} eq $_->{Id}} @{$c->{Member}} ; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
59
|
0
|
0
|
|
|
|
|
defined $m?($m = $member):(push @{$c->{Member}},$member); |
|
0
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
sub del_chatroom_member{ |
62
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
63
|
0
|
|
|
|
|
|
my $chatroom_id = shift; |
64
|
0
|
|
|
|
|
|
my $member_id = shift; |
65
|
0
|
|
|
|
|
|
for(my $i = 0;$i<@{$self->{_data}{chatroom}};$i++){ |
|
0
|
|
|
|
|
|
|
66
|
0
|
0
|
|
|
|
|
if($self->{_data}{chatroom}[$i]{ChatRoomId} eq $chatroom_id){ |
67
|
0
|
|
|
|
|
|
for(my $j=0;$j<@{$self->{_data}{chatroom}[$i]{Member}};$j++){ |
|
0
|
|
|
|
|
|
|
68
|
0
|
0
|
|
|
|
|
if($self->{_data}{chatroom}[$i]{Member}[$j]{Uin} eq $member_id){ |
69
|
0
|
|
|
|
|
|
splice @{$self->{_data}{chatroom}[$i]{Member}[$j]},$j,1; |
|
0
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
return 1; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
return 0; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub update_chatroom_member{ |
80
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
81
|
0
|
|
|
|
|
|
my $chatroom = shift; |
82
|
0
|
|
|
|
|
|
$self->_update_chatroom_member($chatroom); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
sub get_chatroom { |
85
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
86
|
0
|
|
|
|
|
|
my $chatroom_id = shift; |
87
|
0
|
|
|
|
|
|
my $chatroom = $self->_get_chatroom($chatroom_id); |
88
|
0
|
0
|
|
|
|
|
$self->add_chatroom($chatroom,1) if defined $chatroom; |
89
|
0
|
|
|
|
|
|
return $chatroom; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
sub is_chatroom { |
92
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
93
|
0
|
|
|
|
|
|
my $chatroom_id = shift; |
94
|
0
|
0
|
|
|
|
|
return index($chatroom_id,'@@')==0?1:0; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub get_default_chatroomname { |
98
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
99
|
0
|
|
|
|
|
|
my $chatroom = shift; |
100
|
0
|
0
|
|
|
|
|
return $chatroom->{ChatRoomName} if $chatroom->{ChatRoomName} ne ""; |
101
|
0
|
|
|
|
|
|
my $max_count = 3; |
102
|
0
|
|
|
|
|
|
my $i=0; |
103
|
0
|
|
|
|
|
|
my @name; |
104
|
0
|
|
|
|
|
|
for(@{$chatroom->{Member}}){ |
|
0
|
|
|
|
|
|
|
105
|
0
|
0
|
|
|
|
|
last if $i > $max_count; |
106
|
0
|
|
0
|
|
|
|
push @name,$_->{DisplayName}||$_->{RemarkName}||$_->{NickName}; |
107
|
0
|
|
|
|
|
|
$i++; |
108
|
|
|
|
|
|
|
} |
109
|
0
|
0
|
|
|
|
|
return join "、",@name if @name; |
110
|
0
|
|
|
|
|
|
return "[未命名]"; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
1; |