summaryrefslogtreecommitdiff
path: root/gdata/gdata-commentable.c
blob: 4718a9ef058f11e3b1a7a423c02a846e56b353ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/*
 * GData Client
 * Copyright (C) Philip Withnall 2008–2010 <philip@tecnocode.co.uk>
 * Copyright (C) Richard Schwarting 2010 <aquarichy@gmail.com>
 *
 * GData Client is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * GData Client is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with GData Client.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * SECTION:gdata-commentable
 * @short_description: GData commentable interface
 * @stability: Stable
 * @include: gdata/gdata-commentable.h
 *
 * #GDataCommentable is an interface which can be implemented by commentable objects: objects which support having comments added to them by users,
 * such as videos and photos.
 *
 * Comments may be queried, added and deleted. Note that they may not be edited.
 *
 * #GDataCommentable objects may not support all operations on comments, on an instance-by-instance basis (i.e. it's an invalid assumption that if,
 * for example, one #GDataYouTubeVideo doesn't support adding comments all other #GDataYouTubeVideos don't support adding comments either).
 * Specific documentation for a particular type of #GDataCommentable may state otherwise, though.
 *
 * <example>
 * 	<title>Querying for Comments</title>
 * 	<programlisting>
 *	GDataService *service;
 *	GDataCommentable *commentable;
 *
 *	/<!-- -->* Create a service *<!-- -->/
 *	service = create_service ();
 *
 *	/<!-- -->* Retrieve the GDataCommentable which is going to be queried. This may be, for example, a GDataYouTubeVideo. *<!-- -->/
 *	commentable = get_commentable ();
 *
 *	/<!-- -->* Start the async. query for the comments. *<!-- -->/
 *	gdata_commentable_query_comments_async (commentable, service, NULL, NULL, NULL, NULL, NULL, (GAsyncReadyCallback) query_comments_cb, NULL);
 *
 *	g_object_unref (service);
 *	g_object_unref (commentable);
 *
 *	static void
 *	query_comments_cb (GDataCommentable *commentable, GAsyncResult *result, gpointer user_data)
 *	{
 *		GDataFeed *comment_feed;
 *		GList *comments, *i;
 *		GError *error = NULL;
 *
 *		comment_feed = gdata_commentable_query_comments_finish (commentable, result, &error);
 *
 *		if (error != NULL) {
 *			/<!-- -->* Error! *<!-- -->/
 *			g_error ("Error querying comments: %s", error->message);
 *			g_error_free (error);
 *			return;
 *		}
 *
 *		/<!-- -->* Examine the comments. *<!-- -->/
 *		comments = gdata_feed_get_entries (comment_feed);
 *		for (i = comments; i != NULL; i = i->next) {
 *			/<!-- -->* Note that this will actually be a subclass of GDataComment,
 *			 * such as GDataYouTubeComment or GDataPicasaWebComment. *<!-- -->/
 *			GDataComment *comment = GDATA_COMMENT (i->data);
 *			GDataAuthor *author;
 *
 *			/<!-- -->* Note that in practice it might not always be safe to assume that a comment always has an author. *<!-- -->/
 *			author = GDATA_AUTHOR (gdata_entry_get_authors (GDATA_ENTRY (comment))->data);
 *
 *			g_message ("Comment by %s (%s): %s",
 *			           gdata_author_get_name (author),
 *			           gdata_author_get_uri (author),
 *			           gdata_entry_get_content (GDATA_ENTRY (comment)));
 *		}
 *
 *		g_object_unref (comment_feed);
 *	}
 * 	</programlisting>
 * </example>
 *
 * Since: 0.10.0
 */

#include <config.h>
#include <glib.h>
#include <glib/gi18n-lib.h>
#include <string.h>

#include "gdata-commentable.h"
#include "gdata-service.h"

G_DEFINE_INTERFACE (GDataCommentable, gdata_commentable, GDATA_TYPE_ENTRY)

static void
gdata_commentable_default_init (GDataCommentableInterface *iface)
{
	iface->comment_type = G_TYPE_INVALID;
	iface->get_authorization_domain = NULL;
	iface->get_query_comments_uri = NULL;
	iface->get_insert_comment_uri = NULL;
	iface->is_comment_deletable = NULL;
}

