Trait matrix_sdk::EventHandler[][src]

pub trait EventHandler: Send + Sync {
Show methods fn on_room_member<'life0, 'life1, 'async_trait>(
        &'life0 self,
        __arg1: Room,
        __arg2: &'life1 SyncStateEvent<MemberEventContent>
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        Self: 'async_trait
, { ... }
fn on_room_name<'life0, 'life1, 'async_trait>(
        &'life0 self,
        __arg1: Room,
        __arg2: &'life1 SyncStateEvent<NameEventContent>
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        Self: 'async_trait
, { ... }
fn on_room_canonical_alias<'life0, 'life1, 'async_trait>(
        &'life0 self,
        __arg1: Room,
        __arg2: &'life1 SyncStateEvent<CanonicalAliasEventContent>
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        Self: 'async_trait
, { ... }
fn on_room_aliases<'life0, 'life1, 'async_trait>(
        &'life0 self,
        __arg1: Room,
        __arg2: &'life1 SyncStateEvent<AliasesEventContent>
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        Self: 'async_trait
, { ... }
fn on_room_avatar<'life0, 'life1, 'async_trait>(
        &'life0 self,
        __arg1: Room,
        __arg2: &'life1 SyncStateEvent<AvatarEventContent>
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        Self: 'async_trait
, { ... }
fn on_room_message<'life0, 'life1, 'async_trait>(
        &'life0 self,
        __arg1: Room,
        __arg2: &'life1 SyncMessageEvent<MsgEventContent>
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        Self: 'async_trait
, { ... }
fn on_room_message_feedback<'life0, 'life1, 'async_trait>(
        &'life0 self,
        __arg1: Room,
        __arg2: &'life1 SyncMessageEvent<FeedbackEventContent>
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        Self: 'async_trait
, { ... }
fn on_room_reaction<'life0, 'life1, 'async_trait>(
        &'life0 self,
        __arg1: Room,
        __arg2: &'life1 SyncMessageEvent<ReactionEventContent>
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        Self: 'async_trait
, { ... }
fn on_room_call_invite<'life0, 'life1, 'async_trait>(
        &'life0 self,
        __arg1: Room,
        __arg2: &'life1 SyncMessageEvent<InviteEventContent>
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        Self: 'async_trait
, { ... }
fn on_room_call_answer<'life0, 'life1, 'async_trait>(
        &'life0 self,
        __arg1: Room,
        __arg2: &'life1 SyncMessageEvent<AnswerEventContent>
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        Self: 'async_trait
, { ... }
fn on_room_call_candidates<'life0, 'life1, 'async_trait>(
        &'life0 self,
        __arg1: Room,
        __arg2: &'life1 SyncMessageEvent<CandidatesEventContent>
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        Self: 'async_trait
, { ... }
fn on_room_call_hangup<'life0, 'life1, 'async_trait>(
        &'life0 self,
        __arg1: Room,
        __arg2: &'life1 SyncMessageEvent<HangupEventContent>
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        Self: 'async_trait
, { ... }
fn on_room_redaction<'life0, 'life1, 'async_trait>(
        &'life0 self,
        __arg1: Room,
        __arg2: &'life1 SyncRedactionEvent
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        Self: 'async_trait
, { ... }
fn on_room_power_levels<'life0, 'life1, 'async_trait>(
        &'life0 self,
        __arg1: Room,
        __arg2: &'life1 SyncStateEvent<PowerLevelsEventContent>
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        Self: 'async_trait
, { ... }
fn on_room_join_rules<'life0, 'life1, 'async_trait>(
        &'life0 self,
        __arg1: Room,
        __arg2: &'life1 SyncStateEvent<JoinRulesEventContent>
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        Self: 'async_trait
, { ... }
fn on_room_tombstone<'life0, 'life1, 'async_trait>(
        &'life0 self,
        __arg1: Room,
        __arg2: &'life1 SyncStateEvent<TombstoneEventContent>
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        Self: 'async_trait
, { ... }
fn on_room_notification<'life0, 'async_trait>(
        &'life0 self,
        __arg1: Room,
        __arg2: Notification
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
    where
        'life0: 'async_trait,
        Self: 'async_trait
, { ... }
fn on_state_member<'life0, 'life1, 'async_trait>(
        &'life0 self,
        __arg1: Room,
        __arg2: &'life1 SyncStateEvent<MemberEventContent>
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        Self: 'async_trait
, { ... }
fn on_state_name<'life0, 'life1, 'async_trait>(
        &'life0 self,
        __arg1: Room,
        __arg2: &'life1 SyncStateEvent<NameEventContent>
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        Self: 'async_trait
, { ... }
fn on_state_canonical_alias<'life0, 'life1, 'async_trait>(
        &'life0 self,
        __arg1: Room,
        __arg2: &'life1 SyncStateEvent<CanonicalAliasEventContent>
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        Self: 'async_trait
, { ... }
fn on_state_aliases<'life0, 'life1, 'async_trait>(
        &'life0 self,
        __arg1: Room,
        __arg2: &'life1 SyncStateEvent<AliasesEventContent>
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        Self: 'async_trait
, { ... }
fn on_state_avatar<'life0, 'life1, 'async_trait>(
        &'life0 self,
        __arg1: Room,
        __arg2: &'life1 SyncStateEvent<AvatarEventContent>
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        Self: 'async_trait
, { ... }
fn on_state_power_levels<'life0, 'life1, 'async_trait>(
        &'life0 self,
        __arg1: Room,
        __arg2: &'life1 SyncStateEvent<PowerLevelsEventContent>
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        Self: 'async_trait
, { ... }
fn on_state_join_rules<'life0, 'life1, 'async_trait>(
        &'life0 self,
        __arg1: Room,
        __arg2: &'life1 SyncStateEvent<JoinRulesEventContent>
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        Self: 'async_trait
, { ... }
fn on_stripped_state_member<'life0, 'life1, 'async_trait>(
        &'life0 self,
        __arg1: Room,
        __arg2: &'life1 StrippedStateEvent<MemberEventContent>,
        __arg3: Option<MemberEventContent>
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        Self: 'async_trait
, { ... }
fn on_stripped_state_name<'life0, 'life1, 'async_trait>(
        &'life0 self,
        __arg1: Room,
        __arg2: &'life1 StrippedStateEvent<NameEventContent>
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        Self: 'async_trait
, { ... }
fn on_stripped_state_canonical_alias<'life0, 'life1, 'async_trait>(
        &'life0 self,
        __arg1: Room,
        __arg2: &'life1 StrippedStateEvent<CanonicalAliasEventContent>
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        Self: 'async_trait
, { ... }
fn on_stripped_state_aliases<'life0, 'life1, 'async_trait>(
        &'life0 self,
        __arg1: Room,
        __arg2: &'life1 StrippedStateEvent<AliasesEventContent>
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        Self: 'async_trait
, { ... }
fn on_stripped_state_avatar<'life0, 'life1, 'async_trait>(
        &'life0 self,
        __arg1: Room,
        __arg2: &'life1 StrippedStateEvent<AvatarEventContent>
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        Self: 'async_trait
, { ... }
fn on_stripped_state_power_levels<'life0, 'life1, 'async_trait>(
        &'life0 self,
        __arg1: Room,
        __arg2: &'life1 StrippedStateEvent<PowerLevelsEventContent>
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        Self: 'async_trait
, { ... }
fn on_stripped_state_join_rules<'life0, 'life1, 'async_trait>(
        &'life0 self,
        __arg1: Room,
        __arg2: &'life1 StrippedStateEvent<JoinRulesEventContent>
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        Self: 'async_trait
, { ... }
fn on_non_room_presence<'life0, 'life1, 'async_trait>(
        &'life0 self,
        __arg1: Room,
        __arg2: &'life1 PresenceEvent
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        Self: 'async_trait
, { ... }
fn on_non_room_ignored_users<'life0, 'life1, 'async_trait>(
        &'life0 self,
        __arg1: &'life1 GlobalAccountDataEvent<IgnoredUserListEventContent>
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        Self: 'async_trait
, { ... }
fn on_non_room_push_rules<'life0, 'life1, 'async_trait>(
        &'life0 self,
        __arg1: &'life1 GlobalAccountDataEvent<PushRulesEventContent>
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        Self: 'async_trait
, { ... }
fn on_non_room_fully_read<'life0, 'life1, 'async_trait>(
        &'life0 self,
        __arg1: Room,
        __arg2: &'life1 RoomAccountDataEvent<FullyReadEventContent>
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        Self: 'async_trait
, { ... }
fn on_non_room_typing<'life0, 'life1, 'async_trait>(
        &'life0 self,
        __arg1: Room,
        __arg2: &'life1 SyncEphemeralRoomEvent<TypingEventContent>
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        Self: 'async_trait
, { ... }
fn on_non_room_receipt<'life0, 'life1, 'async_trait>(
        &'life0 self,
        __arg1: Room,
        __arg2: &'life1 SyncEphemeralRoomEvent<ReceiptEventContent>
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        Self: 'async_trait
, { ... }
fn on_presence_event<'life0, 'life1, 'async_trait>(
        &'life0 self,
        __arg1: &'life1 PresenceEvent
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        Self: 'async_trait
, { ... }
fn on_unrecognized_event<'life0, 'life1, 'async_trait>(
        &'life0 self,
        __arg1: Room,
        __arg2: &'life1 RawJsonValue
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        Self: 'async_trait
, { ... }
fn on_custom_event<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        __arg1: Room,
        __arg2: &'life1 CustomEvent<'life2>
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        'life2: 'async_trait,
        Self: 'async_trait
, { ... }
}
Expand description

This trait allows any type implementing EventHandler to specify event callbacks for each event. The Client calls each method when the corresponding event is received.

Examples


struct EventCallback;

#[async_trait]
impl EventHandler for EventCallback {
    async fn on_room_message(&self, room: Room, event: &SyncMessageEvent<MessageEventContent>) {
        if let Room::Joined(room) = room {
            if let SyncMessageEvent {
                content:
                    MessageEventContent {
                        msgtype: MessageType::Text(TextMessageEventContent { body: msg_body, .. }),
                        ..
                    },
                sender,
                ..
            } = event
            {
                let member = room.get_member(&sender).await.unwrap().unwrap();
                let name = member
                    .display_name()
                    .unwrap_or_else(|| member.user_id().as_str());
                println!("{}: {}", name, msg_body);
            }
        }
    }
}

Provided methods

Fires when Client receives a RoomEvent::RoomMember event.

Fires when Client receives a RoomEvent::RoomName event.

Fires when Client receives a RoomEvent::RoomCanonicalAlias event.

Fires when Client receives a RoomEvent::RoomAliases event.

Fires when Client receives a RoomEvent::RoomAvatar event.

Fires when Client receives a RoomEvent::RoomMessage event.

Fires when Client receives a RoomEvent::RoomMessageFeedback event.

Fires when Client receives a RoomEvent::Reaction event.

Fires when Client receives a RoomEvent::CallInvite event

Fires when Client receives a RoomEvent::CallAnswer event

Fires when Client receives a RoomEvent::CallCandidates event

Fires when Client receives a RoomEvent::CallHangup event

Fires when Client receives a RoomEvent::RoomRedaction event.

Fires when Client receives a RoomEvent::RoomPowerLevels event.

Fires when Client receives a RoomEvent::RoomJoinRules event.

Fires when Client receives a RoomEvent::Tombstone event.

Fires when Client receives room events that trigger notifications according to the push rules of the user.

Fires when Client receives a StateEvent::RoomMember event.

Fires when Client receives a StateEvent::RoomName event.

Fires when Client receives a StateEvent::RoomCanonicalAlias event.

Fires when Client receives a StateEvent::RoomAliases event.

Fires when Client receives a StateEvent::RoomAvatar event.

Fires when Client receives a StateEvent::RoomPowerLevels event.

Fires when Client receives a StateEvent::RoomJoinRules event.

Fires when Client receives a AnyStrippedStateEvent::StrippedRoomMember event.

Fires when Client receives a AnyStrippedStateEvent::StrippedRoomName event.

Fires when Client receives a AnyStrippedStateEvent::StrippedRoomCanonicalAlias event.

Fires when Client receives a AnyStrippedStateEvent::StrippedRoomAliases event.

Fires when Client receives a AnyStrippedStateEvent::StrippedRoomAvatar event.

Fires when Client receives a AnyStrippedStateEvent::StrippedRoomPowerLevels event.

Fires when Client receives a AnyStrippedStateEvent::StrippedRoomJoinRules event.

Fires when Client receives a NonRoomEvent::RoomPresence event.

Fires when Client receives a NonRoomEvent::RoomName event.

Fires when Client receives a NonRoomEvent::RoomCanonicalAlias event.

Fires when Client receives a NonRoomEvent::RoomAliases event.

Fires when Client receives a NonRoomEvent::Typing event.

Fires when Client receives a NonRoomEvent::Receipt event.

This is always a read receipt.

Fires when Client receives a NonRoomEvent::RoomAliases event.

Fires when Client receives a Event::Custom event or if deserialization fails because the event was unknown to ruma.

The only guarantee this method can give about the event is that it is valid JSON.

Fires when Client receives a Event::Custom event or if deserialization fails because the event was unknown to ruma.

The only guarantee this method can give about the event is that it is in the shape of a valid matrix event.

Implementors