view libervia/web/pages/chat/select/page_meta.py @ 1522:a44f77559279

installation: moved from `setup.py` to `pyproject.toml`: - following backend change, installation is now using `pyproject.toml`, and legacy `setup.py` as well as other legacy files have been deleted/updated. - [hatch](https://hatch.pypa.io) is now used as main building tool. However, thanks to the use of standards, other tools can be used too. - `VERSION` file has been deleted, in favor or using directly `__version__`, in `libervia/web/__init__.py`. Version can be updated directly from Hatch - update .hgignore - several dependencies version bump, with code update to adapt to changes.
author Goffi <goffi@goffi.org>
date Wed, 07 Jun 2023 15:28:10 +0200
parents eb00d593801d
children c57133362fb7
line wrap: on
line source

#!/usr/bin/env python3


from libervia.backend.core.i18n import _
from libervia.web.server.constants import Const as C
from twisted.internet import defer
from twisted.words.protocols.jabber import jid
from libervia.backend.tools.common import data_objects
from libervia.backend.core.log import getLogger

log = getLogger(__name__)

name = "chat_select"
access = C.PAGES_ACCESS_PROFILE
template = "chat/select.html"


@defer.inlineCallbacks
def prepare_render(self, request):
    profile = self.get_profile(request)
    template_data = request.template_data
    rooms = template_data["rooms"] = []
    bookmarks = yield self.host.bridge_call("bookmarks_list", "muc", "all", profile)
    for bm_values in list(bookmarks.values()):
        for room_jid, room_data in bm_values.items():
            url = self.get_page_by_name("chat").get_url(room_jid)
            rooms.append(data_objects.Room(room_jid, name=room_data.get("name"), url=url))
    rooms.sort(key=lambda r: r.name)


@defer.inlineCallbacks
def on_data_post(self, request):
    jid_ = self.get_posted_data(request, "jid")
    if "@" not in jid_:
        profile = self.get_profile(request)
        service = yield self.host.bridge_call("muc_get_service", "", profile)
        if service:
            muc_jid = jid.JID(service)
            muc_jid.user = jid_
            jid_ = muc_jid.full()
        else:
            log.warning(_("Invalid jid received: {jid}".format(jid=jid_)))
            defer.returnValue(C.POST_NO_CONFIRM)
    url = self.get_page_by_name("chat").get_url(jid_)
    self.http_redirect(request, url)