~reedwade/wee-matter-devel

wee-matter: Handle the weechat buffered large responses v1 APPLIED

Reed Wade: 1
 Handle the weechat buffered large responses

 2 files changed, 84 insertions(+), 52 deletions(-)
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/~reedwade/wee-matter-devel/patches/14996/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH wee-matter] Handle the weechat buffered large responses Export this patch

Signed-off-by: Reed Wade <reedwade@misterbanal.net>
---
 main.py            |  20 +++-----
 wee_matter/http.py | 116 ++++++++++++++++++++++++++++++---------------
 2 files changed, 84 insertions(+), 52 deletions(-)

This is based on the work of ~midgard (patch 2)
https://lists.sr.ht/~reedwade/wee-matter-devel/patches/14961

diff --git a/main.py b/main.py
index 875d5b0..a5b945d 100644
--- a/main.py
+++ b/main.py
@@ -1,5 +1,10 @@
import weechat

from wee_matter.room import (handle_multiline_message_cb, room_input_cb,
                             buffer_switch_cb, channel_completion_cb,
                             private_completion_cb, channel_switch_cb,
                             channel_click_cb)

from wee_matter.commands import (matter_command_cb, reply_command_cb,
                                 react_command_cb, unreact_command_cb,
                                 delete_post_command_cb)
@@ -7,20 +12,7 @@ from wee_matter.commands import (matter_command_cb, reply_command_cb,
from wee_matter.websocket import (receive_ws_callback, ws_ping_cb,
                                  reconnection_loop_cb)

from wee_matter.server import (connect_server_cb, connect_server_teams_cb,
                               connect_server_team_channels_cb, disconnect_server_cb,
                               connect_server_users_cb, server_completion_cb,
                               connect_server_team_channel_cb, connect_server_team_cb,
                               new_user_cb)

from wee_matter.room import (hidrate_room_read_posts_cb, hidrate_room_posts_cb,
                             hidrate_room_users_cb, room_input_cb,
                             buffer_switch_cb, channel_completion_cb, private_completion_cb,
                             channel_switch_cb, channel_click_cb, hidrate_room_user_cb, handle_multiline_message_cb)
from wee_matter.post import post_post_cb

from wee_matter.http import singularity_cb
from wee_matter.file import file_get_cb
from wee_matter.http import singularity_cb, buffered_response_cb
import wee_matter

WEECHAT_SCRIPT_NAME = "wee-matter"
diff --git a/wee_matter/http.py b/wee_matter/http.py
index 07f454a..1b5b9c8 100644
--- a/wee_matter/http.py
+++ b/wee_matter/http.py
@@ -3,6 +3,21 @@ import weechat
import wee_matter
import json
import time
import re

from wee_matter.room import (hidrate_room_read_posts_cb, hidrate_room_posts_cb,
                             hidrate_room_users_cb, hidrate_room_user_cb)

from wee_matter.post import post_post_cb

from wee_matter.file import file_get_cb

from wee_matter.server import (connect_server_cb, connect_server_teams_cb,
                               connect_server_team_channels_cb, disconnect_server_cb,
                               connect_server_users_cb, server_completion_cb,
                               connect_server_team_channel_cb, connect_server_team_cb,
                               new_user_cb)


def build_file_url(file_id, server):
    return wee_matter.server.server_root_url(server) + "/api/v4/files/" + file_id
@@ -14,6 +29,31 @@ def singularity_cb(data, command, rc, out, err):

    return weechat.WEECHAT_RC_OK

response_buffers = {}
def buffered_response_cb(data, command, rc, out, err):
    arg_search = re.search('([^\|]*)\|([^\|]*)\|(.*)', data)
    if not arg_search:
        weechat.prnt("", "Bad usage of buffered response cb \"{}\"".format(data))
        return weechat.WEECHAT_RC_ERROR
    response_buffer_name = arg_search.group(1)
    real_cb = arg_search.group(2)
    real_data = arg_search.group(3)

    if not response_buffer_name in response_buffers:
        response_buffers[response_buffer_name] = ""

    if rc == weechat.WEECHAT_HOOK_PROCESS_RUNNING:
        response_buffers[response_buffer_name] += out
        return weechat.WEECHAT_RC_OK

    response = response_buffers[response_buffer_name] + out
    del response_buffers[response_buffer_name]

    return eval(real_cb)(real_data, command, rc, response, err)

def build_buffer_cb_data(url, cb, cb_data):
    return "{}|{}|{}".format(url, cb, cb_data)

def run_get_user_teams(user_id, server, cb, cb_data):
    url = wee_matter.server.server_root_url(server) + "/api/v4/users/" + user_id + "/teams"
    weechat.hook_process_hashtable(
@@ -23,8 +63,8 @@ def run_get_user_teams(user_id, server, cb, cb_data):
            "httpheader": "Authorization: Bearer " + server.user_token,
        },
        30 * 1000,
        cb,
        cb_data
        "buffered_response_cb",
        build_buffer_cb_data(url, cb, cb_data)
    )

