2026-04-22 04:02:14 -04:00
|
|
|
import json
|
|
|
|
|
|
2026-03-19 15:48:59 -04:00
|
|
|
from django.contrib.auth.decorators import login_required
|
2026-03-24 16:46:46 -04:00
|
|
|
from django.db.models import Max, Q
|
2026-04-22 04:02:14 -04:00
|
|
|
from django.http import JsonResponse
|
2026-03-24 16:46:46 -04:00
|
|
|
from django.shortcuts import redirect, render
|
2026-03-19 15:48:59 -04:00
|
|
|
|
2026-04-21 15:46:30 -04:00
|
|
|
from apps.applets.utils import applet_context, apply_applet_toggle
|
2026-04-22 04:02:14 -04:00
|
|
|
from apps.drama.models import GameEvent, Recognition, ScrollPosition
|
2026-04-21 15:46:30 -04:00
|
|
|
from apps.epic.models import Room
|
|
|
|
|
from apps.epic.utils import rooms_for_user
|
2026-03-19 15:48:59 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@login_required(login_url="/")
|
|
|
|
|
def billboard(request):
|
2026-04-21 15:46:30 -04:00
|
|
|
my_rooms = rooms_for_user(request.user).order_by("-created_at")
|
2026-03-24 16:46:46 -04:00
|
|
|
|
|
|
|
|
recent_room = (
|
|
|
|
|
Room.objects.filter(
|
|
|
|
|
Q(owner=request.user) | Q(gate_slots__gamer=request.user)
|
|
|
|
|
)
|
|
|
|
|
.annotate(last_event=Max("events__timestamp"))
|
|
|
|
|
.filter(last_event__isnull=False)
|
|
|
|
|
.order_by("-last_event")
|
|
|
|
|
.distinct()
|
|
|
|
|
.first()
|
|
|
|
|
)
|
|
|
|
|
recent_events = (
|
2026-04-13 00:34:05 -04:00
|
|
|
list(
|
|
|
|
|
recent_room.events
|
|
|
|
|
.select_related("actor")
|
|
|
|
|
.exclude(verb=GameEvent.SIG_UNREADY)
|
|
|
|
|
.exclude(verb=GameEvent.SIG_READY, data__retracted=True)
|
|
|
|
|
.order_by("-timestamp")[:36]
|
|
|
|
|
)[::-1]
|
2026-03-24 16:46:46 -04:00
|
|
|
if recent_room else []
|
|
|
|
|
)
|
|
|
|
|
|
2026-03-19 15:48:59 -04:00
|
|
|
return render(request, "apps/billboard/billboard.html", {
|
|
|
|
|
"my_rooms": my_rooms,
|
2026-03-24 16:46:46 -04:00
|
|
|
"recent_room": recent_room,
|
|
|
|
|
"recent_events": recent_events,
|
|
|
|
|
"viewer": request.user,
|
|
|
|
|
"applets": applet_context(request.user, "billboard"),
|
2026-03-19 15:48:59 -04:00
|
|
|
"page_class": "page-billboard",
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
2026-03-24 16:46:46 -04:00
|
|
|
@login_required(login_url="/")
|
|
|
|
|
def toggle_billboard_applets(request):
|
|
|
|
|
checked = request.POST.getlist("applets")
|
2026-04-21 15:46:30 -04:00
|
|
|
apply_applet_toggle(request.user, "billboard", checked)
|
2026-03-24 16:46:46 -04:00
|
|
|
if request.headers.get("HX-Request"):
|
|
|
|
|
return render(request, "apps/billboard/_partials/_applets.html", {
|
|
|
|
|
"applets": applet_context(request.user, "billboard"),
|
|
|
|
|
})
|
|
|
|
|
return redirect("billboard:billboard")
|
|
|
|
|
|
|
|
|
|
|
2026-03-19 15:48:59 -04:00
|
|
|
@login_required(login_url="/")
|
|
|
|
|
def room_scroll(request, room_id):
|
|
|
|
|
room = Room.objects.get(id=room_id)
|
|
|
|
|
events = room.events.select_related("actor").all()
|
2026-03-24 17:44:34 -04:00
|
|
|
sp = ScrollPosition.objects.filter(user=request.user, room=room).first()
|
2026-03-19 15:48:59 -04:00
|
|
|
return render(request, "apps/billboard/room_scroll.html", {
|
|
|
|
|
"room": room,
|
|
|
|
|
"events": events,
|
|
|
|
|
"viewer": request.user,
|
2026-03-24 17:44:34 -04:00
|
|
|
"scroll_position": sp.position if sp else 0,
|
2026-03-24 16:46:46 -04:00
|
|
|
"page_class": "page-billscroll",
|
2026-03-19 15:48:59 -04:00
|
|
|
})
|
2026-03-24 17:44:34 -04:00
|
|
|
|
|
|
|
|
|
2026-04-22 04:02:14 -04:00
|
|
|
_RECOGNITION_META = {
|
|
|
|
|
"stargazer": {
|
|
|
|
|
"title": "Stargazer",
|
|
|
|
|
"description": "You saved your first personal sky chart.",
|
|
|
|
|
"palette_options": ["palette-bardo", "palette-sheol"],
|
|
|
|
|
},
|
|
|
|
|
"schizo": {
|
|
|
|
|
"title": "Schizo",
|
|
|
|
|
"description": "The socius recognizes the line of flight.",
|
|
|
|
|
"palette_options": [],
|
|
|
|
|
},
|
|
|
|
|
"nomad": {
|
|
|
|
|
"title": "Nomad",
|
|
|
|
|
"description": "The socius recognizes the smooth space.",
|
|
|
|
|
"palette_options": [],
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@login_required(login_url="/")
|
|
|
|
|
def recognition_set_palette(request, slug):
|
|
|
|
|
from django.http import Http404
|
|
|
|
|
try:
|
|
|
|
|
recognition = Recognition.objects.get(user=request.user, slug=slug)
|
|
|
|
|
except Recognition.DoesNotExist:
|
|
|
|
|
raise Http404
|
|
|
|
|
if request.method == "POST":
|
|
|
|
|
body = json.loads(request.body)
|
|
|
|
|
recognition.palette = body.get("palette", "")
|
|
|
|
|
recognition.save(update_fields=["palette"])
|
|
|
|
|
return JsonResponse({"ok": True})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@login_required(login_url="/")
|
|
|
|
|
def recognition_page(request):
|
|
|
|
|
qs = Recognition.objects.filter(user=request.user)
|
|
|
|
|
recognitions = [
|
|
|
|
|
{
|
|
|
|
|
"obj": r,
|
|
|
|
|
"title": _RECOGNITION_META.get(r.slug, {}).get("title", r.slug),
|
|
|
|
|
"description": _RECOGNITION_META.get(r.slug, {}).get("description", ""),
|
|
|
|
|
"palette_options": _RECOGNITION_META.get(r.slug, {}).get("palette_options", []),
|
|
|
|
|
}
|
|
|
|
|
for r in qs
|
|
|
|
|
]
|
|
|
|
|
return render(request, "apps/billboard/recognition.html", {
|
|
|
|
|
"recognitions": qs,
|
|
|
|
|
"recognition_items": recognitions,
|
|
|
|
|
"page_class": "page-recognition",
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
2026-03-24 17:44:34 -04:00
|
|
|
@login_required(login_url="/")
|
|
|
|
|
def save_scroll_position(request, room_id):
|
|
|
|
|
if request.method != "POST":
|
|
|
|
|
from django.http import HttpResponseNotAllowed
|
|
|
|
|
return HttpResponseNotAllowed(["POST"])
|
|
|
|
|
room = Room.objects.get(id=room_id)
|
|
|
|
|
position = int(request.POST.get("position", 0))
|
|
|
|
|
ScrollPosition.objects.update_or_create(
|
|
|
|
|
user=request.user, room=room,
|
|
|
|
|
defaults={"position": position},
|
|
|
|
|
)
|
|
|
|
|
from django.http import HttpResponse
|
|
|
|
|
return HttpResponse(status=204)
|