annotate libervia/pages/_browser/invitation.py @ 1454:fc91b78b71db

server: handle "proxy" scheme in configuration
author Goffi <goffi@goffi.org>
date Tue, 28 Sep 2021 18:18:37 +0200
parents 5a132b85e1ac
children 106bae41f5c8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1331
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
1 from browser import document, window, timer
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
2 from bridge import Bridge
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
3 from template import Template
1386
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
4 import dialog
1331
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
5 from cache import cache
1386
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
6 import javascript
1331
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
7
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
8 bridge = Bridge()
1386
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
9 # we use JS RegExp because Python's re is really long to import in Brython
1373
2938d1b65bd5 browser (invitation): allow invitation of unknown JID:
Goffi <goffi@goffi.org>
parents: 1348
diff changeset
10 # FIXME: this is a naive JID regex, a more accurate should be used instead
1386
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
11 jid_re = javascript.RegExp.new(r"^\w+@\w+\.\w+")
1331
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
12
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
13
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 class InvitationManager:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
15
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
16 def __init__(self, invitation_type, invitation_data):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 self.invitation_type = invitation_type
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
18 self.invitation_data = invitation_data
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
19 manager_panel_tpl = Template('invitation/manager.html')
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
20 self.manager_panel_elt = manager_panel_tpl.get_elt()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
21 self.invite_by_email_tpl = Template('invitation/invite_by_email.html')
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
22 self.affiliation_tpl = Template('invitation/affiliation_item.html')
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
23 self.new_item_tpl = Template('invitation/new_item.html')
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
24 # list of item passing filter when adding a new contact
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
25 self._filtered_new_items = {}
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
26 self._active_new_item = None
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
27 self._idx = 0
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
28
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
29 def attach(self, affiliations=None):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
30 if affiliations is None:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
31 affiliations = {}
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
32 self.affiliations = affiliations
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
33 self.side_panel = self.manager_panel_elt.select_one(
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
34 '.invitation_manager_side_panel')
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
35 self.open()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
36 for close_elt in self.manager_panel_elt.select('.click_to_close'):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
37 close_elt.bind("click", self.on_manager_close)
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
38 self.side_panel.bind("click", lambda evt: evt.stopPropagation())
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
39
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
40 cache.fill_identities(affiliations.keys(), callback=self._set_affiliations)
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
41
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
42 contact_elt = self.manager_panel_elt.select_one('input[name="contact"]')
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
43 contact_elt.bind("input", self.on_contact_input)
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
44 contact_elt.bind("keydown", self.on_contact_keydown)
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
45 contact_elt.bind("focus", self.on_contact_focus)
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
46 contact_elt.bind("blur", self.on_contact_blur)
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
47 document['invite_email'].bind('click', self.on_invite_email_click)
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
48
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
49 def _set_affiliations(self):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
50 for entity_jid, affiliation in self.affiliations.items():
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
51 self.set_affiliation(entity_jid, affiliation)
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
52
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
53 def open(self):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
54 """Re-attach and show a closed panel"""
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
55 self._body_ori_style = document.body.style.height, document.body.style.overflow
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
56 document.body.style.height = '100vh'
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
57 document.body.style.overflow = 'hidden'
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
58 document.body <= self.manager_panel_elt
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
59 timer.set_timeout(lambda: self.side_panel.classList.add("open"), 0)
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
60
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
61 def _on_close_transition_end(self, evt):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
62 self.manager_panel_elt.remove()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
63 # FIXME: not working with Brython, to report upstream
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
64 # self.side_panel.unbind("transitionend", self._on_close_transition_end)
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
65 self.side_panel.unbind("transitionend")
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
66
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
67 def close(self):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
68 """Hide the panel"""
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
69 document.body.style.height, document.body.style.overflow = self._body_ori_style
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
70 self.side_panel.classList.remove('open')
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
71 self.side_panel.bind("transitionend", self._on_close_transition_end)
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
72
1386
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
73 def _invite_jid(self, entity_jid, callback, errback=None):
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
74 if errback is None:
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
75 errback = lambda e: dialog.notification.show(f"invitation failed: {e}", "error")
1331
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
76 if self.invitation_type == 'photos':
1386
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
77 service = self.invitation_data["service"]
1331
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
78 path = self.invitation_data["path"]
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
79 album_name = path.rsplit('/')[-1]
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
80 print(f"inviting {entity_jid}")
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
81 bridge.FISInvite(
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
82 entity_jid,
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
83 service,
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
84 "photos",
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
85 "",
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
86 path,
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
87 album_name,
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
88 '',
1386
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
89 callback=callback,
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
90 errback=errback
1331
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
91 )
1386
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
92 elif self.invitation_type == 'pubsub':
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
93 service = self.invitation_data["service"]
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
94 node = self.invitation_data["node"]
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
95 name = self.invitation_data.get("name")
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
96 namespace = self.invitation_data.get("namespace")
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
97 extra = {}
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
98 if namespace:
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
99 extra["namespace"] = namespace
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
100 print(f"inviting {entity_jid}")
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
101 bridge.psInvite(
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
102 entity_jid,
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
103 service,
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
104 node,
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
105 '',
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
106 name,
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
107 javascript.JSON.stringify(extra),
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
108 callback=callback,
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
109 errback=errback
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
110 )
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
111 else:
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
112 print(f"error: unknown invitation type: {self.invitation_type}")
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
113
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
114 def invite_by_jid(self, entity_jid):
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
115 self._invite_jid(
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
116 entity_jid,
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
117 callback=lambda entity_jid=entity_jid: self._on_jid_invitation_success(entity_jid),
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
118 )
1331
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
119
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
120 def on_manager_close(self, evt):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
121 self.close()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
122
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
123 def _on_jid_invitation_success(self, entity_jid):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
124 form_elt = document['invitation_form']
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
125 contact_elt = form_elt.select_one('input[name="contact"]')
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
126 contact_elt.value = ""
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
127 contact_elt.dispatchEvent(window.Event.new('input'))
1386
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
128 dialog.notification.show(
1331
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
129 f"{entity_jid} has been invited",
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
130 level="success",
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
131 )
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
132 if entity_jid not in self.affiliations:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
133 self.set_affiliation(entity_jid, "member")
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
134
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
135 def on_contact_invite(self, evt, entity_jid):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
136 """User is adding a contact"""
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
137 form_elt = document['invitation_form']
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
138 contact_elt = form_elt.select_one('input[name="contact"]')
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
139 contact_elt.value = ""
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
140 contact_elt.dispatchEvent(window.Event.new('input'))
1348
c74e5a488af6 browser (invitation): minor renaming
Goffi <goffi@goffi.org>
parents: 1331
diff changeset
141 self.invite_by_jid(entity_jid)
1331
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
142
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
143 def on_contact_keydown(self, evt):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
144 if evt.key == "Escape":
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
145 evt.target.value = ""
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
146 evt.target.dispatchEvent(window.Event.new('input'))
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
147 elif evt.key == "ArrowDown":
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
148 evt.stopPropagation()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
149 evt.preventDefault()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
150 content_elt = document['invitation_contact_search'].select_one(
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
151 ".search_dialog__content")
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
152 if self._active_new_item == None:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
153 self._active_new_item = content_elt.firstElementChild
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
154 self._active_new_item.classList.add('selected')
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
155 else:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
156 next_item = self._active_new_item.nextElementSibling
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
157 if next_item is not None:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
158 self._active_new_item.classList.remove('selected')
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
159 self._active_new_item = next_item
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
160 self._active_new_item.classList.add('selected')
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
161 elif evt.key == "ArrowUp":
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
162 evt.stopPropagation()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
163 evt.preventDefault()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
164 content_elt = document['invitation_contact_search'].select_one(
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
165 ".search_dialog__content")
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
166 if self._active_new_item == None:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
167 self._active_new_item = content_elt.lastElementChild
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
168 self._active_new_item.classList.add('selected')
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
169 else:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
170 previous_item = self._active_new_item.previousElementSibling
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
171 if previous_item is not None:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
172 self._active_new_item.classList.remove('selected')
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
173 self._active_new_item = previous_item
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
174 self._active_new_item.classList.add('selected')
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
175 elif evt.key == "Enter":
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
176 evt.stopPropagation()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
177 evt.preventDefault()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
178 if self._active_new_item is not None:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
179 entity_jid = self._active_new_item.dataset.entityJid
1348
c74e5a488af6 browser (invitation): minor renaming
Goffi <goffi@goffi.org>
parents: 1331
diff changeset
180 self.invite_by_jid(entity_jid)
1373
2938d1b65bd5 browser (invitation): allow invitation of unknown JID:
Goffi <goffi@goffi.org>
parents: 1348
diff changeset
181 else:
2938d1b65bd5 browser (invitation): allow invitation of unknown JID:
Goffi <goffi@goffi.org>
parents: 1348
diff changeset
182 if jid_re.exec(evt.target.value):
2938d1b65bd5 browser (invitation): allow invitation of unknown JID:
Goffi <goffi@goffi.org>
parents: 1348
diff changeset
183 self.invite_by_jid(evt.target.value)
2938d1b65bd5 browser (invitation): allow invitation of unknown JID:
Goffi <goffi@goffi.org>
parents: 1348
diff changeset
184 evt.target.value = ""
1331
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
185
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
186 def on_contact_focus(self, evt):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
187 search_dialog = document['invitation_contact_search']
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
188 search_dialog.classList.add('open')
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
189 self._active_new_item = None
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
190 evt.target.dispatchEvent(window.Event.new('input'))
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
191
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
192 def on_contact_blur(self, evt):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
193 search_dialog = document['invitation_contact_search']
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
194 search_dialog.classList.remove('open')
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
195 for elt in self._filtered_new_items.values():
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
196 elt.remove()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
197 self._filtered_new_items.clear()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
198
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
199
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
200 def on_contact_input(self, evt):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
201 text = evt.target.value.strip().lower()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
202 search_dialog = document['invitation_contact_search']
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
203 content_elt = search_dialog.select_one(".search_dialog__content")
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
204 for (entity_jid, identity) in cache.identities.items():
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
205 if not cache.match_identity(entity_jid, text, identity):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
206 # if the entity was present in last pass, we remove it
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
207 try:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
208 filtered_item = self._filtered_new_items.pop(entity_jid)
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
209 except KeyError:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
210 pass
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
211 else:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
212 filtered_item.remove()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
213 continue
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
214 if entity_jid not in self._filtered_new_items:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
215 # we only create a new element if the item was not already there
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
216 new_item_elt = self.new_item_tpl.get_elt({
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
217 "entity_jid": entity_jid,
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
218 "identities": cache.identities,
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
219 })
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
220 content_elt <= new_item_elt
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
221 self._filtered_new_items[entity_jid] = new_item_elt
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
222 for elt in new_item_elt.select('.click_to_ok'):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
223 # we use mousedown instead of click because otherwise it would be
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
224 # ignored due to "blur" event manager (see
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
225 # https://stackoverflow.com/a/9335401)
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
226 elt.bind(
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
227 "mousedown",
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
228 lambda evt, entity_jid=entity_jid: self.on_contact_invite(
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
229 evt, entity_jid),
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
230 )
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
231
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
232 if ((self._active_new_item is not None
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
233 and not self._active_new_item.parentElement)):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
234 # active item has been filtered out
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
235 self._active_new_item = None
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
236
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
237 def _on_email_invitation_success(self, invitee_jid, email, name):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
238 self.set_affiliation(invitee_jid, "member")
1386
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
239 dialog.notification.show(
1331
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
240 f"{name} has been invited, he/she has received an email with a link",
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
241 level="success",
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
242 )
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
243
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
244 def invitationSimpleCreateCb(self, invitation_data, email, name):
1386
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
245 invitee_jid = invitation_data['jid']
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
246 self._invite_jid(
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
247 invitee_jid,
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
248 callback=lambda: self._on_email_invitation_success(invitee_jid, email, name),
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
249 errback=lambda e: dialog.notification.show(
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
250 f"invitation failed for {email}: {e}",
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
251 "error"
1331
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
252 )
1386
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
253 )
1331
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
254
1386
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
255 # we update identities to have the name instead of the invitation jid in
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
256 # affiliations
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
257 cache.identities[invitee_jid] = {'nicknames': [name]}
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
258 cache.update()
1331
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
259
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
260 def invite_by_email(self, email, name):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
261 guest_url_tpl = f'{window.URL.new("/g", document.baseURI).href}/{{uuid}}'
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
262 bridge.invitationSimpleCreate(
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
263 email,
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
264 name,
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
265 guest_url_tpl,
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
266 '',
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
267 callback=lambda data: self.invitationSimpleCreateCb(data, email, name),
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
268 errback=lambda e: window.alert(f"can't send email invitation: {e}")
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
269 )
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
270
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
271 def on_invite_email_submit(self, evt, invite_email_elt):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
272 evt.stopPropagation()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
273 evt.preventDefault()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
274 form = document['email_invitation_form']
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
275 try:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
276 reportValidity = form.reportValidity
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
277 except AttributeError:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
278 print("reportValidity is not supported by this browser!")
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
279 else:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
280 if not reportValidity():
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
281 return
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
282 email = form.select_one('input[name="email"]').value
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
283 name = form.select_one('input[name="name"]').value
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
284 self.invite_by_email(email, name)
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
285 invite_email_elt.remove()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
286 self.open()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
287
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
288 def on_invite_email_close(self, evt, invite_email_elt):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
289 evt.stopPropagation()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
290 evt.preventDefault()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
291 invite_email_elt.remove()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
292 self.open()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
293
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
294 def on_invite_email_click(self, evt):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
295 evt.stopPropagation()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
296 evt.preventDefault()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
297 invite_email_elt = self.invite_by_email_tpl.get_elt()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
298 document.body <= invite_email_elt
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
299 document['email_invitation_submit'].bind(
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
300 'click', lambda evt: self.on_invite_email_submit(evt, invite_email_elt)
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
301 )
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
302 for close_elt in invite_email_elt.select('.click_to_close'):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
303 close_elt.bind(
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
304 "click", lambda evt: self.on_invite_email_close(evt, invite_email_elt))
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
305 self.close()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
306
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
307 ## affiliations
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
308
1386
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
309 def _addAffiliationBindings(self, entity_jid, affiliation_elt):
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
310 for elt in affiliation_elt.select(".click_to_delete"):
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
311 elt.bind(
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
312 "click",
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
313 lambda evt, entity_jid=entity_jid, affiliation_elt=affiliation_elt:
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
314 self.on_affiliation_remove(entity_jid, affiliation_elt)
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
315 )
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
316 for elt in affiliation_elt.select(".click_to_set_publisher"):
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
317 try:
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
318 name = cache.identities[entity_jid]["nicknames"][0]
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
319 except (KeyError, IndexError):
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
320 name = entity_jid
1407
5a132b85e1ac browser (invitation): fix an indentation issue which was breaking invitations
Goffi <goffi@goffi.org>
parents: 1386
diff changeset
321 elt.bind(
5a132b85e1ac browser (invitation): fix an indentation issue which was breaking invitations
Goffi <goffi@goffi.org>
parents: 1386
diff changeset
322 "click",
5a132b85e1ac browser (invitation): fix an indentation issue which was breaking invitations
Goffi <goffi@goffi.org>
parents: 1386
diff changeset
323 lambda evt, entity_jid=entity_jid, name=name,
5a132b85e1ac browser (invitation): fix an indentation issue which was breaking invitations
Goffi <goffi@goffi.org>
parents: 1386
diff changeset
324 affiliation_elt=affiliation_elt:
5a132b85e1ac browser (invitation): fix an indentation issue which was breaking invitations
Goffi <goffi@goffi.org>
parents: 1386
diff changeset
325 self.on_affiliation_set(
5a132b85e1ac browser (invitation): fix an indentation issue which was breaking invitations
Goffi <goffi@goffi.org>
parents: 1386
diff changeset
326 entity_jid, name, affiliation_elt, "publisher"
5a132b85e1ac browser (invitation): fix an indentation issue which was breaking invitations
Goffi <goffi@goffi.org>
parents: 1386
diff changeset
327 ),
5a132b85e1ac browser (invitation): fix an indentation issue which was breaking invitations
Goffi <goffi@goffi.org>
parents: 1386
diff changeset
328 )
1386
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
329 for elt in affiliation_elt.select(".click_to_set_member"):
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
330 try:
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
331 name = cache.identities[entity_jid]["nicknames"][0]
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
332 except (KeyError, IndexError):
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
333 name = entity_jid
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
334 elt.bind(
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
335 "click",
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
336 lambda evt, entity_jid=entity_jid, name=name,
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
337 affiliation_elt=affiliation_elt:
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
338 self.on_affiliation_set(
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
339 entity_jid, name, affiliation_elt, "member"
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
340 ),
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
341 )
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
342
1331
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
343 def set_affiliation(self, entity_jid, affiliation):
1386
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
344 if affiliation not in ('owner', 'member', 'publisher'):
1331
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
345 raise NotImplementedError(
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
346 f'{affiliation} affiliation can not be set with this method for the '
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
347 'moment')
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
348 if entity_jid not in self.affiliations:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
349 self.affiliations[entity_jid] = affiliation
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
350 affiliation_elt = self.affiliation_tpl.get_elt({
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
351 "entity_jid": entity_jid,
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
352 "affiliation": affiliation,
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
353 "identities": cache.identities,
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
354 })
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
355 document['affiliations'] <= affiliation_elt
1386
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
356 self._addAffiliationBindings(entity_jid, affiliation_elt)
1331
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
357
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
358 def _on_affiliation_remove_success(self, affiliation_elt, entity_jid):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
359 affiliation_elt.remove()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
360 del self.affiliations[entity_jid]
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
361
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
362 def on_affiliation_remove(self, entity_jid, affiliation_elt):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
363 if self.invitation_type == 'photos':
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
364 path = self.invitation_data["path"]
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
365 service = self.invitation_data["service"]
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
366 bridge.FISAffiliationsSet(
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
367 service,
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
368 "",
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
369 path,
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
370 {entity_jid: "none"},
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
371 callback=lambda: self._on_affiliation_remove_success(
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
372 affiliation_elt, entity_jid),
1386
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
373 errback=lambda e: dialog.notification.show(
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
374 f"can't remove affiliation: {e}", "error")
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
375 )
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
376 elif self.invitation_type == 'pubsub':
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
377 service = self.invitation_data["service"]
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
378 node = self.invitation_data["node"]
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
379 bridge.psNodeAffiliationsSet(
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
380 service,
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
381 node,
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
382 {entity_jid: "none"},
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
383 callback=lambda: self._on_affiliation_remove_success(
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
384 affiliation_elt, entity_jid),
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
385 errback=lambda e: dialog.notification.show(
1331
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
386 f"can't remove affiliation: {e}", "error")
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
387 )
1386
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
388 else:
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
389 dialog.notification.show(
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
390 f"error: unknown invitation type: {self.invitation_type}",
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
391 "error"
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
392 )
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
393
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
394 def _on_affiliation_set_success(self, entity_jid, name, affiliation_elt, affiliation):
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
395 dialog.notification.show(f"permission updated for {name}")
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
396 self.affiliations[entity_jid] = affiliation
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
397 new_affiliation_elt = self.affiliation_tpl.get_elt({
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
398 "entity_jid": entity_jid,
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
399 "affiliation": affiliation,
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
400 "identities": cache.identities,
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
401 })
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
402 affiliation_elt.replaceWith(new_affiliation_elt)
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
403 self._addAffiliationBindings(entity_jid, new_affiliation_elt)
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
404
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
405 def _on_affiliation_set_ok(self, entity_jid, name, affiliation_elt, affiliation):
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
406 if self.invitation_type == 'pubsub':
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
407 service = self.invitation_data["service"]
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
408 node = self.invitation_data["node"]
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
409 bridge.psNodeAffiliationsSet(
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
410 service,
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
411 node,
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
412 {entity_jid: affiliation},
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
413 callback=lambda: self._on_affiliation_set_success(
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
414 entity_jid, name, affiliation_elt, affiliation
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
415 ),
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
416 errback=lambda e: dialog.notification.show(
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
417 f"can't set affiliation: {e}", "error")
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
418 )
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
419 else:
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
420 dialog.notification.show(
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
421 f"error: unknown invitation type: {self.invitation_type}",
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
422 "error"
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
423 )
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
424
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
425 def _on_affiliation_set_cancel(self, evt, notif_elt):
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
426 notif_elt.remove()
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
427 self.open()
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
428
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
429 def on_affiliation_set(self, entity_jid, name, affiliation_elt, affiliation):
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
430 if affiliation == "publisher":
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
431 message = f"Give autorisation to publish to {name}?"
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
432 elif affiliation == "member":
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
433 message = f"Remove autorisation to publish from {name}?"
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
434 else:
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
435 dialog.notification.show(f"unmanaged affiliation: {affiliation}", "error")
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
436 return
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
437 dialog.Confirm(message).show(
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
438 ok_cb=lambda evt, notif_elt:
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
439 self._on_affiliation_set_ok(
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
440 entity_jid, name, affiliation_elt, affiliation
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
441 ),
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
442 cancel_cb=self._on_affiliation_set_cancel
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
443 )
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
444 self.close()