Ignore:
Timestamp:
2009-11-19T13:11:38Z (14 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
20e830b
Parents:
36cf9fd
Message:

resource_select now defaults to activity instead of priority. Also, adding
a activity_timeout setting. Now, messages to someone who hasn't spoken for
a while will be sent to his/her bare JID, usually resulting in a broadcast.
This should fix issues with messages sometimes arriving on someone's
Crackberry/Android/etc instead of some place s/he's paying attention to.
Last, the activity timer is only reset on incoming messages.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/jabber/jabber_util.c

    r36cf9fd r76c85b4c  
    340340        if( ( bud = g_hash_table_lookup( jd->buddies, full_jid ) ) )
    341341        {
     342                /* The first entry is always a bare JID. If there are more, we
     343                   should ignore the first one here. */
     344                if( bud->next )
     345                        bud = bud->next;
     346               
    342347                /* If this is a transport buddy or whatever, it can't have more
    343348                   than one instance, so this is always wrong: */
     
    374379        else
    375380        {
    376                 /* Keep in mind that full_jid currently isn't really
    377                    a full JID... */
    378                 new->bare_jid = g_strdup( full_jid );
     381                new->full_jid = new->bare_jid = g_strdup( full_jid );
    379382                g_hash_table_insert( jd->buddies, new->bare_jid, new );
     383               
     384                if( s )
     385                {
     386                        new->next = g_new0( struct jabber_buddy, 1 );
     387                        new->next->bare_jid = new->bare_jid;
     388                        new = new->next;
     389                }
    380390        }
    381391       
     
    403413{
    404414        struct jabber_data *jd = ic->proto_data;
    405         struct jabber_buddy *bud;
     415        struct jabber_buddy *bud, *head;
    406416        char *s, *jid;
    407417       
     
    410420        if( ( s = strchr( jid, '/' ) ) )
    411421        {
    412                 int bare_exists = 0;
    413                
    414422                *s = 0;
    415423                if( ( bud = g_hash_table_lookup( jd->buddies, jid ) ) )
    416424                {
     425                        if( bud->next )
     426                                bud = bud->next;
     427                       
    417428                        /* Just return the first one for this bare JID. */
    418429                        if( flags & GET_BUDDY_FIRST )
     
    436447                                        break;
    437448                }
    438                 else
    439                 {
    440                         /* This variable tells the if down here that the bare
    441                            JID already exists and we should feel free to add
    442                            more resources, if the caller asked for that. */
    443                         bare_exists = 1;
    444                 }
    445                
    446                 if( bud == NULL && ( flags & GET_BUDDY_CREAT ) &&
    447                     ( !bare_exists || imcb_find_buddy( ic, jid ) ) )
     449               
     450                if( bud == NULL && ( flags & GET_BUDDY_CREAT ) && imcb_find_buddy( ic, jid ) )
    448451                {
    449452                        *s = '/';
     
    459462                char *set;
    460463               
    461                 bud = g_hash_table_lookup( jd->buddies, jid );
     464                head = g_hash_table_lookup( jd->buddies, jid );
     465                bud = head->next ? head->next : head;
    462466               
    463467                g_free( jid );
     
    476480                        /* Looks like the caller doesn't care about details. */
    477481                        return bud;
     482                else if( flags & GET_BUDDY_BARE )
     483                        return head;
    478484               
    479485                best_prio = best_time = bud;
     
    482488                        if( bud->priority > best_prio->priority )
    483489                                best_prio = bud;
    484                         if( bud->last_act > best_time->last_act )
     490                        if( bud->last_msg > best_time->last_msg )
    485491                                best_time = bud;
    486492                }
     
    488494                if( ( set = set_getstr( &ic->acc->set, "resource_select" ) ) == NULL )
    489495                        return NULL;
    490                 else if( strcmp( set, "activity" ) == 0 )
     496                else if( strcmp( set, "priority" ) == 0 )
     497                        return best_prio;
     498                else if( flags & GET_BUDDY_BARE_OK ) /* && strcmp( set, "activity" ) == 0 */
     499                {
     500                        if( best_time->last_msg + set_getint( &ic->acc->set, "activity_timeout" ) >= time( NULL ) )
     501                                return best_time;
     502                        else
     503                                return head;
     504                }
     505                else
    491506                        return best_time;
    492                 else /* if( strcmp( set, "priority" ) == 0 ) */
    493                         return best_prio;
    494507        }
    495508}
     
    533546{
    534547        struct jabber_data *jd = ic->proto_data;
    535         struct jabber_buddy *bud, *prev, *bi;
     548        struct jabber_buddy *head, *bud, *prev, *bi;
    536549        char *s, *full_jid;
    537550       
     
    541554                *s = 0;
    542555       
    543         if( ( bud = g_hash_table_lookup( jd->buddies, full_jid ) ) )
    544         {
     556        if( ( head = g_hash_table_lookup( jd->buddies, full_jid ) ) )
     557        {
     558                bud = head->next ? head->next : head;
     559               
    545560                /* If there's only one item in the list (and if the resource
    546561                   matches), removing it is simple. (And the hash reference
     
    550565                      ( bud->resource && s && strcmp( bud->resource, s + 1 ) == 0 ) ) )
    551566                {
    552                         g_hash_table_remove( jd->buddies, bud->bare_jid );
    553                         g_free( bud->bare_jid );
    554                         g_free( bud->ext_jid );
    555                         g_free( bud->full_jid );
    556                         g_free( bud->away_message );
    557                         g_free( bud );
    558                        
    559                         g_free( full_jid );
    560                        
    561                         return 1;
     567                        return jabber_buddy_remove_bare( ic, full_jid );
    562568                }
    563569                else if( s == NULL || bud->resource == NULL )
Note: See TracChangeset for help on using the changeset viewer.