Chat
elva.apps.chat
ELVA chat app.
Classes:
-
MessageView
–Widget displaying a single message alongside its metadata.
-
MessageList
–Base container class for
MessageView
widgets. -
History
–List of already sent messages.
-
HistoryParser
–Parser for changes in the message history.
-
Future
–List of currently composed messages.
-
FutureParser
–Parser for changes in currently composed messages.
-
MessagePreview
–Preview of the rendered markdown content.
-
UI
–User interface.
Functions:
-
get_chat_provider
–Get the chat provider handling the given message type.
-
cli
–Send messages with real-time preview.
Attributes:
-
WHITESPACE_ONLY
–Regular Expression for whitespace-only messages.
WHITESPACE_ONLY = re.compile('^\\s*$')
module-attribute
Regular Expression for whitespace-only messages.
MessageView(author, text, **kwargs)
Bases: Widget
Widget displaying a single message alongside its metadata.
Parameters:
-
author
(str
) –the author of the message.
-
text
(Text
) –an instance of a Y text data type holding the message content.
-
kwargs
(dict
, default:{}
) –keyword arguments passed to
Widget
.
Methods:
-
on_mount
–Hook called on mounting the widget.
-
compose
–Hook arranging child widgets.
-
text_callback
–Hook called on changes in the message text.
Source code in src/elva/apps/chat.py
on_mount()
Hook called on mounting the widget.
This method subscribes to changes in the message text and displays it if there is some content to show.
Source code in src/elva/apps/chat.py
compose()
text_callback(event)
Hook called on changes in the message text.
This method updates the visibility of the view in dependence of the message content.
Parameters:
-
event
(TextEvent
) –object holding information about the changes in the Y text.
Source code in src/elva/apps/chat.py
MessageList(messages, user, **kwargs)
Bases: VerticalScroll
Base container class for MessageView
widgets.
Parameters:
-
messages
(Array | Map
) –Y array or Y map containing message objects.
-
user
(str
) –the current username of the app.
-
kwargs
(dict
, default:{}
) –keyword arguments passed to
VerticalScroll
.
Methods:
-
mount_message_view
–Create a
MessageView
.
Source code in src/elva/apps/chat.py
mount_message_view(message, message_id=None)
Create a MessageView
.
Parameters:
-
message
(Map | dict
) –mapping of message attributes.
-
message_id
(None | str
, default:None
) –Textual
DOM tree identifier to assign to the message view.
Returns:
-
MessageView
–a message view to be mounted inside an instance of this class.
Source code in src/elva/apps/chat.py
History(messages, user, **kwargs)
Bases: MessageList
List of already sent messages.
Methods:
-
compose
–Hook arranging child widgets.
Source code in src/elva/apps/chat.py
HistoryParser(history, widget)
Bases: ArrayEventParser
Parser for changes in the message history.
This class reflects the state of the Y array with history message in the History
message list on changes.
Parameters:
-
history
(Array
) –Y array containing already sent messages.
Methods:
-
history_callback
–Hook called on a change in the Y array message history.
-
run
–Hook called after the component sets the
started
signal. -
on_insert
–Hook called on an insert action in a Y array change event.
-
on_delete
–Hook called on a delete action in a Y array change event.
Source code in src/elva/apps/chat.py
history_callback(event)
Hook called on a change in the Y array message history.
This method parses the event and calls the defined action hooks accordingly.
Parameters:
-
event
(ArrayEvent
) –an object holding information about the change in the Y array.
Source code in src/elva/apps/chat.py
run()
async
Hook called after the component sets the started
signal.
This method subscribes to changes in the Y array message history.
Source code in src/elva/apps/chat.py
on_insert(range_offset, insert_value)
async
Hook called on an insert action in a Y array change event.
This methods creates a new message view and mounts it to the message history.
Parameters:
Source code in src/elva/apps/chat.py
on_delete(range_offset, range_length)
async
Hook called on a delete action in a Y array change event.
This method removes the all message views in the given index range.
Parameters:
-
range_offset
(int
) –the start index of the deletion.
-
range_length
(str
) –the number of subsequent indices.
Source code in src/elva/apps/chat.py
Future(messages, user, show_self=False, **kwargs)
Bases: MessageList
List of currently composed messages.
Parameters:
-
messages
(Map
) –mapping of message identifiers to their corresponding message object.
-
user
(str
) –the current username of the app.
-
show_self
(bool
, default:False
) –flag whether to show the own currently composed message.
-
kwargs
(dict
, default:{}
) –keyword arguments passed to
MessageList
.
Methods:
-
compose
–Hook arranging child widgets.
Source code in src/elva/apps/chat.py
compose()
Hook arranging child widgets.
Source code in src/elva/apps/chat.py
FutureParser(future, widget, user, show_self)
Bases: MapEventParser
Parser for changes in currently composed messages.
This class reflects the state of the Y map with currently composed messaged in the Future
message list on changes.
Parameters:
-
future
(Map
) –Y map mapping message identifiers to their corresponding message objects.
-
widget
(Future
) –the message list widget displaying the currently composed messages.
-
user
(str
) –the current username.
-
show_self
(bool
) –flag whether to show the own currently composed message.
Methods:
-
future_callback
–Hook called on changes in the Y map.
-
run
–Hook called after the component set the
started
signal. -
on_add
–Hook called on an add action.
-
on_delete
–Hook called on a delete action.
Source code in src/elva/apps/chat.py
future_callback(event)
Hook called on changes in the Y map.
This method parses the event object and calls action hooks accordingly.
Parameters:
-
event
(MapEvent
) –an object holding information about the change in the Y map.
Source code in src/elva/apps/chat.py
run()
async
Hook called after the component set the started
signal.
This method subscribes to changes in the mapping of currently composed messages.
Source code in src/elva/apps/chat.py
on_add(key, new_value)
async
Hook called on an add action.
This methods generates a message view from the added message object and mounts it to the list of currently composed messages.
Parameters:
-
key
(str
) –the message id that has been added.
-
new_value
(dict
) –the message object that has been added.
Source code in src/elva/apps/chat.py
on_delete(key, old_value)
async
Hook called on a delete action.
This methods removes the message view corresponding to the removed message id.
Parameters:
-
key
(str
) –the message id that has been deleted.
-
old_value
(dict
) –the message object that has been deleted.
Source code in src/elva/apps/chat.py
MessagePreview(ytext, *args, **kwargs)
Bases: Static
Preview of the rendered markdown content.
Parameters:
-
ytext
(Text
) –Y text with the markdown content of the own currently composed message.
-
args
(tuple
, default:()
) –positional arguments passed to
Static
. -
kwargs
(dict
, default:{}
) –keyword arguments passed to
Static
.
Methods:
-
on_show
–Hook called on a show message.
Source code in src/elva/apps/chat.py
UI(user, name, password, server, identifier, messages, file_path, show_self=True)
Bases: App
User interface.
Parameters:
-
user
(str
) –the current user name to login with.
-
name
(str
) –the name to display instead of the user name.
-
password
(str
) –the password to login with.
-
server
(str
) –the server address to connect to for synchronization.
-
identifier
(str
) –the identifier of this chat document.
-
messages
(str
) –the message type to use.
-
file_path
(Path
) –path to an ELVA SQLite database file holding the content of the chat.
-
show_self
(bool
, default:True
) –flag whether to show the own currently composed message.
Methods:
-
get_new_id
–Get a new message id.
-
get_message
–Get a message object.
-
on_exception
–Hook called on an exception raised within the provider component.
-
update_credentials
–Hook called on new credentials.
-
quit_on_error
–Hook called on closing an
ErrorScreen
. -
run_components
–Run all components the chat app needs.
-
on_mount
–Hook called on mounting the app.
-
on_unmount
–Hook called when unmounting, i.e. closing, the app.
-
compose
–Hook arranging child widgets.
-
action_send
–Hook called on an invoked send action.
-
on_tabbed_content_tab_activated
–Hook called on a tab activated message from a tabbed content widget.
Attributes:
Source code in src/elva/apps/chat.py
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 |
|
CSS_PATH = 'chat.tcss'
class-attribute
instance-attribute
Path to the applied textual CSS file.
BINDINGS = [('ctrl+s', 'send', 'Send currently composed message')]
class-attribute
instance-attribute
Key bindings for controlling the app.
get_new_id()
get_message(text, message_id=None)
Get a message object.
Parameters:
-
text
(str
) –the content of the message.
-
message_id
(None | str
, default:None
) –the identifier of the message.
Returns:
-
Map
–a Y map containing a mapping of message attributes.
Source code in src/elva/apps/chat.py
on_exception(exc)
async
Hook called on an exception raised within the provider component.
This method handles connection errors due to wrong credentials or other issues.
Parameters:
-
exc
(Exception
) –exception raised within the provider component.
Source code in src/elva/apps/chat.py
update_credentials(credentials)
Hook called on new credentials.
Parameters:
Source code in src/elva/apps/chat.py
quit_on_error(exc)
async
Hook called on closing an ErrorScreen
.
This method exits the app.
Parameters:
-
exc
(Exception
) –the exception caught by the ErrorScreen.
Source code in src/elva/apps/chat.py
run_components()
async
on_mount()
async
Hook called on mounting the app.
This methods waits for all components to set their started
signal.
Source code in src/elva/apps/chat.py
on_unmount()
async
Hook called when unmounting, i.e. closing, the app.
This methods waits for all components to set their stopped
signal.
Source code in src/elva/apps/chat.py
compose()
Hook arranging child widgets.
Source code in src/elva/apps/chat.py
action_send()
async
Hook called on an invoked send action.
This method transfers the message from the future to the history.
Source code in src/elva/apps/chat.py
on_tabbed_content_tab_activated(event)
Hook called on a tab activated message from a tabbed content widget.
Parameters:
-
event
(Message
) –object holding information about the tab activated message.
Source code in src/elva/apps/chat.py
get_chat_provider(messages)
Get the chat provider handling the given message type.
Parameters:
-
messages
(str
) –string naming the used message type.
Returns:
-
WebsocketProvider | ElvaWebsocketProvider
–the provider component handling Y updates over a network connection.
Source code in src/elva/apps/chat.py
cli(ctx, show_self, file)
Send messages with real-time preview.
Parameters:
-
show_self
(bool
) –flag whether to show the own currently composed message.
-
file
(None | Path
) –path to an ELVA SQLite database file.