updates and fixes
This commit is contained in:
parent
bae87c8d72
commit
dc96f66d8c
@ -291,19 +291,20 @@ def callback_audio(toxav, friend_number, samples, audio_samples_per_channel, aud
|
||||
# Callbacks - group chats
|
||||
# -----------------------------------------------------------------------------------------------------------------
|
||||
|
||||
def group_message(window, tray):
|
||||
def group_message(window, tray, tox):
|
||||
"""
|
||||
New message from friend
|
||||
"""
|
||||
def wrapped(tox, group_number, peer_id, message_type, message, length, user_data):
|
||||
def wrapped(tox_link, group_number, peer_id, message_type, message, length, user_data):
|
||||
profile = Profile.get_instance()
|
||||
settings = Settings.get_instance()
|
||||
message = str(message[:length], 'utf-8')
|
||||
invoke_in_main_thread(profile.new_message, group_number, message_type, message, True)
|
||||
invoke_in_main_thread(profile.new_message, group_number, message_type, message, True, peer_id)
|
||||
if not window.isActiveWindow():
|
||||
bl = settings['notify_all_gc'] or profile.name in message
|
||||
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:
|
||||
invoke_in_main_thread(tray_notification, '', message, tray, window) # TODO: friend name
|
||||
invoke_in_main_thread(tray_notification, name, message, tray, window)
|
||||
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'))
|
||||
@ -352,6 +353,6 @@ def init_callbacks(tox, window, tray):
|
||||
tox.callback_friend_lossless_packet(lossless_packet, 0)
|
||||
tox.callback_friend_lossy_packet(lossy_packet, 0)
|
||||
|
||||
tox.callback_group_message(group_message(window, tray), 0)
|
||||
tox.callback_group_message(group_message(window, tray, tox), 0)
|
||||
tox.callback_group_invite(group_invite, 0)
|
||||
|
||||
|
@ -59,8 +59,10 @@ class MainWindow(QtGui.QMainWindow):
|
||||
self.importPlugin = QtGui.QAction(MainWindow)
|
||||
self.lockApp = QtGui.QAction(MainWindow)
|
||||
self.createGC = QtGui.QAction(MainWindow)
|
||||
self.joinGC = QtGui.QAction(MainWindow)
|
||||
self.gcRequests = QtGui.QAction(MainWindow)
|
||||
self.menuGroupChats.addAction(self.createGC)
|
||||
self.menuGroupChats.addAction(self.joinGC)
|
||||
self.menuGroupChats.addAction(self.gcRequests)
|
||||
self.menuProfile.addAction(self.actionAdd_friend)
|
||||
self.menuProfile.addAction(self.actionSettings)
|
||||
@ -92,6 +94,8 @@ class MainWindow(QtGui.QMainWindow):
|
||||
self.lockApp.triggered.connect(self.lock_app)
|
||||
self.importPlugin.triggered.connect(self.import_plugin)
|
||||
self.createGC.triggered.connect(self.create_groupchat)
|
||||
self.joinGC.triggered.connect(self.join_groupchat)
|
||||
|
||||
QtCore.QMetaObject.connectSlotsByName(MainWindow)
|
||||
|
||||
def languageChange(self, *args, **kwargs):
|
||||
@ -103,6 +107,7 @@ class MainWindow(QtGui.QMainWindow):
|
||||
return super(MainWindow, self).event(event)
|
||||
|
||||
def retranslateUi(self):
|
||||
self.joinGC.setText(QtGui.QApplication.translate("MainWindow", "Join group chat", None, QtGui.QApplication.UnicodeUTF8))
|
||||
self.lockApp.setText(QtGui.QApplication.translate("MainWindow", "Lock", None, QtGui.QApplication.UnicodeUTF8))
|
||||
self.menuGroupChats.setTitle(QtGui.QApplication.translate("MainWindow", "Group chats", None, QtGui.QApplication.UnicodeUTF8))
|
||||
self.createGC.setText(QtGui.QApplication.translate("MainWindow", "Create group chat", None, QtGui.QApplication.UnicodeUTF8))
|
||||
@ -460,6 +465,10 @@ class MainWindow(QtGui.QMainWindow):
|
||||
self.gc = AddGroupchat()
|
||||
self.gc.show()
|
||||
|
||||
def join_groupchat(self):
|
||||
self.gc = JoinGroupchat()
|
||||
self.gc.show()
|
||||
|
||||
def show_chat_menu(self):
|
||||
pr = Profile.get_instance()
|
||||
if not pr.is_active_a_friend():
|
||||
|
@ -38,6 +38,7 @@ class AddGroupchat(CenteredWidget):
|
||||
self.pass_label.setGeometry(QtCore.QRect(50, 130, 470, 20))
|
||||
self.password = LineEdit(self)
|
||||
self.password.setGeometry(QtCore.QRect(50, 150, 470, 27))
|
||||
self.password.setEchoMode(QtGui.QLineEdit.EchoMode.Password)
|
||||
|
||||
self.createGCButton.clicked.connect(self.button_click)
|
||||
QtCore.QMetaObject.connectSlotsByName(self)
|
||||
@ -61,6 +62,46 @@ class AddGroupchat(CenteredWidget):
|
||||
self.close()
|
||||
|
||||
|
||||
class JoinGroupchat(CenteredWidget):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.initUI()
|
||||
self.retranslateUi()
|
||||
self.center()
|
||||
|
||||
def initUI(self):
|
||||
self.setObjectName('AddGC')
|
||||
self.resize(570, 150)
|
||||
self.setMaximumSize(QtCore.QSize(570, 150))
|
||||
self.setMinimumSize(QtCore.QSize(570, 150))
|
||||
self.joinGCButton = QtGui.QPushButton(self)
|
||||
self.joinGCButton.setGeometry(QtCore.QRect(50, 110, 470, 30))
|
||||
self.id = LineEdit(self)
|
||||
self.id.setGeometry(QtCore.QRect(50, 10, 470, 30))
|
||||
self.password = LineEdit(self)
|
||||
self.password.setGeometry(QtCore.QRect(50, 50, 470, 30))
|
||||
self.password.setEchoMode(QtGui.QLineEdit.EchoMode.Password)
|
||||
|
||||
self.joinGCButton.clicked.connect(self.button_click)
|
||||
QtCore.QMetaObject.connectSlotsByName(self)
|
||||
|
||||
def retranslateUi(self):
|
||||
self.setWindowTitle(
|
||||
QtGui.QApplication.translate('JoinGC', "Join group chat", None, QtGui.QApplication.UnicodeUTF8))
|
||||
self.joinGCButton.setText(
|
||||
QtGui.QApplication.translate("JoinGC", "Join", None, QtGui.QApplication.UnicodeUTF8))
|
||||
self.id.setPlaceholderText(
|
||||
QtGui.QApplication.translate('JoinGC', "Group ID", None, QtGui.QApplication.UnicodeUTF8))
|
||||
self.password.setPlaceholderText(
|
||||
QtGui.QApplication.translate('JoinGC', "Optional password", None, QtGui.QApplication.UnicodeUTF8))
|
||||
|
||||
def button_click(self):
|
||||
if self.id.text():
|
||||
Profile.get_instance().join_gc(self.id.text().strip(), self.password.text())
|
||||
self.close()
|
||||
|
||||
|
||||
class AddContact(CenteredWidget):
|
||||
"""Add contact form"""
|
||||
|
||||
|
@ -385,13 +385,14 @@ class Profile(basecontact.BaseContact, Singleton):
|
||||
else:
|
||||
self._tox.group_send_message(number, message_type, message)
|
||||
|
||||
def new_message(self, num, message_type, message, is_group=False):
|
||||
def new_message(self, num, message_type, message, is_group=False, peer_id=-1):
|
||||
"""
|
||||
Current user gets new message
|
||||
:param num: num of friend or gc who sent message
|
||||
:param message_type: message type - plain text or action message (/me)
|
||||
:param message: text of message
|
||||
:param is_group: is group chat message or not
|
||||
:param peer_id: if gc - peer id
|
||||
"""
|
||||
if num == self.get_active_number() and is_group != self.is_active_a_friend(): # add message to list
|
||||
t = time.time()
|
||||
@ -402,6 +403,9 @@ class Profile(basecontact.BaseContact, Singleton):
|
||||
else:
|
||||
if is_group:
|
||||
friend_or_gc = self.get_gc_by_number(num)
|
||||
friend_or_gc.append_message(GroupChatTextMessage(self._tox.group_peer_get_name(num, peer_id),
|
||||
message, MESSAGE_OWNER['FRIEND'],
|
||||
time.time(), message_type))
|
||||
else:
|
||||
friend_or_gc = self.get_friend_by_number(num)
|
||||
friend_or_gc.inc_messages()
|
||||
@ -1239,6 +1243,13 @@ class Profile(basecontact.BaseContact, Singleton):
|
||||
gc = GroupChat(self._tox, num, message_getter, name, topic, item, tox_id)
|
||||
self._friends_and_gc.append(gc)
|
||||
|
||||
def join_gc(self, chat_id, password):
|
||||
num = self._tox.group_join(chat_id, password if password else None)
|
||||
if num != 2 ** 32 - 1:
|
||||
self.add_gc(num)
|
||||
else:
|
||||
pass # TODO: join failed, show error
|
||||
|
||||
def create_gc(self, name, is_public, password):
|
||||
privacy_state = TOX_GROUP_PRIVACY_STATE['TOX_GROUP_PRIVACY_STATE_PUBLIC'] if is_public else TOX_GROUP_PRIVACY_STATE['TOX_GROUP_PRIVACY_STATE_PRIVATE']
|
||||
num = self._tox.group_new(privacy_state, bytes(name, 'utf-8'))
|
||||
|
@ -1570,7 +1570,10 @@ class Tox:
|
||||
"""
|
||||
|
||||
error = c_int()
|
||||
result = Tox.libtoxcore.tox_group_join(self._tox_pointer, chat_id, password, len(password), byref(error))
|
||||
result = Tox.libtoxcore.tox_group_join(self._tox_pointer, chat_id,
|
||||
password,
|
||||
len(password) if password is not None else 0,
|
||||
byref(error))
|
||||
return result
|
||||
|
||||
def group_reconnect(self, groupnumber):
|
||||
|
Loading…
Reference in New Issue
Block a user