[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)); |
---|
| 8 | } |
---|
| 9 | |
---|
| 10 | /* Deal with an "oncoming" message. This means recognizing the user |
---|
| 11 | * has logged in, and sending a message if they were not already |
---|
| 12 | * logged in. |
---|
| 13 | */ |
---|
| 14 | void owl_buddylist_oncoming(owl_buddylist *b, char *screenname) |
---|
| 15 | { |
---|
| 16 | int i, j, found; |
---|
| 17 | owl_message *m; |
---|
| 18 | |
---|
| 19 | found=0; |
---|
| 20 | j=owl_list_get_size(&(b->buddies)); |
---|
| 21 | for (i=0; i<j; i++) { |
---|
| 22 | if (!strcasecmp(owl_list_get_element(&(b->buddies), i), screenname)) { |
---|
| 23 | found=1; |
---|
| 24 | break; |
---|
| 25 | } |
---|
| 26 | } |
---|
| 27 | |
---|
| 28 | if (!found) { |
---|
| 29 | owl_list_append_element(&(b->buddies), owl_strdup(screenname)); |
---|
| 30 | |
---|
| 31 | m=owl_malloc(sizeof(owl_message)); |
---|
[d559df9] | 32 | owl_message_create_aim(m, |
---|
| 33 | screenname, |
---|
| 34 | owl_global_get_aim_screenname(&g), |
---|
| 35 | "", |
---|
| 36 | OWL_MESSAGE_DIRECTION_IN, |
---|
| 37 | 1); |
---|
[aa5f725] | 38 | owl_global_messagequeue_addmsg(&g, m); |
---|
| 39 | } |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | /* Deal with an "offgoing" message. This means recognizing the user |
---|
| 43 | * has logged out, and sending a message if they were logged in. |
---|
| 44 | */ |
---|
| 45 | void owl_buddylist_offgoing(owl_buddylist *b, char *screenname) |
---|
| 46 | { |
---|
| 47 | int i, j, found; |
---|
| 48 | owl_message *m; |
---|
| 49 | |
---|
| 50 | found=0; |
---|
| 51 | j=owl_list_get_size(&(b->buddies)); |
---|
| 52 | for (i=0; i<j; i++) { |
---|
| 53 | if (!strcasecmp(owl_list_get_element(&(b->buddies), i), screenname)) { |
---|
| 54 | found=1; |
---|
| 55 | owl_free(owl_list_get_element(&(b->buddies), i)); |
---|
| 56 | owl_list_remove_element(&(b->buddies), i); |
---|
| 57 | break; |
---|
| 58 | } |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | if (found) { |
---|
| 62 | m=owl_malloc(sizeof(owl_message)); |
---|
[d559df9] | 63 | owl_message_create_aim(m, |
---|
| 64 | screenname, |
---|
| 65 | owl_global_get_aim_screenname(&g), |
---|
| 66 | "", |
---|
| 67 | OWL_MESSAGE_DIRECTION_IN, |
---|
| 68 | -1); |
---|
| 69 | |
---|
[aa5f725] | 70 | owl_global_messagequeue_addmsg(&g, m); |
---|
| 71 | } |
---|
| 72 | } |
---|
| 73 | |
---|
[b2b0773] | 74 | /* return the number of logged in buddies */ |
---|
[aa5f725] | 75 | int owl_buddylist_get_size(owl_buddylist *b) |
---|
| 76 | { |
---|
| 77 | return(owl_list_get_size(&(b->buddies))); |
---|
| 78 | } |
---|
| 79 | |
---|
[b2b0773] | 80 | /* get buddy number 'n' */ |
---|
[aa5f725] | 81 | char *owl_buddylist_get_buddy(owl_buddylist *b, int n) |
---|
| 82 | { |
---|
| 83 | return(owl_list_get_element(&(b->buddies), n)); |
---|
| 84 | } |
---|
| 85 | |
---|
[b2b0773] | 86 | /* remove all buddies from the list */ |
---|
[aa5f725] | 87 | void owl_buddylist_clear(owl_buddylist *b) { |
---|
| 88 | owl_list_free_all(&(b->buddies), owl_free); |
---|
| 89 | owl_list_create(&(b->buddies)); |
---|
| 90 | } |
---|