9 Commits

Author SHA1 Message Date
David Robertson
d27dc37641
Additional context plumbing 2023-04-05 18:24:02 +01:00
David Robertson
83e746ec3c
Assert with context where possible 2023-04-05 18:24:02 +01:00
David Robertson
1f3f14f30c
Report errors to Sentry, plumbing ctxs if needed 2023-04-05 18:24:01 +01:00
Kegan Dougal
7fa433f732 bugfix: fix a bug with list ops when sorting with unread counts; fix a bug which could cause typing/receipts to not be live streamed
Previously, we would not send unread count INCREASES to the client,
as we would expect the actual event update to wake up the client conn.
This was great because it meant the event+unread count arrived atomically
on the client. This was implemented as "parse unread counts first, then events".

However, this introduced a bug when there were >1 user in the same room. In this
scenario, one poller may get the event first, which would go through to the client.
The subsequent unread count update would then be dropped and not sent to the client.
This would just be an unfortunate UI bug if it weren't for sorting by_notification_count
and sorting by_notification_level. Both of these sort operations use the unread counts
to determine room list ordering. This list would be updated on the server, but no
list operation would be sent to the client, causing the room lists to de-sync, and
resulting in incorrect DELETE/INSERT ops. This would manifest as duplicate rooms
on the room list.

In the process of fixing this, also fix a bug where typing notifications would not
always be sent to the client - it would only do so when piggybacked due to incorrect
type switches.

Also fix another bug which prevented receipts from always being sent to the client.
This was caused by the extensions handler not checking if the receipt extension had
data to determine if it should return. This the interacted with an as-yet unfixed bug
which cleared the extension on subequent updates, causing the receipt to be lost entirely.
A fix for this will be inbound soon.
2023-02-07 13:34:26 +00:00
Kegan Dougal
6a14e03d12 bugfix: fix a bug where move updates could go missing between windows
If a room moved from one window range to another window range, and the
index of the destination was the leading edge of a different window,
this would trip up the code into thinking it was a no-op move and hence
not issue a DELETE/INSERT for the 2nd window, even though it was in fact
needed. For example:
```
   w1           w2
[0,1,2] 3,4,5 [6,7,8]

Move 1 to 6 turns the list into:
[0,2,3] 4,5,6 [1,7,8]

which should be the operations:
DELETE 1, INSERT 2 (val=3)
DELETE 6, INSERT 6 (val=1)

but because DELETE/INSERT both have the same index value, and the target
room is the updated room, we thought this was the same as when you have:

[0,1,2] 3,4,5

Move 0 to 0

which should no-op.
```

Fixed by ensuring that we also check that there is only 1 move operation.
If there are >1 move operations then we are moving between lists and should
include the DELETE/INSERT operation with the same index. This could manifest
itself in updated rooms spontaneously disappearing and/or neighbouring rooms
being duplicated.
2022-09-05 16:47:05 +01:00
Kegan Dougal
8ebb1be2c1 bugfix: add torture test for list delta ops
- Randomly move elements 10,000 times in a sliding window.
- Fixed a bug as a result which would cause the algorithm to
  fail to issue a DELETE/INSERT when the room was _inserted_
  to the very end of the window range, due to it misfiring
  with the logic to not issue operations for no-op moves.
2022-09-05 13:43:12 +01:00
Kegan Dougal
cff1be0f1e bugfix: ensure we always INSERT a shifted room when handling a deletion
Previously, this would fail:
```
			//                0    1    2    3    4    5    6    7    8
			before: []string{"a", "b", "c", "d", "e", "f", "g", "h", "i"},
			after:  []string{"b", "c", "d", "e", "f", "g", "h", "i"},
			ranges: SliceRanges{{1, 3}, {5, 7}},
```

because the 2nd window range perfectly matched the list size, it would
ignore the `INSERT,7,i`.
2022-08-31 18:45:22 +01:00
Kegan Dougal
dcad80f51f bugfix: send correct deltas for deletions at the front of windows
Previously we wouldn't send deletions for this, even though they shift
all elements to the left. Add a battery of unit tests for the list delta
algorithm, and standardise on the practice of issuing a DELETE prior to
an INSERT for newly inserted rooms, regardless of where in the window
they appear. Previously, we may skip the DELETE at the end of the list,
which was just inconsistent of us.
2022-08-31 17:54:07 +01:00
Kegan Dougal
10bd0da932 refactor: add ops.go to calculate list ops
re-jig ConnState to use this new function, with unit tests.
2022-08-31 13:43:09 +01:00