def run_get_team(team_id, server, cb, cb_data):
@@ -36,8 +76,8 @@ def run_get_team(team_id, server, cb, cb_data):
            "httpheader": "Authorization: Bearer " + server.user_token,
        },
        30 * 1000,
        cb,
        cb_data
        "buffered_response_cb",
        build_buffer_cb_data(url, cb, cb_data)
    )

def run_get_users(server, page, cb, cb_data):
@@ -49,8 +89,8 @@ def run_get_users(server, page, cb, cb_data):
            "httpheader": "Authorization: Bearer " + server.user_token,
        },
        30 * 1000,
        cb,
        cb_data
        "buffered_response_cb",
        build_buffer_cb_data(url, cb, cb_data)
    )

def run_get_user(server, user_id, cb, cb_data):
@@ -62,8 +102,8 @@ def run_get_user(server, user_id, cb, cb_data):
            "httpheader": "Authorization: Bearer " + server.user_token,
        },
        30 * 1000,
        cb,
        cb_data
        "buffered_response_cb",
        build_buffer_cb_data(url, cb, cb_data)
    )

def run_user_logout(server, cb, cb_data):
@@ -79,8 +119,8 @@ def run_user_logout(server, cb, cb_data):
            ]),
        },
        30 * 1000,
        cb,
        cb_data
        "buffered_response_cb",
        build_buffer_cb_data(url, cb, cb_data)
    )

def run_user_login(server, cb, cb_data):
@@ -98,8 +138,8 @@ def run_user_login(server, cb, cb_data):
            "header": "1",
        },
        30 * 1000,
        cb,
        cb_data
        "buffered_response_cb",
        build_buffer_cb_data(url, cb, cb_data)
    )

def run_get_channel(channel_id, server, cb, cb_data):
@@ -111,8 +151,8 @@ def run_get_channel(channel_id, server, cb, cb_data):
            "httpheader": "Authorization: Bearer " + server.user_token,
        },
        30 * 1000,
        cb,
        cb_data
        "buffered_response_cb",
        build_buffer_cb_data(url, cb, cb_data)
    )

def run_get_user_team_channels(user_id, team_id, server, cb, cb_data):
@@ -124,8 +164,8 @@ def run_get_user_team_channels(user_id, team_id, server, cb, cb_data):
            "httpheader": "Authorization: Bearer " + server.user_token,
        },
        30 * 1000,
        cb,
        cb_data
        "buffered_response_cb",
        build_buffer_cb_data(url, cb, cb_data)
    )

def run_post_post(post, server, cb, cb_data):
@@ -146,8 +186,8 @@ def run_post_post(post, server, cb, cb_data):
            "postfields": json.dumps(params),
        },
        30 * 1000,
        cb,
        cb_data
        "buffered_response_cb",
        build_buffer_cb_data(url, cb, cb_data)
    )

def run_get_channel_posts(channel_id, server, cb, cb_data):
@@ -159,8 +199,8 @@ def run_get_channel_posts(channel_id, server, cb, cb_data):
            "httpheader": "Authorization: Bearer " + server.user_token,
        },
        30 * 1000,
        cb,
        cb_data
        "buffered_response_cb",
        build_buffer_cb_data(url, cb, cb_data)
    )

def run_get_read_channel_posts(user_id, channel_id, server, cb, cb_data):
@@ -172,8 +212,8 @@ def run_get_read_channel_posts(user_id, channel_id, server, cb, cb_data):
            "httpheader": "Authorization: Bearer " + server.user_token,
        },
        30 * 1000,
        cb,
        cb_data
        "buffered_response_cb",
        build_buffer_cb_data(url, cb, cb_data)
    )

def run_get_channel_posts_after(post_id, channel_id, server, cb, cb_data):
@@ -185,8 +225,8 @@ def run_get_channel_posts_after(post_id, channel_id, server, cb, cb_data):
            "httpheader": "Authorization: Bearer " + server.user_token,
        },
        30 * 1000,
        cb,
        cb_data
        "buffered_response_cb",
        build_buffer_cb_data(url, cb, cb_data)
    )

def run_get_channel_members(channel_id, server, cb, cb_data):
@@ -198,8 +238,8 @@ def run_get_channel_members(channel_id, server, cb, cb_data):
            "httpheader": "Authorization: Bearer " + server.user_token,
        },
        30 * 1000,
        cb,
        cb_data
        "buffered_response_cb",
        build_buffer_cb_data(url, cb, cb_data)
    )

def run_get_channel_member(channel_id, member_id, server, cb, cb_data):
@@ -211,8 +251,8 @@ def run_get_channel_member(channel_id, member_id, server, cb, cb_data):
            "httpheader": "Authorization: Bearer " + server.user_token,
        },
        30 * 1000,
        cb,
        cb_data
        "buffered_response_cb",
        build_buffer_cb_data(url, cb, cb_data)
    )

def run_post_channel_view(user_id, channel_id, server, cb, cb_data):
@@ -229,8 +269,8 @@ def run_post_channel_view(user_id, channel_id, server, cb, cb_data):
            "httpheader": "Authorization: Bearer " + server.user_token,
        },
        30 * 1000,
        cb,
        cb_data
        "buffered_response_cb",
        build_buffer_cb_data(url, cb, cb_data)
    )

def run_post_reaction(emoji_name, post_id, server, cb, cb_data):
@@ -250,8 +290,8 @@ def run_post_reaction(emoji_name, post_id, server, cb, cb_data):
            "httpheader": "Authorization: Bearer " + server.user_token,
        },
        30 * 1000,
        cb,
        cb_data
        "buffered_response_cb",
        build_buffer_cb_data(url, cb, cb_data)
    )

def run_delete_reaction(emoji_name, post_id, server, cb, cb_data):
@@ -265,8 +305,8 @@ def run_delete_reaction(emoji_name, post_id, server, cb, cb_data):
            "httpheader": "Authorization: Bearer " + server.user_token,
        },
        30 * 1000,
        cb,
        cb_data
        "buffered_response_cb",
        build_buffer_cb_data(url, cb, cb_data)
    )

def run_delete_post(post_id, server, cb, cb_data):
@@ -280,8 +320,8 @@ def run_delete_post(post_id, server, cb, cb_data):
            "httpheader": "Authorization: Bearer " + server.user_token,
        },
        30 * 1000,
        cb,
        cb_data
        "buffered_response_cb",
        build_buffer_cb_data(url, cb, cb_data)
    )

def run_get_file(file_id, file_out_path, server, cb, cb_data):
@@ -295,7 +335,7 @@ def run_get_file(file_id, file_out_path, server, cb, cb_data):
            "httpheader": "Authorization: Bearer " + server.user_token,
        },
        30 * 1000,
        cb,
        cb_data
        "buffered_response_cb",
        build_buffer_cb_data(url, cb, cb_data)
    )

-- 
2.29.2