aboutsummaryrefslogtreecommitdiff
path: root/src/client
diff options
context:
space:
mode:
authorMishio595 <[email protected]>2018-09-16 11:37:51 -0600
committerMishio595 <[email protected]>2018-09-16 11:37:51 -0600
commit9fdff0acc0162299e704a4e4b9143e6dfffa02bc (patch)
tree49897ea45537a5623ce5d92b08bbe161e793a09b /src/client
parentDon't log event deserialization failures in voice (diff)
downloadserenity-9fdff0acc0162299e704a4e4b9143e6dfffa02bc.tar.xz
serenity-9fdff0acc0162299e704a4e4b9143e6dfffa02bc.zip
Old message is optionally passed with message_update event
Diffstat (limited to 'src/client')
-rw-r--r--src/client/dispatch.rs11
-rw-r--r--src/client/event_handler.rs17
2 files changed, 21 insertions, 7 deletions
diff --git a/src/client/dispatch.rs b/src/client/dispatch.rs
index 3e3bcfa..e201852 100644
--- a/src/client/dispatch.rs
+++ b/src/client/dispatch.rs
@@ -497,13 +497,20 @@ fn handle_event<H: EventHandler + Send + Sync + 'static>(
});
},
DispatchEvent::Model(Event::MessageUpdate(mut event)) => {
- update!(event);
+ let _before = update!(event);
let context = context(data, runner_tx, shard_id);
let event_handler = Arc::clone(event_handler);
threadpool.execute(move || {
- event_handler.message_update(context, event);
+ feature_cache! {{
+ let after = CACHE.read().message(event.channel_id, event.id);
+ if let Some(after) = after {
+ event_handler.message_update(context, _before, after);
+ }
+ } else {
+ event_handler.message_update(context, event);
+ }}
});
},
DispatchEvent::Model(Event::PresencesReplace(mut event)) => {
diff --git a/src/client/event_handler.rs b/src/client/event_handler.rs
index 32fdaa1..5af7314 100644
--- a/src/client/event_handler.rs
+++ b/src/client/event_handler.rs
@@ -212,6 +212,18 @@ pub trait EventHandler {
/// Provides the channel's id and the deleted messages' ids.
fn message_delete_bulk(&self, _ctx: Context, _channel_id: ChannelId, _multiple_deleted_messages_ids: Vec<MessageId>) {}
+ /// Dispatched when a message is updated.
+ ///
+ /// Provides the old message if available and the new message.
+ #[cfg(feature = "cache")]
+ fn message_update(&self, _ctx: Context, _old_if_available: Option<Message>, _new: Message) {}
+
+ /// Dispatched when a message is updated.
+ ///
+ /// Provides the new data of the message.
+ #[cfg(not(feature = "cache"))]
+ fn message_update(&self, _ctx: Context, _new_data: MessageUpdateEvent) {}
+
/// Dispatched when a new reaction is attached to a message.
///
/// Provides the reaction's data.
@@ -227,11 +239,6 @@ pub trait EventHandler {
/// Provides the channel's id and the message's id.
fn reaction_remove_all(&self, _ctx: Context, _channel_id: ChannelId, _removed_from_message_id: MessageId) {}
- /// Dispatched when a message is updated.
- ///
- /// Provides the new data of the message.
- fn message_update(&self, _ctx: Context, _new_data: MessageUpdateEvent) {}
-
fn presence_replace(&self, _ctx: Context, _: Vec<Presence>) {}
/// Dispatched when a user's presence is updated (e.g off -> on).