event.rs

  1// Copyright (c) 2023 xmpp-rs contributors.
  2//
  3// This Source Code Form is subject to the terms of the Mozilla Public
  4// License, v. 2.0. If a copy of the MPL was not distributed with this
  5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
  6
  7use tokio_xmpp::jid::BareJid;
  8#[cfg(feature = "avatars")]
  9use tokio_xmpp::jid::Jid;
 10use tokio_xmpp::parsers::roster::Item as RosterItem;
 11
 12use crate::{delay::StanzaTimeInfo, Error, MessageId, RoomNick};
 13
 14/// An Event notifying the client something has happened that may require attention.
 15///
 16/// 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.
 17#[derive(Debug)]
 18pub enum Event {
 19    /// Client connected.
 20    Online,
 21    /// Client disconnected; if reconnect is disabled, no more event will be received.
 22    Disconnected(Error),
 23    /// Contact received from contact list (roster).
 24    ///
 25    /// This happens when:
 26    ///
 27    /// - it was added recently to the contact list
 28    /// - or when the client just came online and is receiving the existing contact list
 29    ContactAdded(RosterItem),
 30    /// Contact removed from contact list (roster).
 31    ContactRemoved(RosterItem),
 32    /// Contact changed in contact list (roster).
 33    ///
 34    /// This happens when (non-exhaustive):
 35    ///
 36    /// - the contact's nickname changed
 37    /// - the contact's subscription status changed (eg. they accepted a friend request)
 38    /// - the contact has been added to or removed from a contact group
 39    ContactChanged(RosterItem),
 40    #[cfg(feature = "avatars")]
 41    /// Avatar received for a certain JID, with sender JID / avatar path
 42    ///
 43    /// The avatar path is relative file path to the avatar data.
 44    ///
 45    /// 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.
 46    AvatarRetrieved(Jid, String),
 47    /// A chat message was received. It may have been delayed on the network.
 48    /// - The [`MessageId`] is a unique identifier for this message.
 49    /// - The [`BareJid`] is the sender's JID.
 50    /// - The [`String`] is the message body.
 51    /// - The [`StanzaTimeInfo`] about when message was received, and when the message was claimed sent.
 52    ChatMessage(Option<MessageId>, BareJid, String, StanzaTimeInfo),
 53    /// A message in a one-to-one chat was corrected/edited.
 54    /// - The [`MessageId`] is the ID of the message that was corrected.
 55    /// - The [`BareJid`] is the JID of the other participant in the chat.
 56    /// - The [`String`] is the new body of the message, to replace the old one.
 57    /// - The [`StanzaTimeInfo`] is the time the message correction was sent/received
 58    ChatMessageCorrection(MessageId, BareJid, String, StanzaTimeInfo),
 59    /// Room joined; client may receive and send messages from/to this BareJid.
 60    RoomJoined(BareJid),
 61    /// Room left; client may not receive and send messages from/to this BareJid
 62    RoomLeft(BareJid),
 63    /// Room message received with:
 64    /// - An optional [`MessageId`] for the message.
 65    /// - The [`BareJid`] of the room the message was sent from.
 66    /// - The [`RoomNick`] of the sender.
 67    /// - A [`String`] containing the actual message.
 68    /// - The [`StanzaTimeInfo`] containing time related information for the message.
 69    RoomMessage(Option<MessageId>, BareJid, RoomNick, String, StanzaTimeInfo),
 70    /// A message in a MUC was corrected/edited.
 71    /// - The [`MessageId`] is the ID of the message that was corrected.
 72    /// - The [`BareJid`] is the JID of the room where the message was sent.
 73    /// - The [`RoomNick`] is the nickname of the sender of the message.
 74    /// - The [`String`] is the new body of the message, to replace the old one.
 75    /// - The [`StanzaTimeInfo`] is the time the message correction was sent/received
 76    RoomMessageCorrection(MessageId, BareJid, RoomNick, String, StanzaTimeInfo),
 77    /// The subject of a room was received.
 78    /// - The [`BareJid`] is the room's address.
 79    /// - The [`RoomNick`] is the nickname of the room member who set the subject.
 80    /// - The [`String`] is the new subject.
 81    RoomSubject(BareJid, Option<RoomNick>, String, StanzaTimeInfo),
 82    /// A private message received from a room, containing:
 83    /// - An optional [`MessageId`] for the message.
 84    /// - The room's [`BareJid`].
 85    /// - The sender's [`RoomNick`].
 86    /// - A [`String`] containing the actual message.
 87    /// - The [`StanzaTimeInfo`] containing time related information for the message.
 88    RoomPrivateMessage(Option<MessageId>, BareJid, RoomNick, String, StanzaTimeInfo),
 89    /// A private message in a MUC was corrected/edited.
 90    /// - The [`MessageId`] is the ID of the message that was corrected.
 91    /// - The [`BareJid`] is the JID of the room where the message was sent.
 92    /// - The [`RoomNick`] is the nickname of the sender of the message.
 93    /// - The [`String`] is the new body of the message, to replace the old one.
 94    /// - The [`StanzaTimeInfo`] is the time the message correction was sent/received
 95    RoomPrivateMessageCorrection(MessageId, BareJid, RoomNick, String, StanzaTimeInfo),
 96    /// Service message (eg. server notification) received, with:
 97    /// - An optional [`MessageId`] for the message.
 98    /// - The [`BareJid`] of the entity that sent it.
 99    /// - A [`String`] containing the actual message.
100    /// - The [`StanzaTimeInfo`] containing time related information for the message.
101    ServiceMessage(Option<MessageId>, BareJid, String, StanzaTimeInfo),
102    /// A file has been uploaded over HTTP; contains the URL of the file.
103    HttpUploadedFile(String),
104}