Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more fields to MessageUpdateEvent #2154

Merged
merged 2 commits into from
Sep 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 32 additions & 41 deletions src/cache/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,48 +480,39 @@ impl CacheUpdate for MessageCreateEvent {
impl CacheUpdate for MessageUpdateEvent {
type Output = Message;

#[rustfmt::skip]
fn update(&mut self, cache: &Cache) -> Option<Self::Output> {
if let Some(messages) = cache.messages.get_mut(&self.channel_id) {
if let Some(mut message) = messages.get_mut(&self.id) {
let item = message.clone();

if let Some(attachments) = self.attachments.clone() {
message.attachments = attachments;
}

if let Some(content) = self.content.clone() {
message.content = content;
}

if let Some(edited_timestamp) = self.edited_timestamp {
message.edited_timestamp = Some(edited_timestamp);
}

if let Some(mentions) = self.mentions.clone() {
message.mentions = mentions;
}

if let Some(mention_everyone) = self.mention_everyone {
message.mention_everyone = mention_everyone;
}

if let Some(mention_roles) = self.mention_roles.clone() {
message.mention_roles = mention_roles;
}

if let Some(pinned) = self.pinned {
message.pinned = pinned;
}

if self.flags.is_some() {
message.flags = self.flags;
}

return Some(item);
}
}

None
// Destructure, so we get an `unused` warning when we forget to process one of the fields
// in this method
#[allow(deprecated)] // yes rust, exhaustive means exhaustive, even the deprecated ones
let Self {
id, channel_id, content, edited_timestamp, tts, mention_everyone, mentions,
mention_roles, mention_channels, attachments, embeds, reactions, pinned, flags,
components, sticker_items,

author: _, timestamp: _, nonce: _, kind: _, stickers: _, guild_id: _,
} = &self;

let messages = cache.messages.get_mut(channel_id)?;
let mut message = messages.get_mut(id)?;
let old_message = message.clone();

if let Some(x) = attachments { message.attachments = x.clone() }
if let Some(x) = content { message.content = x.clone() }
if let Some(x) = edited_timestamp { message.edited_timestamp = Some(*x) }
if let Some(x) = mentions { message.mentions = x.clone() }
if let Some(x) = mention_everyone { message.mention_everyone = *x }
if let Some(x) = mention_roles { message.mention_roles = x.clone() }
if let Some(x) = mention_channels { message.mention_channels = x.clone() }
if let Some(x) = pinned { message.pinned = *x }
if let Some(x) = flags { message.flags = Some(*x) }
if let Some(x) = tts { message.tts = *x }
if let Some(x) = embeds { message.embeds = x.clone() }
if let Some(x) = reactions { message.reactions = x.clone() }
if let Some(x) = components { message.components = x.clone() }
if let Some(x) = sticker_items { message.sticker_items = x.clone() }

Some(old_message)
}
}

Expand Down
22 changes: 15 additions & 7 deletions src/model/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::fmt;

use serde::de::{Error as DeError, IgnoredAny, MapAccess};

use super::application::component::ActionRow;
use super::prelude::*;
use super::utils::{emojis, roles, stickers};
use crate::constants::OpCode;
Expand Down Expand Up @@ -406,22 +407,29 @@ pub struct MessageDeleteEvent {
#[non_exhaustive]
pub struct MessageUpdateEvent {
pub id: MessageId,
pub guild_id: Option<GuildId>,
pub channel_id: ChannelId,
pub kind: Option<MessageType>,
pub author: Option<User>, // TODO: Is this a Message field that can even change?
pub content: Option<String>,
pub nonce: Option<String>,
pub tts: Option<bool>,
pub pinned: Option<bool>,
pub timestamp: Option<Timestamp>,
pub timestamp: Option<Timestamp>, // TODO: Is this a Message field that can even change?
pub edited_timestamp: Option<Timestamp>,
pub author: Option<User>,
pub tts: Option<bool>,
pub mention_everyone: Option<bool>,
pub mentions: Option<Vec<User>>,
pub mention_roles: Option<Vec<RoleId>>,
pub mention_channels: Option<Vec<ChannelMention>>,
pub attachments: Option<Vec<Attachment>>,
pub embeds: Option<Vec<Embed>>,
pub reactions: Option<Vec<MessageReaction>>,
pub nonce: Option<String>, // TODO: Is this a Message field that can even change?
pub pinned: Option<bool>,
pub kind: Option<MessageType>, // TODO: Is this a Message field that can even change?
pub flags: Option<MessageFlags>,
pub components: Option<Vec<ActionRow>>,
#[deprecated(note = "deprecated by Discord")]
pub stickers: Option<Vec<StickerItem>>,
pub sticker_items: Option<Vec<StickerItem>>,

pub guild_id: Option<GuildId>, // TODO: Is this a Message field that can even change?
arqunis marked this conversation as resolved.
Show resolved Hide resolved
}

/// [Discord docs](https://discord.com/developers/docs/topics/gateway#presence-update).
Expand Down