mirror of
https://github.com/hexedtech/codemp.git
synced 2024-11-22 15:24:48 +01:00
chore: we don't need user_id this deep actually
it's stored in our token anyway
This commit is contained in:
parent
1cf17dc151
commit
f61836e4ca
3 changed files with 4 additions and 12 deletions
|
@ -4,7 +4,6 @@
|
||||||
|
|
||||||
use tokio::sync::{mpsc, broadcast::{self, error::{TryRecvError, RecvError}}, Mutex, watch};
|
use tokio::sync::{mpsc, broadcast::{self, error::{TryRecvError, RecvError}}, Mutex, watch};
|
||||||
use tonic::async_trait;
|
use tonic::async_trait;
|
||||||
use uuid::Uuid;
|
|
||||||
|
|
||||||
use crate::{api::Controller, errors::IgnorableError, proto::cursor::{CursorEvent, CursorPosition}};
|
use crate::{api::Controller, errors::IgnorableError, proto::cursor::{CursorEvent, CursorPosition}};
|
||||||
|
|
||||||
|
@ -21,7 +20,6 @@ use crate::{api::Controller, errors::IgnorableError, proto::cursor::{CursorEvent
|
||||||
/// upon dropping this handle will stop the associated worker
|
/// upon dropping this handle will stop the associated worker
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct CursorController {
|
pub struct CursorController {
|
||||||
user_id: Uuid,
|
|
||||||
op: mpsc::UnboundedSender<CursorPosition>,
|
op: mpsc::UnboundedSender<CursorPosition>,
|
||||||
last_op: Mutex<watch::Receiver<CursorEvent>>,
|
last_op: Mutex<watch::Receiver<CursorEvent>>,
|
||||||
stream: Mutex<broadcast::Receiver<CursorEvent>>,
|
stream: Mutex<broadcast::Receiver<CursorEvent>>,
|
||||||
|
@ -36,13 +34,12 @@ impl Drop for CursorController {
|
||||||
|
|
||||||
impl CursorController {
|
impl CursorController {
|
||||||
pub(crate) fn new(
|
pub(crate) fn new(
|
||||||
user_id: Uuid,
|
|
||||||
op: mpsc::UnboundedSender<CursorPosition>,
|
op: mpsc::UnboundedSender<CursorPosition>,
|
||||||
last_op: Mutex<watch::Receiver<CursorEvent>>,
|
last_op: Mutex<watch::Receiver<CursorEvent>>,
|
||||||
stream: Mutex<broadcast::Receiver<CursorEvent>>,
|
stream: Mutex<broadcast::Receiver<CursorEvent>>,
|
||||||
stop: mpsc::UnboundedSender<()>,
|
stop: mpsc::UnboundedSender<()>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
CursorController { user_id, op, last_op, stream, stop }
|
CursorController { op, last_op, stream, stop }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,14 +2,12 @@ use std::sync::Arc;
|
||||||
|
|
||||||
use tokio::sync::{mpsc, broadcast::{self}, Mutex, watch};
|
use tokio::sync::{mpsc, broadcast::{self}, Mutex, watch};
|
||||||
use tonic::{Streaming, async_trait};
|
use tonic::{Streaming, async_trait};
|
||||||
use uuid::Uuid;
|
|
||||||
|
|
||||||
use crate::{api::controller::ControllerWorker, errors::IgnorableError, proto::cursor::{CursorPosition, CursorEvent}};
|
use crate::{api::controller::ControllerWorker, errors::IgnorableError, proto::cursor::{CursorPosition, CursorEvent}};
|
||||||
|
|
||||||
use super::controller::CursorController;
|
use super::controller::CursorController;
|
||||||
|
|
||||||
pub(crate) struct CursorWorker {
|
pub(crate) struct CursorWorker {
|
||||||
user_id: Uuid,
|
|
||||||
producer: mpsc::UnboundedSender<CursorPosition>,
|
producer: mpsc::UnboundedSender<CursorPosition>,
|
||||||
op: mpsc::UnboundedReceiver<CursorPosition>,
|
op: mpsc::UnboundedReceiver<CursorPosition>,
|
||||||
changed: watch::Sender<CursorEvent>,
|
changed: watch::Sender<CursorEvent>,
|
||||||
|
@ -19,14 +17,13 @@ pub(crate) struct CursorWorker {
|
||||||
stop_control: mpsc::UnboundedSender<()>,
|
stop_control: mpsc::UnboundedSender<()>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CursorWorker {
|
impl Default for CursorWorker {
|
||||||
pub(crate) fn new(user_id: Uuid) -> Self {
|
fn default() -> Self {
|
||||||
let (op_tx, op_rx) = mpsc::unbounded_channel();
|
let (op_tx, op_rx) = mpsc::unbounded_channel();
|
||||||
let (cur_tx, _cur_rx) = broadcast::channel(64);
|
let (cur_tx, _cur_rx) = broadcast::channel(64);
|
||||||
let (end_tx, end_rx) = mpsc::unbounded_channel();
|
let (end_tx, end_rx) = mpsc::unbounded_channel();
|
||||||
let (change_tx, change_rx) = watch::channel(CursorEvent::default());
|
let (change_tx, change_rx) = watch::channel(CursorEvent::default());
|
||||||
Self {
|
Self {
|
||||||
user_id,
|
|
||||||
producer: op_tx,
|
producer: op_tx,
|
||||||
op: op_rx,
|
op: op_rx,
|
||||||
changed: change_tx,
|
changed: change_tx,
|
||||||
|
@ -46,7 +43,6 @@ impl ControllerWorker<CursorEvent> for CursorWorker {
|
||||||
|
|
||||||
fn subscribe(&self) -> CursorController {
|
fn subscribe(&self) -> CursorController {
|
||||||
CursorController::new(
|
CursorController::new(
|
||||||
self.user_id.clone(),
|
|
||||||
self.producer.clone(),
|
self.producer.clone(),
|
||||||
Mutex::new(self.last_op.clone()),
|
Mutex::new(self.last_op.clone()),
|
||||||
Mutex::new(self.channel.subscribe()),
|
Mutex::new(self.channel.subscribe()),
|
||||||
|
@ -58,7 +54,6 @@ impl ControllerWorker<CursorEvent> for CursorWorker {
|
||||||
loop {
|
loop {
|
||||||
tokio::select!{
|
tokio::select!{
|
||||||
Ok(Some(cur)) = rx.message() => {
|
Ok(Some(cur)) = rx.message() => {
|
||||||
if Uuid::from(cur.user.clone()) == self.user_id { continue }
|
|
||||||
self.channel.send(cur.clone()).unwrap_or_warn("could not broadcast event");
|
self.channel.send(cur.clone()).unwrap_or_warn("could not broadcast event");
|
||||||
self.changed.send(cur).unwrap_or_warn("could not update last event");
|
self.changed.send(cur).unwrap_or_warn("could not update last event");
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue