From adddf18f7bb713b7ec0aacdcff85fe733c68f315 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hermann=20H=C3=B6hne?= Date: Fri, 8 Feb 2019 20:56:11 +0100 Subject: [PATCH] Handle group conversations just like ordinary one-to-one conversations. Adjust README. Bump version because of bugfix. --- README.md | 8 ++++---- VERSION | 2 +- glib_compat.h | 43 ------------------------------------------- libsignald.c | 21 ++++++++++++++++----- 4 files changed, 21 insertions(+), 53 deletions(-) delete mode 100644 glib_compat.h diff --git a/README.md b/README.md index d0e7f2b..d97fdf7 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ # purple-signald -A libpurple/Pidgin plugin for [signald](https://git.callpipe.com/finn/signald) +A libpurple/Pidgin plugin for [signald](https://git.callpipe.com/finn/signald) (signal, formerly textsecure). signald is written by Finn Herzfeld. -I never wrote code for use in Pidgin before. EionRobb's purple-discord sources were of great help. +I never wrote code for use in Pidgin before. EionRobb's [purple-discord](https://github.com/EionRobb/purple-discord) sources were of great help. Tested on Ubuntu 18.04. @@ -16,5 +16,5 @@ Tested on Ubuntu 18.04. ### Missing Features * Integrating with the buddy list -* Group chats -* anything beyond messaging single recipients, really +* Proper group chats (right now you can send and receive group messages, but you cannot tell which one of the group members is answering) +* Anything beyond simple messaging, really diff --git a/VERSION b/VERSION index 6c6aa7c..6da28dd 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.1.0 \ No newline at end of file +0.1.1 \ No newline at end of file diff --git a/glib_compat.h b/glib_compat.h deleted file mode 100644 index 7adcc2f..0000000 --- a/glib_compat.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * signald plugin for libpurple - * Copyright (C) 2016-2017 Eion Robb - * Copyright (C) 2017 Alyssa Rosenzweig - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include - -#if !GLIB_CHECK_VERSION(2, 32, 0) -#define g_hash_table_contains(hash_table, key) g_hash_table_lookup_extended(hash_table, key, NULL, NULL) -#endif /* 2.32.0 */ - -/* -static gboolean -g_str_insensitive_equal(gconstpointer v1, gconstpointer v2) -{ - return (g_ascii_strcasecmp(v1, v2) == 0); -} -static guint -g_str_insensitive_hash(gconstpointer v) -{ - guint hash; - gchar *lower_str = g_ascii_strdown(v, -1); - - hash = g_str_hash(lower_str); - g_free(lower_str); - - return hash; -} -*/ diff --git a/libsignald.c b/libsignald.c index 45c0d81..6bbeb39 100644 --- a/libsignald.c +++ b/libsignald.c @@ -39,7 +39,7 @@ #define SIGNALD_PLUGIN_ID "prpl-hehoe-signald" #ifndef SIGNALD_PLUGIN_VERSION -#define SIGNALD_PLUGIN_VERSION "0.1" +#define SIGNALD_PLUGIN_VERSION "0.1.1" #endif #define SIGNALD_PLUGIN_WEBSITE "https://github.com/hoehermann/libpurple-signald" @@ -82,11 +82,13 @@ signald_assume_all_buddies_online(SignaldAccount *sa) void signald_process_message(SignaldAccount *sa, - const gchar *username, const gchar *content, const gchar *timestamp_str) + const gchar *username, const gchar *content, const gchar *timestamp_str, + const gchar *groupid_str, const gchar *groupname) { PurpleMessageFlags flags = PURPLE_MESSAGE_RECV; time_t timestamp = purple_str_to_time(timestamp_str, FALSE, NULL, NULL, NULL); - purple_serv_got_im(sa->pc, username, content, flags, timestamp); + const gchar * sender = groupid_str && *groupid_str ? groupid_str : username; + purple_serv_got_im(sa->pc, sender, content, flags, timestamp); } void @@ -108,6 +110,7 @@ signald_handle_input(SignaldAccount *sa, const char * json) if (purple_strequal(type, "version")) { purple_debug_error("signald", "signald version ignored.\n"); } else if (purple_strequal(type, "success")) { + // TODO: mark message as delayed (maybe do not echo) until success is reported purple_debug_error("signald", "Success noticed.\n"); } else if (purple_strequal(type, "subscribed")) { purple_debug_error("signald", "Subscribed!\n"); @@ -120,13 +123,21 @@ signald_handle_input(SignaldAccount *sa, const char * json) gboolean isreceipt = json_object_get_boolean_member(obj, "isReceipt"); if (isreceipt) { // TODO: this could be displayed in the conversation window + // purple_conv_chat_write(to, username, msg, PURPLE_MESSAGE_SYSTEM | PURPLE_MESSAGE_NO_LOG, time(NULL)); purple_debug_error("signald", "Received reciept.\n"); } else { const gchar *username = json_object_get_string_member(obj, "source"); const gchar *timestamp_str = json_object_get_string_member(obj, "timestampISO"); // TODO: create time_t from integer timestamp as timestampISO probably means "time of delivery" instead of the time the message was sent obj = json_object_get_object_member(obj, "dataMessage"); const gchar *message = json_object_get_string_member(obj, "message"); - signald_process_message(sa, username, message, timestamp_str); + obj = json_object_get_object_member(obj, "groupInfo"); + const gchar *groupid_str = NULL; + const gchar *groupname = NULL; + if (obj) { + groupid_str = json_object_get_string_member(obj, "groupId"); + groupname = json_object_get_string_member(obj, "name"); + } + signald_process_message(sa, username, message, timestamp_str, groupid_str, groupname); } } else { purple_debug_error("signald", "Ignored message of unknown type.\n"); @@ -297,7 +308,7 @@ signald_send_im(PurpleConnection *pc, JsonObject *data = json_object_new(); json_object_set_string_member(data, "type", "send"); json_object_set_string_member(data, "username", purple_account_get_username(sa->account)); - json_object_set_string_member(data, "recipientNumber", who); + json_object_set_string_member(data, who[0]=='+' ? "recipientNumber" : "recipientGroupId", who); json_object_set_string_member(data, "messageBody", message); char *json = json_object_to_string(data); char *jsonn = append_newline(json);