Increase security and reformat
This commit is contained in:
@@ -12,9 +12,15 @@ from core.models import (
|
||||
PersonIdentifier,
|
||||
User,
|
||||
)
|
||||
|
||||
from .inference import fade_confidence, now_ms, should_fade
|
||||
|
||||
POSITIVE_SOURCE_KINDS = {"native_presence", "read_receipt", "typing_start", "message_in"}
|
||||
POSITIVE_SOURCE_KINDS = {
|
||||
"native_presence",
|
||||
"read_receipt",
|
||||
"typing_start",
|
||||
"message_in",
|
||||
}
|
||||
|
||||
|
||||
@dataclass(slots=True)
|
||||
@@ -99,7 +105,8 @@ def record_native_signal(signal: AvailabilitySignal) -> ContactAvailabilityEvent
|
||||
person_identifier=signal.person_identifier,
|
||||
service=str(signal.service or "").strip().lower() or "signal",
|
||||
source_kind=str(signal.source_kind or "").strip() or "native_presence",
|
||||
availability_state=str(signal.availability_state or "unknown").strip() or "unknown",
|
||||
availability_state=str(signal.availability_state or "unknown").strip()
|
||||
or "unknown",
|
||||
confidence=float(signal.confidence or 0.0),
|
||||
ts=_normalize_ts(signal.ts),
|
||||
payload=dict(signal.payload or {}),
|
||||
@@ -109,7 +116,9 @@ def record_native_signal(signal: AvailabilitySignal) -> ContactAvailabilityEvent
|
||||
return event
|
||||
|
||||
|
||||
def record_inferred_signal(signal: AvailabilitySignal) -> ContactAvailabilityEvent | None:
|
||||
def record_inferred_signal(
|
||||
signal: AvailabilitySignal,
|
||||
) -> ContactAvailabilityEvent | None:
|
||||
settings_row = get_settings(signal.user)
|
||||
if not settings_row.enabled or not settings_row.inference_enabled:
|
||||
return None
|
||||
@@ -151,7 +160,9 @@ def ensure_fading_state(
|
||||
return None
|
||||
if latest.source_kind not in POSITIVE_SOURCE_KINDS:
|
||||
return None
|
||||
if not should_fade(int(latest.ts or 0), current_ts, settings_row.fade_threshold_seconds):
|
||||
if not should_fade(
|
||||
int(latest.ts or 0), current_ts, settings_row.fade_threshold_seconds
|
||||
):
|
||||
return None
|
||||
|
||||
elapsed = max(0, current_ts - int(latest.ts or 0))
|
||||
|
||||
@@ -3,6 +3,7 @@ from __future__ import annotations
|
||||
from django.db.models import Q
|
||||
|
||||
from core.models import ContactAvailabilityEvent, ContactAvailabilitySpan, Person, User
|
||||
|
||||
from .engine import ensure_fading_state
|
||||
from .inference import now_ms
|
||||
|
||||
@@ -19,9 +20,7 @@ def spans_for_range(
|
||||
qs = ContactAvailabilitySpan.objects.filter(
|
||||
user=user,
|
||||
person=person,
|
||||
).filter(
|
||||
Q(start_ts__lte=end_ts) & Q(end_ts__gte=start_ts)
|
||||
)
|
||||
).filter(Q(start_ts__lte=end_ts) & Q(end_ts__gte=start_ts))
|
||||
if service:
|
||||
qs = qs.filter(service=str(service).strip().lower())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user