Event polling

not optimal but its tomorrow
This commit is contained in:
2024-10-15 13:42:48 -04:00
Unverified
parent 3e31066a5f
commit 4ec5e3fb56
5 changed files with 114 additions and 70 deletions

View File

@@ -25,6 +25,7 @@ pub struct RealmChatServer {
pub db_pool: Pool<Sqlite>,
pub typing_users: Vec<(String, String)>, //NOTE: user.userid, room.roomid
pub cache: Cache<String, String>,
pub events: Vec<(u32, Event)>,
}
const FETCH_MESSAGE: &str = "SELECT message.*,
@@ -46,6 +47,7 @@ impl RealmChatServer {
.time_to_idle(Duration::from_secs(5*60))
.time_to_live(Duration::from_secs(60*60))
.build(),
events: Vec::new(),
}
}
@@ -217,6 +219,18 @@ impl RealmChat for RealmChatServer {
self.internal_is_user_owner(&userid).await
}
async fn poll_events_since(self, _: Context, index: u32) -> Vec<(u32, Event)> {
let mut events_to_send = Vec::new();
for (i, event) in self.events {
if i > index {
events_to_send.push((i, event));
}
}
events_to_send
}
async fn join_server(self, _: Context, stoken: String, userid: String) -> Result<User, ErrorCode> {
if !self.is_stoken_valid(&userid, &stoken).await {
return Err(Unauthorized)