gatewayd: a turn's speaker, the username of the one person who wrote its burst
Co-Authored-By: ornith-1.5-35b-a3b <agent@wntrmute.dev>
This commit is contained in:
@@ -158,13 +158,21 @@ impl Gateway {
|
||||
self.done_tx.clone(),
|
||||
);
|
||||
let (session, thread) = (batch.session.clone(), batch.thread.clone());
|
||||
let speaker = self.speaker(&batch);
|
||||
let spawned = std::thread::Builder::new().spawn(move || {
|
||||
let posted = |id: u64| registry.was_posted(id);
|
||||
let notice = Notice {
|
||||
posted: &posted,
|
||||
wait,
|
||||
};
|
||||
deliver(client.as_ref(), &socket, &batch, &|line| log(line), ¬ice);
|
||||
deliver(
|
||||
client.as_ref(),
|
||||
&socket,
|
||||
&batch,
|
||||
speaker.as_deref(),
|
||||
&|line| log(line),
|
||||
¬ice,
|
||||
);
|
||||
let _ = done.send(batch.session);
|
||||
});
|
||||
if let Err(e) = spawned {
|
||||
@@ -178,6 +186,29 @@ impl Gateway {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// The turn's speaker: the username of the one person who wrote all of the batch, as
|
||||
/// Mattermost gives it (M5c spec, section 11). `None` when two or more people did, or when
|
||||
/// the name cannot be found: never the user id, never a guess. A name found is kept; a
|
||||
/// failure is logged and not kept, so the next turn looks again.
|
||||
fn speaker(&mut self, batch: &Batch) -> Option<String> {
|
||||
let user = batch.sender()?;
|
||||
if let Some(name) = self.usernames.get(user) {
|
||||
return Some(name.clone());
|
||||
}
|
||||
match self.client.username(user) {
|
||||
Ok(name) => {
|
||||
self.usernames.insert(user.to_string(), name.clone());
|
||||
Some(name)
|
||||
}
|
||||
Err(e) => {
|
||||
(self.log)(&format!(
|
||||
"gatewayd: no username for {user}: {e}; the turn has no speaker"
|
||||
));
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Turns that ended: out of flight, who asked forgotten, and the next batch of each session
|
||||
/// started. Never blocks.
|
||||
pub(super) fn finished(&mut self) -> Result<(), Stop> {
|
||||
|
||||
Reference in New Issue
Block a user