incoming messages
This commit is contained in:
parent
f13274882a
commit
4f42098d56
@ -291,8 +291,23 @@ def callback_audio(toxav, friend_number, samples, audio_samples_per_channel, aud
|
|||||||
# Callbacks - group chats
|
# Callbacks - group chats
|
||||||
# -----------------------------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
def group_message(tox, group_number, peer_id, message, length, user_data):
|
def group_message(window, tray):
|
||||||
pass
|
"""
|
||||||
|
New message from friend
|
||||||
|
"""
|
||||||
|
def wrapped(tox, group_number, peer_id, message_type, message, length, user_data):
|
||||||
|
profile = Profile.get_instance()
|
||||||
|
settings = Settings.get_instance()
|
||||||
|
message = str(message, 'utf-8')
|
||||||
|
invoke_in_main_thread(profile.new_message, group_number, message_type, message, True)
|
||||||
|
if not window.isActiveWindow():
|
||||||
|
bl = settings['notify_all_gc'] or profile.name in message
|
||||||
|
if settings['notifications'] and profile.status != TOX_USER_STATUS['BUSY'] and not settings.locked and bl:
|
||||||
|
invoke_in_main_thread(tray_notification, '', message, tray, window) # TODO: friend name
|
||||||
|
if (settings['sound_notifications'] or bl) and profile.status != TOX_USER_STATUS['BUSY']:
|
||||||
|
sound_notification(SOUND_NOTIFICATION['MESSAGE'])
|
||||||
|
invoke_in_main_thread(tray.setIcon, QtGui.QIcon(curr_directory() + '/images/icon_new_messages.png'))
|
||||||
|
return wrapped
|
||||||
|
|
||||||
|
|
||||||
def group_invite(tox, friend_number, invite_data, length, user_data):
|
def group_invite(tox, friend_number, invite_data, length, user_data):
|
||||||
@ -337,3 +352,6 @@ def init_callbacks(tox, window, tray):
|
|||||||
tox.callback_friend_lossless_packet(lossless_packet, 0)
|
tox.callback_friend_lossless_packet(lossless_packet, 0)
|
||||||
tox.callback_friend_lossy_packet(lossy_packet, 0)
|
tox.callback_friend_lossy_packet(lossy_packet, 0)
|
||||||
|
|
||||||
|
tox.callback_group_message(group_message(window, tray), 0)
|
||||||
|
tox.callback_group_invite(group_invite, 0)
|
||||||
|
|
||||||
|
@ -560,28 +560,33 @@ class NotificationsSettings(CenteredWidget):
|
|||||||
|
|
||||||
def initUI(self):
|
def initUI(self):
|
||||||
self.setObjectName("notificationsForm")
|
self.setObjectName("notificationsForm")
|
||||||
self.resize(350, 180)
|
self.resize(350, 200)
|
||||||
self.setMinimumSize(QtCore.QSize(350, 180))
|
self.setMinimumSize(QtCore.QSize(350, 200))
|
||||||
self.setMaximumSize(QtCore.QSize(350, 180))
|
self.setMaximumSize(QtCore.QSize(350, 200))
|
||||||
self.enableNotifications = QtGui.QCheckBox(self)
|
self.enableNotifications = QtGui.QCheckBox(self)
|
||||||
self.enableNotifications.setGeometry(QtCore.QRect(10, 20, 340, 18))
|
self.enableNotifications.setGeometry(QtCore.QRect(10, 20, 340, 18))
|
||||||
self.callsSound = QtGui.QCheckBox(self)
|
self.callsSound = QtGui.QCheckBox(self)
|
||||||
self.callsSound.setGeometry(QtCore.QRect(10, 120, 340, 18))
|
self.callsSound.setGeometry(QtCore.QRect(10, 120, 340, 18))
|
||||||
self.soundNotifications = QtGui.QCheckBox(self)
|
self.soundNotifications = QtGui.QCheckBox(self)
|
||||||
self.soundNotifications.setGeometry(QtCore.QRect(10, 70, 340, 18))
|
self.soundNotifications.setGeometry(QtCore.QRect(10, 70, 340, 18))
|
||||||
|
self.gcNotifications = QtGui.QCheckBox(self)
|
||||||
|
self.gcNotifications.setGeometry(QtCore.QRect(10, 170, 340, 18))
|
||||||
font = QtGui.QFont()
|
font = QtGui.QFont()
|
||||||
font.setPointSize(12)
|
font.setPointSize(12)
|
||||||
self.callsSound.setFont(font)
|
self.callsSound.setFont(font)
|
||||||
self.soundNotifications.setFont(font)
|
self.soundNotifications.setFont(font)
|
||||||
self.enableNotifications.setFont(font)
|
self.enableNotifications.setFont(font)
|
||||||
|
self.gcNotifications.setFont(font)
|
||||||
s = Settings.get_instance()
|
s = Settings.get_instance()
|
||||||
self.enableNotifications.setChecked(s['notifications'])
|
self.enableNotifications.setChecked(s['notifications'])
|
||||||
self.soundNotifications.setChecked(s['sound_notifications'])
|
self.soundNotifications.setChecked(s['sound_notifications'])
|
||||||
self.callsSound.setChecked(s['calls_sound'])
|
self.callsSound.setChecked(s['calls_sound'])
|
||||||
|
self.gcNotifications.setChecked(s['notify_all_gc'])
|
||||||
self.retranslateUi()
|
self.retranslateUi()
|
||||||
QtCore.QMetaObject.connectSlotsByName(self)
|
QtCore.QMetaObject.connectSlotsByName(self)
|
||||||
|
|
||||||
def retranslateUi(self):
|
def retranslateUi(self):
|
||||||
|
self.gcNotifications.setText(QtGui.QApplication.translate("notificationsForm", "Enable group chat notifications", None, QtGui.QApplication.UnicodeUTF8))
|
||||||
self.setWindowTitle(QtGui.QApplication.translate("notificationsForm", "Notification settings", None, QtGui.QApplication.UnicodeUTF8))
|
self.setWindowTitle(QtGui.QApplication.translate("notificationsForm", "Notification settings", None, QtGui.QApplication.UnicodeUTF8))
|
||||||
self.enableNotifications.setText(QtGui.QApplication.translate("notificationsForm", "Enable notifications", None, QtGui.QApplication.UnicodeUTF8))
|
self.enableNotifications.setText(QtGui.QApplication.translate("notificationsForm", "Enable notifications", None, QtGui.QApplication.UnicodeUTF8))
|
||||||
self.callsSound.setText(QtGui.QApplication.translate("notificationsForm", "Enable call\'s sound", None, QtGui.QApplication.UnicodeUTF8))
|
self.callsSound.setText(QtGui.QApplication.translate("notificationsForm", "Enable call\'s sound", None, QtGui.QApplication.UnicodeUTF8))
|
||||||
|
@ -41,6 +41,7 @@ class Profile(basecontact.BaseContact, Singleton):
|
|||||||
self._call = calls.AV(tox.AV) # object with data about calls
|
self._call = calls.AV(tox.AV) # object with data about calls
|
||||||
self._incoming_calls = set()
|
self._incoming_calls = set()
|
||||||
self._load_history = True
|
self._load_history = True
|
||||||
|
self._gc_invites = {} # dict of gc invites. key - friend number, value - list of gc data
|
||||||
settings = Settings.get_instance()
|
settings = Settings.get_instance()
|
||||||
self._show_online = settings['show_online_friends']
|
self._show_online = settings['show_online_friends']
|
||||||
screen.online_contacts.setCurrentIndex(int(self._show_online))
|
screen.online_contacts.setCurrentIndex(int(self._show_online))
|
||||||
@ -383,25 +384,28 @@ class Profile(basecontact.BaseContact, Singleton):
|
|||||||
else:
|
else:
|
||||||
self._tox.group_send_message(number, message_type, message)
|
self._tox.group_send_message(number, message_type, message)
|
||||||
|
|
||||||
def new_message(self, friend_num, message_type, message):
|
def new_message(self, num, message_type, message, is_group=False):
|
||||||
"""
|
"""
|
||||||
Current user gets new message
|
Current user gets new message
|
||||||
:param friend_num: friend_num of friend who sent message
|
:param num: num of friend or gc who sent message
|
||||||
:param message_type: message type - plain text or action message (/me)
|
:param message_type: message type - plain text or action message (/me)
|
||||||
:param message: text of message
|
:param message: text of message
|
||||||
|
:param is_group: is group chat message or not
|
||||||
"""
|
"""
|
||||||
if friend_num == self.get_active_number(): # add message to list
|
if num == self.get_active_number() and is_group != self.is_active_a_friend(): # add message to list
|
||||||
t = time.time()
|
t = time.time()
|
||||||
self.create_message_item(message, t, MESSAGE_OWNER['FRIEND'], message_type)
|
self.create_message_item(message, t, MESSAGE_OWNER['FRIEND'], message_type)
|
||||||
self._messages.scrollToBottom()
|
self._messages.scrollToBottom()
|
||||||
self._friends_and_gc[self._active_friend_or_gc].append_message(
|
self._friends_and_gc[self._active_friend_or_gc].append_message(
|
||||||
TextMessage(message, MESSAGE_OWNER['FRIEND'], t, message_type))
|
TextMessage(message, MESSAGE_OWNER['FRIEND'], t, message_type))
|
||||||
else:
|
else:
|
||||||
friend = self.get_friend_by_number(friend_num)
|
if is_group:
|
||||||
friend.inc_messages()
|
friend_or_gc = self.get_gc_by_number(num)
|
||||||
friend.append_message(
|
else:
|
||||||
TextMessage(message, MESSAGE_OWNER['FRIEND'], time.time(), message_type))
|
friend_or_gc = self.get_friend_by_number(num)
|
||||||
if not friend.visibility:
|
friend_or_gc.inc_messages()
|
||||||
|
friend_or_gc.append_message(TextMessage(message, MESSAGE_OWNER['FRIEND'], time.time(), message_type))
|
||||||
|
if not friend_or_gc.visibility:
|
||||||
self.update_filtration()
|
self.update_filtration()
|
||||||
|
|
||||||
def send_message(self, text, number=None, is_gc=False):
|
def send_message(self, text, number=None, is_gc=False):
|
||||||
@ -1241,7 +1245,7 @@ class Profile(basecontact.BaseContact, Singleton):
|
|||||||
self.add_gc(num)
|
self.add_gc(num)
|
||||||
|
|
||||||
def process_group_invite(self, friend_num, data):
|
def process_group_invite(self, friend_num, data):
|
||||||
# TODO: add info to list and support password
|
# TODO: support password
|
||||||
try:
|
try:
|
||||||
text = QtGui.QApplication.translate('MainWindow', 'User {} invites you to group',
|
text = QtGui.QApplication.translate('MainWindow', 'User {} invites you to group',
|
||||||
None, QtGui.QApplication.UnicodeUTF8)
|
None, QtGui.QApplication.UnicodeUTF8)
|
||||||
@ -1253,6 +1257,11 @@ class Profile(basecontact.BaseContact, Singleton):
|
|||||||
data = self._tox.get_savedata()
|
data = self._tox.get_savedata()
|
||||||
ProfileHelper.get_instance().save_profile(data)
|
ProfileHelper.get_instance().save_profile(data)
|
||||||
self.add_gc(num)
|
self.add_gc(num)
|
||||||
|
elif reply != QtGui.QMessageBox.No:
|
||||||
|
if friend_num in self._gc_invites:
|
||||||
|
self._gc_invites[friend_num].append(data)
|
||||||
|
else:
|
||||||
|
self._gc_invites[friend_num] = data
|
||||||
except Exception as ex: # something is wrong
|
except Exception as ex: # something is wrong
|
||||||
log('Accept group chat invite failed! ' + str(ex))
|
log('Accept group chat invite failed! ' + str(ex))
|
||||||
|
|
||||||
|
@ -126,7 +126,8 @@ class Settings(dict, Singleton):
|
|||||||
'unread_color': 'red',
|
'unread_color': 'red',
|
||||||
'save_unsent_only': False,
|
'save_unsent_only': False,
|
||||||
'compact_mode': False,
|
'compact_mode': False,
|
||||||
'show_welcome_screen': True
|
'show_welcome_screen': True,
|
||||||
|
'notify_all_gc': False
|
||||||
}
|
}
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
Loading…
Reference in New Issue
Block a user