forked from jmug/stoatchat
fix: preserve order of replies in message (#447)
Signed-off-by: Aeledfyr <aeledfyr@gmail.com>
This commit is contained in:
@@ -440,7 +440,8 @@ impl Message {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Verify replies are valid.
|
// Verify replies are valid.
|
||||||
let mut replies = HashSet::new();
|
let mut replies = Vec::new();
|
||||||
|
|
||||||
if let Some(entries) = data.replies {
|
if let Some(entries) = data.replies {
|
||||||
if entries.len() > config.features.limits.global.message_replies {
|
if entries.len() > config.features.limits.global.message_replies {
|
||||||
return Err(create_error!(TooManyReplies {
|
return Err(create_error!(TooManyReplies {
|
||||||
@@ -448,6 +449,8 @@ impl Message {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
replies.reserve(entries.len());
|
||||||
|
|
||||||
for ReplyIntent {
|
for ReplyIntent {
|
||||||
id,
|
id,
|
||||||
mention,
|
mention,
|
||||||
@@ -461,7 +464,12 @@ impl Message {
|
|||||||
user_mentions.insert(message.author.to_owned());
|
user_mentions.insert(message.author.to_owned());
|
||||||
}
|
}
|
||||||
|
|
||||||
replies.insert(message.id);
|
// This is O(n^2), but this is faster than a HashSet
|
||||||
|
// when n < 20; as long as the message_replies limit
|
||||||
|
// is reasonable, this will be fast.
|
||||||
|
if !replies.contains(&message.id) {
|
||||||
|
replies.push(message.id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// If the referenced message doesn't exist and fail_if_not_exists
|
// If the referenced message doesn't exist and fail_if_not_exists
|
||||||
// is set to false, send the message without the reply.
|
// is set to false, send the message without the reply.
|
||||||
@@ -534,9 +542,7 @@ impl Message {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !replies.is_empty() {
|
if !replies.is_empty() {
|
||||||
message
|
message.replies.replace(replies);
|
||||||
.replies
|
|
||||||
.replace(replies.into_iter().collect::<Vec<String>>());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate final message flags
|
// Calculate final message flags
|
||||||
|
|||||||
Reference in New Issue
Block a user