|
@@ -1,4 +1,5 @@
|
|
-from typing import Optional
|
|
|
|
|
|
+import html
|
|
|
|
+from typing import List, Optional, Union
|
|
|
|
|
|
from ..dependencies import register_component
|
|
from ..dependencies import register_component
|
|
from ..element import Element
|
|
from ..element import Element
|
|
@@ -9,26 +10,36 @@ register_component('chat_message', __file__, 'chat_message.js')
|
|
class ChatMessage(Element):
|
|
class ChatMessage(Element):
|
|
|
|
|
|
def __init__(self,
|
|
def __init__(self,
|
|
- text: str, *,
|
|
|
|
|
|
+ text: Union[str, List[str]], *,
|
|
name: Optional[str] = None,
|
|
name: Optional[str] = None,
|
|
label: Optional[str] = None,
|
|
label: Optional[str] = None,
|
|
stamp: Optional[str] = None,
|
|
stamp: Optional[str] = None,
|
|
avatar: Optional[str] = None,
|
|
avatar: Optional[str] = None,
|
|
sent: bool = False,
|
|
sent: bool = False,
|
|
|
|
+ text_html: bool = False,
|
|
) -> None:
|
|
) -> None:
|
|
"""Chat Message
|
|
"""Chat Message
|
|
|
|
|
|
Based on Quasar's `Chat Message <https://quasar.dev/vue-components/chat/>`_ component.
|
|
Based on Quasar's `Chat Message <https://quasar.dev/vue-components/chat/>`_ component.
|
|
|
|
|
|
- :param text: the message body
|
|
|
|
|
|
+ :param text: the message body (can be a list of strings for multiple message parts)
|
|
:param name: the name of the message author
|
|
:param name: the name of the message author
|
|
:param label: renders a label header/section only
|
|
:param label: renders a label header/section only
|
|
:param stamp: timestamp of the message
|
|
:param stamp: timestamp of the message
|
|
:param avatar: URL to an avatar
|
|
:param avatar: URL to an avatar
|
|
:param sent: render as a sent message (so from current user) (default: False)
|
|
:param sent: render as a sent message (so from current user) (default: False)
|
|
|
|
+ :param text_html: render text as HTML (default: False)
|
|
"""
|
|
"""
|
|
super().__init__('chat_message')
|
|
super().__init__('chat_message')
|
|
|
|
+
|
|
|
|
+ if isinstance(text, str):
|
|
|
|
+ text = [text]
|
|
|
|
+ if not text_html:
|
|
|
|
+ text = [html.escape(part) for part in text]
|
|
|
|
+ text = [part.replace('\n', '<br />') for part in text]
|
|
self._props['text'] = text
|
|
self._props['text'] = text
|
|
|
|
+ self._props['text-html'] = True
|
|
|
|
+
|
|
if name is not None:
|
|
if name is not None:
|
|
self._props['name'] = name
|
|
self._props['name'] = name
|
|
if label is not None:
|
|
if label is not None:
|