Commit df7fd262 authored by Philipp Hörist's avatar Philipp Hörist

Use nbxmpp properties attributes

parent cf55edfc
......@@ -789,7 +789,7 @@ def _nec_mam_decrypted_message_received(self, obj):
if obj.conn.name != self.account:
return
if obj.muc_pm:
if obj.properties.is_muc_pm:
if not obj.with_ == self.contact.get_full_jid():
return
else:
......@@ -810,14 +810,12 @@ def _nec_decrypted_message_received(self, obj):
return True
if obj.conn.name != self.account:
return
if obj.mtype != 'chat':
if not obj.properties.type.is_chat:
return
if obj.session.control != self:
return
typ = ''
if obj.mtype == 'error':
typ = 'error'
if obj.forwarded and obj.sent:
typ = 'out'
......@@ -1286,10 +1284,7 @@ def read_queue(self):
for event in events:
if event.type_ != self.type_id:
continue
if event.kind == 'error':
kind = 'info'
else:
kind = 'print_queue'
kind = 'print_queue'
if event.sent_forwarded:
kind = 'out'
self.add_message(event.message, kind, tim=event.time,
......
......@@ -330,20 +330,23 @@ def handle_incoming_msg_event(self, msg_obj):
if not msg_obj.msgtxt:
return
self.jid = msg_obj.jid
if msg_obj.mtype == 'pm':
if msg_obj.properties.is_muc_pm:
self.jid = msg_obj.fjid
self.control = app.interface.msg_win_mgr.search_control(
msg_obj.jid, self.account, msg_obj.resource)
if self.control is None:
event_type = msg_obj.properties.type.value
if msg_obj.properties.is_muc_pm:
event_type = 'pm'
if len(app.events.get_events(
self.account, msg_obj.jid, [msg_obj.mtype])) <= 1:
self.account, msg_obj.jid, [event_type])) <= 1:
self.first_unread = True
else:
self.control_focused = self.control.has_focus()
if msg_obj.mtype == 'pm':
if msg_obj.properties.is_muc_pm:
nick = msg_obj.resource
else:
nick = app.get_name_from_jid(self.conn.name, self.jid)
......@@ -364,10 +367,10 @@ def handle_incoming_msg_event(self, msg_obj):
# We don't want message preview, do_preview = False
self.popup_text = ''
if msg_obj.mtype == 'normal': # single message
if msg_obj.properties.type.is_normal: # single message
self.popup_msg_type = 'normal'
self.popup_event_type = _('New Single Message')
elif msg_obj.mtype == 'pm':
elif msg_obj.properties.is_muc_pm:
self.popup_msg_type = 'pm'
self.popup_event_type = _('New Private Message')
else: # chat message
......
......@@ -236,7 +236,6 @@ def _mam_message_received(self, _con, stanza, properties):
'timestamp': properties.mam.timestamp,
'self_message': properties.is_self_message,
'groupchat': groupchat,
'muc_pm': properties.is_muc_pm,
'stanza_id': stanza_id,
'origin_id': message_id,
'message_id': properties.id,
......
......@@ -189,14 +189,12 @@ def _message_received(self, _con, stanza, properties):
'unique_id': stanza_id or message_id,
'message_id': properties.id,
'correct_id': parse_correction(properties),
'mtype': type_.value,
'msgtxt': msgtxt,
'thread_id': thread_id,
'session': session,
'self_message': properties.is_self_message,
'timestamp': properties.timestamp,
'delayed': properties.user_timestamp is not None,
'muc_pm': properties.is_muc_pm,
'gc_control': gc_control,
'attention': properties.attention,
'xhtml': xhtml,
......@@ -205,6 +203,7 @@ def _message_received(self, _con, stanza, properties):
'popup': False,
'msg_log_id': None,
'displaymarking': parse_securitylabel(stanza),
'properties': properties,
}
if type_.is_groupchat:
......@@ -247,9 +246,6 @@ def _message_error_received(self, _con, _stanza, properties):
error=properties.error))
def _log_muc_message(self, event):
if event.mtype == 'error':
return
self._check_for_mam_compliance(event.room_jid, event.stanza_id)
if (app.config.should_log(self._account, event.jid) and
......
......@@ -106,12 +106,10 @@ def _messageCB(self, con, stanza, properties):
'unique_id': id_,
'message_id': properties.id,
'correct_id': parse_correction(properties),
'mtype': type_,
'msgtxt': msgtxt,
'thread_id': thread_id,
'session': session,
'self_message': False,
'muc_pm': False,
'gc_control': None,
'attention': properties.attention,
'xhtml': parse_xhtml(properties),
......
......@@ -123,9 +123,9 @@ def _nec_our_status(self, obj):
@staticmethod
def _get_icon_name(obj):
if obj.notif_type == 'msg':
if obj.base_event.mtype == 'pm':
if obj.base_event.properties.is_muc_pm:
return 'gajim-priv_msg_recv'
if obj.base_event.mtype == 'normal':
if obj.base_event.properties.type.is_normal:
return 'gajim-single_msg_recv'
elif obj.notif_type == 'pres':
......
......@@ -373,9 +373,12 @@ def on_gc_message_received(self, obj):
obj.displaymarking, obj.needs_highlight]))
def _nec_decrypted_message_received(self, obj):
event_type = obj.properties.type.value
if obj.properties.is_muc_pm:
event_type = 'pm'
self.raise_signal('NewMessage', (
obj.conn.name, [obj.fjid, obj.msgtxt, obj.timestamp,
obj.encrypted, obj.mtype, obj.subject,
obj.encrypted, event_type, obj.subject,
obj.msg_log_id, obj.user_nick, obj.xhtml]))
def on_our_status(self, obj):
......
......@@ -2652,23 +2652,23 @@ def _nec_signed_in(self, obj):
def _nec_decrypted_message_received(self, obj):
if not obj.msgtxt:
return True
if obj.mtype not in ('normal', 'chat'):
if obj.properties.type.value not in ('normal', 'chat'):
return
if obj.mtype == 'normal' and obj.popup:
if obj.properties.type.is_normal and obj.popup:
# it's single message to be autopopuped
SingleMessageWindow(obj.conn.name, obj.jid,
action='receive', from_whom=obj.jid, subject=obj.subject,
message=obj.msgtxt, resource=obj.resource, session=obj.session)
return
if obj.popup and obj.mtype == 'chat' and not obj.session.control:
if obj.popup and obj.properties.type.is_chat and not obj.session.control:
contact = app.contacts.get_contact(obj.conn.name, obj.jid)
obj.session.control = app.interface.new_chat(contact,
obj.conn.name, session=obj.session)
if app.events.get_events(obj.conn.name, obj.fjid):
obj.session.control.read_queue()
if obj.show_in_roster:
if not obj.properties.is_muc_pm and obj.show_in_roster:
self.draw_contact(obj.jid, obj.conn.name)
self.show_title() # we show the * or [n]
# Select the big brother contact in roster, it's visible because it
......
......@@ -83,7 +83,7 @@ def _nec_decrypted_message_received(self, obj):
if obj.session != self:
return
if obj.muc_pm:
if obj.properties.is_muc_pm:
contact = app.contacts.get_gc_contact(
self.conn.name, obj.jid, obj.resource)
else:
......@@ -100,7 +100,7 @@ def _nec_decrypted_message_received(self, obj):
if self.control.resource:
self.control.change_resource(self.resource)
if obj.mtype == 'chat':
if obj.properties.type.is_chat:
if not obj.msgtxt:
return
......@@ -115,11 +115,6 @@ def _nec_decrypted_message_received(self, obj):
treat_as = app.config.get('treat_incoming_messages')
if treat_as:
obj.mtype = treat_as
pm = False
if obj.muc_pm or (obj.gc_control and obj.resource):
# It's a Private message
pm = True
obj.mtype = 'pm'
if self.is_loggable() and obj.msgtxt:
if obj.xhtml and app.config.get('log_xhtml_messages'):
......@@ -128,7 +123,7 @@ def _nec_decrypted_message_received(self, obj):
msg_to_log = obj.msgtxt
jid = obj.fjid
if not pm:
if not obj.properties.is_muc_pm:
jid = obj.jid
obj.msg_log_id = app.logger.insert_into_logs(
......@@ -139,7 +134,7 @@ def _nec_decrypted_message_received(self, obj):
stanza_id=obj.unique_id,
message_id=obj.message_id)
if obj.muc_pm and not obj.gc_control:
if obj.properties.is_muc_pm and not obj.gc_control:
# This is a carbon of a PM from a MUC we are not currently
# joined. We log it silently without notification.
return True
......@@ -159,7 +154,7 @@ def _nec_decrypted_message_received(self, obj):
else:
self.control.contact = contact
if not pm:
if not obj.properties.is_muc_pm:
self.roster_message2(obj)
def roster_message2(self, obj):
......@@ -216,11 +211,11 @@ def roster_message2(self, obj):
event_t = events.ChatEvent
event_type = 'message_received'
if obj.mtype == 'normal':
if obj.properties.type.is_normal:
event_t = events.NormalEvent
event_type = 'single_message_received'
if self.control and obj.mtype != 'normal':
if self.control and not obj.properties.type.is_normal:
# We have a ChatControl open
obj.show_in_roster = False
obj.show_in_systray = False
......@@ -241,12 +236,13 @@ def roster_message2(self, obj):
# Everything else
obj.show_in_roster = get_show_in_roster(event_type, self)
obj.show_in_systray = get_show_in_systray(event_type, contact.jid)
if obj.mtype == 'normal' and obj.popup:
if obj.properties.type.is_normal and obj.popup:
do_event = False
else:
do_event = True
if do_event:
event = event_t(obj.msgtxt, obj.subject, obj.mtype, obj.timestamp,
kind = obj.properties.type.value
event = event_t(obj.msgtxt, obj.subject, kind, obj.timestamp,
obj.encrypted, obj.resource, obj.msg_log_id,
correct_id=obj.correct_id,
message_id=obj.message_id,
......
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