[aa5f725] | 1 | #include "owl.h" |
---|
| 2 | |
---|
[bd3f232] | 3 | static const char fileIdent[] = "$Id$"; |
---|
| 4 | |
---|
[aa5f725] | 5 | void owl_buddylist_init(owl_buddylist *b) |
---|
| 6 | { |
---|
| 7 | owl_list_create(&(b->buddies)); |
---|
[de03334] | 8 | owl_list_create(&(b->idletimes)); |
---|
[aa5f725] | 9 | } |
---|
| 10 | |
---|
| 11 | /* Deal with an "oncoming" message. This means recognizing the user |
---|
| 12 | * has logged in, and sending a message if they were not already |
---|
| 13 | * logged in. |
---|
| 14 | */ |
---|
| 15 | void owl_buddylist_oncoming(owl_buddylist *b, char *screenname) |
---|
| 16 | { |
---|
| 17 | int i, j, found; |
---|
| 18 | owl_message *m; |
---|
[de03334] | 19 | int *zero; |
---|
[aa5f725] | 20 | |
---|
| 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 | } |
---|
| 29 | |
---|
| 30 | if (!found) { |
---|
[de03334] | 31 | /* add the buddy */ |
---|
[aa5f725] | 32 | owl_list_append_element(&(b->buddies), owl_strdup(screenname)); |
---|
[de03334] | 33 | zero=owl_malloc(sizeof(int)); |
---|
| 34 | *zero=0; |
---|
| 35 | owl_list_append_element(&(b->idletimes), zero); |
---|
[aa5f725] | 36 | |
---|
[de03334] | 37 | /* do a request for idle time */ |
---|
| 38 | owl_buddylist_request_idletimes(owl_global_get_buddylist(&g)); |
---|
| 39 | |
---|
[ceb8cfb] | 40 | /* are we ingoring login messages for a while? */ |
---|
| 41 | if (!owl_timer_is_expired(owl_global_get_aim_login_timer(&g))) return; |
---|
| 42 | |
---|
[aa5f725] | 43 | m=owl_malloc(sizeof(owl_message)); |
---|
[d559df9] | 44 | owl_message_create_aim(m, |
---|
| 45 | screenname, |
---|
| 46 | owl_global_get_aim_screenname(&g), |
---|
| 47 | "", |
---|
| 48 | OWL_MESSAGE_DIRECTION_IN, |
---|
| 49 | 1); |
---|
[aa5f725] | 50 | owl_global_messagequeue_addmsg(&g, m); |
---|
[de03334] | 51 | |
---|
[aa5f725] | 52 | } |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | /* Deal with an "offgoing" message. This means recognizing the user |
---|
| 56 | * has logged out, and sending a message if they were logged in. |
---|
| 57 | */ |
---|
| 58 | void owl_buddylist_offgoing(owl_buddylist *b, char *screenname) |
---|
| 59 | { |
---|
| 60 | int i, j, found; |
---|
| 61 | owl_message *m; |
---|
| 62 | |
---|
| 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)); |
---|
[de03334] | 69 | owl_free(owl_list_get_element(&(b->idletimes), i)); |
---|
[aa5f725] | 70 | owl_list_remove_element(&(b->buddies), i); |
---|
[de03334] | 71 | owl_list_remove_element(&(b->idletimes), i); |
---|
[aa5f725] | 72 | break; |
---|
| 73 | } |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | if (found) { |
---|
| 77 | m=owl_malloc(sizeof(owl_message)); |
---|
[d559df9] | 78 | owl_message_create_aim(m, |
---|
| 79 | screenname, |
---|
| 80 | owl_global_get_aim_screenname(&g), |
---|
| 81 | "", |
---|
| 82 | OWL_MESSAGE_DIRECTION_IN, |
---|
| 83 | -1); |
---|
| 84 | |
---|
[aa5f725] | 85 | owl_global_messagequeue_addmsg(&g, m); |
---|
| 86 | } |
---|
| 87 | } |
---|
| 88 | |
---|
[de03334] | 89 | /* send requests to the AIM server to retrieve info |
---|
| 90 | * on all buddies. The AIM callback then fills in the |
---|
| 91 | * values when the responses are received |
---|
| 92 | */ |
---|
| 93 | void owl_buddylist_request_idletimes(owl_buddylist *b) |
---|
| 94 | { |
---|
| 95 | int i, j; |
---|
| 96 | |
---|
| 97 | j=owl_buddylist_get_size(b); |
---|
| 98 | for (i=0; i<j; i++) { |
---|
| 99 | owl_aim_get_idle(owl_buddylist_get_buddy(b, i)); |
---|
| 100 | } |
---|
| 101 | } |
---|
| 102 | |
---|
[b2b0773] | 103 | /* return the number of logged in buddies */ |
---|
[aa5f725] | 104 | int owl_buddylist_get_size(owl_buddylist *b) |
---|
| 105 | { |
---|
| 106 | return(owl_list_get_size(&(b->buddies))); |
---|
| 107 | } |
---|
| 108 | |
---|
[b2b0773] | 109 | /* get buddy number 'n' */ |
---|
[aa5f725] | 110 | char *owl_buddylist_get_buddy(owl_buddylist *b, int n) |
---|
| 111 | { |
---|
| 112 | return(owl_list_get_element(&(b->buddies), n)); |
---|
| 113 | } |
---|
| 114 | |
---|
[de03334] | 115 | /* get the idle time for buddy number 'n' */ |
---|
| 116 | int owl_buddylist_get_idletime(owl_buddylist *b, int n) |
---|
| 117 | { |
---|
| 118 | int *foo; |
---|
| 119 | |
---|
| 120 | foo=owl_list_get_element(&(b->idletimes), n); |
---|
| 121 | return(*foo); |
---|
| 122 | } |
---|
| 123 | |
---|
| 124 | /* set the idle time for user 'screenname'. If the given |
---|
| 125 | * screenname is not on the buddy list do nothing |
---|
| 126 | */ |
---|
[5b85d19] | 127 | void owl_buddylist_set_idletime(owl_buddylist *b, char *screenname, int minutes) |
---|
[de03334] | 128 | { |
---|
| 129 | int i, j, *idle; |
---|
| 130 | |
---|
| 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)); |
---|
[5b85d19] | 136 | *idle=minutes; |
---|
[de03334] | 137 | owl_list_replace_element(&(b->idletimes), i, idle); |
---|
| 138 | return; |
---|
| 139 | } |
---|
| 140 | } |
---|
| 141 | } |
---|
| 142 | |
---|
[b2b0773] | 143 | /* remove all buddies from the list */ |
---|
[aa5f725] | 144 | void owl_buddylist_clear(owl_buddylist *b) { |
---|
| 145 | owl_list_free_all(&(b->buddies), owl_free); |
---|
[de03334] | 146 | owl_list_free_all(&(b->idletimes), owl_free); |
---|
[aa5f725] | 147 | owl_list_create(&(b->buddies)); |
---|
[de03334] | 148 | owl_list_create(&(b->idletimes)); |
---|
[aa5f725] | 149 | } |
---|