static GType
get_comment_type (GDataCommentableInterface *iface)
{
	GType comment_type;

	comment_type = iface->comment_type;
	g_assert (g_type_is_a (comment_type, GDATA_TYPE_COMMENT) == TRUE);

	return comment_type;
}

/**
 * gdata_commentable_query_comments:
 * @self: a #GDataCommentable
 * @service: a #GDataService representing the service with which the object's comments will be manipulated
 * @query: (allow-none): a #GDataQuery with query parameters, or %NULL
 * @cancellable: (allow-none): optional #GCancellable object, or %NULL
 * @progress_callback: (allow-none) (scope call) (closure progress_user_data): a #GDataQueryProgressCallback to call when a comment is loaded, or %NULL
 * @progress_user_data: (closure): data to pass to the @progress_callback function
 * @error: a #GError, or %NULL
 *
 * Retrieves a #GDataFeed containing the #GDataComments representing the comments on the #GDataCommentable which match the given @query.
 *
 * If the #GDataCommentable doesn't support commenting, %NULL will be returned and @error will be set to %GDATA_SERVICE_ERROR_FORBIDDEN. This is in
 * contrast to if it does support commenting but hasn't had any comments added yet, in which case an empty #GDataFeed will be returned and no error
 * will be set.
 *
 * Return value: (transfer full) (allow-none): a #GDataFeed of #GDataComments, or %NULL; unref with g_object_unref()
 *
 * Since: 0.10.0
 */
GDataFeed *
gdata_commentable_query_comments (GDataCommentable *self, GDataService *service, GDataQuery *query,
                                  GCancellable *cancellable, GDataQueryProgressCallback progress_callback,
                                  gpointer progress_user_data, GError **error)
{
	GDataCommentableInterface *iface;
	gchar *uri;
	GDataFeed *feed;
	GDataAuthorizationDomain *domain = NULL;

	g_return_val_if_fail (GDATA_IS_COMMENTABLE (self), NULL);
	g_return_val_if_fail (GDATA_IS_SERVICE (service), NULL);
	g_return_val_if_fail (query == NULL || GDATA_IS_QUERY (query), NULL);
	g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
	g_return_val_if_fail (error == NULL || *error == NULL, NULL);

	iface = GDATA_COMMENTABLE_GET_IFACE (self);

	/* Get the comment feed URI. */
	g_assert (iface->get_query_comments_uri != NULL);
	uri = iface->get_query_comments_uri (self);

	/* The URI can be NULL when no comments and thus no feedLink is present in a GDataCommentable */
	if (uri == NULL) {
		/* Translators: This is an error message for if a user attempts to retrieve comments from an entry (such as a video) which doesn't
		 * support comments. */
		g_set_error_literal (error, GDATA_SERVICE_ERROR, GDATA_SERVICE_ERROR_FORBIDDEN, _("This entry does not support comments."));
		return NULL;
	}

	/* Get the authorisation domain. */
	if (iface->get_authorization_domain != NULL) {
		domain = iface->get_authorization_domain (self);
	}

	/* Get the comment feed. */
	feed = gdata_service_query (service, domain, uri, query, get_comment_type (iface), cancellable, progress_callback, progress_user_data, error);
	g_free (uri);

	return feed;
}

static void
query_comments_async_cb (GDataService *service, GAsyncResult *service_result, gpointer user_data)
{
	g_autoptr(GTask) commentable_task = G_TASK (user_data);
	g_autoptr(GDataFeed) feed = NULL;
	g_autoptr(GError) error = NULL;

	feed = gdata_service_query_finish (service, service_result, &error);

	if (error != NULL)
		g_task_return_error (commentable_task, g_steal_pointer (&error));
	else
		g_task_return_pointer (commentable_task, g_steal_pointer (&feed), g_object_unref);
}

