move serialised who mechanism in to Server. dont rely on exclusive wait_for
This commit is contained in:
parent
6e25b6c51d
commit
67e6064b67
2 changed files with 18 additions and 19 deletions
|
@ -1,17 +0,0 @@
|
|||
from typing import Dict, Iterable, List, Optional
|
||||
from irctokens import build
|
||||
from ircstates.numerics import *
|
||||
|
||||
from .contexts import ServerContext
|
||||
from .matching import Response, ANY, Folded
|
||||
|
||||
class WHOContext(ServerContext):
|
||||
async def ensure(self, channel: str):
|
||||
if self.server.isupport.whox:
|
||||
await self.server.send(self.server.prepare_whox(channel))
|
||||
else:
|
||||
await self.server.send(build("WHO", [channel]))
|
||||
|
||||
line = await self.server.wait_for(
|
||||
Response(RPL_ENDOFWHO, [ANY, Folded(channel)])
|
||||
)
|
|
@ -15,7 +15,6 @@ from irctokens import build, Line, tokenise
|
|||
from .ircv3 import (CAPContext, sts_transmute, CAP_ECHO, CAP_SASL,
|
||||
CAP_LABEL, LABEL_TAG_MAP, resume_transmute)
|
||||
from .sasl import SASLContext, SASLResult
|
||||
from .join_info import WHOContext
|
||||
from .matching import (ResponseOr, Responses, Response, ANY, SELF, MASK_SELF,
|
||||
Folded)
|
||||
from .asyncs import MaybeAwait, WaitFor
|
||||
|
@ -67,6 +66,8 @@ class Server(IServer):
|
|||
self._wait_fors: List[Tuple[WaitFor, Optional[Awaitable]]] = []
|
||||
self._wait_for_fut: Optional[Future[WaitFor]] = None
|
||||
|
||||
self._pending_who: Deque[str] = deque()
|
||||
|
||||
def hostmask(self) -> str:
|
||||
hostmask = self.nickname
|
||||
if not self.username is None:
|
||||
|
@ -179,10 +180,25 @@ class Server(IServer):
|
|||
elif emit.command == "JOIN":
|
||||
if emit.self and not emit.channel is None:
|
||||
await self.send(build("MODE", [emit.channel.name]))
|
||||
await WHOContext(self).ensure(emit.channel.name)
|
||||
|
||||
self._pending_who.append(emit.channel.name)
|
||||
if len(self._pending_who) == 1:
|
||||
await self._serial_who()
|
||||
|
||||
await self.line_read(line)
|
||||
|
||||
async def _serial_who(self):
|
||||
while self._pending_who:
|
||||
next = self._pending_who.popleft()
|
||||
if self.isupport.whox:
|
||||
await self.send(self.prepare_whox(next))
|
||||
else:
|
||||
await self.send(build("WHO", [next]))
|
||||
|
||||
end = Response(RPL_ENDOFWHO, [ANY, Folded(next)])
|
||||
line = await self.wait_for(end)
|
||||
|
||||
|
||||
async def _next_lines(self) -> List[Tuple[Line, Optional[Emit]]]:
|
||||
ping_sent = False
|
||||
while True:
|
||||
|
|
Loading…
Reference in a new issue