use bevy_net_backend::{BearerToken, Credentials, OutgoingRequest, WsPushMessage, WsRequest};
use crate::auth::AccessToken;
use crate::chat::{
ChatHistory, ChatMessage, EditMessage, JoinRoom, LeaveRoom, ListMembers, ListReceipts, MarkRead, MessageDeleted, MessageEdited, Presence, ReadReceipt,
RoomUpdate, SendMessage, SetTyping, TypingUpdate, UnreadQuery,
};
use crate::envelope::{ServerPush, WsCall};
use crate::friends::FriendPresence;
use crate::lobbies::{LobbyMemberUpdate, LobbyUpdate};
use crate::matchmaking::{MatchFound, TicketExpired};
use crate::notifications::{CountNotifications, DeleteNotification, MarkNotifications, Notification, NotificationQuery};
macro_rules! ws_requests {
($($request:ty),* $(,)?) => {
$(
impl WsRequest for $request {
type Response = <$request as WsCall>::Response;
const KIND: &'static str = <$request as WsCall>::KIND;
}
)*
};
}
macro_rules! ws_pushes {
($($push:ty),* $(,)?) => {
$(
impl WsPushMessage for $push {
const KIND: &'static str = <$push as ServerPush>::KIND;
}
)*
};
}
ws_requests!(
JoinRoom,
LeaveRoom,
SendMessage,
ChatHistory,
ListMembers,
EditMessage,
MarkRead,
ListReceipts,
UnreadQuery,
SetTyping,
NotificationQuery,
CountNotifications,
MarkNotifications,
DeleteNotification
);
ws_pushes!(
ChatMessage,
MessageDeleted,
Presence,
MessageEdited,
ReadReceipt,
TypingUpdate,
RoomUpdate,
Notification,
FriendPresence,
LobbyMemberUpdate,
LobbyUpdate,
MatchFound,
TicketExpired
);
impl Credentials for AccessToken {
fn apply(&self, request: &mut OutgoingRequest) {
BearerToken::new(self.expose()).apply(request);
}
}