Commit 1e37e384 authored by Philipp Hörist's avatar Philipp Hörist

Improve code

parent 8914a8af
Pipeline #4356 passed with stages
in 3 minutes and 6 seconds
......@@ -1640,6 +1640,7 @@ class Connection(CommonConnection, ConnectionHandlers):
msg_iq.setID(obj.stanza_id)
if obj.message:
msg_iq.setOriginID(obj.stanza_id)
msg_iq.setMarkable()
if obj.correct_id:
msg_iq.setTag('replace', attrs={'id': obj.correct_id},
......
......@@ -31,36 +31,61 @@ class ChatMarkers(BaseModule):
self.handlers = [
StanzaHandler(name='message',
callback=self._process_message_marker,
callback=self._process_read_state_sync,
ns=nbxmpp.NS_CHATMARKERS,
priority=47),
StanzaHandler(name='message',
callback=self._process_chat_marker,
ns=nbxmpp.NS_CHATMARKERS,
priority=48),
]
def _process_message_marker(self, _con, _stanza, properties):
if not properties.is_displayed_marker:
def _process_read_state_sync(self, _con, _stanza, properties):
if not properties.is_marker:
return
if not properties.marker.is_displayed:
return
if properties.type.is_error:
return
if (not properties.type.is_groupchat and
properties.carbon_type != 'sent'):
# Only act on displayed marker received by own devices for now
if properties.is_mam_message:
return
self._log.info('%s: %s %s',
if properties.type.is_groupchat:
manager = self._con.get_module('MUC').get_manager()
muc_data = manager.get(properties.muc_jid)
if muc_data is None:
return
if properties.muc_nickname != muc_data.nick:
return
elif not properties.is_carbon_message or not properties.carbon.is_sent:
return
self._log.info('Read state sync: %s %s',
properties.jid,
properties.marker.type,
properties.marker.id)
app.nec.push_outgoing_event(
NetworkEvent('displayed-marker-received',
NetworkEvent('read-state-sync',
account=self._account,
jid=properties.jid,
properties=properties,
type=properties.type,
is_muc_pm=properties.is_muc_pm,
marker_id=properties.marker.id))
raise nbxmpp.NodeProcessed
def _process_chat_marker(self, _con, _stanza, properties):
if not properties.is_marker:
return
# TODO: Implement showing displayed state in ConversationsTextview
raise nbxmpp.NodeProcessed
def send_marker(self, jid, marker, id_, is_gc):
if is_gc:
message = nbxmpp.Message(to=jid, typ='groupchat')
......
......@@ -285,24 +285,14 @@ class Interface:
if ctrl and ctrl.session and len(obj.contact_list) > 1:
ctrl.remove_session(ctrl.session)
def handle_event_chat_marker_received(self, event):
def handle_event_read_state_sync(self, event):
if event.type.is_groupchat:
control = self.get_groupchat_control(event.account, event.jid)
control = self.get_groupchat_control(event.account,
event.jid.getBare())
if control is None:
log.warning('Groupchat control not found')
return
con = app.connections[event.account]
manager = con.get_module('MUC').get_manager()
muc_data = manager.get(event.jid.getBare())
if muc_data is None:
log.warning('Unknown MUC')
return
if event.jid.getResource() != muc_data.nick:
return
jid = event.jid.getBare()
types = ['printed_gc_msg', 'printed_marked_gc_msg']
......@@ -325,7 +315,7 @@ class Interface:
if not app.events.remove_events(event.account, jid, types=types):
# There were events to remove
if control is None:
if control is not None:
control.redraw_after_event_removed(event.jid)
def handle_event_msgerror(self, obj):
......@@ -1216,7 +1206,7 @@ class Interface:
'unsubscribed-presence-received': [
self.handle_event_unsubscribed_presence],
'zeroconf-name-conflict': [self.handle_event_zc_name_conflict],
'displayed-marker-received': [self.handle_event_chat_marker_received],
'read-state-sync': [self.handle_event_read_state_sync],
}
def register_core_handlers(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment