aboutsummaryrefslogtreecommitdiff
path: root/src/client
diff options
context:
space:
mode:
authorAdelyn Breelove <[email protected]>2018-12-31 10:38:26 -0700
committerAdelyn Breelove <[email protected]>2018-12-31 10:38:26 -0700
commit483265d06282b1ed9aa61af3faff9e75b1e5ec15 (patch)
tree4109d1ff9da4e0621d3cce4d45e4569e4ac1478b /src/client
parentImplement the proposed change to the sharemap (`Mutex` => `RwLock`) (#453) (diff)
downloadserenity-483265d06282b1ed9aa61af3faff9e75b1e5ec15.tar.xz
serenity-483265d06282b1ed9aa61af3faff9e75b1e5ec15.zip
Modify message_update behaviour when cache is enabled
Diffstat (limited to 'src/client')
-rw-r--r--src/client/dispatch.rs9
-rw-r--r--src/client/event_handler.rs19
2 files changed, 21 insertions, 7 deletions
diff --git a/src/client/dispatch.rs b/src/client/dispatch.rs
index 57160d4..fa0f801 100644
--- a/src/client/dispatch.rs
+++ b/src/client/dispatch.rs
@@ -490,11 +490,16 @@ fn handle_event<H: EventHandler + Send + Sync + 'static>(
});
},
DispatchEvent::Model(Event::MessageUpdate(mut event)) => {
- update!(cache_and_http, event);
+ let _before = update!(cache_and_http, event);
let event_handler = Arc::clone(event_handler);
threadpool.execute(move || {
- event_handler.message_update(context, event);
+ feature_cache! {{
+ let _after = cache_and_http.cache.read().message(event.channel_id, event.id);
+ event_handler.message_update(context, _before, _after, event);
+ } 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 4b39fef..9fc7c69 100644
--- a/src/client/event_handler.rs
+++ b/src/client/event_handler.rs
@@ -212,6 +212,20 @@ 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,
+ /// the new message as an option in case of cache inconsistencies,
+ /// and the raw MessageUpdateEvent as a fallback.
+ #[cfg(feature = "cache")]
+ fn message_update(&self, _ctx: Context, _old_if_available: Option<Message>, _new: Option<Message>, _event: MessageUpdateEvent) {}
+
+ /// 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 +241,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).