Commit 79cb44c7 authored by Daniel Brötzmann's avatar Daniel Brötzmann Committed by Philipp Hörist

Improvements 2

parent 9d722383
Pipeline #6737 passed with stages
in 3 minutes and 49 seconds
......@@ -1165,7 +1165,7 @@ def add_message(self,
if message_id:
if self._type.is_groupchat:
self.last_msg_id = stanza_id
self.last_msg_id = stanza_id or message_id
else:
self.last_msg_id = message_id
......
......@@ -14,13 +14,13 @@
# Chat Markers (XEP-0333)
import nbxmpp
from nbxmpp.namespaces import Namespace
from nbxmpp.structs import StanzaHandler
from gajim.common import app
from gajim.common.nec import NetworkEvent
from gajim.common.modules.base import BaseModule
from gajim.common.structs import OutgoingMessage
class ChatMarkers(BaseModule):
......@@ -91,8 +91,14 @@ def _send_marker(self, contact, marker, id_, type_):
jid = app.get_jid_without_resource(contact.jid)
if type_ in ('gc', 'pm'):
disco_info = app.storage.cache.get_last_disco_info(jid)
context = 'public'
if disco_info is not None and disco_info.muc_is_members_only:
context = 'private'
if not app.settings.get_group_chat_setting(
self._account, jid, 'send_marker'):
self._account, jid, 'send_marker', context=context):
return
else:
if not app.settings.get_contact_setting(
......@@ -100,10 +106,14 @@ def _send_marker(self, contact, marker, id_, type_):
return
typ = 'groupchat' if type_ == 'gc' else 'chat'
message = nbxmpp.Message(to=contact.jid, typ=typ)
message.setMarker(marker, id_)
message = OutgoingMessage(account=self._account,
contact=contact,
message=None,
type_=typ,
marker=(marker, id_),
play_sound=False)
self._con.send_message(message)
self._log.info('Send %s: %s', marker, contact.jid)
self._nbxmpp().send(message)
def send_displayed_marker(self, contact, id_, type_):
self._send_marker(contact, 'displayed', id_, str(type_))
......
......@@ -308,8 +308,6 @@ def build_message_stanza(self, message):
stanza.setID(message.message_id)
stanza.setOriginID(message.message_id)
stanza.setMarkable()
if message.label:
stanza.addChild(node=message.label.to_node())
......@@ -355,6 +353,9 @@ def build_message_stanza(self, message):
# XEP-0333
if message.message:
stanza.setMarkable()
if message.marker:
marker, id_ = message.marker
stanza.setMarker(marker, id_)
# Add other nodes
if message.nodes is not None:
......
......@@ -678,11 +678,13 @@ def set_group_chat_setting(self,
def set_group_chat_settings(self,
setting: str,
value: SETTING_TYPE) -> None:
value: SETTING_TYPE,
context: str = None) -> None:
for account in self._account_settings:
for jid in self._account_settings[account]['group_chat']:
self.set_group_chat_setting(account, jid, setting, value)
self.set_group_chat_setting(
account, jid, setting, value, context)
def get_contact_setting(self,
account: str,
......
......@@ -55,6 +55,7 @@ def __init__(self,
type_,
subject=None,
chatstate=None,
marker=None,
resource=None,
user_nick=None,
label=None,
......@@ -69,7 +70,7 @@ def __init__(self,
if type_ not in ('chat', 'groupchat', 'normal', 'headline'):
raise ValueError('Unknown message type: %s' % type_)
if not message and chatstate is None:
if not message and chatstate is None and marker is None:
raise ValueError('Trying to send message without content')
self.account = account
......@@ -91,6 +92,7 @@ def __init__(self,
self.subject = subject
self.chatstate = chatstate
self.marker = marker
self.resource = resource
self.user_nick = user_nick
self.label = label
......
......@@ -807,13 +807,16 @@ def _on_gc_message_received(self, event):
else:
if event.properties.muc_nickname == self.nick:
self.last_sent_txt = event.msgtxt
stanza_id = None
if event.properties.stanza_id:
stanza_id = event.properties.stanza_id.id
self.add_message(event.msgtxt,
contact=event.properties.muc_nickname,
tim=event.properties.timestamp,
displaymarking=event.displaymarking,
correct_id=event.correct_id,
message_id=event.properties.id,
stanza_id=event.properties.stanza_id.id,
stanza_id=stanza_id,
additional_data=event.additional_data)
event.needs_highlight = self.needs_visual_notification(event.msgtxt)
......
......@@ -730,7 +730,7 @@ def __init__(self, account):
'button-style': 'destructive-action',
'button-callback': self._reset_gc_send_chatstate}),
Setting(SettingKind.SWITCH,
Setting(SettingKind.SWITCH,
_('Send Read Markers'),
SettingType.VALUE,
app.settings.get_account_setting(
......@@ -771,7 +771,8 @@ def _send_read_marker(self, state, _data):
def _reset_send_read_marker(self, button):
button.set_sensitive(False)
app.settings.set_contact_settings('send_marker', None)
# app.settings.set_group_chat_settings('send_marker', None)
app.settings.set_group_chat_settings(
'send_marker', None, context='private')
for ctrl in app.interface.msg_win_mgr.get_controls(acct=self._account):
ctrl.update_actions()
......
......@@ -267,7 +267,7 @@ def handle_event_read_state_sync(event):
return
if event.type.is_groupchat:
id_ = events_[-1].stanza_id
id_ = events_[-1].stanza_id or events_[-1].message_id
else:
id_ = events_[-1].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