private messages - types
This commit is contained in:
parent
eba7e0c0dc
commit
5e1f060fac
5 changed files with 81 additions and 17 deletions
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -7,19 +7,19 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>600</width>
|
||||
<height>400</height>
|
||||
<height>500</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>600</width>
|
||||
<height>400</height>
|
||||
<height>500</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>600</width>
|
||||
<height>400</height>
|
||||
<height>500</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
|
@ -31,7 +31,7 @@
|
|||
<x>110</x>
|
||||
<y>10</y>
|
||||
<width>431</width>
|
||||
<height>41</height>
|
||||
<height>40</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
|
@ -42,7 +42,7 @@
|
|||
<property name="geometry">
|
||||
<rect>
|
||||
<x>50</x>
|
||||
<y>120</y>
|
||||
<y>140</y>
|
||||
<width>500</width>
|
||||
<height>50</height>
|
||||
</rect>
|
||||
|
@ -55,7 +55,7 @@
|
|||
<property name="geometry">
|
||||
<rect>
|
||||
<x>50</x>
|
||||
<y>70</y>
|
||||
<y>100</y>
|
||||
<width>500</width>
|
||||
<height>23</height>
|
||||
</rect>
|
||||
|
@ -68,8 +68,8 @@
|
|||
<property name="geometry">
|
||||
<rect>
|
||||
<x>50</x>
|
||||
<y>200</y>
|
||||
<width>521</width>
|
||||
<y>300</y>
|
||||
<width>500</width>
|
||||
<height>161</height>
|
||||
</rect>
|
||||
</property>
|
||||
|
@ -77,6 +77,45 @@
|
|||
<string>GroupBox</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="roleLabel">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>50</x>
|
||||
<y>60</y>
|
||||
<width>67</width>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>TextLabel</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="roleNameLabel">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>140</x>
|
||||
<y>60</y>
|
||||
<width>401</width>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>TextLabel</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="copyPublicKeyPushButton">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>50</x>
|
||||
<y>210</y>
|
||||
<width>500</width>
|
||||
<height>50</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>PushButton</string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue