Esempio n. 1
0
def post_message(request, party_id):
  redis = StrictRedis(connection_pool=redis_connection_pool)
  message_type = request.POST.get('messageType')
  user = User.from_request(redis, request)
  party = Party.get(redis, party_id)

  m = Message.for_party(redis, party)

  if message_type == 'chat':
    text = request.POST.get('text')
    m.text = text

  if message_type == 'favorite':
    track = request.POST.get('trackKey')
    m.track = track

  if message_type == 'vote_to_skip':
    track = request.POST.get('trackKey')
    m.track = track

  m.user_id = user.id
  m.message_type = message_type
  m.save(redis)

  party.broadcast_message_added(redis, m)

  return HttpResponse(status=httplib.CREATED)
Esempio n. 2
0
def party(request, room_name):
    if room_name is None:
        return redirect("/p/rdio")

    connection = StrictRedis(connection_pool=redis_connection_pool)
    party = Party.get(connection, room_name)
    if not party:
        party = Party()
        party.id = room_name
        party.name = room_name
        party.save(connection)

    user = User.from_request(connection, request)
    party.add_user(connection, user)
    party.broadcast_user_list_state(connection)
    party.save(connection)

    context = {
        "room_name": room_name,
        "body_class": "party",
        "room_id": room_name,
        "initial_player_state_json": json.dumps(party.get_player_state_payload()),
        "initial_queue_state_json": json.dumps(party.get_queue_state_payload()),
        "initial_user_list_state_json": json.dumps(party.get_user_list_state_payload()),
        "initial_messages_state_json": json.dumps(party.get_messages_state_payload(connection)),
        "initial_theme_state_json": json.dumps(party.get_theme_state_payload()),
        "current_user": json.dumps(user.to_dict()),
    }
    make_room_daemon(room_name)
    return render(request, "party.html", context)
Esempio n. 3
0
def ping(request):
  redis = StrictRedis(connection_pool=redis_connection_pool)
  user = User.from_request(redis, request)
  if user:
    user.last_check_in = datetime.datetime.utcnow()
    user.save(redis)
    return JsonResponse({'success': True})
  else:
    return HttpResponseNotFound()
Esempio n. 4
0
def vote_to_skip(request, party_id):
  if request.method == "POST":
    redis = StrictRedis(connection_pool=redis_connection_pool)
    user = User.from_request(redis, request)
    party = Party.get(redis, party_id)
    party.vote_to_skip(user)
    party.save(redis)
    return JsonResponse({'success': True})
  else:
    return HttpResponseNotFound()
Esempio n. 5
0
def add_to_queue(request, party_id):
  if request.method == "POST":
    redis = StrictRedis(connection_pool=redis_connection_pool)
    user = User.from_request(redis, request)
    party = Party.get(redis, party_id)
    party.enqueue_song(user, request.POST.get('trackKey'))

    party.save(redis)
    party.broadcast_queue_state(redis)
    return JsonResponse({'success': True})
  else:
    return HttpResponseNotFound()
Esempio n. 6
0
def downvote(request, party_id):
  if request.method == "POST":
    redis = StrictRedis(connection_pool=redis_connection_pool)
    user = User.from_request(redis, request)
    party = Party.get(redis, party_id)
    queue_entry = party.get_queue_entry(request.POST.get('id'))
    queue_entry.downvote(user)
    party.save(redis)
    party.broadcast_queue_state(redis)
    return JsonResponse({'success': True})
  else:
    return HttpResponseNotFound()
Esempio n. 7
0
def ping_party(request, party_id):
  redis = StrictRedis(connection_pool=redis_connection_pool)
  party = None
  user = User.from_request(redis, request)
  if user:
    party = Party.get(redis, party_id)
  if user and party:
    user.visit_party(party_id)
    user.save(redis)
    party.add_user(redis, user)
    return JsonResponse({'success': True})
  else:
    return HttpResponseNotFound()