| _roomService = roomService; | _roomService = roomService; | ||||
| } | } | ||||
| [HttpGet] | |||||
| public async Task<IActionResult> GetAll() | |||||
| [Authorize(Roles = "Customer,Support")] | |||||
| [HttpGet("rooms-with-filtered-messages")] | |||||
| public async Task<ActionResult<List<Room>>> GetAllRoomsWithFilteredMessages(string customerId) | |||||
| { | { | ||||
| return Ok(await _roomService.GetRoomsAsync()); | |||||
| var rooms = await _roomService.GetRoomsAsync(); | |||||
| foreach (var room in rooms) | |||||
| { | |||||
| List<Message> msg = new(); | |||||
| var customer = room.Customers.Where(c => c.CustomerId == customerId).FirstOrDefault(); | |||||
| if (customer is not null) | |||||
| { | |||||
| foreach (var message in room.Messages) | |||||
| { | |||||
| if (message.CreatedAtUtc >= customer.DateOfEnteringRoom) | |||||
| msg.Add(message); | |||||
| } | |||||
| room.Messages = msg; | |||||
| } | |||||
| else | |||||
| { | |||||
| room.Messages = new List<Message>(); | |||||
| } | |||||
| } | |||||
| return rooms; | |||||
| } | } | ||||
| [HttpPost] | [HttpPost] |
| "@csstools/postcss-stepped-value-functions": "^1.0.0", | "@csstools/postcss-stepped-value-functions": "^1.0.0", | ||||
| "@csstools/postcss-trigonometric-functions": "^1.0.1", | "@csstools/postcss-trigonometric-functions": "^1.0.1", | ||||
| "@csstools/postcss-unset-value": "^1.0.1", | "@csstools/postcss-unset-value": "^1.0.1", | ||||
| "autoprefixer": "^10.4.7", | |||||
| "autoprefixer": "10.4.5", | |||||
| "browserslist": "^4.21.0", | "browserslist": "^4.21.0", | ||||
| "css-blank-pseudo": "^3.0.3", | "css-blank-pseudo": "^3.0.3", | ||||
| "css-has-pseudo": "^3.0.4", | "css-has-pseudo": "^3.0.4", |
| }, [user, dispatch, loadedNotification]); | }, [user, dispatch, loadedNotification]); | ||||
| useEffect(() => { | useEffect(() => { | ||||
| dispatch(fetchChatRoomsAsync()); | |||||
| (user !== null && dispatch(fetchChatRoomsAsync(user.id))) | |||||
| dispatch(fetchRequestsAsync()); | dispatch(fetchRequestsAsync()); | ||||
| }, [dispatch]); | }, [dispatch]); | ||||
| }); | }); | ||||
| const fulfilled = () => { | const fulfilled = () => { | ||||
| connection.send("Subscribe", user.id); | |||||
| connection.send("Subscribe", user && user.id); | |||||
| }; | }; | ||||
| const rejected = () => {}; | const rejected = () => {}; |
| const responseBody = (response) => response.data; | const responseBody = (response) => response.data; | ||||
| const methods = { | const methods = { | ||||
| getChats: () => axios.get("/Chat").then(responseBody), | |||||
| getChats: (customerId) => axios.get(`/Chat/rooms-with-filtered-messages?customerId=${customerId}`).then(responseBody), | |||||
| createChat: (payload) => axios.post("/Chat", payload).then(responseBody), | createChat: (payload) => axios.post("/Chat", payload).then(responseBody), | ||||
| }; | }; | ||||
| export const fetchChatRoomsAsync = createAsyncThunk( | export const fetchChatRoomsAsync = createAsyncThunk( | ||||
| "chat/fetchChatRoomsAsync", | "chat/fetchChatRoomsAsync", | ||||
| async (_, thunkAPI) => { | |||||
| async (payload, thunkAPI) => { | |||||
| try { | try { | ||||
| return await chatService.getChats(); | |||||
| return await chatService.getChats(payload); | |||||
| } catch (error) { | } catch (error) { | ||||
| return thunkAPI.rejectWithValue({ error }); | return thunkAPI.rejectWithValue({ error }); | ||||
| } | } | ||||
| }); | }); | ||||
| builder.addCase(loadNotifications.fulfilled, (state, action) => { | builder.addCase(loadNotifications.fulfilled, (state, action) => { | ||||
| state.status = "idle"; | state.status = "idle"; | ||||
| console.log(action.payload); | |||||
| if (action.payload.length === 0) { | if (action.payload.length === 0) { | ||||
| state.notifications = []; | state.notifications = []; | ||||
| } else { | } else { |