Changeset a352335c for buddylist.c


Ignore:
Timestamp:
Jul 5, 2003, 7:38:16 AM (17 years ago)
Author:
James M. Kretchmar <kretch@mit.edu>
Branches:
master, barnowl_perlaim, debian, owl, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
6873455
Parents:
c045455
Message:
Fixed bug in buddy idle time stuff
File:
1 edited

Legend:

Unmodified
Added
Removed
  • buddylist.c

    r5b85d19 ra352335c  
    1010
    1111/* Deal with an "oncoming" message.  This means recognizing the user
    12  * has logged in, and sending a message if they were not already
     12 * has logged in, and displaying a message if they were not already
    1313 * logged in.
    1414 */
    1515void owl_buddylist_oncoming(owl_buddylist *b, char *screenname)
    1616{
    17   int i, j, found;
     17  int *zero;
    1818  owl_message *m;
    19   int *zero;
    2019
    21   found=0;
    22   j=owl_list_get_size(&(b->buddies));
    23   for (i=0; i<j; i++) {
    24     if (!strcasecmp(owl_list_get_element(&(b->buddies), i), screenname)) {
    25       found=1;
    26       break;
    27     }
    28   }
     20  if (!owl_buddylist_is_buddy_loggedin(b, screenname)) {
    2921
    30   if (!found) {
    3122    /* add the buddy */
    3223    owl_list_append_element(&(b->buddies), owl_strdup(screenname));
     
    3627
    3728    /* do a request for idle time */
    38     owl_buddylist_request_idletimes(owl_global_get_buddylist(&g));
     29    owl_buddylist_request_idletime(b, screenname);
    3930       
    4031    /* are we ingoring login messages for a while? */
    4132    if (!owl_timer_is_expired(owl_global_get_aim_login_timer(&g))) return;
    4233
     34    /* if not, create the login message */
    4335    m=owl_malloc(sizeof(owl_message));
    4436    owl_message_create_aim(m,
     
    4941                           1);
    5042    owl_global_messagequeue_addmsg(&g, m);
    51 
    5243  }
    5344}
     
    5849void owl_buddylist_offgoing(owl_buddylist *b, char *screenname)
    5950{
    60   int i, j, found;
     51  int index;
    6152  owl_message *m;
    6253
    63   found=0;
    64   j=owl_list_get_size(&(b->buddies));
    65   for (i=0; i<j; i++) {
    66     if (!strcasecmp(owl_list_get_element(&(b->buddies), i), screenname)) {
    67       found=1;
    68       owl_free(owl_list_get_element(&(b->buddies), i));
    69       owl_free(owl_list_get_element(&(b->idletimes), i));
    70       owl_list_remove_element(&(b->buddies), i);
    71       owl_list_remove_element(&(b->idletimes), i);
    72       break;
    73     }
    74   }
     54  index=owl_buddylist_get_buddy_index(b, screenname);
     55  if (index==-1) return;
    7556
    76   if (found) {
    77     m=owl_malloc(sizeof(owl_message));
    78     owl_message_create_aim(m,
    79                            screenname,
    80                            owl_global_get_aim_screenname(&g),
    81                            "",
    82                            OWL_MESSAGE_DIRECTION_IN,
    83                            -1);
     57  owl_free(owl_list_get_element(&(b->buddies), index));
     58  owl_free(owl_list_get_element(&(b->idletimes), index));
     59  owl_list_remove_element(&(b->buddies), index);
     60  owl_list_remove_element(&(b->idletimes), index);
    8461
    85     owl_global_messagequeue_addmsg(&g, m);
    86   }
     62  m=owl_malloc(sizeof(owl_message));
     63  owl_message_create_aim(m,
     64                         screenname,
     65                         owl_global_get_aim_screenname(&g),
     66                         "",
     67                         OWL_MESSAGE_DIRECTION_IN,
     68                         -1);
     69  owl_global_messagequeue_addmsg(&g, m);
    8770}
    8871
     
    10184}
    10285
     86/* send request to the AIM server to retrieve info on one buddy.  The
     87 * AIM callback then fills in the values when the responses are
     88 * received.  The buddy must be logged in or no request will be
     89 * performed.
     90 */
     91void owl_buddylist_request_idletime(owl_buddylist *b, char *screenname)
     92{
     93  if (!owl_buddylist_is_buddy_loggedin(b, screenname)) return;
     94  owl_aim_get_idle(screenname);
     95}
     96
    10397/* return the number of logged in buddies */
    10498int owl_buddylist_get_size(owl_buddylist *b)
     
    110104char *owl_buddylist_get_buddy(owl_buddylist *b, int n)
    111105{
     106  if (n > owl_buddylist_get_size(b)-1) return("");
    112107  return(owl_list_get_element(&(b->buddies), n));
     108}
     109
     110/* Return the index of the buddy 'screename' or -1
     111 * if the buddy is not logged in.
     112 */
     113int owl_buddylist_get_buddy_index(owl_buddylist *b, char *screenname)
     114{
     115  int i, j;
     116 
     117  j=owl_list_get_size(&(b->buddies));
     118  for (i=0; i<j; i++) {
     119    if (!strcasecmp(owl_list_get_element(&(b->buddies), i), screenname)) {
     120      return(i);
     121    }
     122  }
     123  return(-1);
     124}
     125
     126/* return 1 if the buddy 'screenname' is logged in,
     127 * otherwise return 0
     128 */
     129int owl_buddylist_is_buddy_loggedin(owl_buddylist *b, char *screenname)
     130{
     131  if (owl_buddylist_get_buddy_index(b, screenname)!=-1) return(1);
     132  return(0);
    113133}
    114134
     
    127147void owl_buddylist_set_idletime(owl_buddylist *b, char *screenname, int minutes)
    128148{
    129   int i, j, *idle;
     149  int index, *idle;
    130150
    131   j=owl_buddylist_get_size(b);
    132   for (i=0; i<j; i++) {
    133     if (!strcasecmp(owl_list_get_element(&(b->buddies), i), screenname)) {
    134       owl_free(owl_list_get_element(&(b->idletimes), i));
    135       idle=owl_malloc(sizeof(int));
    136       *idle=minutes;
    137       owl_list_replace_element(&(b->idletimes), i, idle);
    138       return;
    139     }
    140   }
     151  index=owl_buddylist_get_buddy_index(b, screenname);
     152  if (index==-1) return;
     153
     154  owl_free(owl_list_get_element(&(b->idletimes), index));
     155  idle=owl_malloc(sizeof(int));
     156  *idle=minutes;
     157  owl_list_replace_element(&(b->idletimes), index, idle);
    141158}
    142159
Note: See TracChangeset for help on using the changeset viewer.