[Pkg-privacy-commits] [irssi-plugin-otr] 81/267: Finally support for /me.

Ximin Luo infinity0 at moszumanska.debian.org
Sat Aug 22 12:26:20 UTC 2015


This is an automated email from the git hooks/post-receive script.

infinity0 pushed a commit to branch debian
in repository irssi-plugin-otr.

commit 4fcd27c36485b44a30ccc9e258ba3b8c00b5cab7
Author: Uli Meis <a.sporto+bee at gmail.com>
Date:   Wed Sep 12 22:26:50 2012 +0200

    Finally support for /me.
    
    Due to the way libotr works these are handled inline, i.e. they are not
    send out as IRC CTCP action messages but as regular private messages.
    However, the prefix '/me ' is prepended to them and when irssi-otr
    receives a message with that prefix it will inject it as a /me locally
    so that this is transparent to the user. Interoperability with other
    clients is of course an issue here but for now this seems to be the best
    solution.
---
 irssi/irssi_otr.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 irssi/irssi_otr.h |  2 ++
 otr.h             |  8 +++++++
 3 files changed, 73 insertions(+), 1 deletion(-)

diff --git a/irssi/irssi_otr.c b/irssi/irssi_otr.c
index 1f0df0e..4bee5a8 100644
--- a/irssi/irssi_otr.c
+++ b/irssi/irssi_otr.c
@@ -77,12 +77,72 @@ static void sig_message_private(SERVER_REC *server, const char *msg,
 	newmsg = otr_receive(server,msg,nick);
 
 	if (newmsg&&(newmsg!=msg)) {
-		signal_continue(4,server,newmsg,nick,address);
+		if (g_str_has_prefix(newmsg,IRCACTIONMARK)) {
+			signal_stop();
+			signal_emit("message irc action",
+				    5,
+				    server,
+				    newmsg+IRCACTIONMARKLEN,
+				    nick,
+				    address,
+				    nick);
+
+		} else {
+			signal_continue(4,server,newmsg,nick,address);
+		}
 		otrl_message_free(newmsg);
 	} else if (newmsg==NULL)
 		signal_stop();
 }
 
+static void cmd_me(const char *data, IRC_SERVER_REC *server, WI_ITEM_REC *item)
+{
+	QUERY_REC *query = QUERY(item);
+        const char *target;
+	char *otrmsg,*msg;
+	int unchanged;
+
+	if (!query || !query->server)
+		return;
+
+        CMD_IRC_SERVER(server);
+        if (!IS_IRC_QUERY(item))
+                return;
+
+        if (server == NULL || !server->connected)
+                cmd_return_error(CMDERR_NOT_CONNECTED);
+
+        target = window_item_get_target(item);
+
+#ifdef HAVE_GREGEX_H
+	if (g_regex_match(regex_nickignore,target,0,NULL))
+		return;
+#endif
+
+	/* since we can't track the message anymore once it's encrypted,
+	 * mark it as a /me inline.
+	 */
+	msg = g_strconcat(IRCACTIONMARK,data,NULL);
+	otrmsg = otr_send(query->server,msg,target);
+
+	unchanged = otrmsg==msg;
+	g_free(msg);
+
+	if (unchanged)
+		return;
+
+	signal_stop();
+
+	if (otrmsg) {
+		irc_send_message(SERVER(server), target, otrmsg);
+		otrl_message_free(otrmsg);
+	}
+
+        signal_emit("message irc own_action", 3, server, data,
+                    item->visible_name);
+}
+
+
 /*
  * Finish an OTR conversation when its query is closed.
  */
@@ -193,6 +253,7 @@ void otr_init(void)
 
 	signal_add_first("server sendmsg", (SIGNAL_FUNC) sig_server_sendmsg);
 	signal_add_first("message private", (SIGNAL_FUNC) sig_message_private);
+	command_bind_irc_first("me", NULL, (SIGNAL_FUNC) cmd_me);
 	signal_add("query destroyed", (SIGNAL_FUNC) sig_query_destroyed);
 
 	command_bind("otr", NULL, (SIGNAL_FUNC) cmd_otr);
@@ -225,6 +286,7 @@ void otr_deinit(void)
 
 	signal_remove("server sendmsg", (SIGNAL_FUNC) sig_server_sendmsg);
 	signal_remove("message private", (SIGNAL_FUNC) sig_message_private);
+	command_unbind("me", (SIGNAL_FUNC) cmd_me);
 	signal_remove("query destroyed", (SIGNAL_FUNC) sig_query_destroyed);
 
 	command_unbind("otr", (SIGNAL_FUNC) cmd_otr);
diff --git a/irssi/irssi_otr.h b/irssi/irssi_otr.h
index 6b0eb5b..024d6ff 100644
--- a/irssi/irssi_otr.h
+++ b/irssi/irssi_otr.h
@@ -31,6 +31,8 @@
 #include <core/settings.h>
 #include <irc/core/irc.h>
 #include <irc/core/irc-queries.h>
+#include <irc/core/irc-servers.h>
+#include <irc/core/irc-commands.h>
 
 #include <fe-text/statusbar-item.h>
 
diff --git a/otr.h b/otr.h
index d7375ca..58353b9 100644
--- a/otr.h
+++ b/otr.h
@@ -112,6 +112,14 @@ void otr_log(IRC_CTX *server, const char *to,
 #define IO_DEFAULT_POLICY_KNOWN "* always"
 #define IO_DEFAULT_IGNORE "xmlconsole[0-9]*"
 
+/* used as a prefix for /me messages.
+ * This makes it readable and sensible for
+ * people not on IRC (i.e. in case of a gateway
+ * like bitlbee)
+ */ 
+#define IRCACTIONMARK "/me "
+#define IRCACTIONMARKLEN 4
+
 /* one for each OTR context (=communication pair) */
 struct co_info {
 	char *msgqueue;			/* holds partially reconstructed base64

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/irssi-plugin-otr.git



More information about the Pkg-privacy-commits mailing list