From 5e1f060fac4eecb06d251072695b3bd46dc1ffca Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Sun, 22 Jul 2018 19:39:42 +0300 Subject: [PATCH] private messages - types --- toxygen/messenger/messenger.py | 14 ++++++--- toxygen/middleware/callbacks.py | 4 +-- toxygen/ui/peer_screen.py | 18 +++++++++++ toxygen/ui/views/peer_screen.ui | 55 ++++++++++++++++++++++++++++----- toxygen/wrapper/tox.py | 7 +++-- 5 files changed, 81 insertions(+), 17 deletions(-) diff --git a/toxygen/messenger/messenger.py b/toxygen/messenger/messenger.py index 0768f2b..99d7f2f 100644 --- a/toxygen/messenger/messenger.py +++ b/toxygen/messenger/messenger.py @@ -170,14 +170,20 @@ class Messenger(tox_save.ToxSave): if not text or group_number < 0 or peer_id < 0: return + if text.startswith('/me '): + message_type = TOX_MESSAGE_TYPE['ACTION'] + text = text[4:] + else: + message_type = TOX_MESSAGE_TYPE['NORMAL'] + group_peer_contact = self._contacts_manager.get_or_create_group_peer_contact(group_number, peer_id) group = self._get_group_by_number(group_number) messages = self._split_message(text.encode('utf-8')) t = util.get_unix_time() for message in messages: - self._tox.group_send_private_message(group_number, peer_id, message) + self._tox.group_send_private_message(group_number, peer_id, message_type, message) message_author = MessageAuthor(group.get_self_name(), MESSAGE_AUTHOR['GC_PEER']) - message = OutgoingTextMessage(text, message_author, t, MESSAGE_TYPE['TEXT']) + message = OutgoingTextMessage(text, message_author, t, message_type) group_peer_contact.append_message(message) if not self._contacts_manager.is_contact_active(group_peer_contact): return @@ -185,7 +191,7 @@ class Messenger(tox_save.ToxSave): self._screen.messageEdit.clear() self._screen.messages.scrollToBottom() - def new_group_private_message(self, group_number, message, peer_id): + def new_group_private_message(self, group_number, message_type, message, peer_id): """ Current user gets new message :param message: text of message @@ -194,7 +200,7 @@ class Messenger(tox_save.ToxSave): group = self._get_group_by_number(group_number) peer = group.get_peer_by_id(peer_id) text_message = TextMessage(message, MessageAuthor(peer.name, MESSAGE_AUTHOR['GC_PEER']), - t, MESSAGE_TYPE['TEXT']) + t, message_type) group_peer_contact = self._contacts_manager.get_or_create_group_peer_contact(group_number, peer_id) self._add_message(text_message, group_peer_contact) diff --git a/toxygen/middleware/callbacks.py b/toxygen/middleware/callbacks.py index 323d5d1..9e6059c 100644 --- a/toxygen/middleware/callbacks.py +++ b/toxygen/middleware/callbacks.py @@ -379,9 +379,9 @@ def group_private_message(window, tray, tox, messenger, settings, profile): """ New private message in group chat """ - def wrapped(tox_link, group_number, peer_id, message, length, user_data): + def wrapped(tox_link, group_number, peer_id, message_type, message, length, user_data): message = str(message[:length], 'utf-8') - invoke_in_main_thread(messenger.new_group_private_message, group_number, message, peer_id) + invoke_in_main_thread(messenger.new_group_private_message, group_number, message_type, message, 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) diff --git a/toxygen/ui/peer_screen.py b/toxygen/ui/peer_screen.py index 4145fe1..6850125 100644 --- a/toxygen/ui/peer_screen.py +++ b/toxygen/ui/peer_screen.py @@ -24,13 +24,31 @@ class PeerScreen(CenteredWidget): self.peerNameLabel.setText(self._peer.name) self.ignorePeerCheckBox.setChecked(self._peer.is_muted) self.sendPrivateMessagePushButton.clicked.connect(self._send_private_message) + self.copyPublicKeyPushButton.clicked.connect(self._copy_public_key) + self.roleNameLabel.setText(self._get_role_name()) self._retranslate_ui() def _retranslate_ui(self): self.setWindowTitle(util_ui.tr('Peer details')) self.ignorePeerCheckBox.setText(util_ui.tr('Ignore peer')) + self.roleLabel.setText(util_ui.tr('Role:')) + self.copyPublicKeyPushButton.setText(util_ui.tr('Copy public key')) self.sendPrivateMessagePushButton.setText(util_ui.tr('Send private message')) + def _get_role_name(self): + roles = { + 0: util_ui.tr('Administrator'), + 1: util_ui.tr('Moderator'), + 2: util_ui.tr('User'), + 3: util_ui.tr('Observer') + } + + return roles[self._peer.role] + def _send_private_message(self): self._contacts_manager.add_group_peer(self._group, self._peer) self.close() + + def _copy_public_key(self): + clipboard = QtWidgets.QApplication.clipboard() + clipboard.setText(self._peer.public_key) diff --git a/toxygen/ui/views/peer_screen.ui b/toxygen/ui/views/peer_screen.ui index cf221c0..f719ec6 100644 --- a/toxygen/ui/views/peer_screen.ui +++ b/toxygen/ui/views/peer_screen.ui @@ -7,19 +7,19 @@ 0 0 600 - 400 + 500 600 - 400 + 500 600 - 400 + 500 @@ -31,7 +31,7 @@ 110 10 431 - 41 + 40 @@ -42,7 +42,7 @@ 50 - 120 + 140 500 50 @@ -55,7 +55,7 @@ 50 - 70 + 100 500 23 @@ -68,8 +68,8 @@ 50 - 200 - 521 + 300 + 500 161 @@ -77,6 +77,45 @@ GroupBox + + + + 50 + 60 + 67 + 20 + + + + TextLabel + + + + + + 140 + 60 + 401 + 20 + + + + TextLabel + + + + + + 50 + 210 + 500 + 50 + + + + PushButton + + diff --git a/toxygen/wrapper/tox.py b/toxygen/wrapper/tox.py index 7912103..64b55ea 100644 --- a/toxygen/wrapper/tox.py +++ b/toxygen/wrapper/tox.py @@ -2060,7 +2060,7 @@ class Tox: len(data), byref(error)) return result - def group_send_private_message(self, group_number, peer_id, message): + def group_send_private_message(self, group_number, peer_id, message_type, message): """ Send a text chat message to the specified peer in the specified group. @@ -2079,7 +2079,8 @@ class Tox: """ error = c_int() - result = Tox.libtoxcore.tox_group_send_private_message(self._tox_pointer, group_number, peer_id, message, + result = Tox.libtoxcore.tox_group_send_private_message(self._tox_pointer, group_number, peer_id, + message_type, message, len(message), byref(error)) return result @@ -2135,7 +2136,7 @@ class Tox: This event is triggered when the client receives a private message. """ - c_callback = CFUNCTYPE(None, c_void_p, c_uint32, c_uint32, c_char_p, c_size_t, c_void_p) + c_callback = CFUNCTYPE(None, c_void_p, c_uint32, c_uint32, c_uint8, c_char_p, c_size_t, c_void_p) self.group_private_message_cb = c_callback(callback) Tox.libtoxcore.tox_callback_group_private_message(self._tox_pointer, self.group_private_message_cb, user_data)