comparison libervia/pages/_browser/invitation.py @ 1373:2938d1b65bd5

browser (invitation): allow invitation of unknown JID: If something like a JID is entered in invitation field and it is unknown (i.e. not in roster), pressing "enter" will send an invitation to it.
author Goffi <goffi@goffi.org>
date Sun, 29 Nov 2020 17:08:36 +0100
parents c74e5a488af6
children e3e303a30a74
comparison
equal deleted inserted replaced
1372:19eb8b6c02d4 1373:2938d1b65bd5
1 from browser import document, window, timer 1 from browser import document, window, timer
2 from bridge import Bridge 2 from bridge import Bridge
3 from template import Template 3 from template import Template
4 from dialog import notification 4 from dialog import notification
5 from cache import cache 5 from cache import cache
6 # we use JS RegExp because Python're is really long to import in Brython
7 from javascript import RegExp
6 8
7 bridge = Bridge() 9 bridge = Bridge()
10 # FIXME: this is a naive JID regex, a more accurate should be used instead
11 jid_re = RegExp.new(r"^\w+@\w+\.\w+")
8 12
9 13
10 class InvitationManager: 14 class InvitationManager:
11 15
12 def __init__(self, invitation_type, invitation_data): 16 def __init__(self, invitation_type, invitation_data):
144 evt.stopPropagation() 148 evt.stopPropagation()
145 evt.preventDefault() 149 evt.preventDefault()
146 if self._active_new_item is not None: 150 if self._active_new_item is not None:
147 entity_jid = self._active_new_item.dataset.entityJid 151 entity_jid = self._active_new_item.dataset.entityJid
148 self.invite_by_jid(entity_jid) 152 self.invite_by_jid(entity_jid)
153 else:
154 if jid_re.exec(evt.target.value):
155 self.invite_by_jid(evt.target.value)
156 evt.target.value = ""
149 157
150 def on_contact_focus(self, evt): 158 def on_contact_focus(self, evt):
151 search_dialog = document['invitation_contact_search'] 159 search_dialog = document['invitation_contact_search']
152 search_dialog.classList.add('open') 160 search_dialog.classList.add('open')
153 self._active_new_item = None 161 self._active_new_item = None