/**
 * gdata_commentable_query_comments_async:
 * @self: a #GDataCommentable
 * @service: a #GDataService representing the service with which the object's comments will be manipulated
 * @query: (allow-none): a #GDataQuery with query parameters, or %NULL
 * @cancellable: (allow-none): optional #GCancellable object, or %NULL
 * @progress_callback: (allow-none) (scope notified) (closure progress_user_data): a #GDataQueryProgressCallback to call when a comment is loaded,
 * or %NULL
 * @progress_user_data: (closure): data to pass to the @progress_callback function
 * @destroy_progress_user_data: (allow-none): a function to call when @progress_callback will not be called any more, or %NULL; this function will be
 * called with @progress_user_data as a parameter and can be used to free any memory allocated for it
 * @callback: a #GAsyncReadyCallback to call when the query is finished
 * @user_data: (closure): data to pass to the @callback function
 *
 * Retrieves a #GDataFeed containing the #GDataComments representing the comments on the #GDataCommentable which match the given @query.
 * @self, @service and @query are all reffed when this method is called, so can safely be freed after this method returns.
 *
 * For more details, see gdata_commentable_query_comments(), which is the synchronous version of this method.
 *
 * When the operation is finished, @callback will be called. You can then call gdata_commentable_query_comments_finish() to get the results of the
 * operation.
 *
 * Since: 0.10.0
 */
void
gdata_commentable_query_comments_async (GDataCommentable *self, GDataService *service, GDataQuery *query, GCancellable *cancellable,
                                        GDataQueryProgressCallback progress_callback, gpointer progress_user_data,
                                        GDestroyNotify destroy_progress_user_data, GAsyncReadyCallback callback, gpointer user_data)
{
	GDataCommentableInterface *iface;
	gchar *uri;
	g_autoptr(GTask) task = NULL;
	GDataAuthorizationDomain *domain = NULL;

	g_return_if_fail (GDATA_IS_COMMENTABLE (self));
	g_return_if_fail (GDATA_IS_SERVICE (service));
	g_return_if_fail (query == NULL || GDATA_IS_QUERY (query));
	g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
	g_return_if_fail (callback != NULL);

	iface = GDATA_COMMENTABLE_GET_IFACE (self);

	/* Get the comment feed URI. */
	g_assert (iface->get_query_comments_uri != NULL);
	uri = iface->get_query_comments_uri (self);

	/* Build the async result. */
	task = g_task_new (self, cancellable, callback, user_data);
	g_task_set_source_tag (task, gdata_commentable_query_comments_async);

	/* The URI can be NULL when no comments and thus no feedLink is present in a GDataCommentable */
	if (uri == NULL) {
		g_task_return_new_error (task, GDATA_SERVICE_ERROR, GDATA_SERVICE_ERROR_FORBIDDEN,
		                         /* Translators: This is an error message for if a user attempts to retrieve comments from an entry
		                          * (such as a video) which doesn't support comments. */
		                         _("This entry does not support comments."));
		return;
	}

	/* Get the authorisation domain. */
	if (iface->get_authorization_domain != NULL) {
		domain = iface->get_authorization_domain (self);
	}

	/* Get the comment feed. */
	gdata_service_query_async (service, domain, uri, query, get_comment_type (iface), cancellable, progress_callback, progress_user_data,
	                           destroy_progress_user_data, (GAsyncReadyCallback) query_comments_async_cb, g_object_ref (task));
	g_free (uri);
}

/**
 * gdata_commentable_query_comments_finish:
 * @self: a #GDataCommentable
 * @result: a #GAsyncResult
 * @error: a #GError, or %NULL
 *
 * Finishes an asynchronous comment query operation started with gdata_commentable_query_comments_async().
 *
 * Return value: (transfer full) (allow-none): a #GDataFeed of #GDataComments, or %NULL; unref with g_object_unref()
 *
 * Since: 0.10.0
 */
GDataFeed *
gdata_commentable_query_comments_finish (GDataCommentable *self, GAsyncResult *result, GError **error)
{
	g_return_val_if_fail (GDATA_IS_COMMENTABLE (self), NULL);
	g_return_val_if_fail (G_IS_ASYNC_RESULT (result), NULL);
	g_return_val_if_fail (error == NULL || *error == NULL, NULL);
	g_return_val_if_fail (g_task_is_valid (result, self), NULL);
	g_return_val_if_fail (g_async_result_is_tagged (result, gdata_commentable_query_comments_async), NULL);

	return g_task_propagate_pointer (G_TASK (result), error);
}

