From 57c43aa4237c27d5acfca7ec5a8c07fb407f4a50 Mon Sep 17 00:00:00 2001 From: bqv Date: Mon, 14 Mar 2022 13:51:37 +0000 Subject: [PATCH] better version and editing --- README.org | 14 +++++++++++--- channel.cpp | 6 +++++- command.cpp | 29 +++++++++++++++++++++++++++++ connection.cpp | 22 ++++++++++++++++++++++ makefile | 8 ++++++-- plugin.hh | 8 ++++++++ 6 files changed, 81 insertions(+), 6 deletions(-) diff --git a/README.org b/README.org index 2635814..60cc3c1 100644 --- a/README.org +++ b/README.org @@ -52,6 +52,7 @@ - lmdb (dynamic, dependency) - libomemo-c (libsignal-protocol-c) (dynamic, dependency) - rnp (dynamic, dependency) + - gpgme (dynamic, dependency) - weechat (>= v3.0) .. or just use the guix spec in .envrc @@ -96,7 +97,7 @@ * [-] OOB messages * [X] Single media on a line * [ ] Multiple media inline (protocol?) - * [ ] Encrypted (pgp/omemo) + * [ ] [#D] Encrypted (pgp/omemo) * [X] Buffer autoswitch on enter/open * [X] Handle open/enter jids with a resource without breaking * [X] Allow /close without crashing @@ -113,7 +114,7 @@ * [-] [#B] Edits * [X] [#B] Displaying * [X] [#B] Tagging - * [ ] [#B] Making + * [ ] [#B] Making (/edit) * [X] [#C] Diff highlighting * [ ] [#B] Handle errors gracefully * [X] [#B] Presence/nicklist @@ -145,9 +146,14 @@ * [X] Message Delivery (XEP-0184) * [X] Message Carbons * [ ] Service Disco + * [ ] /disco [domain] + * [ ] /whois [user|muc] + * [ ] User Avatars + * [ ] MUC Icons * [X] MAM Fetching * [-] Bookmarks / Roster * [X] Autojoin bookmarks + * [ ] Except biboumi rooms * [ ] Add bookmarks * [ ] Delete bookmarks * [ ] Roster @@ -158,8 +164,10 @@ * [X] Decryption * [X] Encryption * [X] Custom set/clear key (/pgp) + * [ ] Save pgp key set per jid/muc + * [ ] GPGME * [ ] Room Explorer (https://search.jabber.network/docs/api) -** TODO [#C] Implement completion engine (milestone v0.3) +** TODO [#C] Adhere to CCS (milestone v0.3) ** TODO [#D] Close all issues (milestone v1.0) * Contributing diff --git a/channel.cpp b/channel.cpp index 985a125..6ee2b7d 100644 --- a/channel.cpp +++ b/channel.cpp @@ -201,8 +201,12 @@ struct t_gui_buffer *channel__create_buffer(struct t_account *account, account_option_set(account, ACCOUNT_OPTION_NICKNAME, xmpp_jid_node(account->context, account_jid(account))); + // Set notify level for buffer: "0" = never add to hotlist + // "1" = add for highlights only + // "2" = add for highlights and messages + // "3" = add for all messages. weechat_buffer_set(ptr_buffer, "notify", - (type == CHANNEL_TYPE_PM) ? "3" : "1"); + (type == CHANNEL_TYPE_PM) ? "3" : "2"); weechat_buffer_set(ptr_buffer, "localvar_set_type", (type == CHANNEL_TYPE_PM) ? "private" : "channel"); weechat_buffer_set(ptr_buffer, "localvar_set_nick", diff --git a/command.cpp b/command.cpp index 55d4824..d328185 100644 --- a/command.cpp +++ b/command.cpp @@ -906,6 +906,26 @@ int command__xml(const void *pointer, void *data, return WEECHAT_RC_OK; } +int command__xmpp(const void *pointer, void *data, + struct t_gui_buffer *buffer, int argc, + char **argv, char **argv_eol) +{ + struct t_account *ptr_account = NULL; + struct t_channel *ptr_channel = NULL; + xmpp_stanza_t *stanza; + + (void) pointer; + (void) data; + (void) argv; + + weechat_printf(nullptr, + _("%s%s %s [%s]"), + weechat_prefix("info"), WEECHAT_XMPP_PLUGIN_NAME, + WEECHAT_XMPP_PLUGIN_VERSION, XMPP_PLUGIN_COMMIT); + + return WEECHAT_RC_OK; +} + void command__init() { struct t_hook *hook; @@ -1015,4 +1035,13 @@ void command__init() NULL, &command__xml, NULL, NULL); if (!hook) weechat_printf(NULL, "Failed to setup command /xml"); + + hook = weechat_hook_command( + "xmpp", + N_("get xmpp plugin version"), + N_(""), + N_(""), + NULL, &command__xmpp, NULL, NULL); + if (!hook) + weechat_printf(NULL, "Failed to setup command /xmpp"); } diff --git a/connection.cpp b/connection.cpp index 2da97c9..a35ed2b 100644 --- a/connection.cpp +++ b/connection.cpp @@ -156,16 +156,21 @@ int connection__presence_handler(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void case 210: // Nick Modified: [presence | Entering a room]: Inform user that the service has assigned or modified the occupant's roomnick break; case 301: // : [presence | Removal from room]: Inform user that he or she has been banned from the room + weechat_printf(channel->buffer, "[!]\t%sBanned from Room", weechat_color("gray")); break; case 303: // : [presence | Exiting a room]: Inform all occupants of new room nickname break; case 307: // : [presence | Removal from room]: Inform user that he or she has been kicked from the room + weechat_printf(channel->buffer, "[!]\t%sKicked from room", weechat_color("gray")); break; case 321: // : [presence | Removal from room]: Inform user that he or she is being removed from the room because of an affiliation change + weechat_printf(channel->buffer, "[!]\t%sRoom Affiliation changed, kicked", weechat_color("gray")); break; case 322: // : [presence | Removal from room]: Inform user that he or she is being removed from the room because the room has been changed to members-only and the user is not a member + weechat_printf(channel->buffer, "[!]\t%sRoom now members-only, kicked", weechat_color("gray")); break; case 332: // : [presence | Removal from room]: Inform user that he or she is being removed from the room because of a system shutdown + weechat_printf(channel->buffer, "[!]\t%sRoom Shutdown", weechat_color("gray")); break; default: break; @@ -618,6 +623,8 @@ int connection__message_handler(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void * { char **visual = weechat_string_dyn_alloc(256); char ch[2] = {0}; + int retention = 0; + int modification = 0; for (size_t i = 0; i < result.sessz; i++) switch (result.ses[i].type) @@ -626,11 +633,13 @@ int connection__message_handler(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void * weechat_string_dyn_concat(visual, weechat_color("green"), -1); *ch = *(const char *)result.ses[i].e; weechat_string_dyn_concat(visual, ch, -1); + modification++; break; case DIFF_DELETE: weechat_string_dyn_concat(visual, weechat_color("red"), -1); *ch = *(const char *)result.ses[i].e; weechat_string_dyn_concat(visual, ch, -1); + modification++; break; case DIFF_COMMON: default: @@ -638,11 +647,24 @@ int connection__message_handler(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void * *ch = *(const char *)result.ses[i].e; weechat_string_dyn_concat(visual, ch, -1); + retention++; break; } free(result.ses); free(result.lcs); + if ((modification > 20) && (modification > retention)) { + weechat_string_dyn_free(visual, 1); + visual = weechat_string_dyn_alloc(256); + weechat_string_dyn_concat(visual, weechat_color("red"), -1); + if (strlen(orig) >= 16) { + weechat_string_dyn_concat(visual, orig, 16); + weechat_string_dyn_concat(visual, "...", -1); + } else + weechat_string_dyn_concat(visual, orig, -1); + weechat_string_dyn_concat(visual, weechat_color("green"), -1); + weechat_string_dyn_concat(visual, text, -1); + } difftext = strdup(*visual); weechat_string_dyn_free(visual, 1); } diff --git a/makefile b/makefile index 0597b80..03b44f0 100644 --- a/makefile +++ b/makefile @@ -8,6 +8,7 @@ FIND=find INCLUDES=-Ilibstrophe -Ideps -Ideps/fmt/include \ $(shell xml2-config --cflags) \ + $(shell pkg-config --cflags gpgme) \ $(shell pkg-config --cflags librnp) \ $(shell pkg-config --cflags libsignal-protocol-c) CFLAGS+=$(DBGCFLAGS) \ @@ -34,6 +35,7 @@ LDFLAGS+=$(DBGLDFLAGS) \ LDLIBS=-lstrophe \ -lpthread \ $(shell xml2-config --libs) \ + $(shell pkg-config --libs gpgme) \ $(shell pkg-config --libs librnp) \ $(shell pkg-config --libs libsignal-protocol-c) \ -lgcrypt \ @@ -94,10 +96,12 @@ xmpp.so: $(OBJS) $(DEPS) $(HDRS) $(CXX) $(LDFLAGS) -o $@ $(OBJS) $(DEPS) $(LDLIBS) .%.o: %.c - $(CC) $(CFLAGS) -c $< -o $@ + $(eval GIT_REF=$(shell git describe --abbrev=6 --always --dirty 2>/dev/null || true)) + $(CC) -DGIT_COMMIT=$(GIT_REF) $(CFLAGS) -c $< -o $@ .%.o: %.cpp - $(CXX) $(CPPFLAGS) -c $< -o $@ + $(eval GIT_REF=$(shell git describe --abbrev=6 --always --dirty 2>/dev/null || true)) + $(CXX) -DGIT_COMMIT=$(GIT_REF) $(CPPFLAGS) -c $< -o $@ .%.cov.o: %.cpp @$(CXX) --coverage $(CPPFLAGS) -O0 -c $< -o $@ diff --git a/plugin.hh b/plugin.hh index f60f7b6..86e5535 100644 --- a/plugin.hh +++ b/plugin.hh @@ -4,9 +4,17 @@ #pragma once +#define STR(X) #X +#define XSTR(X) STR(X) #define weechat_plugin weechat_xmpp_plugin #define WEECHAT_XMPP_PLUGIN_NAME "xmpp" +#ifdef GIT_COMMIT +#define XMPP_PLUGIN_COMMIT XSTR(GIT_COMMIT) +#define WEECHAT_XMPP_PLUGIN_VERSION "0.2.0@" XMPP_PLUGIN_COMMIT +#else//GIT_COMMIT +#define XMPP_PLUGIN_COMMIT "unknown" #define WEECHAT_XMPP_PLUGIN_VERSION "0.2.0" +#endif//GIT_COMMIT #define TIMER_INTERVAL_SEC 0.01 extern struct t_weechat_plugin *weechat_xmpp_plugin;