Fix Signal receiving
This commit is contained in:
@@ -2361,6 +2361,131 @@ class ComposeContactMatch(LoginRequiredMixin, View):
|
||||
)
|
||||
|
||||
|
||||
class ComposeContactCreate(LoginRequiredMixin, View):
|
||||
template_name = "pages/compose-contact-match.html"
|
||||
|
||||
def post(self, request):
|
||||
service = _default_service(request.POST.get("service"))
|
||||
identifier = str(request.POST.get("identifier") or "").strip()
|
||||
person_name = str(request.POST.get("person_name") or "").strip()
|
||||
|
||||
if not identifier:
|
||||
return render(
|
||||
request,
|
||||
self.template_name,
|
||||
self._context(request, "Identifier is required.", "warning"),
|
||||
)
|
||||
|
||||
if not person_name:
|
||||
return render(
|
||||
request,
|
||||
self.template_name,
|
||||
self._context(request, "Person name is required.", "warning"),
|
||||
)
|
||||
|
||||
existing = PersonIdentifier.objects.filter(
|
||||
user=request.user,
|
||||
service=service,
|
||||
identifier=identifier,
|
||||
).first()
|
||||
|
||||
if existing and existing.person:
|
||||
return render(
|
||||
request,
|
||||
self.template_name,
|
||||
self._context(
|
||||
request,
|
||||
f"{identifier} ({service}) is already linked to {existing.person.name}.",
|
||||
"warning",
|
||||
),
|
||||
)
|
||||
|
||||
person = Person.objects.create(user=request.user, name=person_name)
|
||||
|
||||
PersonIdentifier.objects.create(
|
||||
user=request.user,
|
||||
person=person,
|
||||
service=service,
|
||||
identifier=identifier,
|
||||
)
|
||||
|
||||
message = f"Created person '{person_name}' and linked {identifier} ({service})."
|
||||
return render(
|
||||
request,
|
||||
self.template_name,
|
||||
self._context(request, message, "success"),
|
||||
)
|
||||
|
||||
|
||||
class ComposeContactCreateAll(LoginRequiredMixin, View):
|
||||
template_name = "pages/compose-contact-match.html"
|
||||
|
||||
def post(self, request):
|
||||
candidates = _manual_contact_rows(request.user)
|
||||
|
||||
created_count = 0
|
||||
skipped_count = 0
|
||||
errors = []
|
||||
|
||||
for candidate in candidates:
|
||||
if candidate.get("linked_person"):
|
||||
skipped_count += 1
|
||||
continue
|
||||
|
||||
detected_name = candidate.get("detected_name", "")
|
||||
if not detected_name:
|
||||
skipped_count += 1
|
||||
continue
|
||||
|
||||
service = candidate.get("service", "")
|
||||
identifier = candidate.get("identifier", "")
|
||||
|
||||
if not service or not identifier:
|
||||
skipped_count += 1
|
||||
continue
|
||||
|
||||
existing = PersonIdentifier.objects.filter(
|
||||
user=request.user,
|
||||
service=service,
|
||||
identifier=identifier,
|
||||
).first()
|
||||
|
||||
if existing and existing.person:
|
||||
skipped_count += 1
|
||||
continue
|
||||
|
||||
try:
|
||||
person = Person.objects.create(user=request.user, name=detected_name)
|
||||
|
||||
PersonIdentifier.objects.create(
|
||||
user=request.user,
|
||||
person=person,
|
||||
service=service,
|
||||
identifier=identifier,
|
||||
)
|
||||
|
||||
created_count += 1
|
||||
except Exception as e:
|
||||
errors.append(f"{identifier} ({service}): {str(e)}")
|
||||
skipped_count += 1
|
||||
|
||||
if errors:
|
||||
message = f"Created {created_count} contacts. Errors: {'; '.join(errors[:5])}"
|
||||
level = "warning"
|
||||
elif created_count > 0:
|
||||
message = f"Created {created_count} new contact{'s' if created_count != 1 else ''}. Skipped {skipped_count}."
|
||||
level = "success"
|
||||
else:
|
||||
message = f"No new contacts to create. {skipped_count} already linked or without names."
|
||||
level = "info"
|
||||
|
||||
return render(
|
||||
request,
|
||||
self.template_name,
|
||||
self._context(request, message, level),
|
||||
)
|
||||
|
||||
|
||||
class ComposePage(LoginRequiredMixin, View):
|
||||
template_name = "pages/compose.html"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user