Ticket #672: blist-account-tag-olafurw.patch

File blist-account-tag-olafurw.patch, 3.5 KB (added by olafurw@…, at 2012-07-27T00:33:55Z)

Patch I did that does this.

  • bitlbee-3.0.5/root_commands.c

    old new  
    10651065        cmd_set_real( irc, cmd, &irc->b->set, NULL );
    10661066}
    10671067
     1068// Sets the visibility variables based on the command given
     1069static void set_visibility( char *cmd, int *online, int *away, int *offline )
     1070{
     1071        if( g_strcasecmp( cmd, "all" ) == 0 )
     1072        {
     1073                *online = *offline = *away = 1;
     1074        }
     1075        else if( g_strcasecmp( cmd, "offline" ) == 0 )
     1076        {
     1077                *offline = 1;
     1078        }
     1079        else if( g_strcasecmp( cmd, "away" ) == 0 )
     1080        {
     1081                *away = 1;
     1082        }
     1083        else if( g_strcasecmp( cmd, "online" ) == 0 )
     1084        {
     1085                *online = 1;
     1086        }
     1087}
     1088
    10681089static void cmd_blist( irc_t *irc, char **cmd )
    10691090{
    10701091        int online = 0, away = 0, offline = 0;
    10711092        GSList *l;
    10721093        char s[256];
    10731094        char *format;
     1095        char *tag = 0;
    10741096        int n_online = 0, n_away = 0, n_offline = 0;
    1075        
    1076         if( cmd[1] && g_strcasecmp( cmd[1], "all" ) == 0 )
    1077                 online = offline = away = 1;
    1078         else if( cmd[1] && g_strcasecmp( cmd[1], "offline" ) == 0 )
    1079                 offline = 1;
    1080         else if( cmd[1] && g_strcasecmp( cmd[1], "away" ) == 0 )
    1081                 away = 1;
    1082         else if( cmd[1] && g_strcasecmp( cmd[1], "online" ) == 0 )
    1083                 online = 1;
     1097
     1098        // User is specifing an account tag and visibility
     1099        // > blist fb all
     1100        // > blist msn away
     1101        if( cmd[1] && cmd[2] )
     1102        {
     1103                tag = cmd[1];
     1104                set_visibility(cmd[2], &online, &away, &offline );
     1105        }
     1106        // User is either specifing only visibility
     1107        // > blist all
     1108        // > blist away
     1109        // Or only specifying account tag
     1110        // > blist fb
     1111        // > blist msn
     1112        else if( cmd[1] )
     1113        {
     1114                // Only visibility
     1115                if( g_strcasecmp( cmd[1], "all" ) == 0 ||
     1116                    g_strcasecmp( cmd[1], "offline" ) == 0 ||
     1117                    g_strcasecmp( cmd[1], "away" ) == 0 ||
     1118                    g_strcasecmp( cmd[1], "online" ) == 0 )
     1119                {
     1120                        set_visibility(cmd[1], &online, &away, &offline );
     1121                }
     1122                // Only tag
     1123                else
     1124                {
     1125                        tag = cmd[1];
     1126                        online = away = 1;
     1127                }
     1128        }
     1129        // User is not specifying anything
     1130        // > blist
    10841131        else
     1132        {
    10851133                online = away = 1;
     1134        }
    10861135       
    10871136        if( strchr( irc->umode, 'b' ) != NULL )
    10881137                format = "%s\t%s\t%s";
     
    11041153                    ( bu->flags & ( BEE_USER_ONLINE | BEE_USER_AWAY ) ) != BEE_USER_ONLINE )
    11051154                        continue;
    11061155               
    1107                 if( online == 1 )
     1156                if( ( online == 1 && !tag ) ||
     1157                    ( online == 1 && g_strcasecmp( tag, bu->ic->acc->tag ) == 0 ) )
    11081158                {
    11091159                        char st[256] = "Online";
    11101160                       
     
    11131163                       
    11141164                        g_snprintf( s, sizeof( s ) - 1, "%s %s", bu->handle, bu->ic->acc->tag );
    11151165                        irc_rootmsg( irc, format, iu->nick, s, st );
     1166                        n_online ++;
    11161167                }
    1117                
    1118                 n_online ++;
    11191168        }
    11201169
    11211170        for( l = irc->users; l; l = l->next )
     
    11271176                    !( bu->flags & BEE_USER_ONLINE ) || !( bu->flags & BEE_USER_AWAY ) )
    11281177                        continue;
    11291178               
    1130                 if( away == 1 )
     1179                if( ( away == 1 && !tag ) ||
     1180                    ( away == 1 && g_strcasecmp( tag, bu->ic->acc->tag ) == 0 ) )
    11311181                {
    11321182                        g_snprintf( s, sizeof( s ) - 1, "%s %s", bu->handle, bu->ic->acc->tag );
    11331183                        irc_rootmsg( irc, format, iu->nick, s, irc_user_get_away( iu ) );
     1184                        n_away ++;
    11341185                }
    1135                 n_away ++;
    11361186        }
    11371187       
    11381188        for( l = irc->users; l; l = l->next )
     
    11441194                    bu->flags & BEE_USER_ONLINE )
    11451195                        continue;
    11461196               
    1147                 if( offline == 1 )
     1197                if( ( offline == 1 && !tag ) ||
     1198                    ( offline == 1 && g_strcasecmp( tag, bu->ic->acc->tag ) == 0 ) )
    11481199                {
    11491200                        g_snprintf( s, sizeof( s ) - 1, "%s %s", bu->handle, bu->ic->acc->tag );
    11501201                        irc_rootmsg( irc, format, iu->nick, s, "Offline" );
     1202                        n_offline ++;
    11511203                }
    1152                 n_offline ++;
    11531204        }
    11541205       
    11551206        irc_rootmsg( irc, "%d buddies (%d available, %d away, %d offline)", n_online + n_away + n_offline, n_online, n_away, n_offline );