| ... |
... |
@@ -21,6 +21,7 @@ |
|
21
|
21
|
from typing import overload
|
|
22
|
22
|
|
|
23
|
23
|
import cairo
|
|
|
24
|
+from gi.repository.GObject import Value
|
|
24
|
25
|
from nbxmpp.const import Affiliation
|
|
25
|
26
|
from nbxmpp.const import Chatstate
|
|
26
|
27
|
from nbxmpp.const import Role
|
| ... |
... |
@@ -122,6 +123,56 @@ def _on_client_state_changed(self, |
|
122
|
123
|
if state.is_disconnected:
|
|
123
|
124
|
self._reset_presence()
|
|
124
|
125
|
|
|
|
126
|
+ def add_chat_contact(self, jid: Union[str, JID]) -> BareContact:
|
|
|
127
|
+ if isinstance(jid, str):
|
|
|
128
|
+ jid = JID.from_string(jid)
|
|
|
129
|
+
|
|
|
130
|
+ contact = self._contacts.get(jid)
|
|
|
131
|
+ if contact is not None:
|
|
|
132
|
+ if not isinstance(contact, BareContact):
|
|
|
133
|
+ raise ValueError(f'Trying to add GroupchatContact {jid}, '
|
|
|
134
|
+ f'but contact exists already as {contact}')
|
|
|
135
|
+ return contact
|
|
|
136
|
+
|
|
|
137
|
+ contact = BareContact(self._log, jid, self._account)
|
|
|
138
|
+
|
|
|
139
|
+ self._contacts[jid] = contact
|
|
|
140
|
+ return contact
|
|
|
141
|
+
|
|
|
142
|
+ def add_group_chat_contact(self, jid: Union[str, JID]) -> GroupchatContact:
|
|
|
143
|
+ if isinstance(jid, str):
|
|
|
144
|
+ jid = JID.from_string(jid)
|
|
|
145
|
+
|
|
|
146
|
+ contact = self._contacts.get(jid)
|
|
|
147
|
+ if contact is not None:
|
|
|
148
|
+ if not isinstance(contact, GroupchatContact):
|
|
|
149
|
+ raise ValueError(f'Trying to add GroupchatContact {jid}, '
|
|
|
150
|
+ f'but contact exists already as {contact}')
|
|
|
151
|
+ return contact
|
|
|
152
|
+
|
|
|
153
|
+ contact = GroupchatContact(self._log, jid, self._account)
|
|
|
154
|
+
|
|
|
155
|
+ self._contacts[jid] = contact
|
|
|
156
|
+ return contact
|
|
|
157
|
+
|
|
|
158
|
+ def add_private_contact(self, jid: Union[str, JID]) -> GroupchatParticipant:
|
|
|
159
|
+ if isinstance(jid, str):
|
|
|
160
|
+ jid = JID.from_string(jid)
|
|
|
161
|
+
|
|
|
162
|
+ if jid.resource is None:
|
|
|
163
|
+ raise ValueError(f'Trying to add a bare JID as private {jid}')
|
|
|
164
|
+
|
|
|
165
|
+ contact = self._contacts.get(jid.bare)
|
|
|
166
|
+ if not isinstance(contact, GroupchatContact):
|
|
|
167
|
+ raise ValueError(f'Trying to add GroupchatParticipant {jid}, '
|
|
|
168
|
+ f'to BareContact {contact}')
|
|
|
169
|
+
|
|
|
170
|
+ if contact is None:
|
|
|
171
|
+ group_chat_contact = self.add_group_chat_contact(jid.bare)
|
|
|
172
|
+ return group_chat_contact.add_resource(jid.resource)
|
|
|
173
|
+
|
|
|
174
|
+ return contact.add_resource(jid.resource)
|
|
|
175
|
+
|
|
125
|
176
|
def add_contact(self,
|
|
126
|
177
|
jid: Union[str, JID],
|
|
127
|
178
|
groupchat: bool = False) -> Union[BareContact,
|
| ... |
... |
@@ -597,6 +648,10 @@ def add_resource(self, resource: str) -> GroupchatParticipant: |
|
597
|
648
|
# codebase is type checked and it creates hard to track
|
|
598
|
649
|
# problems if we create a GroupchatParticipant without resource
|
|
599
|
650
|
|
|
|
651
|
+ contact = self._resources.get(resource)
|
|
|
652
|
+ if contact is not None:
|
|
|
653
|
+ return contact
|
|
|
654
|
+
|
|
600
|
655
|
jid = self._jid.new_with(resource=resource)
|
|
601
|
656
|
assert isinstance(self._log, LogAdapter)
|
|
602
|
657
|
contact = GroupchatParticipant(self._log, jid, self._account)
|