Implement executing tasks
This commit is contained in:
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user