Yahoo username with trailing whitespace -> zombified connection.
[thrasher.git] / thpresence.c
blob571307371b4bdedfb144c3fd4d5f61fc44b5c219
1 /*
2 * Thrasher Bird - XMPP transport via libpurple
3 * Copyright (C) 2008 Barracuda Networks, Inc.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with Thrasher Bird; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
19 #include <glib.h>
20 #include "status.h"
21 #include "account.h"
22 #include "thpresence.h"
26 void thrasher_set_presence (PurpleAccount *pa, PurpleStatusPrimitive primitive, gchar *message)
28 PurplePresence *presence;
29 PurpleStatus *status;
30 PurpleStatusType *type;
31 char *status_id = NULL;
33 /* Get the status_id so we can create a new type.
35 * Differs from purple_primitive_get_id_from_type() because
36 * purple_account_set_status() will fail if we send an invalid
37 * status ID for the account and we want to keep consistent with
38 * what the Perl-side supports. E.g. PURPLE_STATUS_UNAVAILABLE:
39 * prpls have it as "dnd" while _get_id_from_type() gives
40 * "unavailable".
42 switch (primitive)
44 case PURPLE_STATUS_UNSET:
45 /* See PURPLE_STATUS_EXTENDED_AWAY */
46 status_id = g_strdup("away");
47 break;
48 case PURPLE_STATUS_OFFLINE:
49 status_id = g_strdup("offline");
50 break;
51 case PURPLE_STATUS_AVAILABLE:
52 status_id = g_strdup("available");
53 break;
54 case PURPLE_STATUS_UNAVAILABLE:
55 status_id = g_strdup("dnd");
56 break;
57 case PURPLE_STATUS_INVISIBLE:
58 /* Currently unsupported */
59 break;
60 case PURPLE_STATUS_AWAY:
61 status_id = g_strdup("away");
62 break;
63 case PURPLE_STATUS_EXTENDED_AWAY:
64 /* We need to do the abstraction in Perl, but for now we're doing it painfully here... */
65 status_id = g_strdup("away");
66 break;
67 case PURPLE_STATUS_MOBILE:
68 /* Currently unsupported */
69 break;
70 case PURPLE_STATUS_TUNE:
71 /* Currently unsupported */
72 break;
73 case PURPLE_STATUS_NUM_PRIMITIVES:
74 /* Unsupported */
75 break;
78 /* No reason to trip statuses if we don't have a status_id */
79 if (status_id)
81 /* Create a new status */
82 if (message)
83 type = purple_status_type_new_with_attrs(primitive, status_id, status_id,
84 TRUE, TRUE, TRUE, "message",
85 "message",
86 purple_value_new(PURPLE_TYPE_STRING),
87 NULL);
88 else
89 type = purple_status_type_new(primitive, status_id, status_id, TRUE);
91 /* Wrap these two calls together */
92 presence = purple_presence_new_for_account(pa);
93 status = purple_status_new(type, presence);
95 /* Flip the status on */
96 if (message)
97 purple_account_set_status(pa, status_id, TRUE, "message", message, NULL);
98 else
99 purple_account_set_status(pa, status_id, TRUE, NULL);