Skip to content

Commit

Permalink
Simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
megrogan committed Dec 13, 2024
1 parent 62517ea commit 2d7cafc
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 37 deletions.
2 changes: 1 addition & 1 deletion backend/libraries/chat_events/src/chat_event_internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ mod tests {
let event_bytes = msgpack::serialize_then_unwrap(&event);
let event_bytes_len = event_bytes.len();

assert_eq!(message_bytes_len, 165);
assert_eq!(message_bytes_len, 230);
assert_eq!(event_bytes_len, message_bytes_len + 18);

let _deserialized: EventWrapperInternal<ChatEventInternal> = msgpack::deserialize_then_unwrap(&event_bytes);
Expand Down
73 changes: 37 additions & 36 deletions backend/libraries/group_chat_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -642,48 +642,49 @@ impl GroupChatCore {

// If there is an existing message with the same message id then this is invalid unless
// a bot is finalising its unfinalised message
if let Some(reader) = self.events.events_reader(EventIndex::default(), thread_root_message_index) {
if let Some(message) = reader.message_internal(message_id.into()) {
if let Caller::BotV2(bot_now) = &caller {
if let Some(bot_message) = message.bot_context {
if bot_now.bot == message.sender
&& bot_now.initiator == bot_message.initiator
&& bot_now.command_text == bot_message.command_text
&& bot_now.finalised
&& !bot_message.finalised
{
let edit_message_args = EditMessageArgs {
sender: caller.agent(),
min_visible_event_index: EventIndex::default(),
thread_root_message_index,
message_id,
content,
block_level_markdown: Some(block_level_markdown),
finalise_bot_message: true,
now,
};
if let Some((message, _)) =
self.events
.message_internal(EventIndex::default(), thread_root_message_index, message_id.into())
{
if let Caller::BotV2(bot_now) = &caller {
if let Some(bot_message) = message.bot_context {
if bot_now.bot == message.sender
&& bot_now.initiator == bot_message.initiator
&& bot_now.command_text == bot_message.command_text
&& bot_now.finalised
&& !bot_message.finalised
{
let edit_message_args = EditMessageArgs {
sender: caller.agent(),
min_visible_event_index: EventIndex::default(),
thread_root_message_index,
message_id,
content,
block_level_markdown: Some(block_level_markdown),
finalise_bot_message: true,
now,
};

match self.events.edit_message::<CdkRuntime>(edit_message_args, None) {
chat_events::EditMessageResult::Success => {
let reader = self
.events
.events_reader(EventIndex::default(), thread_root_message_index)
.unwrap();
let message_event = reader.message_event(message_id.into(), Some(caller.agent())).unwrap();
return SendMessageResult::Success(SendMessageSuccess {
message_event,
users_to_notify: vec![],
bot_message_finalised: true,
});
}
_ => unreachable!(),
match self.events.edit_message::<CdkRuntime>(edit_message_args, None) {
chat_events::EditMessageResult::Success => {
let reader = self
.events
.events_reader(EventIndex::default(), thread_root_message_index)
.unwrap();
let message_event = reader.message_event(message_id.into(), Some(caller.agent())).unwrap();
return SendMessageResult::Success(SendMessageSuccess {
message_event,
users_to_notify: vec![],
bot_message_finalised: true,
});
}
_ => unreachable!(),
}
}
}

return SendMessageResult::MessageAlreadyExists;
}

return SendMessageResult::MessageAlreadyExists;
}

self.send_message(
Expand Down

0 comments on commit 2d7cafc

Please sign in to comment.