2023-12-29 21:56:37 +01:00
// Copyright (c) 2023 xmpp-rs contributors.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
2024-12-18 12:44:59 +01:00
use tokio_xmpp ::jid ::BareJid ;
2024-01-18 15:18:33 +01:00
#[ cfg(feature = " avatars " ) ]
2024-07-24 20:52:10 +02:00
use tokio_xmpp ::jid ::Jid ;
2025-04-18 12:26:27 +02:00
use tokio_xmpp ::parsers ::roster ::Item as RosterItem ;
2023-12-29 21:56:37 +01:00
2025-08-26 21:28:41 +02:00
use crate ::parsers ::confirm ::Confirm ;
2024-12-21 00:10:13 +01:00
use crate ::{ delay ::StanzaTimeInfo , Error , MessageId , RoomNick } ;
2023-12-29 21:56:37 +01:00
2024-07-31 14:27:32 +02:00
/// An Event notifying the client something has happened that may require attention.
///
/// This can be an XMPP event received from the server, or existing state communicated by the server to the client, like when receiving the contact list.
2023-12-29 21:56:37 +01:00
#[ derive(Debug) ]
pub enum Event {
2024-07-31 14:27:32 +02:00
/// Client connected.
2023-12-29 21:56:37 +01:00
Online ,
2024-07-31 14:27:32 +02:00
/// Client disconnected; if reconnect is disabled, no more event will be received.
2023-12-29 21:56:37 +01:00
Disconnected ( Error ) ,
2024-07-31 14:27:32 +02:00
/// Contact received from contact list (roster).
///
/// This happens when:
///
/// - it was added recently to the contact list
/// - or when the client just came online and is receiving the existing contact list
2023-12-29 21:56:37 +01:00
ContactAdded ( RosterItem ) ,
2024-07-31 14:27:32 +02:00
/// Contact removed from contact list (roster).
2023-12-29 21:56:37 +01:00
ContactRemoved ( RosterItem ) ,
2024-07-31 14:27:32 +02:00
/// Contact changed in contact list (roster).
///
/// This happens when (non-exhaustive):
///
/// - the contact's nickname changed
/// - the contact's subscription status changed (eg. they accepted a friend request)
/// - the contact has been added to or removed from a contact group
2023-12-29 21:56:37 +01:00
ContactChanged ( RosterItem ) ,
#[ cfg(feature = " avatars " ) ]
2024-07-31 14:27:32 +02:00
/// Avatar received for a certain JID, with sender JID / avatar path
///
/// The avatar path is relative file path to the avatar data.
///
/// NOTE: For now, it's not possible to configure where the avatars are stored, see [issue 112](https://gitlab.com/xmpp-rs/xmpp-rs/-/issues/112) for more information.
2023-12-29 21:56:37 +01:00
AvatarRetrieved ( Jid , String ) ,
2023-12-31 21:06:15 +01:00
/// A chat message was received. It may have been delayed on the network.
2024-12-21 00:10:13 +01:00
/// - The [`MessageId`] is a unique identifier for this message.
2023-12-31 21:06:15 +01:00
/// - The [`BareJid`] is the sender's JID.
2025-04-18 12:26:27 +02:00
/// - The [`String`] is the message body.
2023-12-31 21:06:15 +01:00
/// - The [`StanzaTimeInfo`] about when message was received, and when the message was claimed sent.
2025-04-18 12:26:27 +02:00
ChatMessage ( Option < MessageId > , BareJid , String , StanzaTimeInfo ) ,
2024-12-19 17:20:11 +01:00
/// A message in a one-to-one chat was corrected/edited.
2024-12-21 00:10:13 +01:00
/// - The [`MessageId`] is the ID of the message that was corrected.
2024-12-19 17:20:11 +01:00
/// - The [`BareJid`] is the JID of the other participant in the chat.
2025-04-18 12:26:27 +02:00
/// - The [`String`] is the new body of the message, to replace the old one.
2024-12-19 17:20:11 +01:00
/// - The [`StanzaTimeInfo`] is the time the message correction was sent/received
2025-04-18 12:26:27 +02:00
ChatMessageCorrection ( MessageId , BareJid , String , StanzaTimeInfo ) ,
2025-08-26 21:28:41 +02:00
/// A XEP-0070 authentication request or confirmation was received.
/// - The [`BareJid`] is the sender's JID.
/// - The [`Confirm`] is the info about the authentication request.
/// - The [`StanzaTimeInfo`] about when message was received, and when the message was claimed sent.
AuthConfirm ( BareJid , Confirm , StanzaTimeInfo ) ,
/// A XEP-0070 authentication rejection was received.
/// - The [`BareJid`] is the sender's JID.
/// - The [`Confirm`] is the info about the authentication request that was rejected.
/// - The [`StanzaTimeInfo`] about when message was received, and when the message was claimed sent.
AuthReject ( BareJid , Confirm , StanzaTimeInfo ) ,
2024-07-31 14:27:32 +02:00
/// Room joined; client may receive and send messages from/to this BareJid.
2023-12-29 21:56:37 +01:00
RoomJoined ( BareJid ) ,
2024-07-31 14:27:32 +02:00
/// Room left; client may not receive and send messages from/to this BareJid
2023-12-29 21:56:37 +01:00
RoomLeft ( BareJid ) ,
2024-07-31 14:27:32 +02:00
/// Room message received with:
/// - An optional [`MessageId`] for the message.
/// - The [`BareJid`] of the room the message was sent from.
/// - The [`RoomNick`] of the sender.
/// - A [`String`] containing the actual message.
/// - The [`StanzaTimeInfo`] containing time related information for the message.
2025-04-18 12:26:27 +02:00
RoomMessage ( Option < MessageId > , BareJid , RoomNick , String , StanzaTimeInfo ) ,
2024-12-19 17:20:11 +01:00
/// A message in a MUC was corrected/edited.
2024-12-21 00:10:13 +01:00
/// - The [`MessageId`] is the ID of the message that was corrected.
2024-12-19 17:20:11 +01:00
/// - The [`BareJid`] is the JID of the room where the message was sent.
/// - The [`RoomNick`] is the nickname of the sender of the message.
2025-04-18 12:26:27 +02:00
/// - The [`String`] is the new body of the message, to replace the old one.
2024-12-19 17:20:11 +01:00
/// - The [`StanzaTimeInfo`] is the time the message correction was sent/received
2025-04-18 12:26:27 +02:00
RoomMessageCorrection ( MessageId , BareJid , RoomNick , String , StanzaTimeInfo ) ,
2023-12-31 19:41:34 +01:00
/// The subject of a room was received.
2024-07-31 14:27:32 +02:00
/// - The [`BareJid`] is the room's address.
/// - The [`RoomNick`] is the nickname of the room member who set the subject.
/// - The [`String`] is the new subject.
2024-12-18 12:44:59 +01:00
RoomSubject ( BareJid , Option < RoomNick > , String , StanzaTimeInfo ) ,
2024-07-31 14:27:32 +02:00
/// A private message received from a room, containing:
/// - An optional [`MessageId`] for the message.
/// - The room's [`BareJid`].
/// - The sender's [`RoomNick`].
/// - A [`String`] containing the actual message.
/// - The [`StanzaTimeInfo`] containing time related information for the message.
2025-04-18 12:26:27 +02:00
RoomPrivateMessage ( Option < MessageId > , BareJid , RoomNick , String , StanzaTimeInfo ) ,
2024-12-19 17:20:11 +01:00
/// A private message in a MUC was corrected/edited.
2024-12-21 00:10:13 +01:00
/// - The [`MessageId`] is the ID of the message that was corrected.
2024-12-19 17:20:11 +01:00
/// - The [`BareJid`] is the JID of the room where the message was sent.
/// - The [`RoomNick`] is the nickname of the sender of the message.
2025-04-18 12:26:27 +02:00
/// - The [`String`] is the new body of the message, to replace the old one.
2024-12-19 17:20:11 +01:00
/// - The [`StanzaTimeInfo`] is the time the message correction was sent/received
2025-04-18 12:26:27 +02:00
RoomPrivateMessageCorrection ( MessageId , BareJid , RoomNick , String , StanzaTimeInfo ) ,
2024-07-31 14:27:32 +02:00
/// Service message (eg. server notification) received, with:
/// - An optional [`MessageId`] for the message.
/// - The [`BareJid`] of the entity that sent it.
/// - A [`String`] containing the actual message.
/// - The [`StanzaTimeInfo`] containing time related information for the message.
2025-04-18 12:26:27 +02:00
ServiceMessage ( Option < MessageId > , BareJid , String , StanzaTimeInfo ) ,
2024-07-31 14:27:32 +02:00
/// A file has been uploaded over HTTP; contains the URL of the file.
2023-12-29 21:56:37 +01:00
HttpUploadedFile ( String ) ,
}