| ... |
... |
@@ -96,7 +96,7 @@ class _Settings: |
|
96
|
96
|
print('remove handler', handler)
|
|
97
|
97
|
handlers.remove(handler)
|
|
98
|
98
|
|
|
99
|
|
- def _notify(self, setting, account=None, jid=None):
|
|
|
99
|
+ def _notify(self, value, setting, account=None, jid=None):
|
|
100
|
100
|
log.info('Signal: %s changed', setting)
|
|
101
|
101
|
|
|
102
|
102
|
callbacks = self._callbacks[(setting, account, jid)]
|
| ... |
... |
@@ -105,7 +105,7 @@ class _Settings: |
|
105
|
105
|
callbacks.remove(func)
|
|
106
|
106
|
continue
|
|
107
|
107
|
try:
|
|
108
|
|
- func()(setting, account, jid)
|
|
|
108
|
+ func()(value, setting, account, jid)
|
|
109
|
109
|
except Exception:
|
|
110
|
110
|
log.exception('Error while executing signal callback')
|
|
111
|
111
|
|
| ... |
... |
@@ -418,24 +418,24 @@ class _Settings: |
|
418
|
418
|
if setting not in APP_SETTINGS:
|
|
419
|
419
|
raise ValueError(f'Invalid app setting: {setting}')
|
|
420
|
420
|
|
|
|
421
|
+ default = APP_SETTINGS[setting]
|
|
|
422
|
+ if not isinstance(value, type(default)) and value is not None:
|
|
|
423
|
+ raise TypeError(f'Invalid type for {setting}: '
|
|
|
424
|
+ f'{value} {type(value)}')
|
|
|
425
|
+
|
|
421
|
426
|
if value is None:
|
|
422
|
427
|
try:
|
|
423
|
428
|
del self._settings['app'][setting]
|
|
424
|
429
|
except KeyError:
|
|
425
|
430
|
pass
|
|
426
|
431
|
|
|
427
|
|
- self._notify(setting)
|
|
|
432
|
+ self._notify(default, setting)
|
|
428
|
433
|
return
|
|
429
|
434
|
|
|
430
|
|
- default = APP_SETTINGS[setting]
|
|
431
|
|
- if not isinstance(value, type(default)):
|
|
432
|
|
- raise TypeError(f'Invalid type for {setting}: '
|
|
433
|
|
- f'{value} {type(value)}')
|
|
434
|
|
-
|
|
435
|
435
|
self._settings['app'][setting] = value
|
|
436
|
436
|
|
|
437
|
437
|
self._commit_settings('app')
|
|
438
|
|
- self._notify(setting)
|
|
|
438
|
+ self._notify(value, setting)
|
|
439
|
439
|
|
|
440
|
440
|
set = set_app_setting
|
|
441
|
441
|
|
| ... |
... |
@@ -529,22 +529,24 @@ class _Settings: |
|
529
|
529
|
if setting not in ACCOUNT_SETTINGS['account']:
|
|
530
|
530
|
raise ValueError(f'Invalid account setting: {setting}')
|
|
531
|
531
|
|
|
|
532
|
+ default = ACCOUNT_SETTINGS['account'][setting]
|
|
|
533
|
+ if not isinstance(value, type(default)) and value is not None:
|
|
|
534
|
+ raise TypeError(f'Invalid type for {setting}: '
|
|
|
535
|
+ f'{value} {type(value)}')
|
|
|
536
|
+
|
|
532
|
537
|
if value is None:
|
|
533
|
538
|
try:
|
|
534
|
539
|
del self._account_settings[account]['account'][setting]
|
|
535
|
540
|
except KeyError:
|
|
536
|
541
|
pass
|
|
537
|
|
- return
|
|
538
|
542
|
|
|
539
|
|
- default = ACCOUNT_SETTINGS['account'][setting]
|
|
540
|
|
- if not isinstance(value, type(default)):
|
|
541
|
|
- raise TypeError(f'Invalid type for {setting}: '
|
|
542
|
|
- f'{value} {type(value)}')
|
|
|
543
|
+ self._notify(default, setting, account)
|
|
|
544
|
+ return
|
|
543
|
545
|
|
|
544
|
546
|
self._account_settings[account]['account'][setting] = value
|
|
545
|
547
|
|
|
546
|
548
|
self._commit_account_settings(account)
|
|
547
|
|
- self._notify(setting, account)
|
|
|
549
|
+ self._notify(value, setting, account)
|
|
548
|
550
|
|
|
549
|
551
|
def get_group_chat_setting(self,
|
|
550
|
552
|
account: str,
|
| ... |
... |
@@ -582,13 +584,6 @@ class _Settings: |
|
582
|
584
|
if setting not in ACCOUNT_SETTINGS['group_chat']:
|
|
583
|
585
|
raise ValueError(f'Invalid group chat setting: {setting}')
|
|
584
|
586
|
|
|
585
|
|
- if value is None:
|
|
586
|
|
- try:
|
|
587
|
|
- del self._account_settings[account]['group_chat'][setting]
|
|
588
|
|
- except KeyError:
|
|
589
|
|
- pass
|
|
590
|
|
- return
|
|
591
|
|
-
|
|
592
|
587
|
default = ACCOUNT_SETTINGS['group_chat'][setting]
|
|
593
|
588
|
if default is HAS_APP_DEFAULT:
|
|
594
|
589
|
if context is None:
|
| ... |
... |
@@ -596,10 +591,19 @@ class _Settings: |
|
596
|
591
|
else:
|
|
597
|
592
|
default = APP_SETTINGS[f'gc_{setting}_{context}_default']
|
|
598
|
593
|
|
|
599
|
|
- if not isinstance(value, type(default)):
|
|
|
594
|
+ if not isinstance(value, type(default)) and value is not None:
|
|
600
|
595
|
raise TypeError(f'Invalid type for {setting}: '
|
|
601
|
596
|
f'{value} {type(value)}')
|
|
602
|
597
|
|
|
|
598
|
+ if value is None:
|
|
|
599
|
+ try:
|
|
|
600
|
+ del self._account_settings[account]['group_chat'][setting]
|
|
|
601
|
+ except KeyError:
|
|
|
602
|
+ pass
|
|
|
603
|
+
|
|
|
604
|
+ self._notify(default, setting, account, jid)
|
|
|
605
|
+ return
|
|
|
606
|
+
|
|
603
|
607
|
group_chat_settings = self._account_settings[account]['group_chat']
|
|
604
|
608
|
if jid not in group_chat_settings:
|
|
605
|
609
|
group_chat_settings[jid] = {setting: value}
|
| ... |
... |
@@ -607,7 +611,7 @@ class _Settings: |
|
607
|
611
|
group_chat_settings[jid][setting] = value
|
|
608
|
612
|
|
|
609
|
613
|
self._commit_account_settings(account)
|
|
610
|
|
- self._notify(setting, account, jid)
|
|
|
614
|
+ self._notify(value, setting, account, jid)
|
|
611
|
615
|
|
|
612
|
616
|
def get_contact_setting(self,
|
|
613
|
617
|
account: str,
|
| ... |
... |
@@ -640,19 +644,21 @@ class _Settings: |
|
640
|
644
|
if setting not in ACCOUNT_SETTINGS['contact']:
|
|
641
|
645
|
raise ValueError(f'Invalid contact setting: {setting}')
|
|
642
|
646
|
|
|
|
647
|
+ default = ACCOUNT_SETTINGS['contact'][setting]
|
|
|
648
|
+ if default is HAS_APP_DEFAULT:
|
|
|
649
|
+ default = APP_SETTINGS[f'{setting}_default']
|
|
|
650
|
+ if not isinstance(value, type(default)) and value is not None:
|
|
|
651
|
+ raise TypeError(f'Invalid type for {setting}: '
|
|
|
652
|
+ f'{value} {type(value)}')
|
|
|
653
|
+
|
|
643
|
654
|
if value is None:
|
|
644
|
655
|
try:
|
|
645
|
656
|
del self._account_settings[account]['contact'][setting]
|
|
646
|
657
|
except KeyError:
|
|
647
|
658
|
pass
|
|
648
|
|
- return
|
|
649
|
659
|
|
|
650
|
|
- default = ACCOUNT_SETTINGS['contact'][setting]
|
|
651
|
|
- if default is HAS_APP_DEFAULT:
|
|
652
|
|
- default = APP_SETTINGS[f'{setting}_default']
|
|
653
|
|
- if not isinstance(value, type(default)):
|
|
654
|
|
- raise TypeError(f'Invalid type for {setting}: '
|
|
655
|
|
- f'{value} {type(value)}')
|
|
|
660
|
+ self._notify(default, setting, account, jid)
|
|
|
661
|
+ return
|
|
656
|
662
|
|
|
657
|
663
|
contact_settings = self._account_settings[account]['contact']
|
|
658
|
664
|
if jid not in contact_settings:
|
| ... |
... |
@@ -661,7 +667,7 @@ class _Settings: |
|
661
|
667
|
contact_settings[jid][setting] = value
|
|
662
|
668
|
|
|
663
|
669
|
self._commit_account_settings(account)
|
|
664
|
|
- self._notify(setting, account, jid)
|
|
|
670
|
+ self._notify(value, setting, account, jid)
|
|
665
|
671
|
|
|
666
|
672
|
def set_soundevent_setting(self,
|
|
667
|
673
|
event_name: str,
|