/**
 * gdata_commentable_insert_comment:
 * @self: a #GDataCommentable
 * @service: a #GDataService with which the comment will be added
 * @comment_: a new comment to be added to the #GDataCommentable
 * @cancellable: (allow-none): optional #GCancellable object, or %NULL
 * @error: a #GError, or %NULL
 *
 * Adds @comment to the #GDataCommentable.
 *
 * If the #GDataCommentable doesn't support commenting, %NULL will be returned and @error will be set to %GDATA_SERVICE_ERROR_FORBIDDEN.
 *
 * Return value: (transfer full) (allow-none): the added #GDataComment, or %NULL; unref with g_object_unref()
 *
 * Since: 0.10.0
 */
GDataComment *
gdata_commentable_insert_comment (GDataCommentable *self, GDataService *service, GDataComment *comment_, GCancellable *cancellable, GError **error)
{
	GDataCommentableInterface *iface;
	gchar *uri;
	GDataComment *new_comment;
	GDataAuthorizationDomain *domain = NULL;

	g_return_val_if_fail (GDATA_IS_COMMENTABLE (self), NULL);
	g_return_val_if_fail (GDATA_IS_SERVICE (service), NULL);
	g_return_val_if_fail (GDATA_IS_COMMENT (comment_), NULL);
	g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
	g_return_val_if_fail (error == NULL || *error == NULL, NULL);

	iface = GDATA_COMMENTABLE_GET_IFACE (self);

	g_return_val_if_fail (g_type_is_a (G_OBJECT_TYPE (comment_), get_comment_type (iface)) == TRUE, NULL);

	/* Get the upload URI. */
	g_assert (iface->get_insert_comment_uri != NULL);
	uri = iface->get_insert_comment_uri (self, comment_);

	if (uri == NULL) {
		/* Translators: This is an error message for if a user attempts to add a comment to an entry (such as a video) which doesn't support
		 * comments. */
		g_set_error_literal (error, GDATA_SERVICE_ERROR, GDATA_SERVICE_ERROR_FORBIDDEN, _("Comments may not be added to this entry."));
		return NULL;
	}

	/* Get the authorisation domain. */
	if (iface->get_authorization_domain != NULL) {
		domain = iface->get_authorization_domain (self);
	}

	/* Add the comment. */
	new_comment = GDATA_COMMENT (gdata_service_insert_entry (service, domain, uri, GDATA_ENTRY (comment_), cancellable, error));

	g_free (uri);

	return new_comment;
}

static void
insert_comment_async_cb (GDataService *service, GAsyncResult *service_result, gpointer user_data)
{
	g_autoptr(GTask) commentable_task = G_TASK (user_data);
	g_autoptr(GDataEntry) new_comment = NULL;
	g_autoptr(GError) error = NULL;

	new_comment = gdata_service_insert_entry_finish (service, service_result, &error);

	if (error != NULL)
		g_task_return_error (commentable_task, g_steal_pointer (&error));
	else
		g_task_return_pointer (commentable_task, g_steal_pointer (&new_comment), g_object_unref);
}

/**
 * gdata_commentable_insert_comment_async:
 * @self: a #GDataCommentable
 * @service: a #GDataService with which the comment will be added
 * @comment_: a new comment to be added to the #GDataCommentable
 * @cancellable: (allow-none): optional #GCancellable object, or %NULL
 * @callback: a #GAsyncReadyCallback to call when the operation is finished
 * @user_data: (closure): data to pass to the @callback function
 *
 * Adds @comment to the #GDataCommentable. @self, @service and @comment_ are all reffed when this method is called, so can safely be freed after this
 * method returns.
 *
 * For more details, see gdata_commentable_insert_comment(), which is the synchronous version of this method.
 *
 * When the operation is finished, @callback will be called. You can then call gdata_commentable_insert_comment_finish() to get the results of the
 * operation.
 *
 * Since: 0.10.0
 */
