Implement executing tasks
This commit is contained in:
@@ -12,6 +12,8 @@ from mixins.views import ObjectList, ObjectRead
|
||||
|
||||
from core.clients import transport
|
||||
from core.models import Chat, PersonIdentifier, PlatformChatLink
|
||||
from core.presence import get_settings as get_availability_settings
|
||||
from core.presence import latest_state_for_people
|
||||
from core.views.manage.permissions import SuperUserRequiredMixin
|
||||
|
||||
|
||||
@@ -211,6 +213,10 @@ class SignalChatsList(SuperUserRequiredMixin, ObjectList):
|
||||
|
||||
def get_queryset(self, *args, **kwargs):
|
||||
pk = self.kwargs.get("pk", "")
|
||||
availability_settings = get_availability_settings(self.request.user)
|
||||
show_availability = bool(
|
||||
availability_settings.enabled and availability_settings.show_in_groups
|
||||
)
|
||||
chats = list(
|
||||
Chat.objects.filter(
|
||||
Q(account=pk) | Q(account__isnull=True) | Q(account="")
|
||||
@@ -265,6 +271,9 @@ class SignalChatsList(SuperUserRequiredMixin, ObjectList):
|
||||
"person_name": (
|
||||
person_identifier.person.name if person_identifier else ""
|
||||
),
|
||||
"person_id": (
|
||||
str(person_identifier.person_id) if person_identifier else ""
|
||||
),
|
||||
"manual_icon_class": "fa-solid fa-paper-plane",
|
||||
"can_compose": bool(compose_page_url),
|
||||
"match_url": (
|
||||
@@ -300,6 +309,56 @@ class SignalChatsList(SuperUserRequiredMixin, ObjectList):
|
||||
}
|
||||
)
|
||||
|
||||
if show_availability:
|
||||
person_ids = [
|
||||
str(item.get("person_id") or "").strip()
|
||||
for item in rows
|
||||
if str(item.get("person_id") or "").strip()
|
||||
]
|
||||
person_ids = [pid for pid in person_ids if pid]
|
||||
state_map = latest_state_for_people(
|
||||
user=self.request.user,
|
||||
person_ids=person_ids,
|
||||
service="signal",
|
||||
)
|
||||
for row in rows:
|
||||
pid = str(row.get("person_id") or "").strip()
|
||||
if pid and pid in state_map:
|
||||
state_row = state_map.get(pid) or {}
|
||||
row["availability_state"] = str(state_row.get("state") or "unknown")
|
||||
row["availability_label"] = (
|
||||
f"{str(state_row.get('state') or 'unknown').title()} "
|
||||
f"({float(state_row.get('confidence') or 0.0):.2f})"
|
||||
)
|
||||
signal_person_ids = list(
|
||||
PersonIdentifier.objects.filter(
|
||||
user=self.request.user,
|
||||
service="signal",
|
||||
)
|
||||
.exclude(person_id__isnull=True)
|
||||
.values_list("person_id", flat=True)
|
||||
.distinct()
|
||||
)
|
||||
group_states = latest_state_for_people(
|
||||
user=self.request.user,
|
||||
person_ids=[str(pid) for pid in signal_person_ids if str(pid)],
|
||||
service="signal",
|
||||
)
|
||||
aggregate_counts = {"available": 0, "fading": 0}
|
||||
for state_row in group_states.values():
|
||||
state_text = str((state_row or {}).get("state") or "").strip().lower()
|
||||
if state_text in aggregate_counts:
|
||||
aggregate_counts[state_text] += 1
|
||||
aggregate_label = (
|
||||
f"{aggregate_counts['available']} available · {aggregate_counts['fading']} fading"
|
||||
if (aggregate_counts["available"] or aggregate_counts["fading"])
|
||||
else ""
|
||||
)
|
||||
if aggregate_label:
|
||||
for row in rows:
|
||||
if row.get("is_group"):
|
||||
row["availability_label"] = aggregate_label
|
||||
|
||||
return rows
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user