settings.py: add Chat.Composer.TypingNotifications
This commit is contained in:
		@@ -1312,6 +1312,13 @@ class MatrixClient(nio.AsyncClient):
 | 
				
			|||||||
    ):
 | 
					    ):
 | 
				
			||||||
        """Set typing notice to the server."""
 | 
					        """Set typing notice to the server."""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if not utils.config_get_account_room_rule(
 | 
				
			||||||
 | 
					            rules   = self.backend.settings.Chat.Composer.TypingNotifications,
 | 
				
			||||||
 | 
					            user_id = self.user_id,
 | 
				
			||||||
 | 
					            room_id = room_id,
 | 
				
			||||||
 | 
					        ):
 | 
				
			||||||
 | 
					            return
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        presence = self.models["accounts"][self.user_id].presence
 | 
					        presence = self.models["accounts"][self.user_id].presence
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if presence not in [Presence.State.invisible, Presence.State.offline]:
 | 
					        if presence not in [Presence.State.invisible, Presence.State.offline]:
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -179,6 +179,11 @@ class Section(MutableMapping):
 | 
				
			|||||||
        return f"{name}({content})"
 | 
					        return f"{name}({content})"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def children(self) -> Tuple[Tuple[str, Union["Section", Any]], ...]:
 | 
				
			||||||
 | 
					        """Return pairs of (name, value) for child sections and properties."""
 | 
				
			||||||
 | 
					        return tuple((name, getattr(self, name)) for name in self)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @classmethod
 | 
					    @classmethod
 | 
				
			||||||
    def _register_set_attr(cls, name: str, add_to_set_name: str) -> None:
 | 
					    def _register_set_attr(cls, name: str, add_to_set_name: str) -> None:
 | 
				
			||||||
        cls.methods.discard(name)
 | 
					        cls.methods.discard(name)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -9,6 +9,7 @@ import html
 | 
				
			|||||||
import inspect
 | 
					import inspect
 | 
				
			||||||
import io
 | 
					import io
 | 
				
			||||||
import json
 | 
					import json
 | 
				
			||||||
 | 
					import re
 | 
				
			||||||
import sys
 | 
					import sys
 | 
				
			||||||
import xml.etree.cElementTree as xml_etree
 | 
					import xml.etree.cElementTree as xml_etree
 | 
				
			||||||
from concurrent.futures import ProcessPoolExecutor
 | 
					from concurrent.futures import ProcessPoolExecutor
 | 
				
			||||||
@@ -33,6 +34,7 @@ from nio.crypto import async_generator_from_data
 | 
				
			|||||||
from PIL import Image as PILImage
 | 
					from PIL import Image as PILImage
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from .color import Color
 | 
					from .color import Color
 | 
				
			||||||
 | 
					from .pcn.section import Section
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if sys.version_info >= (3, 7):
 | 
					if sys.version_info >= (3, 7):
 | 
				
			||||||
    from contextlib import asynccontextmanager
 | 
					    from contextlib import asynccontextmanager
 | 
				
			||||||
@@ -105,6 +107,20 @@ def flatten_dict_keys(
 | 
				
			|||||||
    return flat
 | 
					    return flat
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def config_get_account_room_rule(
 | 
				
			||||||
 | 
					    rules: Section, user_id: str, room_id: str,
 | 
				
			||||||
 | 
					) -> Any:
 | 
				
			||||||
 | 
					    """Return best matching rule value for an account/room PCN free Section."""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    for name, value in reversed(rules.children()):
 | 
				
			||||||
 | 
					        name = re.sub(r"\s+", " ", name.strip())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if name in (user_id, room_id, f"{user_id} {room_id}"):
 | 
				
			||||||
 | 
					            return value
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return rules.default
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async def is_svg(file: File) -> bool:
 | 
					async def is_svg(file: File) -> bool:
 | 
				
			||||||
    """Return whether the file is a SVG (`lxml` is used for detection)."""
 | 
					    """Return whether the file is a SVG (`lxml` is used for detection)."""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -98,7 +98,7 @@ class Chat:
 | 
				
			|||||||
    always_center_header: bool = False
 | 
					    always_center_header: bool = False
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # When the chat timeline is larger than this pixel number,
 | 
					    # When the chat timeline is larger than this pixel number,
 | 
				
			||||||
    # Align your own messages to the left of the timeline instead of right.
 | 
					    # align your own messages to the left of the timeline instead of right.
 | 
				
			||||||
    # Can be 0 to always show your messages on the left.
 | 
					    # Can be 0 to always show your messages on the left.
 | 
				
			||||||
    own_messages_on_left_above: int = 895
 | 
					    own_messages_on_left_above: int = 895
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -122,6 +122,21 @@ class Chat:
 | 
				
			|||||||
    mark_read_delay: float = 0.2
 | 
					    mark_read_delay: float = 0.2
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    class Composer:
 | 
					    class Composer:
 | 
				
			||||||
 | 
					        class TypingNotifications:
 | 
				
			||||||
 | 
					            # Rules controlling whether "<user> is typing..." notifications
 | 
				
			||||||
 | 
					            # should be sent to other users in rooms.
 | 
				
			||||||
 | 
					            # The `default` property is required. Other properties can be
 | 
				
			||||||
 | 
					            # added: user IDs, room IDs, or space-separated user + room IDs.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            # Send typing notifications everywhere by default:
 | 
				
			||||||
 | 
					            default: bool = True
 | 
				
			||||||
 | 
					            # But don't send them for rooms under this account:
 | 
				
			||||||
 | 
					            "@account_1:example.org": bool = False
 | 
				
			||||||
 | 
					            # Neither send them in this room, regardless of the account used:
 | 
				
			||||||
 | 
					            "!room:example.org": bool = False
 | 
				
			||||||
 | 
					            # Except if it's this account and this room, then send them:
 | 
				
			||||||
 | 
					            "@account_2:example.org !room:example.org": bool = True
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        class Aliases:
 | 
					        class Aliases:
 | 
				
			||||||
            # Each property is the user ID of an account, value is the alias.
 | 
					            # Each property is the user ID of an account, value is the alias.
 | 
				
			||||||
            # From any chat, start a message with an alias followed by a space
 | 
					            # From any chat, start a message with an alias followed by a space
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user