void
gdata_commentable_insert_comment_async (GDataCommentable *self, GDataService *service, GDataComment *comment_, GCancellable *cancellable,
                                        GAsyncReadyCallback callback, gpointer user_data)
{
	GDataCommentableInterface *iface;
	g_autofree gchar *uri = NULL;
	g_autoptr(GTask) task = NULL;
	GDataAuthorizationDomain *domain = NULL;

	g_return_if_fail (GDATA_IS_COMMENTABLE (self));
	g_return_if_fail (GDATA_IS_SERVICE (service));
	g_return_if_fail (GDATA_IS_COMMENT (comment_));
	g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));

	iface = GDATA_COMMENTABLE_GET_IFACE (self);

	g_return_if_fail (g_type_is_a (G_OBJECT_TYPE (comment_), get_comment_type (iface)) == TRUE);

	/* Get the upload URI. */
	g_assert (iface->get_insert_comment_uri != NULL);
	uri = iface->get_insert_comment_uri (self, comment_);

	/* Build the async result. */
	task = g_task_new (self, cancellable, callback, user_data);
	g_task_set_source_tag (task, gdata_commentable_insert_comment_async);

	/* The URI can be NULL when no comments and thus no feedLink is present in a GDataCommentable */
	if (uri == NULL) {
		g_task_return_new_error (task, GDATA_SERVICE_ERROR, GDATA_SERVICE_ERROR_FORBIDDEN,
		                         /* Translators: This is an error message for if a user attempts to add a comment to an entry
		                          * (such as a video) which doesn't support comments. */
		                         _("Comments may not be added to this entry."));
		return;
	}

	/* Get the authorisation domain. */
	if (iface->get_authorization_domain != NULL) {
		domain = iface->get_authorization_domain (self);
	}

	/* Add the comment. */
	gdata_service_insert_entry_async (service, domain, uri, GDATA_ENTRY (comment_), cancellable, (GAsyncReadyCallback) insert_comment_async_cb,
	                                  g_object_ref (task));
}

/**
 * gdata_commentable_insert_comment_finish:
 * @self: a #GDataCommentable
 * @result: a #GAsyncResult
 * @error: a #GError, or %NULL
 *
 * Finishes an asynchronous comment insertion operation started with gdata_commentable_insert_comment_async().
 *
 * Return value: (transfer full) (allow-none): the added #GDataComment, or %NULL; unref with g_object_unref()
 *
 * Since: 0.10.0
 */
GDataComment *
gdata_commentable_insert_comment_finish (GDataCommentable *self, GAsyncResult *result, GError **error)
{
	g_return_val_if_fail (GDATA_IS_COMMENTABLE (self), NULL);
	g_return_val_if_fail (G_IS_ASYNC_RESULT (result), NULL);
	g_return_val_if_fail (error == NULL || *error == NULL, NULL);
	g_return_val_if_fail (g_task_is_valid (result, self), NULL);
	g_return_val_if_fail (g_async_result_is_tagged (result, gdata_commentable_insert_comment_async), NULL);

	return g_task_propagate_pointer (G_TASK (result), error);
}

/**
 * gdata_commentable_delete_comment:
 * @self: a #GDataCommentable
 * @service: a #GDataService with which the comment will be deleted
 * @comment_: a comment to be deleted
 * @cancellable: (allow-none): optional #GCancellable object, or %NULL
 * @error: a #GError, or %NULL
 *
 * Deletes @comment from the #GDataCommentable.
 *
 * If the given @comment isn't deletable (either because the service doesn't support deleting comments at all, or because this particular comment
 * is not deletable due to having insufficient permissions), %GDATA_SERVICE_ERROR_FORBIDDEN will be set in @error and %FALSE will be returned.
 *
 * Return value: %TRUE if the comment was successfully deleted, %FALSE otherwise
 *
 * Since: 0.10.0
 */
gboolean
gdata_commentable_delete_comment (GDataCommentable *self, GDataService *service, GDataComment *comment_, GCancellable *cancellable, GError **error)
{
	GDataCommentableInterface *iface;
	GDataAuthorizationDomain *domain = NULL;

	g_return_val_if_fail (GDATA_IS_COMMENTABLE (self), FALSE);
	g_return_val_if_fail (GDATA_IS_SERVICE (service), FALSE);
	g_return_val_if_fail (GDATA_IS_COMMENT (comment_), FALSE);
	g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
	g_return_val_if_fail (error == NULL || *error == NULL, FALSE);

	iface = GDATA_COMMENTABLE_GET_IFACE (self);

	g_return_val_if_fail (g_type_is_a (G_OBJECT_TYPE (comment_), get_comment_type (iface)) == TRUE, FALSE);

	g_assert (iface->is_comment_deletable != NULL);
	if (iface->is_comment_deletable (self, comment_) == FALSE) {
		/* Translators: This is an error message for if a user attempts to delete a comment they're not allowed to delete. */
		g_set_error_literal (error, GDATA_SERVICE_ERROR, GDATA_SERVICE_ERROR_FORBIDDEN, _("This comment may not be deleted."));
		return FALSE;
	}

	/* Get the authorisation domain. */
	if (iface->get_authorization_domain != NULL) {
		domain = iface->get_authorization_domain (self);
	}

	/* Delete the comment. */
	return gdata_service_delete_entry (service, domain, GDATA_ENTRY (comment_), cancellable, error);
}

