File Coverage

blib/lib/Mojo/Webqq/Model/Remote/_get_group_info_ext.pm
Criterion Covered Total %
statement 3 65 4.6
branch 0 22 0.0
condition 0 3 0.0
subroutine 1 4 25.0
pod n/a
total 4 94 4.2


line stmt bran cond sub pod time code
1 1     1   7 use strict;
  1         2  
  1         629  
2             sub Mojo::Webqq::Model::_get_group_info_ext {
3 0     0     my $self = shift;
4 0           my $uid = shift;
5 0           my $callback = shift;
6             #my $api = "http://qinfo.clt.qq.com/cgi-bin/qun_info/get_group_members_new";
7 0           my $api = "http://qinfo.clt.qq.com/cgi-bin/qun_info/get_group_members";
8 0 0         my $is_blocking = ref $callback eq "CODE"?0:1;
9             my $handle = sub {
10 0     0     my $json = shift;
11 0 0         return if not defined $json;
12 0 0         return if $json->{ec}!=0;
13 0 0         if(ref $json->{mems} ne 'ARRAY'){
14 0           $self->warn("更新群[$uid]扩展信息失败: 返回数据异常");
15 0           return;
16             }
17 0           my %levelname;
18 0           for(keys %{$json->{levelname}}){
  0            
19 0           $levelname{$_} = $json->{levelname}{$_};
20             }
21 0           my %last_speak_time;
22 0           for (keys %{$json->{times}}){
  0            
23 0           $last_speak_time{$_} = $json->{times}{$_};
24             }
25 0           my %join_time;
26 0           for (keys %{$json->{join}}){
  0            
27 0           $join_time{$_} = $json->{join}{$_};
28             }
29 0           my %adm;
30 0           $adm{$_} = 1 for @{$json->{adm}};
  0            
31              
32 0           my %card;
33 0           for(keys %{$json->{cards}}){
  0            
34 0           $card{$_} = $json->{cards}{$_};
35             }
36              
37 0           my $group = {member=>[]};
38              
39 0           $group->{max_admin} = undef;
40 0           $group->{admin_count} = undef;
41 0           $group->{member_count} = undef;
42 0           $group->{max_member} = undef;
43              
44 0           $group->{uid} = $uid;
45 0           $group->{owner_uid} = $json->{owner};
46 0           for(@{$json->{mems}}){
  0            
47 0           my $member = {};
48 0           $member->{uid} = $_->{u};
49              
50 0 0         if($member->{uid} eq $group->{owner_uid}){
    0          
51 0           $member->{role} = 'owner';
52             }
53             elsif($adm{ $member->{uid} } == 1){
54 0           $member->{role} = 'admin';
55             }
56             else{
57 0           $member->{role} = 'member';
58             }
59 0 0 0       $member->{card} = (defined $card{$member->{uid}} and $card{$member->{uid}} ne "")?$self->xmlescape_parse($card{$member->{uid}}): undef;
60 0 0         if ($self->group_member_use_fullcard) {
61 0           $member->{fullcard} = $member->{card};
62             }
63 0 0         if(not $self->group_member_card_ext_only){
64 0 0         $member->{card} = $self->safe_truncate($member->{card},$self->group_member_card_cut_length) if defined $member->{card};
65             }
66 0           $member->{name} = $self->xmlescape_parse($_->{n});
67 0           $member->{last_speak_time} = $last_speak_time{$member->{uid}};
68 0           $member->{join_time} = $join_time{$member->{uid}};
69 0           push @{$group->{member}},$member;
  0            
70             }
71 0           return $group;
72 0           };
73 0 0         if($is_blocking){
74 0           return $handle->( $self->http_post($api,{Referer=>"http://qinfo.clt.qq.com/member.html",json=>1},form=>{gc=>$uid,u=>$self->user->uid,bkn=>$self->get_csrf_token},) );
75             }
76             else{
77             $self->http_post($api,{Referer=>"http://qinfo.clt.qq.com/member.html",json=>1},form=>{gc=>$uid,u=>$self->user->uid,bkn=>$self->get_csrf_token},sub{
78 0     0     my $json = shift;
79 0           $callback->( $handle->($json) );
80 0           });
81             }
82             }
83             1;