Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

presence: Record stats for invisible users.

ritwik-69dd56e04dc662
diff --git a/help/status-and-availability.md b/help/status-and-availability.md
index c3d7a43a27c..4e44797988a 100644
--- a/help/status-and-availability.md
+++ b/help/status-and-availability.md
@@ -154,6 +154,7 @@ Zulip.
With this setting, your "Last active" time displayed to other users in
the UI will be frozen as the approximate time you enabled this setting.
+Your activity will still be included in your organization's [statistics](/help/analytics).
!!! tip ""
diff --git a/zerver/actions/presence.py b/zerver/actions/presence.py
index 91e5792db37..16e6b33511b 100644
--- a/zerver/actions/presence.py
+++ b/zerver/actions/presence.py
@@ -290,6 +290,7 @@ def update_user_presence(
client,
status,
)
- do_update_user_presence(user_profile, client, log_time, status)
+ if user_profile.presence_enabled:
+ do_update_user_presence(user_profile, client, log_time, status)
if new_user_input:
update_user_activity_interval(user_profile, log_time)
diff --git a/zerver/tests/test_presence.py b/zerver/tests/test_presence.py
index 0974d380722..5fab91acdba 100644
--- a/zerver/tests/test_presence.py
+++ b/zerver/tests/test_presence.py
@@ -996,23 +996,30 @@ class GetRealmStatusesTest(ZulipTestCase):
othello.save(update_fields=["presence_enabled"])
hamlet.save(update_fields=["presence_enabled"])
+ # Verify the initial UserActivityInterval state is as expected.
+ self.assertEqual(UserActivityInterval.objects.filter(user_profile=othello).count(), 0)
+
result = self.api_post(
othello,
"/api/v1/users/me/presence",
- dict(status="active"),
+ # Include new_user_input=true to test the UserActivityInterval update
+ # codepath.
+ dict(status="active", new_user_input="true"),
HTTP_USER_AGENT="ZulipAndroid/1.0",
)
-
result = self.api_post(
hamlet,
"/api/v1/users/me/presence",
dict(status="idle"),
HTTP_USER_AGENT="ZulipDesktop/1.0",
)
+
json = self.assert_json_success(result)
# Othello's presence status is disabled so it won't be reported.
self.assertEqual(set(json["presences"].keys()), {hamlet.email})
+ # However, UserActivit Interval still gets updated.
+ self.assertEqual(UserActivityInterval.objects.filter(user_profile=othello).count(), 1)
result = self.api_post(
hamlet,
diff --git a/zerver/views/presence.py b/zerver/views/presence.py
index 91a3c50fdc0..e92b7c6db41 100644
--- a/zerver/views/presence.py
+++ b/zerver/views/presence.py
@@ -164,10 +164,10 @@ def update_active_status_backend(
status_val = UserPresence.status_from_string(status)
if status_val is None:
raise JsonableError(_("Invalid status: {status}").format(status=status))
- elif user_profile.presence_enabled:
- client = RequestNotes.get_notes(request).client
- assert client is not None
- update_user_presence(user_profile, client, timezone_now(), status_val, new_user_input)
+
+ client = RequestNotes.get_notes(request).client
+ assert client is not None
+ update_user_presence(user_profile, client, timezone_now(), status_val, new_user_input)
if ping_only:
ret: dict[str, Any] = {}