Philipp Hörist pushed to branch master at gajim / gajim
Commits:
-
55b2ab5b
by wurstsalat at 2022-10-07T20:52:10+02:00
5 changed files:
- gajim/common/helpers.py
- gajim/common/modules/contacts.py
- gajim/common/settings.py
- gajim/gtk/conversation/rows/message.py
- gajim/gtk/notification_manager.py
Changes:
| ... | ... | @@ -1427,16 +1427,6 @@ def get_group_chat_nick(account: str, room_jid: Union[JID, str]) -> str: |
| 1427 | 1427 | return nick
|
| 1428 | 1428 | |
| 1429 | 1429 | |
| 1430 | -def get_muc_context(jid: JID) -> Optional[str]:
|
|
| 1431 | - disco_info = app.storage.cache.get_last_disco_info(jid)
|
|
| 1432 | - if disco_info is None:
|
|
| 1433 | - return None
|
|
| 1434 | - |
|
| 1435 | - if (disco_info.muc_is_members_only and disco_info.muc_is_nonanonymous):
|
|
| 1436 | - return 'private'
|
|
| 1437 | - return 'public'
|
|
| 1438 | - |
|
| 1439 | - |
|
| 1440 | 1430 | def get_random_muc_localpart() -> str:
|
| 1441 | 1431 | rand = random.randrange(4)
|
| 1442 | 1432 | is_vowel = bool(random.getrandbits(1))
|
| ... | ... | @@ -671,6 +671,16 @@ def is_irc(self) -> bool: |
| 671 | 671 | return False
|
| 672 | 672 | return disco_info.is_irc
|
| 673 | 673 | |
| 674 | + @property
|
|
| 675 | + def muc_context(self) -> Optional[str]:
|
|
| 676 | + disco_info = self.get_disco()
|
|
| 677 | + if disco_info is None:
|
|
| 678 | + return None
|
|
| 679 | + |
|
| 680 | + if disco_info.muc_is_members_only and disco_info.muc_is_nonanonymous:
|
|
| 681 | + return 'private'
|
|
| 682 | + return 'public'
|
|
| 683 | + |
|
| 674 | 684 | @property
|
| 675 | 685 | def encryption_available(self) -> bool:
|
| 676 | 686 | disco_info = self.get_disco()
|
| ... | ... | @@ -41,7 +41,6 @@ |
| 41 | 41 | from gajim.common import app
|
| 42 | 42 | from gajim.common import configpaths
|
| 43 | 43 | from gajim.common import optparser
|
| 44 | -from gajim.common.helpers import get_muc_context
|
|
| 45 | 44 | from gajim.common.storage.base import Encoder
|
| 46 | 45 | from gajim.common.storage.base import json_decoder
|
| 47 | 46 | from gajim.common.setting_values import APP_SETTINGS
|
| ... | ... | @@ -842,7 +841,9 @@ def get_group_chat_setting(self, |
| 842 | 841 | return self._account_settings[account]['group_chat'][jid][setting]
|
| 843 | 842 | except KeyError:
|
| 844 | 843 | |
| 845 | - context = get_muc_context(jid)
|
|
| 844 | + client = app.get_client(account)
|
|
| 845 | + contact = client.get_module('Contacts').get_contact(jid)
|
|
| 846 | + context = contact.muc_context
|
|
| 846 | 847 | if context is None:
|
| 847 | 848 | # If there is no disco info available
|
| 848 | 849 | # to determine the context assume public
|
| ... | ... | @@ -905,7 +906,9 @@ def set_group_chat_setting(self, |
| 905 | 906 | default = ACCOUNT_SETTINGS['group_chat'][setting]
|
| 906 | 907 | if default in (HAS_APP_DEFAULT, HAS_ACCOUNT_DEFAULT):
|
| 907 | 908 | |
| 908 | - context = get_muc_context(jid)
|
|
| 909 | + client = app.get_client(account)
|
|
| 910 | + contact = client.get_module('Contacts').get_contact(jid)
|
|
| 911 | + context = contact.muc_context
|
|
| 909 | 912 | if context is None:
|
| 910 | 913 | # If there is no disco info available
|
| 911 | 914 | # to determine the context assume public
|
| ... | ... | @@ -951,7 +954,9 @@ def set_group_chat_settings(self, |
| 951 | 954 | for account, acc_settings in self._account_settings.items():
|
| 952 | 955 | for jid in acc_settings['group_chat']:
|
| 953 | 956 | if context is not None:
|
| 954 | - if get_muc_context(jid) != context:
|
|
| 957 | + client = app.get_client(account)
|
|
| 958 | + contact = client.get_module('Contacts').get_contact(jid)
|
|
| 959 | + if contact.muc_context != context:
|
|
| 955 | 960 | continue
|
| 956 | 961 | self.set_group_chat_setting(account, jid, setting, value)
|
| 957 | 962 |
| ... | ... | @@ -40,7 +40,6 @@ |
| 40 | 40 | from gajim.common.helpers import AdditionalDataDict
|
| 41 | 41 | from gajim.common.helpers import from_one_line
|
| 42 | 42 | from gajim.common.helpers import get_group_chat_nick
|
| 43 | -from gajim.common.helpers import get_muc_context
|
|
| 44 | 43 | from gajim.common.helpers import message_needs_highlight
|
| 45 | 44 | from gajim.common.helpers import to_user_string
|
| 46 | 45 | from gajim.common.i18n import _
|
| ... | ... | @@ -118,12 +117,12 @@ def __init__(self, |
| 118 | 117 | text, additional_data)
|
| 119 | 118 | |
| 120 | 119 | if is_previewable:
|
| 121 | - context = None
|
|
| 122 | - if self._is_groupchat:
|
|
| 123 | - context = get_muc_context(self._contact.jid)
|
|
| 120 | + muc_context = None
|
|
| 121 | + if isinstance(self._contact, GroupchatContact):
|
|
| 122 | + muc_context = self._contact.muc_context
|
|
| 124 | 123 | self._message_widget = PreviewWidget(account)
|
| 125 | 124 | app.preview_manager.create_preview(
|
| 126 | - text, self._message_widget, from_us, context)
|
|
| 125 | + text, self._message_widget, from_us, muc_context)
|
|
| 127 | 126 | else:
|
| 128 | 127 | self._message_widget = MessageWidget(account)
|
| 129 | 128 | self._message_widget.add_with_styling(text, nickname=name)
|
| ... | ... | @@ -34,7 +34,6 @@ |
| 34 | 34 | from gajim.common.events import MucInvitation
|
| 35 | 35 | from gajim.common.events import MucDecline
|
| 36 | 36 | from gajim.common.helpers import get_groupchat_name
|
| 37 | -from gajim.common.helpers import get_muc_context
|
|
| 38 | 37 | |
| 39 | 38 | from .menus import get_subscription_menu
|
| 40 | 39 | from .util import open_window
|
| ... | ... | @@ -240,8 +239,9 @@ def add_invitation_received(self, event: MucInvitation) -> None: |
| 240 | 239 | self.update_unread_count()
|
| 241 | 240 | |
| 242 | 241 | jid = event.from_.bare
|
| 243 | - muc_context = get_muc_context(event.muc)
|
|
| 244 | - if (muc_context == 'private' and
|
|
| 242 | + client = app.get_client(event.account)
|
|
| 243 | + contact = client.get_module('Contacts').get_contact(event.muc)
|
|
| 244 | + if (contact.muc_context == 'private' and
|
|
| 245 | 245 | not event.muc.bare_match(event.from_)):
|
| 246 | 246 | contact = self._client.get_module('Contacts').get_contact(jid)
|
| 247 | 247 | text = _('%(contact)s invited you to %(chat)s') % {
|
| ... | ... | @@ -411,8 +411,9 @@ def __init__(self, account: str, event: MucInvitation) -> None: |
| 411 | 411 | title_label.get_style_context().add_class('bold')
|
| 412 | 412 | self.grid.attach(title_label, 2, 1, 1, 1)
|
| 413 | 413 | |
| 414 | - muc_context = get_muc_context(event.muc)
|
|
| 415 | - if (muc_context == 'private' and
|
|
| 414 | + client = app.get_client(event.account)
|
|
| 415 | + contact = client.get_module('Contacts').get_contact(event.muc)
|
|
| 416 | + if (contact.muc_context == 'private' and
|
|
| 416 | 417 | not event.muc.bare_match(event.from_)):
|
| 417 | 418 | contact = self._client.get_module('Contacts').get_contact(jid)
|
| 418 | 419 | invitation_text = _('%(contact)s invited you to %(chat)s') % {
|