aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWill Thompson <will.thompson@collabora.co.uk>2009-07-02 06:43:27 +0800
committerWill Thompson <will.thompson@collabora.co.uk>2009-07-02 06:43:27 +0800
commit5af5dedd2bd5a57f700d3abf7a326d0462494caa (patch)
treef330c95ffc94a0688b3882da11d1f434ad2725e0
parent0e9e2124eee55872b7e6209cbcfd626c9e366e40 (diff)
parentfdbb5ae44e2b82a36f7103b63e5c8a2041faea6c (diff)
downloadgsoc2013-empathy-5af5dedd2bd5a57f700d3abf7a326d0462494caa.tar
gsoc2013-empathy-5af5dedd2bd5a57f700d3abf7a326d0462494caa.tar.gz
gsoc2013-empathy-5af5dedd2bd5a57f700d3abf7a326d0462494caa.tar.bz2
gsoc2013-empathy-5af5dedd2bd5a57f700d3abf7a326d0462494caa.tar.lz
gsoc2013-empathy-5af5dedd2bd5a57f700d3abf7a326d0462494caa.tar.xz
gsoc2013-empathy-5af5dedd2bd5a57f700d3abf7a326d0462494caa.tar.zst
gsoc2013-empathy-5af5dedd2bd5a57f700d3abf7a326d0462494caa.zip
Merge branch 'part-reasons'
-rw-r--r--libempathy-gtk/empathy-chat.c73
-rw-r--r--libempathy/empathy-tp-chat.c65
2 files changed, 114 insertions, 24 deletions
diff --git a/libempathy-gtk/empathy-chat.c b/libempathy-gtk/empathy-chat.c
index 1f5225348..1729e5305 100644
--- a/libempathy-gtk/empathy-chat.c
+++ b/libempathy-gtk/empathy-chat.c
@@ -1161,6 +1161,56 @@ chat_contacts_completion_func (const gchar *s1,
return ret;
}
+static gchar *
+build_part_message (guint reason,
+ const gchar *name,
+ EmpathyContact *actor,
+ const gchar *message)
+{
+ GString *s = g_string_new ("");
+ const gchar *actor_name = NULL;
+
+ if (actor != NULL) {
+ actor_name = empathy_contact_get_name (actor);
+ }
+
+ /* Having an actor only really makes sense for a few actions... */
+ switch (reason) {
+ case TP_CHANNEL_GROUP_CHANGE_REASON_OFFLINE:
+ g_string_append_printf (s, _("%s has disconnected"), name);
+ break;
+ case TP_CHANNEL_GROUP_CHANGE_REASON_KICKED:
+ if (actor_name != NULL) {
+ g_string_append_printf (s, _("%s was kicked by %s"),
+ name, actor_name);
+ } else {
+ g_string_append_printf (s, _("%s was kicked"), name);
+ }
+ break;
+ case TP_CHANNEL_GROUP_CHANGE_REASON_BANNED:
+ if (actor_name != NULL) {
+ g_string_append_printf (s, _("%s was banned by %s"),
+ name, actor_name);
+ } else {
+ g_string_append_printf (s, _("%s was banned"), name);
+ }
+ break;
+ default:
+ g_string_append_printf (s, _("%s has left the room"), name);
+ }
+
+ if (!EMP_STR_EMPTY (message)) {
+ /* Note to translators: this string is appended to
+ * notifications like "foo has left the room", with the message
+ * given by the user living the room. If this poses a problem,
+ * please let us know. :-)
+ */
+ g_string_append_printf (s, _(" (%s)"), message);
+ }
+
+ return g_string_free (s, FALSE);
+}
+
static void
chat_members_changed_cb (EmpathyTpChat *tp_chat,
EmpathyContact *contact,
@@ -1171,20 +1221,21 @@ chat_members_changed_cb (EmpathyTpChat *tp_chat,
EmpathyChat *chat)
{
EmpathyChatPriv *priv = GET_PRIV (chat);
+ const gchar *name = empathy_contact_get_name (contact);
+ gchar *str;
- if (priv->block_events_timeout_id == 0) {
- gchar *str;
+ if (priv->block_events_timeout_id != 0)
+ return;
- if (is_member) {
- str = g_strdup_printf (_("%s has joined the room"),
- empathy_contact_get_name (contact));
- } else {
- str = g_strdup_printf (_("%s has left the room"),
- empathy_contact_get_name (contact));
- }
- empathy_chat_view_append_event (chat->view, str);
- g_free (str);
+ if (is_member) {
+ str = g_strdup_printf (_("%s has joined the room"),
+ name);
+ } else {
+ str = build_part_message (reason, name, actor, message);
}
+
+ empathy_chat_view_append_event (chat->view, str);
+ g_free (str);
}
static gboolean
diff --git a/libempathy/empathy-tp-chat.c b/libempathy/empathy-tp-chat.c
index ac61392e0..a3282818f 100644
--- a/libempathy/empathy-tp-chat.c
+++ b/libempathy/empathy-tp-chat.c
@@ -875,6 +875,34 @@ tp_chat_got_added_contacts_cb (EmpathyTpContactFactory *factory,
tp_chat_check_if_ready (EMPATHY_TP_CHAT (chat));
}
+static EmpathyContact *
+chat_lookup_contact (EmpathyTpChat *chat,
+ TpHandle handle,
+ gboolean remove)
+{
+ EmpathyTpChatPriv *priv = GET_PRIV (chat);
+ GList *l;
+
+ for (l = priv->members; l; l = l->next) {
+ EmpathyContact *c = l->data;
+
+ if (empathy_contact_get_handle (c) != handle) {
+ continue;
+ }
+
+ if (remove) {
+ /* Caller takes the reference. */
+ priv->members = g_list_delete_link (priv->members, l);
+ } else {
+ g_object_ref (c);
+ }
+
+ return c;
+ }
+
+ return NULL;
+}
+
static void
tp_chat_group_members_changed_cb (TpChannel *self,
gchar *message,
@@ -888,23 +916,30 @@ tp_chat_group_members_changed_cb (TpChannel *self,
{
EmpathyTpChatPriv *priv = GET_PRIV (chat);
EmpathyContact *contact;
- TpHandle handle;
+ EmpathyContact *actor_contact = NULL;
guint i;
- GList *l;
+
+ if (actor != 0) {
+ actor_contact = chat_lookup_contact (chat, actor, FALSE);
+ if (actor_contact == NULL) {
+ /* FIXME: handle this a tad more gracefully: perhaps
+ * the actor was a server op. We could use the
+ * contact-ids detail of MembersChangedDetailed.
+ */
+ DEBUG ("actor %u not a channel member", actor);
+ }
+ }
/* Remove contacts that are not members anymore */
for (i = 0; i < removed->len; i++) {
- for (l = priv->members; l; l = l->next) {
- contact = l->data;
- handle = empathy_contact_get_handle (contact);
- if (handle == g_array_index (removed, TpHandle, i)) {
- priv->members = g_list_delete_link (priv->members, l);
- g_signal_emit_by_name (chat, "members-changed",
- contact, NULL, reason,
- message, FALSE);
- g_object_unref (contact);
- break;
- }
+ contact = chat_lookup_contact (chat,
+ g_array_index (removed, TpHandle, i), TRUE);
+
+ if (contact != NULL) {
+ g_signal_emit_by_name (chat, "members-changed", contact,
+ actor_contact, reason, message,
+ FALSE);
+ g_object_unref (contact);
}
}
@@ -917,6 +952,10 @@ tp_chat_group_members_changed_cb (TpChannel *self,
}
tp_chat_update_remote_contact (chat);
+
+ if (actor_contact != NULL) {
+ g_object_unref (actor_contact);
+ }
}
static void