Maintain order of fronters when switching
This commit is contained in:
parent
799ea01f03
commit
16b757ae36
@ -426,9 +426,9 @@ async def switch_member(conn, message, args):
|
|||||||
return False, "Couldn't find member \"{}\".".format(member_name)
|
return False, "Couldn't find member \"{}\".".format(member_name)
|
||||||
members.append(member)
|
members.append(member)
|
||||||
|
|
||||||
member_ids = {member["id"] for member in members}
|
# Lists, because order matters, it makes sense to just swap fronters
|
||||||
|
member_ids = [member["id"] for member in members]
|
||||||
fronter_ids = set((await get_fronter_ids(conn, system["id"]))[0])
|
fronter_ids = (await get_fronter_ids(conn, system["id"]))[0]
|
||||||
if member_ids == fronter_ids:
|
if member_ids == fronter_ids:
|
||||||
if len(members) == 1:
|
if len(members) == 1:
|
||||||
return False, "{} is already fronting.".format(members[0]["name"])
|
return False, "{} is already fronting.".format(members[0]["name"])
|
||||||
|
@ -189,20 +189,6 @@ async def delete_message(conn, message_id: str):
|
|||||||
logger.debug("Deleting message (id={})".format(message_id))
|
logger.debug("Deleting message (id={})".format(message_id))
|
||||||
await conn.execute("delete from messages where mid = $1", int(message_id))
|
await conn.execute("delete from messages where mid = $1", int(message_id))
|
||||||
|
|
||||||
# @db_wrap
|
|
||||||
# async def front_history(conn, system_id: int, count: int):
|
|
||||||
# return await conn.fetch("""select
|
|
||||||
# switches.timestamp, members.name, members.id, switches.id as switch_id
|
|
||||||
# from
|
|
||||||
# (
|
|
||||||
# select * from switches where system = $1 order by timestamp desc limit $2
|
|
||||||
# ) as switches
|
|
||||||
# left outer join switch_members
|
|
||||||
# on switch_members.switch = switches.id
|
|
||||||
# left outer join members
|
|
||||||
# on switch_members.member = members.id
|
|
||||||
# order by switches.timestamp desc""", system_id, count)
|
|
||||||
|
|
||||||
@db_wrap
|
@db_wrap
|
||||||
async def front_history(conn, system_id: int, count: int):
|
async def front_history(conn, system_id: int, count: int):
|
||||||
return await conn.fetch("""select
|
return await conn.fetch("""select
|
||||||
@ -210,6 +196,7 @@ async def front_history(conn, system_id: int, count: int):
|
|||||||
array(
|
array(
|
||||||
select member from switch_members
|
select member from switch_members
|
||||||
where switch_members.switch = switches.id
|
where switch_members.switch = switches.id
|
||||||
|
order by switch_members.id asc
|
||||||
) as members
|
) as members
|
||||||
from switches
|
from switches
|
||||||
where switches.system = $1
|
where switches.system = $1
|
||||||
|
@ -59,8 +59,10 @@ async def get_fronter_ids(conn, system_id):
|
|||||||
|
|
||||||
async def get_fronters(conn, system_id):
|
async def get_fronters(conn, system_id):
|
||||||
member_ids, timestamp = await get_fronter_ids(conn, system_id)
|
member_ids, timestamp = await get_fronter_ids(conn, system_id)
|
||||||
members = await db.get_members(conn, member_ids)
|
|
||||||
return members, timestamp
|
# Collect in dict and then look up as list, to preserve return order
|
||||||
|
members = {member["id"]: member for member in await db.get_members(conn, member_ids)}
|
||||||
|
return [members[member_id] for member_id in member_ids], timestamp
|
||||||
|
|
||||||
async def get_front_history(conn, system_id, count):
|
async def get_front_history(conn, system_id, count):
|
||||||
# Get history from DB
|
# Get history from DB
|
||||||
|
Loading…
Reference in New Issue
Block a user