Skip to content

Commit ff77b4c

Browse files
committed
fix(ipc): handle multi-session contexts better
1 parent d1ba121 commit ff77b4c

File tree

3 files changed

+31
-28
lines changed

3 files changed

+31
-28
lines changed

src/messages/events/client/clear_activity.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,6 @@ impl OnEvent for ClearActivityEvent {
5353

5454
if let Some(session) = latest {
5555
if let Some(mut activity) = session.last_activity.clone() {
56-
if let Some(global) = &global_last_activity {
57-
if global == &activity {
58-
return Ok(());
59-
}
60-
}
61-
6256
if ctx.cord.config.shared_timestamps {
6357
let shared_ts =
6458
&ctx.cord.session_manager.shared_timestamp;
@@ -77,6 +71,12 @@ impl OnEvent for ClearActivityEvent {
7771
}
7872
}
7973

74+
if let Some(global) = &global_last_activity {
75+
if global == &activity {
76+
return Ok(());
77+
}
78+
}
79+
8080
ctx.cord
8181
.session_manager
8282
.last_activity

src/messages/events/client/disconnect.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,6 @@ impl OnEvent for DisconnectEvent {
2424
return Ok(());
2525
}
2626

27-
if ctx
28-
.cord
29-
.session_manager
30-
.last_activity
31-
.read()
32-
.unwrap()
33-
.is_none()
34-
{
35-
return Ok(());
36-
}
37-
3827
let latest = sessions
3928
.iter()
4029
.filter(|s| s.1.last_activity.is_some())
@@ -63,6 +52,14 @@ impl OnEvent for DisconnectEvent {
6352
}
6453

6554
ctx.cord.activity_manager.update(activity.clone())?;
55+
} else {
56+
let mut last_activity =
57+
ctx.cord.session_manager.last_activity.write().unwrap();
58+
if last_activity.is_some() {
59+
*last_activity = None;
60+
drop(last_activity);
61+
ctx.cord.activity_manager.clear()?;
62+
}
6663
}
6764

6865
Ok(())

src/messages/events/client/update_activity.rs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,26 +66,32 @@ impl OnEvent for UpdateActivityEvent {
6666
}
6767
}
6868

69+
if let Some(mut session) =
70+
ctx.cord.session_manager.get_session_mut(ctx.client_id)
6971
{
72+
session.set_last_activity(activity.clone());
73+
session.last_updated = now().as_nanos();
74+
}
75+
76+
let should_update = {
7077
let mut last_activity =
7178
ctx.cord.session_manager.last_activity.write().unwrap();
7279

7380
if let Some(global_last_activity) = last_activity.as_ref() {
7481
if !self.force && global_last_activity == &activity {
75-
return Ok(());
82+
false
83+
} else {
84+
*last_activity = Some(activity.clone());
85+
true
7686
}
87+
} else {
88+
*last_activity = Some(activity.clone());
89+
true
7790
}
91+
};
7892

79-
*last_activity = Some(activity.clone());
80-
}
81-
82-
ctx.cord.activity_manager.update(activity.clone())?;
83-
84-
if let Some(mut session) =
85-
ctx.cord.session_manager.get_session_mut(ctx.client_id)
86-
{
87-
session.set_last_activity(activity);
88-
session.last_updated = now().as_nanos();
93+
if should_update {
94+
ctx.cord.activity_manager.update(activity)?;
8995
}
9096

9197
Ok(())

0 commit comments

Comments
 (0)