Delete existing rooms
This commit is contained in:
parent
3e9ceba302
commit
19d9a19c06
2 changed files with 29 additions and 0 deletions
|
|
@ -225,6 +225,15 @@ impl Rooms {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
KeyCode::Char('D') => {
|
||||||
|
if let Some(cursor) = &self.cursor {
|
||||||
|
if let Some(room) = rooms.get(cursor.index) {
|
||||||
|
self.euph_rooms.remove(room);
|
||||||
|
self.euph_chats.remove(room);
|
||||||
|
self.vault.euph(room.clone()).delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -100,6 +100,11 @@ impl EuphVault {
|
||||||
let _ = self.tx.send(request.into());
|
let _ = self.tx.send(request.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn delete(self) {
|
||||||
|
let request = EuphRequest::Delete { room: self.room };
|
||||||
|
let _ = self.tx.send(request.into());
|
||||||
|
}
|
||||||
|
|
||||||
pub fn add_message(&self, msg: Message, prev_msg: Option<Snowflake>) {
|
pub fn add_message(&self, msg: Message, prev_msg: Option<Snowflake>) {
|
||||||
let request = EuphRequest::AddMsg {
|
let request = EuphRequest::AddMsg {
|
||||||
room: self.room.clone(),
|
room: self.room.clone(),
|
||||||
|
|
@ -210,6 +215,9 @@ pub(super) enum EuphRequest {
|
||||||
Join {
|
Join {
|
||||||
room: String,
|
room: String,
|
||||||
},
|
},
|
||||||
|
Delete {
|
||||||
|
room: String,
|
||||||
|
},
|
||||||
AddMsg {
|
AddMsg {
|
||||||
room: String,
|
room: String,
|
||||||
msg: Message,
|
msg: Message,
|
||||||
|
|
@ -259,6 +267,7 @@ impl EuphRequest {
|
||||||
let result = match self {
|
let result = match self {
|
||||||
EuphRequest::Rooms { result } => Self::rooms(conn, result),
|
EuphRequest::Rooms { result } => Self::rooms(conn, result),
|
||||||
EuphRequest::Join { room } => Self::join(conn, room),
|
EuphRequest::Join { room } => Self::join(conn, room),
|
||||||
|
EuphRequest::Delete { room } => Self::delete(conn, room),
|
||||||
EuphRequest::AddMsg {
|
EuphRequest::AddMsg {
|
||||||
room,
|
room,
|
||||||
msg,
|
msg,
|
||||||
|
|
@ -315,6 +324,17 @@ impl EuphRequest {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn delete(conn: &mut Connection, room: String) -> rusqlite::Result<()> {
|
||||||
|
conn.execute(
|
||||||
|
"
|
||||||
|
DELETE FROM euph_rooms
|
||||||
|
WHERE room = ?
|
||||||
|
",
|
||||||
|
[room],
|
||||||
|
)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
fn insert_msgs(tx: &Transaction, room: &str, msgs: Vec<Message>) -> rusqlite::Result<()> {
|
fn insert_msgs(tx: &Transaction, room: &str, msgs: Vec<Message>) -> rusqlite::Result<()> {
|
||||||
let mut insert_msg = tx.prepare(
|
let mut insert_msg = tx.prepare(
|
||||||
"
|
"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue