Store the original message when linking
Now we can search the database for non-original messages Only for when we want to scan for editable messages and stuffmain
parent
baeaa8575b
commit
316835c2f6
|
@ -3,8 +3,10 @@ CREATE TABLE message_links (
|
|||
) STRICT;
|
||||
|
||||
CREATE TABLE messages (
|
||||
link_id INTEGER NOT NULL REFERENCES message_links(id),
|
||||
message_id INTEGER PRIMARY KEY,
|
||||
link_id INTEGER NOT NULL REFERENCES message_links(id),
|
||||
service TEXT NOT NULL,
|
||||
channel TEXT NOT NULL,
|
||||
message TEXT NOT NULL
|
||||
)
|
||||
message TEXT NOT NULL,
|
||||
original INTEGER
|
||||
) STRICT;
|
||||
|
|
|
@ -55,17 +55,34 @@ pub async fn link_messages(
|
|||
.await?
|
||||
.last_insert_rowid();
|
||||
|
||||
for resultant in std::iter::once(origin).chain(messages) {
|
||||
let original_id = {
|
||||
let service = &origin.channel.service;
|
||||
let channel = &origin.channel.id;
|
||||
let message = &origin.message_id;
|
||||
|
||||
let query = sqlx::query!(
|
||||
"INSERT INTO messages (link_id, service, channel, message, original) VALUES (?, ?, ?, ?, NULL)",
|
||||
message_link,
|
||||
service,
|
||||
channel,
|
||||
message
|
||||
);
|
||||
|
||||
query.execute(&mut *conn).await?.last_insert_rowid()
|
||||
};
|
||||
|
||||
for resultant in messages {
|
||||
let service = &resultant.channel.service;
|
||||
let channel = &resultant.channel.id;
|
||||
let message = &resultant.message_id;
|
||||
|
||||
let query = sqlx::query!(
|
||||
"INSERT INTO messages VALUES (?, ?, ?, ?)",
|
||||
"INSERT INTO messages (link_id, service, channel, message, original) VALUES (?, ?, ?, ?, ?)",
|
||||
message_link,
|
||||
service,
|
||||
channel,
|
||||
message
|
||||
message,
|
||||
original_id
|
||||
);
|
||||
|
||||
let _ = query.execute(&mut *conn).await?;
|
||||
|
|
Loading…
Reference in New Issue