From cb597736f15fef4be1237846647ad9ad772f9991 Mon Sep 17 00:00:00 2001 From: Tony Olagbaiye Date: Sun, 13 May 2018 11:22:00 +0100 Subject: [PATCH] Officially support tab-completion of standard slack emoji Using the weechat-idiomatic interface. TODO: Deprecate /input complete_* code --- README.org | 16 ++++++++++++---- slack-completion.c | 23 ++++++++++++++++++++++- slack-emoji.c | 11 ++++++++++- 3 files changed, 44 insertions(+), 6 deletions(-) diff --git a/README.org b/README.org index 4fd6d44..333fd24 100644 --- a/README.org +++ b/README.org @@ -17,9 +17,10 @@ [[https://github.com/bqv/weechat-slack/blob/master/LICENSE][file:https://img.shields.io/github/license/bqv/weechat-slack.svg]] [[https://github.com/bqv/weechat-extras/][file:https://img.shields.io/badge/weechat--extras-slack-yellow.svg]] - | Status: | Under Development | - | Location: | [[http://github.com/bqv/weechat-slack]] | - | Version: | 0.1.0 | + | Status: | Under Development | + | Location: | [[http://github.com/bqv/weechat-slack]] | + | Version: | 0.1.0 | + | Disclaimer: | Slack's API is a thing of horror | * Description @@ -77,7 +78,7 @@ - [ ] Implement sending websocket =typing= message ** TODO [#B] Implement completion engine (milestone v0.3) - [ ] Tab completion for slack emoji (see [[http://github.com/bqv/weechat-slack/issues/3][#3]]) - - [ ] Support Slack Emoji + - [X] +Support Slack Emoji+ - [ ] Support Custom Emoji - [ ] Tab completion for display/user names (see [[http://github.com/bqv/weechat-slack/issues/1][#1]]) - [ ] Sort nick-completion by recent (see [[http://github.com/bqv/weechat-slack/issues/4][#4]]) @@ -101,6 +102,13 @@ *Your contributions are always welcome!* Please submit a pull request or create an issue to add a new or missing feature. + +* Appropriating + + As there is no C library for Slack at the time of + writing, this project implements the APIs from + scratch, and as such one could butcher this repository + to create a minimal Slack C library. * License diff --git a/slack-completion.c b/slack-completion.c index b0b3c6f..7be5449 100644 --- a/slack-completion.c +++ b/slack-completion.c @@ -2,7 +2,9 @@ // License, version 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. +#include #include +#include #include "weechat-plugin.h" #include "slack.h" @@ -13,6 +15,10 @@ void slack_completion_init() { + struct t_config_option *option; + const char *default_template; + + /* weechat_hook_command_run("/input return", &slack_emoji_input_replace_cb, NULL, NULL); @@ -20,9 +26,24 @@ void slack_completion_init() weechat_hook_command_run("/input complete*", &slack_emoji_input_complete_cb, NULL, NULL); - + */ weechat_hook_completion("slack_emoji", N_("slack emoji"), &slack_emoji_complete_by_name_cb, NULL, NULL); + + option = weechat_config_get("weechat.completion.default_template"); + default_template = weechat_config_string(option); + if (!weechat_strcasestr(default_template, "%(slack_emoji)")) + { + size_t length = snprintf(NULL, 0, "%s|%s", + default_template, + "%(slack_emoji)") + 1; + char *new_template = malloc(length); + snprintf(new_template, length, "%s|%s", + default_template, + "%(slack_emoji)"); + weechat_config_option_set(option, new_template, 1); + free(new_template); + } } diff --git a/slack-emoji.c b/slack-emoji.c index 42e3eb9..7ea1392 100644 --- a/slack-emoji.c +++ b/slack-emoji.c @@ -8,6 +8,9 @@ #include "weechat-plugin.h" #include "slack.h" +#include "slack-workspace.h" +#include "slack-channel.h" +#include "slack-buffer.h" #include "slack-emoji.h" #include "slack-emoji.inc" @@ -99,10 +102,14 @@ int slack_emoji_complete_by_name_cb(const void *pointer, void *data, struct t_gui_buffer *buffer, struct t_gui_completion *completion) { + struct t_slack_workspace *workspace; + struct t_slack_channel *channel; + (void) pointer; (void) data; (void) completion_item; - (void) buffer; + + slack_buffer_get_workspace_and_channel(buffer, &workspace, &channel); size_t i, emoji_count = sizeof(slack_emoji_by_name) / sizeof(struct t_slack_emoji_by_name); @@ -200,6 +207,8 @@ int slack_emoji_input_replace_cb(const void *pointer, void *data, (void) data; (void) buffer; (void) command; + + /* TBI */ return WEECHAT_RC_OK; }