Implement executing tasks

This commit is contained in:
2026-03-03 16:41:28 +00:00
parent d6bd56dace
commit 9c14e51b43
42 changed files with 3410 additions and 121 deletions

View File

@@ -8,6 +8,8 @@ from mixins.views import ObjectList, ObjectRead
from core.clients import transport
from core.models import PersonIdentifier, PlatformChatLink
from core.presence import get_settings as get_availability_settings
from core.presence import latest_state_for_people
from core.util import logs
from core.views.compose import _compose_urls, _service_icon_class
from core.views.manage.permissions import SuperUserRequiredMixin
@@ -265,6 +267,10 @@ class WhatsAppChatsList(WhatsAppContactsList):
def get_queryset(self, *args, **kwargs):
rows = []
seen = set()
availability_settings = get_availability_settings(self.request.user)
show_availability = bool(
availability_settings.enabled and availability_settings.show_in_groups
)
state = transport.get_runtime_state("whatsapp")
runtime_contacts = state.get("contacts") or []
@@ -414,7 +420,36 @@ class WhatsAppChatsList(WhatsAppContactsList):
if not row.get("is_group") and row.get("identifier") in db_group_ids:
row["is_group"] = True
return [row for row in rows if row.get("is_group")]
group_rows = [row for row in rows if row.get("is_group")]
if show_availability and group_rows:
whatsapp_person_ids = list(
PersonIdentifier.objects.filter(
user=self.request.user,
service="whatsapp",
)
.exclude(person_id__isnull=True)
.values_list("person_id", flat=True)
.distinct()
)
state_map = latest_state_for_people(
user=self.request.user,
person_ids=[str(pid) for pid in whatsapp_person_ids if str(pid)],
service="whatsapp",
)
counts = {"available": 0, "fading": 0}
for value in state_map.values():
state_text = str((value or {}).get("state") or "").strip().lower()
if state_text in counts:
counts[state_text] += 1
aggregate = (
f"{counts['available']} available · {counts['fading']} fading"
if (counts["available"] or counts["fading"])
else ""
)
if aggregate:
for row in group_rows:
row["availability_label"] = aggregate
return group_rows
class WhatsAppAccountAdd(SuperUserRequiredMixin, ObjectRead):