Skip to content

Commit 57ec07f

Browse files
committed
model: Do not allow adding self as typist.
The server usually does not send events notifying the user themself typing. But having this check gives us a stronger guarantee that the maps do not contain the self user. Signed-off-by: Zixuan James Li <[email protected]>
1 parent 65d9b62 commit 57ec07f

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

lib/model/typing_status.dart

+4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ class TypingStatus extends ChangeNotifier {
3939
}
4040

4141
bool _addTypist(SendableNarrow narrow, int typistUserId) {
42+
if (typistUserId == selfUserId) {
43+
assert(debugLog('typing status: adding self as typist'));
44+
return false;
45+
}
4246
final narrowTimerMap = _timerMapsByNarrow[narrow] ??= {};
4347
final typistTimer = narrowTimerMap[typistUserId];
4448
final isNewTypist = typistTimer == null;

test/model/typing_status_test.dart

+9
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,15 @@ void main() {
9797
checkTypists({groupNarrow: [eg.otherUser, eg.thirdUser]});
9898
checkNotifiedOnce();
9999
});
100+
101+
test('ignore adding self as typist', () {
102+
prepareModel();
103+
104+
model.handleTypingEvent(
105+
eg.typingEvent(groupNarrow, TypingOp.start, eg.selfUser.userId));
106+
checkTypists({});
107+
checkNotNotified();
108+
});
100109
});
101110

102111
group('handle typing stop events', () {

0 commit comments

Comments
 (0)