# Slixmpp: The Slick XMPP Library# Copyright (C) 2025 nicoco# This file is part of Slixmpp.# See the file LICENSE for copying permission.fromtypingimportLiteral,Optional,castfromslixmppimportregister_stanza_pluginfromslixmpp.plugins.xep_0402.stanzaimportExtensionsfromslixmpp.typesimportClientTypesfromslixmpp.xmlstreamimportElementBaseNS="urn:xmpp:notification-settings:0"WhenLiteral=Literal["never","always","on-mention"]
[docs]classNotify(ElementBase):""" Chat notification settings element To enable it on a Conference element, use configure() like this: .. code-block::python # C being a Conference element C['extensions']["notify"].configure("always", client_type="pc") Which will add the <notify> element to the <extensions> element. """namespace=NSname="notify"plugin_attrib="notify"interfaces={"notify"}
[docs]defconfigure(self,when:WhenLiteral,client_type:Optional[ClientTypes]=None)->None:""" Configure the chat notification settings for this bookmark. This method ensures that there are no conflicting settings, e.g., both a <never /> and a <always /> element. """cls=_CLASS_MAP[when]element=cls()ifclient_typeisnotNone:element["client-type"]=client_typematch=client_typeifclient_typeisnotNoneelse""forchildinself:ifisinstance(child,_Base)andchild["client-type"]==match:self.xml.remove(child.xml)self.append(element)
[docs]defget_config(self,client_type:Optional[ClientTypes]=None)->Optional[WhenLiteral]:""" Get the chat notification settings for this bookmark. :param client_type: Optionally, get the notification for a specific client type. If unset, returns the global notification setting. :return: The chat notification setting as a string, or None if unset. """match=client_typeifclient_typeisnotNoneelse""forchildinself:ifisinstance(child,_Base)andchild["client-type"]==match:returncast(WhenLiteral,child.name)returnNone