ban fixes
This commit is contained in:
parent
c0a34d3e14
commit
ce19efe340
@ -1 +1 @@
|
|||||||
{"nodes":[{"ipv4":"80.211.19.83","ipv6":"-","port":33445,"public_key":"A05AFD9C7B785ADBB93DCD55FC8992177A2BA50413AAD7AD8D3442EE5E7ADA21","status_udp":true,"status_tcp":true}]}
|
{"nodes":[{"ipv4":"80.211.19.83","ipv6":"-","port":33445,"public_key":"A2D7BF17C10A12C339B9F4E8DD77DEEE8457D580535A6F0D0F9AF04B8B4C4420","status_udp":true,"status_tcp":true}]}
|
@ -190,9 +190,8 @@ class GroupMenuGenerator(BaseContactMenuGenerator):
|
|||||||
.with_optional_action(util_ui.tr('Set topic'),
|
.with_optional_action(util_ui.tr('Set topic'),
|
||||||
lambda: groups_service.set_group_topic(self._contact),
|
lambda: groups_service.set_group_topic(self._contact),
|
||||||
self._contact.is_self_moderator_or_founder())
|
self._contact.is_self_moderator_or_founder())
|
||||||
.with_optional_action(util_ui.tr('Bans list'),
|
.with_action(util_ui.tr('Bans list'),
|
||||||
lambda: groups_service.show_bans_list(self._contact),
|
lambda: groups_service.show_bans_list(self._contact))
|
||||||
self._contact.is_self_moderator_or_founder())
|
|
||||||
.with_action(util_ui.tr('Reconnect to group'),
|
.with_action(util_ui.tr('Reconnect to group'),
|
||||||
lambda: groups_service.reconnect_to_group(self._contact.number))
|
lambda: groups_service.reconnect_to_group(self._contact.number))
|
||||||
.with_optional_action(util_ui.tr('Disconnect from group'),
|
.with_optional_action(util_ui.tr('Disconnect from group'),
|
||||||
|
@ -82,6 +82,9 @@ class GroupChat(contact.Contact, ToxSave):
|
|||||||
self._peers.append(peer)
|
self._peers.append(peer)
|
||||||
|
|
||||||
def remove_peer(self, peer_id):
|
def remove_peer(self, peer_id):
|
||||||
|
if peer_id == self.get_self_peer().id: # we were kicked or banned
|
||||||
|
self.remove_all_peers_except_self()
|
||||||
|
else:
|
||||||
peer = self.get_peer_by_id(peer_id)
|
peer = self.get_peer_by_id(peer_id)
|
||||||
self._peers.remove(peer)
|
self._peers.remove(peer)
|
||||||
|
|
||||||
|
@ -194,11 +194,9 @@ class GroupsService(tox_save.ToxSave):
|
|||||||
|
|
||||||
def ban_peer(self, group, peer_id, ban_type):
|
def ban_peer(self, group, peer_id, ban_type):
|
||||||
self._tox.group_mod_ban_peer(group.number, peer_id, ban_type)
|
self._tox.group_mod_ban_peer(group.number, peer_id, ban_type)
|
||||||
group.remove_peer(peer_id)
|
|
||||||
|
|
||||||
def kick_peer(self, group, peer_id):
|
def kick_peer(self, group, peer_id):
|
||||||
self._tox.group_mod_remove_peer(group.number, peer_id)
|
self._tox.group_mod_remove_peer(group.number, peer_id)
|
||||||
group.remove_peer(peer_id)
|
|
||||||
|
|
||||||
def cancel_ban(self, group_number, ban_id):
|
def cancel_ban(self, group_number, ban_id):
|
||||||
self._tox.group_mod_remove_ban(group_number, ban_id)
|
self._tox.group_mod_remove_ban(group_number, ban_id)
|
||||||
|
@ -6,19 +6,24 @@ import utils.ui as util_ui
|
|||||||
|
|
||||||
class GroupBanItem(QtWidgets.QWidget):
|
class GroupBanItem(QtWidgets.QWidget):
|
||||||
|
|
||||||
def __init__(self, ban, cancel_ban, parent=None):
|
def __init__(self, ban, cancel_ban, can_cancel_ban, parent=None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
self._ban = ban
|
self._ban = ban
|
||||||
self._cancel_ban = cancel_ban
|
self._cancel_ban = cancel_ban
|
||||||
|
self._can_cancel_ban = can_cancel_ban
|
||||||
|
|
||||||
|
uic.loadUi(util.get_views_path('gc_ban_item'), self)
|
||||||
|
self._update_ui()
|
||||||
|
|
||||||
def _update_ui(self):
|
def _update_ui(self):
|
||||||
self._retranslate_ui()
|
self._retranslate_ui()
|
||||||
|
|
||||||
self.banTargetLabel.setText(self._ban.target)
|
self.banTargetLabel.setText(self._ban.ban_target)
|
||||||
ban_time = self._ban.ban_time
|
ban_time = self._ban.ban_time
|
||||||
self.banTimeLabel.setText(util.unix_time_to_long_str(ban_time))
|
self.banTimeLabel.setText(util.unix_time_to_long_str(ban_time))
|
||||||
|
|
||||||
self.cancelPushButton.clicked.connect(self._cancel_ban)
|
self.cancelPushButton.clicked.connect(self._cancel_ban)
|
||||||
|
self.cancelPushButton.setEnabled(self._can_cancel_ban)
|
||||||
|
|
||||||
def _retranslate_ui(self):
|
def _retranslate_ui(self):
|
||||||
self.cancelPushButton.setText(util_ui.tr('Cancel ban'))
|
self.cancelPushButton.setText(util_ui.tr('Cancel ban'))
|
||||||
@ -47,11 +52,12 @@ class GroupBansScreen(CenteredWidget):
|
|||||||
|
|
||||||
def _refresh_bans_list(self):
|
def _refresh_bans_list(self):
|
||||||
self.bansListWidget.clear()
|
self.bansListWidget.clear()
|
||||||
|
can_cancel_ban = self._group.is_self_moderator_or_founder()
|
||||||
for ban in self._group.bans:
|
for ban in self._group.bans:
|
||||||
self._create_ban_item(ban)
|
self._create_ban_item(ban, can_cancel_ban)
|
||||||
|
|
||||||
def _create_ban_item(self, ban):
|
def _create_ban_item(self, ban, can_cancel_ban):
|
||||||
item = GroupBanItem(ban, self._on_ban_cancelled, self.bansListWidget)
|
item = GroupBanItem(ban, self._on_ban_cancelled, can_cancel_ban, self.bansListWidget)
|
||||||
elem = QtWidgets.QListWidgetItem()
|
elem = QtWidgets.QListWidgetItem()
|
||||||
elem.setSizeHint(QtCore.QSize(item.width(), item.height()))
|
elem.setSizeHint(QtCore.QSize(item.width(), item.height()))
|
||||||
self.bansListWidget.addItem(elem)
|
self.bansListWidget.addItem(elem)
|
||||||
|
@ -97,9 +97,11 @@ class PeerScreen(CenteredWidget):
|
|||||||
def _ban_peer(self):
|
def _ban_peer(self):
|
||||||
ban_type = self._get_ban_type()
|
ban_type = self._get_ban_type()
|
||||||
self._groups_service.ban_peer(self._group, self._peer.id, ban_type)
|
self._groups_service.ban_peer(self._group, self._peer.id, ban_type)
|
||||||
|
self.close()
|
||||||
|
|
||||||
def _kick_peer(self):
|
def _kick_peer(self):
|
||||||
self._groups_service.kick_peer(self._group, self._peer.id)
|
self._groups_service.kick_peer(self._group, self._peer.id)
|
||||||
|
self.close()
|
||||||
|
|
||||||
def _get_ban_type(self):
|
def _get_ban_type(self):
|
||||||
if self.ipBanRadioButton.isChecked():
|
if self.ipBanRadioButton.isChecked():
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
<widget class="QPushButton" name="cancelPushButton">
|
<widget class="QPushButton" name="cancelPushButton">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>320</x>
|
<x>330</x>
|
||||||
<y>30</y>
|
<y>30</y>
|
||||||
<width>161</width>
|
<width>161</width>
|
||||||
<height>41</height>
|
<height>41</height>
|
||||||
@ -29,9 +29,9 @@
|
|||||||
<widget class="QLabel" name="banTargetLabel">
|
<widget class="QLabel" name="banTargetLabel">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>20</x>
|
<x>15</x>
|
||||||
<y>20</y>
|
<y>20</y>
|
||||||
<width>200</width>
|
<width>305</width>
|
||||||
<height>20</height>
|
<height>20</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
@ -42,9 +42,9 @@
|
|||||||
<widget class="QLabel" name="banTimeLabel">
|
<widget class="QLabel" name="banTimeLabel">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>20</x>
|
<x>15</x>
|
||||||
<y>50</y>
|
<y>50</y>
|
||||||
<width>200</width>
|
<width>305</width>
|
||||||
<height>20</height>
|
<height>20</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
|
@ -2474,6 +2474,17 @@ class Tox:
|
|||||||
result = Tox.libtoxcore.tox_group_ban_get_list(self._tox_pointer, group_number, bans_list, byref(error))
|
result = Tox.libtoxcore.tox_group_ban_get_list(self._tox_pointer, group_number, bans_list, byref(error))
|
||||||
return bans_list[:bans_list_size]
|
return bans_list[:bans_list_size]
|
||||||
|
|
||||||
|
def group_ban_get_type(self, group_number, ban_id):
|
||||||
|
"""
|
||||||
|
Return the type for the ban list entry designated by ban_id, in the
|
||||||
|
group designated by the given group number. If either group_number or ban_id is invalid,
|
||||||
|
the return value is unspecified.
|
||||||
|
"""
|
||||||
|
|
||||||
|
error = c_int()
|
||||||
|
result = Tox.libtoxcore.tox_group_ban_get_type(self._tox_pointer, group_number, ban_id, byref(error))
|
||||||
|
return result
|
||||||
|
|
||||||
def group_ban_get_target_size(self, group_number, ban_id):
|
def group_ban_get_target_size(self, group_number, ban_id):
|
||||||
"""
|
"""
|
||||||
Return the length of the name for the ban list entry designated by ban_id, in the
|
Return the length of the name for the ban list entry designated by ban_id, in the
|
||||||
@ -2498,9 +2509,12 @@ class Tox:
|
|||||||
error = c_int()
|
error = c_int()
|
||||||
size = self.group_ban_get_target_size(group_number, ban_id)
|
size = self.group_ban_get_target_size(group_number, ban_id)
|
||||||
target = create_string_buffer(size)
|
target = create_string_buffer(size)
|
||||||
|
target_type = self.group_ban_get_type(group_number, ban_id)
|
||||||
|
|
||||||
result = Tox.libtoxcore.tox_group_ban_get_target(self._tox_pointer, group_number, ban_id,
|
result = Tox.libtoxcore.tox_group_ban_get_target(self._tox_pointer, group_number, ban_id,
|
||||||
target, byref(error))
|
target, byref(error))
|
||||||
|
if target_type == TOX_GROUP_BAN_TYPE['PUBLIC_KEY']:
|
||||||
|
return bin_to_string(target, size)
|
||||||
return str(target[:size], 'utf-8')
|
return str(target[:size], 'utf-8')
|
||||||
|
|
||||||
def group_ban_get_time_set(self, group_number, ban_id):
|
def group_ban_get_time_set(self, group_number, ban_id):
|
||||||
|
@ -919,7 +919,6 @@ TOX_GROUP_BAN_TYPE = {
|
|||||||
'PUBLIC_KEY': 1,
|
'PUBLIC_KEY': 1,
|
||||||
|
|
||||||
'NICK': 2
|
'NICK': 2
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TOX_PUBLIC_KEY_SIZE = 32
|
TOX_PUBLIC_KEY_SIZE = 32
|
||||||
|
Loading…
Reference in New Issue
Block a user