Commit b3313cd
committed
fix(user_status): make setUserStatus() idempotent for concurrent duplicate requests
When two automated events of the same type fire simultaneously (e.g. a
calendar webhook is delivered twice, or two Talk clients both trigger a
call status at the same time), both requests race through setUserStatus().
The first request succeeds: it creates a backup of the user's previous
status and sets the new automated status. The second request finds the
backup slot already occupied (unique constraint on user_id), so
backupCurrentStatus() returns false. Previously this caused setUserStatus()
to return null, which the caller interpreted as a failure even though the
desired status was already correctly set by the first request.
Fix: after backupCurrentStatus() returns false, re-read the current active
status row. If it already carries the same messageId that we were trying to
set, the operation is effectively complete — return the existing status
instead of null. If it carries a different messageId (a higher-priority
automated status is active), we still return null to abort as before.
This also covers the meeting-with-call scenario: if a calendar BUSY status
is active and a Talk call starts, the call correctly overrides it via the
priority shortcut path. If the calendar fires a duplicate webhook while the
call is already active, the re-read finds MESSAGE_CALL ≠ MESSAGE_CALENDAR_BUSY
and correctly aborts rather than overriding the ongoing call.
AI-Assisted-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Anna Larch <anna@nextcloud.com>1 parent 354c641 commit b3313cd
2 files changed
Lines changed: 45 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
284 | 284 | | |
285 | 285 | | |
286 | 286 | | |
287 | | - | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
288 | 299 | | |
289 | 300 | | |
290 | 301 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
802 | 802 | | |
803 | 803 | | |
804 | 804 | | |
805 | | - | |
| 805 | + | |
806 | 806 | | |
807 | 807 | | |
808 | 808 | | |
| |||
825 | 825 | | |
826 | 826 | | |
827 | 827 | | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
828 | 860 | | |
0 commit comments