source: buddylist.c @ a352335c

barnowl_perlaimdebianowlrelease-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since a352335c was a352335c, checked in by James M. Kretchmar <kretch@mit.edu>, 21 years ago
Fixed bug in buddy idle time stuff
  • Property mode set to 100644
File size: 4.4 KB
RevLine 
[aa5f725]1#include "owl.h"
2
[bd3f232]3static const char fileIdent[] = "$Id$";
4
[aa5f725]5void 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
[a352335c]12 * has logged in, and displaying a message if they were not already
[aa5f725]13 * logged in.
14 */
15void owl_buddylist_oncoming(owl_buddylist *b, char *screenname)
16{
[de03334]17  int *zero;
[a352335c]18  owl_message *m;
[aa5f725]19
[a352335c]20  if (!owl_buddylist_is_buddy_loggedin(b, screenname)) {
[aa5f725]21
[de03334]22    /* add the buddy */
[aa5f725]23    owl_list_append_element(&(b->buddies), owl_strdup(screenname));
[de03334]24    zero=owl_malloc(sizeof(int));
25    *zero=0;
26    owl_list_append_element(&(b->idletimes), zero);
[aa5f725]27
[de03334]28    /* do a request for idle time */
[a352335c]29    owl_buddylist_request_idletime(b, screenname);
[de03334]30       
[ceb8cfb]31    /* are we ingoring login messages for a while? */
32    if (!owl_timer_is_expired(owl_global_get_aim_login_timer(&g))) return;
33
[a352335c]34    /* if not, create the login message */
[aa5f725]35    m=owl_malloc(sizeof(owl_message));
[d559df9]36    owl_message_create_aim(m,
37                           screenname,
38                           owl_global_get_aim_screenname(&g),
39                           "",
40                           OWL_MESSAGE_DIRECTION_IN,
41                           1);
[aa5f725]42    owl_global_messagequeue_addmsg(&g, m);
43  }
44}
45
46/* Deal with an "offgoing" message.  This means recognizing the user
47 * has logged out, and sending a message if they were logged in.
48 */
49void owl_buddylist_offgoing(owl_buddylist *b, char *screenname)
50{
[a352335c]51  int index;
[aa5f725]52  owl_message *m;
53
[a352335c]54  index=owl_buddylist_get_buddy_index(b, screenname);
55  if (index==-1) return;
56
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);
61
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);
[aa5f725]70}
71
[de03334]72/* send requests to the AIM server to retrieve info
73 * on all buddies.  The AIM callback then fills in the
74 * values when the responses are received
75 */
76void owl_buddylist_request_idletimes(owl_buddylist *b)
77{
78  int i, j;
79
80  j=owl_buddylist_get_size(b);
81  for (i=0; i<j; i++) {
82    owl_aim_get_idle(owl_buddylist_get_buddy(b, i));
83  }
84}
85
[a352335c]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
[b2b0773]97/* return the number of logged in buddies */
[aa5f725]98int owl_buddylist_get_size(owl_buddylist *b)
99{
100  return(owl_list_get_size(&(b->buddies)));
101}
102
[b2b0773]103/* get buddy number 'n' */
[aa5f725]104char *owl_buddylist_get_buddy(owl_buddylist *b, int n)
105{
[a352335c]106  if (n > owl_buddylist_get_size(b)-1) return("");
[aa5f725]107  return(owl_list_get_element(&(b->buddies), n));
108}
109
[a352335c]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);
133}
134
[de03334]135/* get the idle time for buddy number 'n' */
136int owl_buddylist_get_idletime(owl_buddylist *b, int n)
137{
138  int *foo;
139
140  foo=owl_list_get_element(&(b->idletimes), n);
141  return(*foo);
142}
143
144/* set the idle time for user 'screenname'.  If the given
145 * screenname is not on the buddy list do nothing
146 */
[5b85d19]147void owl_buddylist_set_idletime(owl_buddylist *b, char *screenname, int minutes)
[de03334]148{
[a352335c]149  int index, *idle;
[de03334]150
[a352335c]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);
[de03334]158}
159
[b2b0773]160/* remove all buddies from the list */
[aa5f725]161void owl_buddylist_clear(owl_buddylist *b) {
162  owl_list_free_all(&(b->buddies), owl_free);
[de03334]163  owl_list_free_all(&(b->idletimes), owl_free);
[aa5f725]164  owl_list_create(&(b->buddies));
[de03334]165  owl_list_create(&(b->idletimes));
[aa5f725]166}
Note: See TracBrowser for help on using the repository browser.