forked from lavina/lavina
Rename
This commit is contained in:
parent
f9eb510062
commit
d02c394e34
|
@ -18,7 +18,7 @@ use tracing::{Instrument, Span};
|
||||||
|
|
||||||
use crate::clustering::room::*;
|
use crate::clustering::room::*;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use crate::room::{HistoryMessage, RoomHandle, RoomId, RoomInfo};
|
use crate::room::{RoomHandle, RoomId, RoomInfo, StoredMessage};
|
||||||
use crate::table::{AnonTable, Key as AnonKey};
|
use crate::table::{AnonTable, Key as AnonKey};
|
||||||
use crate::LavinaCore;
|
use crate::LavinaCore;
|
||||||
|
|
||||||
|
@ -112,7 +112,7 @@ impl PlayerConnection {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip(self), name = "PlayerConnection::get_room_message_history")]
|
#[tracing::instrument(skip(self), name = "PlayerConnection::get_room_message_history")]
|
||||||
pub async fn get_room_message_history(&self, room_id: RoomId) -> Result<(Vec<HistoryMessage>)> {
|
pub async fn get_room_message_history(&self, room_id: RoomId) -> Result<(Vec<StoredMessage>)> {
|
||||||
let (promise, deferred) = oneshot();
|
let (promise, deferred) = oneshot();
|
||||||
let cmd = ClientCommand::GetRoomHistory { room_id, promise };
|
let cmd = ClientCommand::GetRoomHistory { room_id, promise };
|
||||||
self.player_handle.send(ActorCommand::ClientCommand(cmd, self.connection_id.clone())).await;
|
self.player_handle.send(ActorCommand::ClientCommand(cmd, self.connection_id.clone())).await;
|
||||||
|
@ -222,7 +222,7 @@ pub enum ClientCommand {
|
||||||
},
|
},
|
||||||
GetRoomHistory {
|
GetRoomHistory {
|
||||||
room_id: RoomId,
|
room_id: RoomId,
|
||||||
promise: Promise<Vec<HistoryMessage>>,
|
promise: Promise<Vec<StoredMessage>>,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -575,7 +575,7 @@ impl Player {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip(self), name = "Player::retrieve_room_history")]
|
#[tracing::instrument(skip(self), name = "Player::retrieve_room_history")]
|
||||||
async fn get_room_history(&mut self, room_id: RoomId) -> Vec<HistoryMessage> {
|
async fn get_room_history(&mut self, room_id: RoomId) -> Vec<StoredMessage> {
|
||||||
let room = self.my_rooms.get(&room_id);
|
let room = self.my_rooms.get(&room_id);
|
||||||
if let Some(room) = room {
|
if let Some(room) = room {
|
||||||
match room {
|
match room {
|
||||||
|
|
|
@ -89,13 +89,3 @@ pub struct StoredDialog {
|
||||||
pub participant_2: u32,
|
pub participant_2: u32,
|
||||||
pub message_count: u32,
|
pub message_count: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(FromRow)]
|
|
||||||
pub struct StoredMessageWithAuthor {
|
|
||||||
pub room_id: u32,
|
|
||||||
pub id: u32,
|
|
||||||
pub content: String,
|
|
||||||
pub author_id: u32,
|
|
||||||
pub author_name: String,
|
|
||||||
pub created_at: DateTime<Utc>,
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
use crate::repo::dialog::StoredMessageWithAuthor;
|
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
use sqlx::FromRow;
|
use sqlx::FromRow;
|
||||||
|
|
||||||
use crate::repo::Storage;
|
use crate::repo::Storage;
|
||||||
use crate::room::{HistoryMessage, RoomId, User};
|
use crate::room::{RoomId, StoredMessage, StoredUser};
|
||||||
|
|
||||||
#[derive(FromRow)]
|
#[derive(FromRow)]
|
||||||
pub struct StoredRoom {
|
pub struct StoredRoom {
|
||||||
|
@ -31,7 +30,7 @@ impl Storage {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip(self), name = "Storage::retrieve_room_message_history")]
|
#[tracing::instrument(skip(self), name = "Storage::retrieve_room_message_history")]
|
||||||
pub async fn get_room_message_history(&self, room_id: u32) -> Result<Vec<HistoryMessage>> {
|
pub async fn get_room_message_history(&self, room_id: u32) -> Result<Vec<StoredMessage>> {
|
||||||
let mut executor = self.conn.lock().await;
|
let mut executor = self.conn.lock().await;
|
||||||
let res = sqlx::query_as(
|
let res = sqlx::query_as(
|
||||||
"
|
"
|
||||||
|
|
|
@ -160,7 +160,7 @@ impl RoomHandle {
|
||||||
lock.broadcast_update(update, player_id).await;
|
lock.broadcast_update(update, player_id).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_message_history(&self, services: &LavinaCore) -> Vec<HistoryMessage> {
|
pub async fn get_message_history(&self, services: &LavinaCore) -> Vec<StoredMessage> {
|
||||||
return services.storage.get_room_message_history(self.0.read().await.storage_id).await.unwrap();
|
return services.storage.get_room_message_history(self.0.read().await.storage_id).await.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -287,24 +287,24 @@ pub struct RoomInfo {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct User {
|
pub struct StoredUser {
|
||||||
pub id: u32,
|
pub id: u32,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct HistoryMessage {
|
pub struct StoredMessage {
|
||||||
pub id: u32,
|
pub id: u32,
|
||||||
pub author: User,
|
pub author: StoredUser,
|
||||||
pub content: String,
|
pub content: String,
|
||||||
pub created_at: DateTime<Utc>,
|
pub created_at: DateTime<Utc>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromRow<'_, SqliteRow> for HistoryMessage {
|
impl FromRow<'_, SqliteRow> for StoredMessage {
|
||||||
fn from_row(row: &SqliteRow) -> sqlx::Result<Self> {
|
fn from_row(row: &SqliteRow) -> sqlx::Result<Self> {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
id: row.try_get("id")?,
|
id: row.try_get("id")?,
|
||||||
author: User {
|
author: StoredUser {
|
||||||
id: row.try_get("author_id")?,
|
id: row.try_get("author_id")?,
|
||||||
name: row.try_get("author_name")?,
|
name: row.try_get("author_name")?,
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue