~tardypad/wee-most-devel

convert dict_keys to list before reversing v1 APPLIED

Kjetil Torgrim Homme: 4
 convert dict_keys to list before reversing
 allow reply/react/unreact commands to be used with prefix matching on post id
 add look.thread_prefix_length to configure length of the post ID excerpt
 add look.thread_prefix_always_show so ID is always available for reply/react

 4 files changed, 31 insertions(+), 2 deletions(-)
wow, I didn't know about the cursor mode.  that's a bit hidden in
Weechat's own documentation, too.  there's not even a default key
binding to enter it, I see.  I bound it to meta-g now, it works fine.

I had however patched wee_most.py to get rid of wee_most from the
channel/buffer name of every Mattermost buffer:

  wee_most.look.buffer_name_prefix: Prefix to use for all wee_most
buffer names [default: "wee_most."]                                   

and that makes the context binding more tricky.  I guess that can be
solved by documenting the need for adding new key bindings if the
buffer_name_prefix is changed.  I'll have to look at this more closely
before submitting the patch.
Next
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~tardypad/wee-most-devel/patches/42027/mbox | git am -3
Learn more about email & git

[PATCH 1/4] convert dict_keys to list before reversing Export this patch

Prior to Python 3.8, you will get error message:

  TypeError: 'dict_keys' object is not reversible

Increased memory usage for this list instantiation should be minimal
and worth it to support older Python.  Tested with Python 3.6 on EL7.
---
 wee_most.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/wee_most.py b/wee_most.py
index b5140ec..d46b87e 100644
--- a/wee_most.py
+++ b/wee_most.py
@@ -1073,7 +1073,7 @@ class ChannelBase:
            line = weechat.hdata_pointer(weechat.hdata_get("line"), line, "prev_line")
            line_data = weechat.hdata_pointer(weechat.hdata_get("line"), line, "data")

        for file_id in reversed(post.files.keys()):
        for file_id in reversed(list(post.files.keys())):
            tags = get_line_data_tags(line_data)
            tags.append("file_id_{}".format(file_id))
            weechat.hdata_update(weechat.hdata_get("line_data"), line_data, {"tags_array": ",".join(tags)})
-- 
2.40.1
Thank you, I've applied it this first part.

[PATCH 2/4] allow reply/react/unreact commands to be used with prefix matching on post id Export this patch

Without this, I had to use /debug tags to find the tag
`post_id_3y8x6qot7pn63qa4ku5p9bjj6w` and then manually
`/mattermost reply 3y8x6qot7pn63qa4ku5p9bjj6w` which was rather awkward
to say the least :)
Now I have `/alias reply /mattermost reply $*` and can `/reply 3y8 great!`

---
 wee_most.py | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/wee_most.py b/wee_most.py
index d46b87e..9c84131 100644
--- a/wee_most.py
+++ b/wee_most.py
@@ -510,6 +510,7 @@ def command_reply(args, buffer):

    server = get_server_from_buffer(buffer)
    channel = server.get_channel_from_buffer(buffer)
    post_id = channel.find_thread(post_id)
    post = channel.posts.get(post_id, None)

    if not post:
@@ -536,6 +537,8 @@ def command_react(args, buffer):
    emoji_name = emoji_name.strip(":")

    server = get_server_from_buffer(buffer)
    channel = server.get_channel_from_buffer(buffer)
    post_id = channel.find_thread(post_id)

    run_post_reaction(emoji_name, post_id, server, "singularity_cb", buffer)

@@ -551,6 +554,8 @@ def command_unreact(args, buffer):
    emoji_name = emoji_name.strip(":")

    server = get_server_from_buffer(buffer)
    channel = server.get_channel_from_buffer(buffer)
    post_id = channel.find_thread(post_id)

    run_delete_reaction(emoji_name, post_id, server, "singularity_cb", buffer)

@@ -1108,6 +1113,17 @@ class ChannelBase:

        return "\n".join(lines)

    def find_thread(self, post_id_prefix):
        newest = None
        for i, post in self.posts.items():
            if i.startswith(post_id_prefix):
                if newest is None or post.created_at > newest.created_at:
                    newest = post
        if newest is None:
            return post_id_prefix
        else:
            return newest.id

    def remove_post(self, post_id):
        del self.posts[post_id]

-- 
2.40.1

[PATCH 3/4] add look.thread_prefix_length to configure length of the post ID excerpt Export this patch

I just thought this should be configurable.  The chance of a short-id
collision is pretty large with just 3 characters, but since the previous
patch which does prefix matching will prefer the newest matching thread
it doesn't cause much problems in practice.  also that code does not care
if you give it 1 or 26 characters to match against.  Personally I prefer
to display 4 characters, but I think 2 will work reasonably well, too.

---
 wee_most.py | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/wee_most.py b/wee_most.py
index 9c84131..1a7762d 100644
--- a/wee_most.py
+++ b/wee_most.py
@@ -158,6 +158,10 @@ class Config:
            self.sections["look"], "thread_prefix_suffix", "string",
            "String displayed after the thread prefix, if empty uses value from weechat.look.prefix_suffix",
            "", 0, 0, None, None, 1, "", "", "", "", "", ""), "type": "string" }
        self.options["look.thread_prefix_length"] = { "pointer": weechat.config_new_option(self.file,
            self.sections["look"], "thread_prefix_length", "integer",
            "How many characters to include from thread prefix",
            "", 2, 26, "3", None, 0, "", "", "", "", "", ""), "type": "integer" }
        self.options["look.thread_prefix_user_color"] = { "pointer": weechat.config_new_option(self.file,
            self.sections["look"], "thread_prefix_user_color", "boolean",
            "Use root post user color for the thread prefix",
@@ -1103,7 +1107,8 @@ class ChannelBase:
        suffix_color = config.get_value("color", "thread_prefix_suffix") or weechat.config_string(weechat.config_get("weechat.color.chat_prefix_suffix"))
        suffix = colorize(suffix_string, suffix_color)

        prefix = prefix_format.format(post_id[:3])
        prefix_length = config.get_value("look", "thread_prefix_length")
        prefix = prefix_format.format(post_id[:prefix_length])
        prefix_empty = "{} {} ".format(" " * len(prefix), suffix)
        prefix = colorize(prefix, prefix_color)
        prefix_full = "{} {} ".format(prefix, suffix)
-- 
2.40.1

[PATCH 4/4] add look.thread_prefix_always_show so ID is always available for reply/react Export this patch

The root id was only displayed by update(), called when a post got
a reply.  This meant it is not visible for easy replies until someone
else has made the post into a thread.  The default behaviour is unchanged.

The option name was chosen to match "weechat.look.read_marker_always_show"

---
 wee_most.py | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/wee_most.py b/wee_most.py
index 1a7762d..763263f 100644
--- a/wee_most.py
+++ b/wee_most.py
@@ -162,6 +162,10 @@ class Config:
            self.sections["look"], "thread_prefix_length", "integer",
            "How many characters to include from thread prefix",
            "", 2, 26, "3", None, 0, "", "", "", "", "", ""), "type": "integer" }
        self.options["look.thread_prefix_always_show"] = { "pointer": weechat.config_new_option(self.file,
            self.sections["look"], "thread_prefix_always_show", "boolean",
            "Show thread id for all posts, also those with no replies yet",
            "", 0, 0, "off", "off", 0, "", "", "", "", "", ""), "type": "boolean" }
        self.options["look.thread_prefix_user_color"] = { "pointer": weechat.config_new_option(self.file,
            self.sections["look"], "thread_prefix_user_color", "boolean",
            "Use root post user color for the thread prefix",
@@ -1159,6 +1163,8 @@ class ChannelBase:
            message = self._prefix_thread_message(message, post.root_id, root=False)
        elif post.thread_root:
            message = self._prefix_thread_message(message, post.id, root=True)
        elif config.get_value("look", "thread_prefix_always_show"):
            message = self._prefix_thread_message(message, post.id, root=False)

        lines = message.split("\n")

@@ -1218,6 +1224,8 @@ class ChannelBase:
        message = post.render_message() + post.render_reactions()
        if post.root_id:
            message = self._prefix_thread_message(message, post.root_id, root=False)
        elif config.get_value("look", "thread_prefix_always_show"):
            message = self._prefix_thread_message(message, post.id, root=False)

        date = int(post.created_at / 1000)

-- 
2.40.1