Store time of first and last join for each room
This commit is contained in:
parent
19d9a19c06
commit
9cd7ee008d
3 changed files with 15 additions and 8 deletions
|
|
@ -3,6 +3,7 @@ use std::sync::Arc;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use anyhow::bail;
|
use anyhow::bail;
|
||||||
|
use chrono::Utc;
|
||||||
use log::{error, info, warn};
|
use log::{error, info, warn};
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use tokio::sync::{mpsc, oneshot};
|
use tokio::sync::{mpsc, oneshot};
|
||||||
|
|
@ -170,7 +171,7 @@ impl State {
|
||||||
}
|
}
|
||||||
Data::SnapshotEvent(d) => {
|
Data::SnapshotEvent(d) => {
|
||||||
info!("e&{}: successfully joined", self.name);
|
info!("e&{}: successfully joined", self.name);
|
||||||
self.vault.join();
|
self.vault.join(Utc::now());
|
||||||
self.last_msg_id = Some(d.log.last().map(|m| m.id));
|
self.last_msg_id = Some(d.log.last().map(|m| m.id));
|
||||||
self.vault.add_messages(d.log, None);
|
self.vault.add_messages(d.log, None);
|
||||||
let _ = self.ui_event_tx.send(UiEvent::Redraw);
|
let _ = self.ui_event_tx.send(UiEvent::Redraw);
|
||||||
|
|
|
||||||
|
|
@ -93,9 +93,10 @@ pub struct EuphVault {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EuphVault {
|
impl EuphVault {
|
||||||
pub fn join(&self) {
|
pub fn join(&self, time: DateTime<Utc>) {
|
||||||
let request = EuphRequest::Join {
|
let request = EuphRequest::Join {
|
||||||
room: self.room.clone(),
|
room: self.room.clone(),
|
||||||
|
time,
|
||||||
};
|
};
|
||||||
let _ = self.tx.send(request.into());
|
let _ = self.tx.send(request.into());
|
||||||
}
|
}
|
||||||
|
|
@ -214,6 +215,7 @@ pub(super) enum EuphRequest {
|
||||||
},
|
},
|
||||||
Join {
|
Join {
|
||||||
room: String,
|
room: String,
|
||||||
|
time: DateTime<Utc>,
|
||||||
},
|
},
|
||||||
Delete {
|
Delete {
|
||||||
room: String,
|
room: String,
|
||||||
|
|
@ -266,7 +268,7 @@ impl EuphRequest {
|
||||||
pub(super) fn perform(self, conn: &mut Connection) {
|
pub(super) fn perform(self, conn: &mut Connection) {
|
||||||
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, time } => Self::join(conn, room, time),
|
||||||
EuphRequest::Delete { room } => Self::delete(conn, room),
|
EuphRequest::Delete { room } => Self::delete(conn, room),
|
||||||
EuphRequest::AddMsg {
|
EuphRequest::AddMsg {
|
||||||
room,
|
room,
|
||||||
|
|
@ -313,13 +315,15 @@ impl EuphRequest {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn join(conn: &mut Connection, room: String) -> rusqlite::Result<()> {
|
fn join(conn: &mut Connection, room: String, time: DateTime<Utc>) -> rusqlite::Result<()> {
|
||||||
conn.execute(
|
conn.execute(
|
||||||
"
|
"
|
||||||
INSERT OR IGNORE INTO euph_rooms (room)
|
INSERT INTO euph_rooms (room, first_joined, last_joined)
|
||||||
VALUES (?)
|
VALUES (:room, :time, :time)
|
||||||
|
ON CONFLICT (room) DO UPDATE
|
||||||
|
SET last_joined = :time
|
||||||
",
|
",
|
||||||
[room],
|
named_params! {":room": room, ":time": time},
|
||||||
)?;
|
)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,9 @@ fn m1(tx: &mut Transaction) -> rusqlite::Result<()> {
|
||||||
tx.execute_batch(
|
tx.execute_batch(
|
||||||
"
|
"
|
||||||
CREATE TABLE euph_rooms (
|
CREATE TABLE euph_rooms (
|
||||||
room TEXT NOT NULL PRIMARY KEY
|
room TEXT NOT NULL PRIMARY KEY,
|
||||||
|
first_joined TEXT NOT NULL,
|
||||||
|
last_joined TEXT NOT NULL
|
||||||
) STRICT;
|
) STRICT;
|
||||||
|
|
||||||
CREATE TABLE euph_msgs (
|
CREATE TABLE euph_msgs (
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue