diff --git a/src/snek/app.py b/src/snek/app.py index a7bc195..81259bc 100644 --- a/src/snek/app.py +++ b/src/snek/app.py @@ -143,6 +143,31 @@ class Application(BaseApplication): # @time_cache_async(60) async def render_template(self, template, request, context=None): + channels = [] + if not context: + context = {} + if request.session.get("uid"): + async for subscribed_channel in self.services.channel_member.find(user_uid=request.session.get("uid"), deleted_at=None, is_banned=False): + item = {} + other_user = await self.services.channel_member.get_other_dm_user(subscribed_channel["channel_uid"], request.session.get("uid")) + parent_object = await subscribed_channel.get_channel() + last_message =await parent_object.get_last_message() + item["last_message_on"] = parent_object["last_message_on"] + item["is_private"] = parent_object["tag"] == "dm" + if other_user: + item["name"] = other_user["nick"] + item["uid"] = subscribed_channel["channel_uid"] + else: + item["name"] = subscribed_channel["label"] + item["uid"] = subscribed_channel["channel_uid"] + channels.append(item) + + channels.sort(key=lambda x: x['last_message_on'] or '', reverse=True) + if not 'channels' in context: + context['channels'] = channels + if not 'user' in context: + context['user'] = await self.services.user.get(uid=request.session.get("uid")) + return await super().render_template(template, request, context) diff --git a/src/snek/view/terminal.py b/src/snek/view/terminal.py index e54dfb7..8af82e7 100644 --- a/src/snek/view/terminal.py +++ b/src/snek/view/terminal.py @@ -17,9 +17,8 @@ class TerminalSocketView(BaseView): terminal_folder = pathlib.Path("terminal") for path in terminal_folder.iterdir(): destination_path = root.joinpath(path.name) - if not destination_path.exists(): - if not path.is_dir(): - destination_path.write_bytes(path.read_bytes()) + if not path.is_dir(): + destination_path.write_bytes(path.read_bytes()) return root async def get(self): diff --git a/terminal/.bashrc b/terminal/.bashrc index 2b5d791..d8b23c1 100644 --- a/terminal/.bashrc +++ b/terminal/.bashrc @@ -94,11 +94,11 @@ fi cp ~/r /usr/local/bin -chmod -x /usr/local/bin/* +chmod -x /usr/local/bin/r -apt update && apt install libreadline-dev libcurl4-openssl-dev libssl-dev libncurses5-dev libncursesw5-dev libsqlite3-dev libreadline6-dev zlib1g-dev libbz2-dev libffi-dev liblzma-dev python3 python3-pip python3-venv -y +apt update && apt install libreadline-dev libcurl4-openssl-dev libssl-dev libncurses5-dev libncursesw5-dev libsqlite3-dev libreadline6-dev zlib1g-dev libbz2-dev libffi-dev liblzma-dev python3 python3-pip python3-venv libjson-c-dev -y -echo "r is installed." +echo "R is installed. Type r to run it." # enable programmable completion features (you don't need to enable # this, if it's already enabled in /etc/bash.bashrc and /etc/profile @@ -106,3 +106,4 @@ echo "r is installed." #if [ -f /etc/bash_completion ] && ! shopt -oq posix; then # . /etc/bash_completion #fi +export PS1="root@snek: "