diff --git a/toxygen/bootstrap/nodes.json b/toxygen/bootstrap/nodes.json index 4f4f011..5314998 100644 --- a/toxygen/bootstrap/nodes.json +++ b/toxygen/bootstrap/nodes.json @@ -1 +1 @@ -{"nodes":[{"ipv4":"80.211.19.83","ipv6":"-","port":33445,"public_key":"A05AFD9C7B785ADBB93DCD55FC8992177A2BA50413AAD7AD8D3442EE5E7ADA21","status_udp":true,"status_tcp":true}]} \ No newline at end of file +{"nodes":[{"ipv4":"80.211.19.83","ipv6":"-","port":33445,"public_key":"A2D7BF17C10A12C339B9F4E8DD77DEEE8457D580535A6F0D0F9AF04B8B4C4420","status_udp":true,"status_tcp":true}]} \ No newline at end of file diff --git a/toxygen/contacts/contact_menu.py b/toxygen/contacts/contact_menu.py index da1cddb..b1c23f5 100644 --- a/toxygen/contacts/contact_menu.py +++ b/toxygen/contacts/contact_menu.py @@ -190,9 +190,8 @@ class GroupMenuGenerator(BaseContactMenuGenerator): .with_optional_action(util_ui.tr('Set topic'), lambda: groups_service.set_group_topic(self._contact), self._contact.is_self_moderator_or_founder()) - .with_optional_action(util_ui.tr('Bans list'), - lambda: groups_service.show_bans_list(self._contact), - self._contact.is_self_moderator_or_founder()) + .with_action(util_ui.tr('Bans list'), + lambda: groups_service.show_bans_list(self._contact)) .with_action(util_ui.tr('Reconnect to group'), lambda: groups_service.reconnect_to_group(self._contact.number)) .with_optional_action(util_ui.tr('Disconnect from group'), diff --git a/toxygen/contacts/group_chat.py b/toxygen/contacts/group_chat.py index 1ef6742..19ebc8e 100644 --- a/toxygen/contacts/group_chat.py +++ b/toxygen/contacts/group_chat.py @@ -82,8 +82,11 @@ class GroupChat(contact.Contact, ToxSave): self._peers.append(peer) def remove_peer(self, peer_id): - peer = self.get_peer_by_id(peer_id) - self._peers.remove(peer) + 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) + self._peers.remove(peer) def get_peer_by_id(self, peer_id): peers = list(filter(lambda p: p.id == peer_id, self._peers)) diff --git a/toxygen/groups/groups_service.py b/toxygen/groups/groups_service.py index 058e7ea..b8fc7cc 100644 --- a/toxygen/groups/groups_service.py +++ b/toxygen/groups/groups_service.py @@ -194,11 +194,9 @@ class GroupsService(tox_save.ToxSave): def ban_peer(self, group, 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): self._tox.group_mod_remove_peer(group.number, peer_id) - group.remove_peer(peer_id) def cancel_ban(self, group_number, ban_id): self._tox.group_mod_remove_ban(group_number, ban_id) diff --git a/toxygen/ui/group_bans_widgets.py b/toxygen/ui/group_bans_widgets.py index 45a5f2b..b2758c7 100644 --- a/toxygen/ui/group_bans_widgets.py +++ b/toxygen/ui/group_bans_widgets.py @@ -6,19 +6,24 @@ import utils.ui as util_ui 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) self._ban = 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): self._retranslate_ui() - self.banTargetLabel.setText(self._ban.target) + self.banTargetLabel.setText(self._ban.ban_target) ban_time = self._ban.ban_time self.banTimeLabel.setText(util.unix_time_to_long_str(ban_time)) self.cancelPushButton.clicked.connect(self._cancel_ban) + self.cancelPushButton.setEnabled(self._can_cancel_ban) def _retranslate_ui(self): self.cancelPushButton.setText(util_ui.tr('Cancel ban')) @@ -47,11 +52,12 @@ class GroupBansScreen(CenteredWidget): def _refresh_bans_list(self): self.bansListWidget.clear() + can_cancel_ban = self._group.is_self_moderator_or_founder() 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): - item = GroupBanItem(ban, self._on_ban_cancelled, self.bansListWidget) + def _create_ban_item(self, ban, can_cancel_ban): + item = GroupBanItem(ban, self._on_ban_cancelled, can_cancel_ban, self.bansListWidget) elem = QtWidgets.QListWidgetItem() elem.setSizeHint(QtCore.QSize(item.width(), item.height())) self.bansListWidget.addItem(elem) diff --git a/toxygen/ui/peer_screen.py b/toxygen/ui/peer_screen.py index f366aad..8f2d5ba 100644 --- a/toxygen/ui/peer_screen.py +++ b/toxygen/ui/peer_screen.py @@ -97,9 +97,11 @@ class PeerScreen(CenteredWidget): def _ban_peer(self): ban_type = self._get_ban_type() self._groups_service.ban_peer(self._group, self._peer.id, ban_type) + self.close() def _kick_peer(self): self._groups_service.kick_peer(self._group, self._peer.id) + self.close() def _get_ban_type(self): if self.ipBanRadioButton.isChecked(): diff --git a/toxygen/ui/views/gc_ban_item.ui b/toxygen/ui/views/gc_ban_item.ui index 20e1e16..a57d0e1 100644 --- a/toxygen/ui/views/gc_ban_item.ui +++ b/toxygen/ui/views/gc_ban_item.ui @@ -16,7 +16,7 @@ - 320 + 330 30 161 41 @@ -29,9 +29,9 @@ - 20 + 15 20 - 200 + 305 20 @@ -42,9 +42,9 @@ - 20 + 15 50 - 200 + 305 20 diff --git a/toxygen/wrapper/tox.py b/toxygen/wrapper/tox.py index a2abf6a..fcdf266 100644 --- a/toxygen/wrapper/tox.py +++ b/toxygen/wrapper/tox.py @@ -2474,6 +2474,17 @@ class Tox: result = Tox.libtoxcore.tox_group_ban_get_list(self._tox_pointer, group_number, bans_list, byref(error)) 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): """ 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() size = self.group_ban_get_target_size(group_number, ban_id) 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, target, byref(error)) + if target_type == TOX_GROUP_BAN_TYPE['PUBLIC_KEY']: + return bin_to_string(target, size) return str(target[:size], 'utf-8') def group_ban_get_time_set(self, group_number, ban_id): diff --git a/toxygen/wrapper/toxcore_enums_and_consts.py b/toxygen/wrapper/toxcore_enums_and_consts.py index 1e134f9..b34e272 100644 --- a/toxygen/wrapper/toxcore_enums_and_consts.py +++ b/toxygen/wrapper/toxcore_enums_and_consts.py @@ -919,7 +919,6 @@ TOX_GROUP_BAN_TYPE = { 'PUBLIC_KEY': 1, 'NICK': 2 - } TOX_PUBLIC_KEY_SIZE = 32