libpurple/purplecontact.c

Wed, 14 Aug 2024 19:26:26 -0500

author
Gary Kramlich <grim@reaperworld.com>
date
Wed, 14 Aug 2024 19:26:26 -0500
changeset 42874
c53e5e1ff6b1
parent 42676
e28d0c86b62c
child 43071
071588186662
permissions
-rw-r--r--

Remove uri handling from libpurple

Testing Done:
Called in the turtles.

Reviewed at https://reviews.imfreedom.org/r/3387/

41739
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
1 /*
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
2 * Purple - Internet Messaging Library
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
3 * Copyright (C) Pidgin Developers <devel@pidgin.im>
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
4 *
42594
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42584
diff changeset
5 * Purple is the legal property of its developers, whose names are too numerous
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42584
diff changeset
6 * to list here. Please refer to the COPYRIGHT file distributed with this
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42584
diff changeset
7 * source distribution.
41739
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
8 *
42594
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42584
diff changeset
9 * This library is free software; you can redistribute it and/or modify it
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42584
diff changeset
10 * under the terms of the GNU General Public License as published by the Free
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42584
diff changeset
11 * Software Foundation; either version 2 of the License, or (at your option)
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42584
diff changeset
12 * any later version.
41739
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
13 *
42594
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42584
diff changeset
14 * This library is distributed in the hope that it will be useful, but WITHOUT
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42584
diff changeset
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42584
diff changeset
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42584
diff changeset
17 * more details.
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42584
diff changeset
18 *
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42584
diff changeset
19 * You should have received a copy of the GNU General Public License along with
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42584
diff changeset
20 * this library; if not, see <https://www.gnu.org/licenses/>.
41739
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
21 */
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
22
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
23 #include "purplecontact.h"
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
24
42532
eca0c08ed2a3 Add purple_contact_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 41960
diff changeset
25 #include "purpleconversationmanager.h"
42674
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
26 #include "purpleprotocolconversation.h"
41918
106ae46b290b Add a permission property to PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41771
diff changeset
27
41948
6d844d2faff1 Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41933
diff changeset
28 struct _PurpleContact {
6d844d2faff1 Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41933
diff changeset
29 PurpleContactInfo parent;
41739
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
30
41948
6d844d2faff1 Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41933
diff changeset
31 PurpleAccount *account;
6d844d2faff1 Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41933
diff changeset
32 };
41739
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
33
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
34 enum {
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
35 PROP_0,
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
36 PROP_ACCOUNT,
42584
687260353985 Make signal and property enums and initializers consistent
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 42576
diff changeset
37 N_PROPERTIES,
41739
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
38 };
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
39 static GParamSpec *properties[N_PROPERTIES] = {NULL, };
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
40
42576
ab1ca778ddb2 Make sure all of the final types in libpurple are defined as such
Gary Kramlich <grim@reaperworld.com>
parents: 42532
diff changeset
41 G_DEFINE_FINAL_TYPE(PurpleContact, purple_contact, PURPLE_TYPE_CONTACT_INFO)
41739
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
42
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
43 /******************************************************************************
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
44 * Helpers
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
45 *****************************************************************************/
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
46 static void
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
47 purple_contact_set_account(PurpleContact *contact, PurpleAccount *account) {
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
48 g_return_if_fail(PURPLE_IS_CONTACT(contact));
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
49 g_return_if_fail(PURPLE_IS_ACCOUNT(account));
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
50
41948
6d844d2faff1 Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41933
diff changeset
51 if(g_set_object(&contact->account, account)) {
41739
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
52 g_object_notify_by_pspec(G_OBJECT(contact), properties[PROP_ACCOUNT]);
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
53 }
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
54 }
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
55
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
56 /******************************************************************************
42674
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
57 * Callbacks
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
58 *****************************************************************************/
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
59 static void
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
60 purple_contact_create_dm_cb(GObject *obj, GAsyncResult *result, gpointer data)
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
61 {
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
62 PurpleProtocolConversation *protocol = PURPLE_PROTOCOL_CONVERSATION(obj);
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
63 PurpleConversation *conversation = NULL;
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
64 GError *error = NULL;
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
65 GTask *task = data;
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
66
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
67 /* task and result share a cancellable, so we just need to clear task to
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
68 * make sure it's callback gets called.
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
69 */
42676
e28d0c86b62c Fix a few issues with the new dm stuff in PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 42674
diff changeset
70 if(g_task_return_error_if_cancelled(G_TASK(task))) {
42674
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
71 g_clear_object(&task);
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
72
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
73 return;
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
74 }
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
75
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
76 conversation = purple_protocol_conversation_create_conversation_finish(protocol,
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
77 result,
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
78 &error);
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
79
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
80 if(error != NULL) {
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
81 g_task_return_error(task, error);
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
82 } else {
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
83 g_task_return_pointer(task, conversation, g_object_unref);
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
84 }
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
85
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
86 g_clear_object(&task);
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
87 }
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
88
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
89 /******************************************************************************
41739
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
90 * GObject Implementation
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
91 *****************************************************************************/
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
92 static void
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
93 purple_contact_get_property(GObject *obj, guint param_id, GValue *value,
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
94 GParamSpec *pspec)
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
95 {
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
96 PurpleContact *contact = PURPLE_CONTACT(obj);
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
97
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
98 switch(param_id) {
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
99 case PROP_ACCOUNT:
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
100 g_value_set_object(value, purple_contact_get_account(contact));
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
101 break;
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
102 default:
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
103 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec);
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
104 break;
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
105 }
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
106 }
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
107
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
108 static void
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
109 purple_contact_set_property(GObject *obj, guint param_id, const GValue *value,
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
110 GParamSpec *pspec)
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
111 {
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
112 PurpleContact *contact = PURPLE_CONTACT(obj);
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
113
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
114 switch(param_id) {
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
115 case PROP_ACCOUNT:
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
116 purple_contact_set_account(contact, g_value_get_object(value));
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
117 break;
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
118 default:
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
119 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec);
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
120 break;
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
121 }
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
122 }
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
123
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
124 static void
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
125 purple_contact_dispose(GObject *obj) {
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
126 PurpleContact *contact = PURPLE_CONTACT(obj);
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
127
41948
6d844d2faff1 Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41933
diff changeset
128 g_clear_object(&contact->account);
41739
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
129
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
130 G_OBJECT_CLASS(purple_contact_parent_class)->dispose(obj);
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
131 }
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
132
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
133 static void
41960
c8a4853205e3 Bump C standard to C99 for libpurple files and fix warnings
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41948
diff changeset
134 purple_contact_init(G_GNUC_UNUSED PurpleContact *contact) {
41739
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
135 }
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
136
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
137 static void
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
138 purple_contact_class_init(PurpleContactClass *klass) {
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
139 GObjectClass *obj_class = G_OBJECT_CLASS(klass);
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
140
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
141 obj_class->dispose = purple_contact_dispose;
41918
106ae46b290b Add a permission property to PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41771
diff changeset
142 obj_class->get_property = purple_contact_get_property;
106ae46b290b Add a permission property to PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41771
diff changeset
143 obj_class->set_property = purple_contact_set_property;
41739
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
144
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
145 /**
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
146 * PurpleContact:account:
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
147 *
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
148 * The account that this contact belongs to.
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
149 *
42613
780d7efe37c2 Remove the micro version from since tags for libpurple part 2
Gary Kramlich <grim@reaperworld.com>
parents: 42594
diff changeset
150 * Since: 3.0
41739
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
151 */
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
152 properties[PROP_ACCOUNT] = g_param_spec_object(
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
153 "account", "account",
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
154 "The account this contact belongs to",
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
155 PURPLE_TYPE_ACCOUNT,
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
156 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
157
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
158 g_object_class_install_properties(obj_class, N_PROPERTIES, properties);
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
159 }
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
160
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
161 /******************************************************************************
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
162 * Public API
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
163 *****************************************************************************/
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
164 PurpleContact *
41759
1ecc0512e714 Make purple_contact_new take the id instead of the username.
Gary Kramlich <grim@reaperworld.com>
parents: 41755
diff changeset
165 purple_contact_new(PurpleAccount *account, const gchar *id) {
41739
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
166 g_return_val_if_fail(PURPLE_IS_ACCOUNT(account), NULL);
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
167
41933
8ccd6fdc7ceb Make PurpleContact derivable
Gary Kramlich <grim@reaperworld.com>
parents: 41929
diff changeset
168 return g_object_new(
8ccd6fdc7ceb Make PurpleContact derivable
Gary Kramlich <grim@reaperworld.com>
parents: 41929
diff changeset
169 PURPLE_TYPE_CONTACT,
41739
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
170 "account", account,
41759
1ecc0512e714 Make purple_contact_new take the id instead of the username.
Gary Kramlich <grim@reaperworld.com>
parents: 41755
diff changeset
171 "id", id,
41739
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
172 NULL);
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
173 }
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
174
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
175 PurpleAccount *
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
176 purple_contact_get_account(PurpleContact *contact) {
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
177 g_return_val_if_fail(PURPLE_IS_CONTACT(contact), NULL);
f589ceec0172 Create the new PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
178
41948
6d844d2faff1 Split PurpleContactInfo out of PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41933
diff changeset
179 return contact->account;
41918
106ae46b290b Add a permission property to PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 41771
diff changeset
180 }
42532
eca0c08ed2a3 Add purple_contact_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 41960
diff changeset
181
eca0c08ed2a3 Add purple_contact_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 41960
diff changeset
182 PurpleConversation *
42676
e28d0c86b62c Fix a few issues with the new dm stuff in PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 42674
diff changeset
183 purple_contact_find_dm(PurpleContact *contact) {
42532
eca0c08ed2a3 Add purple_contact_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 41960
diff changeset
184 PurpleConversationManager *manager = NULL;
eca0c08ed2a3 Add purple_contact_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 41960
diff changeset
185
eca0c08ed2a3 Add purple_contact_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 41960
diff changeset
186 g_return_val_if_fail(PURPLE_IS_CONTACT(contact), NULL);
eca0c08ed2a3 Add purple_contact_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 41960
diff changeset
187
eca0c08ed2a3 Add purple_contact_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 41960
diff changeset
188 manager = purple_conversation_manager_get_default();
eca0c08ed2a3 Add purple_contact_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 41960
diff changeset
189
42676
e28d0c86b62c Fix a few issues with the new dm stuff in PurpleContact
Gary Kramlich <grim@reaperworld.com>
parents: 42674
diff changeset
190 return purple_conversation_manager_find_dm(manager, contact);
42532
eca0c08ed2a3 Add purple_contact_find_dm
Gary Kramlich <grim@reaperworld.com>
parents: 41960
diff changeset
191 }
42674
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
192
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
193 void
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
194 purple_contact_create_dm_async(PurpleContact *contact,
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
195 GCancellable *cancellable,
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
196 GAsyncReadyCallback callback,
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
197 gpointer data)
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
198 {
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
199 PurpleProtocol *protocol = NULL;
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
200 PurpleProtocolConversation *protocol_conversation = NULL;
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
201 PurpleCreateConversationDetails *details = NULL;
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
202 GListStore *participants = NULL;
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
203 GTask *task = NULL;
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
204 gboolean implements = FALSE;
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
205
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
206 task = g_task_new(contact, cancellable, callback, data);
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
207 g_task_set_source_tag(task, purple_contact_create_dm_async);
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
208
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
209 protocol = purple_account_get_protocol(contact->account);
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
210 if(!PURPLE_IS_PROTOCOL_CONVERSATION(protocol)) {
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
211 g_task_return_new_error(task, PURPLE_CONTACT_DOMAIN, 0,
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
212 "protocol %s does not implement the "
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
213 "ProtocolConversation interface.",
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
214 purple_account_get_protocol_id(contact->account));
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
215 g_clear_object(&task);
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
216
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
217 return;
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
218 }
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
219
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
220 protocol_conversation = PURPLE_PROTOCOL_CONVERSATION(protocol);
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
221 implements = purple_protocol_conversation_implements_create_conversation(protocol_conversation);
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
222 if(!implements) {
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
223 g_task_return_new_error(task, PURPLE_CONTACT_DOMAIN, 0,
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
224 "protocol %s does not implement creating "
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
225 "conversations.",
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
226 purple_account_get_protocol_id(contact->account));
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
227 g_clear_object(&task);
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
228
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
229 return;
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
230 }
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
231
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
232 details = purple_protocol_conversation_get_create_conversation_details(protocol_conversation,
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
233 contact->account);
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
234
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
235 participants = g_list_store_new(PURPLE_TYPE_CONTACT);
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
236 g_list_store_append(participants, contact);
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
237 purple_create_conversation_details_set_participants(details,
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
238 G_LIST_MODEL(participants));
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
239 g_clear_object(&participants);
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
240
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
241 purple_protocol_conversation_create_conversation_async(protocol_conversation,
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
242 contact->account,
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
243 details,
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
244 cancellable,
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
245 purple_contact_create_dm_cb,
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
246 task);
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
247 }
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
248
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
249 PurpleConversation *
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
250 purple_contact_create_dm_finish(PurpleContact *contact, GAsyncResult *result,
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
251 GError **error)
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
252 {
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
253 GTask *task = NULL;
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
254
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
255 g_return_val_if_fail(PURPLE_IS_CONTACT(contact), NULL);
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
256 g_return_val_if_fail(G_IS_TASK(result), NULL);
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
257
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
258 task = G_TASK(result);
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
259
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
260 g_return_val_if_fail(g_task_get_source_tag(task) == purple_contact_create_dm_async,
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
261 NULL);
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
262
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
263 return g_task_propagate_pointer(task, error);
b37a9a8ad04a Add PurpleContact.create_dm_async and create_dm_finish
Gary Kramlich <grim@reaperworld.com>
parents: 42653
diff changeset
264 }

mercurial