source: buddylist.c @ e6449bc

barnowl_perlaimdebianowlrelease-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since e6449bc was ceb8cfb, checked in by James M. Kretchmar <kretch@mit.edu>, 21 years ago
Fixed bug causing buddies not to be added to buddy list during ingorelogin timer
  • Property mode set to 100644
File size: 2.2 KB
Line 
1#include "owl.h"
2
3static const char fileIdent[] = "$Id$";
4
5void 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 */
14void 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    /* are we ingoring login messages for a while? */
32    if (!owl_timer_is_expired(owl_global_get_aim_login_timer(&g))) return;
33
34    m=owl_malloc(sizeof(owl_message));
35    owl_message_create_aim(m,
36                           screenname,
37                           owl_global_get_aim_screenname(&g),
38                           "",
39                           OWL_MESSAGE_DIRECTION_IN,
40                           1);
41    owl_global_messagequeue_addmsg(&g, m);
42  }
43}
44
45/* Deal with an "offgoing" message.  This means recognizing the user
46 * has logged out, and sending a message if they were logged in.
47 */
48void owl_buddylist_offgoing(owl_buddylist *b, char *screenname)
49{
50  int i, j, found;
51  owl_message *m;
52
53  found=0;
54  j=owl_list_get_size(&(b->buddies));
55  for (i=0; i<j; i++) {
56    if (!strcasecmp(owl_list_get_element(&(b->buddies), i), screenname)) {
57      found=1;
58      owl_free(owl_list_get_element(&(b->buddies), i));
59      owl_list_remove_element(&(b->buddies), i);
60      break;
61    }
62  }
63
64  if (found) {
65    m=owl_malloc(sizeof(owl_message));
66    owl_message_create_aim(m,
67                           screenname,
68                           owl_global_get_aim_screenname(&g),
69                           "",
70                           OWL_MESSAGE_DIRECTION_IN,
71                           -1);
72
73    owl_global_messagequeue_addmsg(&g, m);
74  }
75}
76
77/* return the number of logged in buddies */
78int owl_buddylist_get_size(owl_buddylist *b)
79{
80  return(owl_list_get_size(&(b->buddies)));
81}
82
83/* get buddy number 'n' */
84char *owl_buddylist_get_buddy(owl_buddylist *b, int n)
85{
86  return(owl_list_get_element(&(b->buddies), n));
87}
88
89/* remove all buddies from the list */
90void owl_buddylist_clear(owl_buddylist *b) {
91  owl_list_free_all(&(b->buddies), owl_free);
92  owl_list_create(&(b->buddies));
93}
Note: See TracBrowser for help on using the repository browser.