Commit 93d4e512 authored by Philipp Hörist's avatar Philipp Hörist

Contacts: Add can_notify() method for group chats

parent 4493fead
Pipeline #5985 passed with stages
in 4 minutes and 47 seconds
......@@ -1138,7 +1138,7 @@ class ChatControlBase(ChatCommandProcessor, CommandTools, EventHelper):
if kind == 'incoming':
if (not self._type.is_groupchat or
helpers.notify_for_muc(jid) or
self.contact.can_notify() or
'marked' in other_tags_for_text):
# it's a normal message, or a muc message with want to be
# notified about if quitting just after
......@@ -1176,7 +1176,7 @@ class ChatControlBase(ChatCommandProcessor, CommandTools, EventHelper):
event = 'message_received'
show_in_roster = get_show_in_roster(event, self.session)
show_in_systray = get_show_in_systray(
event_type.type_, self.contact.jid)
event_type.type_, self.account, self.contact.jid)
event = event_type(text,
subject,
......
......@@ -305,8 +305,9 @@ class NotificationEvent(nec.NetworkIncomingEvent):
self.control_focused = self.control.has_focus()
if app.config.get('notify_on_new_message'):
notify_for_muc = (helpers.notify_for_muc(self.jid) or
sound == 'highlight')
contact = app.contacts.get_groupchat_contact(self.account,
self.jid)
notify_for_muc = sound == 'highlight' or contact.can_notify()
if not notify_for_muc:
self.do_popup = False
......
......@@ -243,6 +243,14 @@ class Contact(CommonContact):
# if not '@' or '@' starts the jid then contact is transport
return self.jid.find('@') <= 0
def can_notify(self):
if not self.is_groupchat:
raise ValueError
all_ = app.config.get('notify_on_all_muc_messages')
room = app.config.get_per('rooms', self.jid, 'notify_on_all_messages')
return all_ or room
class GC_Contact(CommonContact):
"""
......
......@@ -1434,9 +1434,3 @@ def should_log(account, jid):
no_log_for = no_log_for.split()
return (account not in no_log_for) and (jid not in no_log_for)
def notify_for_muc(room):
all_ = app.config.get('notify_on_all_muc_messages')
room = app.config.get_per('rooms', room, 'notify_on_all_messages')
return all_ or room
......@@ -962,7 +962,7 @@ class GroupchatControl(ChatControlBase):
def get_nb_unread(self):
type_events = ['printed_marked_gc_msg']
if helpers.notify_for_muc(self.room_jid):
if self.contact.can_notify():
type_events.append('printed_gc_msg')
nb = len(app.events.get_events(self.account,
self.room_jid,
......@@ -984,7 +984,7 @@ class GroupchatControl(ChatControlBase):
"""
highlight, sound = None, None
notify = helpers.notify_for_muc(self.room_jid)
notify = self.contact.can_notify()
message_sound_enabled = app.config.get_per('soundevents',
'muc_message_received',
'enabled')
......
......@@ -48,7 +48,6 @@ from gajim.common import configpaths
from gajim.common import i18n
from gajim.common.i18n import _
from gajim.common.helpers import URL_REGEX
from gajim.common.helpers import notify_for_muc
from gajim.common.const import MOODS
from gajim.common.const import ACTIVITIES
from gajim.common.const import LOCATION_DATA
......@@ -497,12 +496,14 @@ def get_show_in_roster(event, session=None):
return True
def get_show_in_systray(type_, jid):
def get_show_in_systray(type_, account, jid):
"""
Return True if this event must be shown in systray, else False
"""
notify = notify_for_muc(jid)
if type_ == 'printed_gc_msg' and not notify:
if type_ == 'printed_gc_msg':
contact = app.contacts.get_groupchat_contact(account, jid)
if contact is not None:
return contact.can_notify()
# it's not an highlighted message, don't show in systray
return False
return app.config.get('trayicon_notification_on_events')
......
......@@ -1058,7 +1058,7 @@ class Interface:
'file-completed': 'ft_finished'}
event_type = event_types.get(event.type_)
show_in_roster = get_show_in_roster(event_type, jid)
show_in_systray = get_show_in_systray(event_type, jid)
show_in_systray = get_show_in_systray(event_type, account, jid)
event.show_in_roster = show_in_roster
event.show_in_systray = show_in_systray
app.events.add_event(account, jid, event)
......
......@@ -36,7 +36,6 @@ from gajim.common import app
from gajim.common import ged
from gajim.common.i18n import Q_
from gajim.common.i18n import _
from gajim.common.helpers import notify_for_muc
from gajim.common.nec import EventHelper
from gajim import gtkgui_helpers
......@@ -492,8 +491,8 @@ class MessageWindow(EventHelper):
unread = 0
for ctrl in self.controls():
if (ctrl.is_groupchat and
not notify_for_muc(ctrl.room_jid) and
not ctrl.attention_flag):
not ctrl.contact.can_notify() and
not ctrl.attention_flag):
# count only pm messages
unread += ctrl.get_nb_unread_pm()
continue
......@@ -510,7 +509,7 @@ class MessageWindow(EventHelper):
if control.is_groupchat:
name = control.contact.get_shown_name()
urgent = (control.attention_flag or
notify_for_muc(control.room_jid))
control.contact.can_notify())
else:
name = control.contact.get_shown_name()
if control.resource:
......
......@@ -884,8 +884,12 @@ class GajimRemote(Server):
def get_unread_msgs_number(self):
unread = app.events.get_nb_events()
for event in app.events.get_all_events(['printed_gc_msg']):
if not helpers.notify_for_muc(event.jid):
contact = app.contacts.get_groupchat_contact(event.account,
event.jid)
if contact is None or not contact.can_notify():
unread -= 1
continue
return str(unread)
def start_chat(self, jid=''):
......
......@@ -2368,7 +2368,9 @@ class RosterWindow:
unread = app.events.get_nb_events()
for event in app.events.get_all_events(['printed_gc_msg']):
if not helpers.notify_for_muc(event.jid):
contact = app.contacts.get_groupchat_contact(event.account,
event.jid)
if contact is None or not contact.can_notify():
unread -= 1
# check if we have recent messages
......
......@@ -218,7 +218,9 @@ class ChatControlSession:
else:
# 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)
obj.show_in_systray = get_show_in_systray(event_type,
obj.conn.name,
contact.jid)
do_event = True
if do_event:
kind = obj.properties.type.value
......@@ -321,7 +323,9 @@ class ChatControlSession:
event_type = 'message_received'
show_in_roster = get_show_in_roster(event_type, self)
show_in_systray = get_show_in_systray(event_type, contact.jid)
show_in_systray = get_show_in_systray(event_type,
self.conn.name,
contact.jid)
event = event_t(msg, subject, msg_type, tim, resource,
msg_log_id, session=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