From d67245f5ffcd6c7e8e32a12b88ec24d474bf6e82 Mon Sep 17 00:00:00 2001 From: Stefan Becker Date: Sat, 17 Aug 2013 19:21:40 +0300 Subject: [PATCH] ucs: add support to remove buddy from list The RemoveImContactFromGroup automatically removes a buddy from the contact list when a buddy is removed from the last group. There is also a RemoveContactFromImList operation, but it doesn't seem to work at all. I have no idea what it is for... --- src/core/sipe-buddy.c | 27 +++++++++++++++++---------- src/core/sipe-ucs.c | 34 +++++++++++++++++++++------------- src/core/sipe-ucs.h | 2 +- 3 files changed, 39 insertions(+), 24 deletions(-) diff --git a/src/core/sipe-buddy.c b/src/core/sipe-buddy.c index 9c4c10c1..75a890a0 100644 --- a/src/core/sipe-buddy.c +++ b/src/core/sipe-buddy.c @@ -447,19 +447,26 @@ void sipe_core_buddy_remove(struct sipe_core_public *sipe_public, } if (g_slist_length(b->groups) < 1) { - gchar *request = g_strdup_printf("%s", - b->name); - sip_soap_request(sipe_private, - "deleteContact", - request); - g_free(request); + + if (sipe_ucs_is_migrated(sipe_private)) { + sipe_ucs_group_remove_buddy(sipe_private, + g, + b); + } else { + gchar *request = g_strdup_printf("%s", + b->name); + sip_soap_request(sipe_private, + "deleteContact", + request); + g_free(request); + } + sipe_buddy_remove(sipe_private, b); } else { if (sipe_ucs_is_migrated(sipe_private)) { - if (g) - sipe_ucs_group_remove_buddy(sipe_private, - g, - b); + sipe_ucs_group_remove_buddy(sipe_private, + g, + b); } else /* updates groups on server */ sipe_group_update_buddy(sipe_private, b); diff --git a/src/core/sipe-ucs.c b/src/core/sipe-ucs.c index 4b80fe2d..6019d0e8 100644 --- a/src/core/sipe-ucs.c +++ b/src/core/sipe-ucs.c @@ -258,20 +258,28 @@ void sipe_ucs_group_remove_buddy(struct sipe_core_private *sipe_private, struct sipe_group *group, struct sipe_buddy *buddy) { - gchar *body = g_strdup_printf("" - " " - " " - "", - buddy->exchange_key, - buddy->change_key, - group->exchange_key, - group->change_key); + if (group) { + /* + * If a contact is removed from last group, it will also be + * removed from contact list completely. The documentation has + * a RemoveContactFromImList operation, but that doesn't seem + * to work at all, i.e. it is always rejected by the server. + */ + gchar *body = g_strdup_printf("" + " " + " " + "", + buddy->exchange_key, + buddy->change_key, + group->exchange_key, + group->change_key); - sipe_ucs_http_request(sipe_private, - body, - sipe_ucs_ignore_response, - NULL); - g_free(body); + sipe_ucs_http_request(sipe_private, + body, + sipe_ucs_ignore_response, + NULL); + g_free(body); + } } static struct sipe_group *ucs_create_group(struct sipe_core_private *sipe_private, diff --git a/src/core/sipe-ucs.h b/src/core/sipe-ucs.h index e9c29201..49a87a57 100644 --- a/src/core/sipe-ucs.h +++ b/src/core/sipe-ucs.h @@ -50,7 +50,7 @@ gboolean sipe_ucs_is_migrated(struct sipe_core_private *sipe_private); * Remove buddy from group * * @param sipe_private SIPE core private data - * @param group sipe_group structure + * @param group sipe_group structure (may be @c NULL) * @param buddy sipe_buddy structure */ void sipe_ucs_group_remove_buddy(struct sipe_core_private *sipe_private, -- 2.11.4.GIT