static void
delete_comment_async_cb (GDataService *service, GAsyncResult *service_result, gpointer user_data)
{
	g_autoptr(GTask) commentable_task = G_TASK (user_data);
	g_autoptr(GError) error = NULL;

	if (!gdata_service_delete_entry_finish (service, service_result, &error))
		g_task_return_error (commentable_task, g_steal_pointer (&error));
	else
		g_task_return_boolean (commentable_task, TRUE);
}

/**
 * gdata_commentable_delete_comment_async:
 * @self: a #GDataCommentable
 * @service: a #GDataService with which the comment will be deleted
 * @comment_: a comment to be deleted
 * @cancellable: (allow-none): optional #GCancellable object, or %NULL
 * @callback: a #GAsyncReadyCallback to call when the operation is finished
 * @user_data: (closure): data to pass to the @callback function
 *
 * Deletes @comment from the #GDataCommentable. @self, @service and @comment_ are all reffed when this method is called, so can safely be freed after
 * this method returns.
 *
 * For more details, see gdata_commentable_delete_comment(), which is the synchronous version of this method.
 *
 * When the operation is finished, @callback will be called. You can then call gdata_commentable_delete_comment_finish() to get the results of the
 * operation.
 *
 * Since: 0.10.0
 */
void
gdata_commentable_delete_comment_async (GDataCommentable *self, GDataService *service, GDataComment *comment_, GCancellable *cancellable,
                                        GAsyncReadyCallback callback, gpointer user_data)
{
	GDataCommentableInterface *iface;
	g_autoptr(GTask) task = NULL;
	GDataAuthorizationDomain *domain = NULL;

	g_return_if_fail (GDATA_IS_COMMENTABLE (self));
	g_return_if_fail (GDATA_IS_SERVICE (service));
	g_return_if_fail (GDATA_IS_COMMENT (comment_));
	g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));

	iface = GDATA_COMMENTABLE_GET_IFACE (self);

	g_return_if_fail (g_type_is_a (G_OBJECT_TYPE (comment_), get_comment_type (iface)) == TRUE);

	/* Build the async result. */
	task = g_task_new (self, cancellable, callback, user_data);
	g_task_set_source_tag (task, gdata_commentable_delete_comment_async);

	g_assert (iface->is_comment_deletable != NULL);
	if (iface->is_comment_deletable (self, comment_) == FALSE) {
		g_task_return_new_error (task, GDATA_SERVICE_ERROR, GDATA_SERVICE_ERROR_FORBIDDEN,
		                         /* Translators: This is an error message for if a user attempts to delete a comment they're not allowed to delete. */
		                         _("This comment may not be deleted."));
		return;
	}

	/* Get the authorisation domain. */
	if (iface->get_authorization_domain != NULL) {
		domain = iface->get_authorization_domain (self);
	}

	/* Delete the comment. */
	gdata_service_delete_entry_async (service, domain, GDATA_ENTRY (comment_), cancellable, (GAsyncReadyCallback) delete_comment_async_cb, g_object_ref (task));
}

/**
 * gdata_commentable_delete_comment_finish:
 * @self: a #GDataCommentable
 * @result: a #GAsyncResult
 * @error: a #GError, or %NULL
 *
 * Finishes an asynchronous comment deletion operation started with gdata_commentable_delete_comment_async().
 *
 * Return value: %TRUE if the comment was successfully deleted, %FALSE otherwise
 *
 * Since: 0.10.0
 */
gboolean
gdata_commentable_delete_comment_finish (GDataCommentable *self, GAsyncResult *result, GError **error)
{
	g_return_val_if_fail (GDATA_IS_COMMENTABLE (self), FALSE);
	g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
	g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
	g_return_val_if_fail (g_task_is_valid (result, self), FALSE);
	g_return_val_if_fail (g_async_result_is_tagged (result, gdata_commentable_delete_comment_async), FALSE);

	return g_task_propagate_boolean (G_TASK (result), error);
}