tray notification on gc invite

This commit is contained in:
ingvar1995 2018-07-28 18:16:26 +03:00
parent 184ba55aed
commit 603dfd40b5

View file

@ -363,7 +363,8 @@ def group_message(window, tray, tox, messenger, settings, profile):
def wrapped(tox_link, group_number, peer_id, message_type, message, length, user_data): def wrapped(tox_link, group_number, peer_id, message_type, message, length, user_data):
message = str(message[:length], 'utf-8') message = str(message[:length], 'utf-8')
invoke_in_main_thread(messenger.new_group_message, group_number, message_type, message, peer_id) invoke_in_main_thread(messenger.new_group_message, group_number, message_type, message, peer_id)
if not window.isActiveWindow(): if window.isActiveWindow():
return
bl = settings['notify_all_gc'] or profile.name in message bl = settings['notify_all_gc'] or profile.name in message
name = tox.group_peer_get_name(group_number, peer_id) name = tox.group_peer_get_name(group_number, peer_id)
if settings['notifications'] and profile.status != TOX_USER_STATUS['BUSY'] and (not settings.locked) and bl: if settings['notifications'] and profile.status != TOX_USER_STATUS['BUSY'] and (not settings.locked) and bl:
@ -372,6 +373,7 @@ def group_message(window, tray, tox, messenger, settings, profile):
sound_notification(SOUND_NOTIFICATION['MESSAGE']) sound_notification(SOUND_NOTIFICATION['MESSAGE'])
icon = os.path.join(util.get_images_directory(), 'icon_new_messages.png') icon = os.path.join(util.get_images_directory(), 'icon_new_messages.png')
invoke_in_main_thread(tray.setIcon, QtGui.QIcon(icon)) invoke_in_main_thread(tray.setIcon, QtGui.QIcon(icon))
return wrapped return wrapped
@ -382,7 +384,8 @@ def group_private_message(window, tray, tox, messenger, settings, profile):
def wrapped(tox_link, group_number, peer_id, message_type, message, length, user_data): def wrapped(tox_link, group_number, peer_id, message_type, message, length, user_data):
message = str(message[:length], 'utf-8') message = str(message[:length], 'utf-8')
invoke_in_main_thread(messenger.new_group_private_message, group_number, message_type, message, peer_id) invoke_in_main_thread(messenger.new_group_private_message, group_number, message_type, message, peer_id)
if not window.isActiveWindow(): if window.isActiveWindow():
return
bl = settings['notify_all_gc'] or profile.name in message bl = settings['notify_all_gc'] or profile.name in message
name = tox.group_peer_get_name(group_number, peer_id) name = tox.group_peer_get_name(group_number, peer_id)
if settings['notifications'] and profile.status != TOX_USER_STATUS['BUSY'] and (not settings.locked) and bl: if settings['notifications'] and profile.status != TOX_USER_STATUS['BUSY'] and (not settings.locked) and bl:
@ -395,12 +398,21 @@ def group_private_message(window, tray, tox, messenger, settings, profile):
return wrapped return wrapped
def group_invite(groups_service): def group_invite(window, settings, tray, profile, groups_service, contacts_provider):
def wrapped(tox, friend_number, invite_data, length, group_name, group_name_length, user_data): def wrapped(tox, friend_number, invite_data, length, group_name, group_name_length, user_data):
group_name = bytes(group_name[:group_name_length]) group_name = str(bytes(group_name[:group_name_length]), 'utf-8')
invoke_in_main_thread(groups_service.process_group_invite, invoke_in_main_thread(groups_service.process_group_invite,
friend_number, str(group_name, 'utf-8'), friend_number, group_name,
bytes(invite_data[:length])) bytes(invite_data[:length]))
if window.isActiveWindow():
return
if settings['notifications'] and profile.status != TOX_USER_STATUS['BUSY'] and not settings.locked:
friend = contacts_provider.get_friend_by_number(friend_number)
title = util_ui.tr('New invite to group chat')
text = util_ui.tr('{} invites you to group {}').format(friend.name, group_name)
invoke_in_main_thread(tray_notification, title, text, tray, window)
icon = os.path.join(util.get_images_directory(), 'icon_new_messages.png')
invoke_in_main_thread(tray.setIcon, QtGui.QIcon(icon))
return wrapped return wrapped
@ -552,7 +564,7 @@ def init_callbacks(tox, profile, settings, plugin_loader, contacts_manager,
# gc callbacks # gc callbacks
tox.callback_group_message(group_message(main_window, tray, tox, messenger, settings, profile), 0) tox.callback_group_message(group_message(main_window, tray, tox, messenger, settings, profile), 0)
tox.callback_group_private_message(group_private_message(main_window, tray, tox, messenger, settings, profile), 0) tox.callback_group_private_message(group_private_message(main_window, tray, tox, messenger, settings, profile), 0)
tox.callback_group_invite(group_invite(groups_service), 0) tox.callback_group_invite(group_invite(main_window, settings, tray, profile, groups_service, contacts_provider), 0)
tox.callback_group_self_join(group_self_join(contacts_provider, groups_service), 0) tox.callback_group_self_join(group_self_join(contacts_provider, groups_service), 0)
tox.callback_group_peer_join(group_peer_join(contacts_provider, groups_service), 0) tox.callback_group_peer_join(group_peer_join(contacts_provider, groups_service), 0)
tox.callback_group_peer_exit(group_peer_exit(contacts_provider, groups_service, contacts_manager), 0) tox.callback_group_peer_exit(group_peer_exit(contacts_provider, groups_service, contacts_manager), 0)