-{-
--- | Matches a message of type @a@.
-message :: forall a. (Typeable a, FromJSON a) => Session a
-message =
- let parser = decode . encodeMsg :: FromServerMessage -> Maybe a
- in named (T.pack $ show $ head $ snd $ splitTyConApp $ last $ typeRepArgs $ typeOf parser) $
- satisfyMaybe parser
--}
+
+-- | Matches a request or a notification coming from the server.
+message :: SServerMethod m -> Session (ServerMessage m)
+message m1 = named (T.pack $ show m1) $ satisfyMaybe $ \case
+ FromServerMess m2 msg -> do
+ HRefl <- mEqServer m1 m2
+ pure msg
+ _ -> Nothing
+
+customRequest :: T.Text -> Session (ServerMessage (CustomMethod :: Method FromServer Request))
+customRequest m = named m $ satisfyMaybe $ \case
+ FromServerMess m1 msg -> case splitServerMethod m1 of
+ IsServerEither -> case msg of
+ ReqMess _ | m1 == SCustomMethod m -> Just msg
+ _ -> Nothing
+ _ -> Nothing
+ _ -> Nothing
+
+customNotification :: T.Text -> Session (ServerMessage (CustomMethod :: Method FromServer Notification))
+customNotification m = named m $ satisfyMaybe $ \case
+ FromServerMess m1 msg -> case splitServerMethod m1 of
+ IsServerEither -> case msg of
+ NotMess _ | m1 == SCustomMethod m -> Just msg
+ _ -> Nothing
+ _ -> Nothing
+ _ -> Nothing