#7 chat history

Sammanfogat
Dzenis sammanfogade 1 incheckningar från feature/317_chat_history in i development 3 år sedan

+ 25
- 3
Backend/Diligent.WebAPI.Host/Controllers/ChatController.cs Visa fil

@@ -18,10 +18,32 @@ namespace Diligent.WebAPI.Host.Controllers
_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]

+ 1
- 1
Frontend/package-lock.json Visa fil

@@ -27517,7 +27517,7 @@
"@csstools/postcss-stepped-value-functions": "^1.0.0",
"@csstools/postcss-trigonometric-functions": "^1.0.1",
"@csstools/postcss-unset-value": "^1.0.1",
"autoprefixer": "^10.4.7",
"autoprefixer": "10.4.5",
"browserslist": "^4.21.0",
"css-blank-pseudo": "^3.0.3",
"css-has-pseudo": "^3.0.4",

+ 1
- 1
Frontend/src/components/ChatList.js Visa fil

@@ -46,7 +46,7 @@ const ChatList = () => {
}, [user, dispatch, loadedNotification]);

useEffect(() => {
dispatch(fetchChatRoomsAsync());
(user !== null && dispatch(fetchChatRoomsAsync(user.id)))
dispatch(fetchRequestsAsync());
}, [dispatch]);


+ 1
- 1
Frontend/src/components/MiddleContainer.js Visa fil

@@ -44,7 +44,7 @@ const MiddleContainer = ({ showTerm }) => {
});

const fulfilled = () => {
connection.send("Subscribe", user.id);
connection.send("Subscribe", user && user.id);
};

const rejected = () => {};

+ 1
- 1
Frontend/src/services/chatService.js Visa fil

@@ -6,7 +6,7 @@ axios.defaults.baseURL = apiUrl;
const responseBody = (response) => response.data;

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),
};


+ 2
- 3
Frontend/src/store/chat-slice.js Visa fil

@@ -20,9 +20,9 @@ const initialState = {

export const fetchChatRoomsAsync = createAsyncThunk(
"chat/fetchChatRoomsAsync",
async (_, thunkAPI) => {
async (payload, thunkAPI) => {
try {
return await chatService.getChats();
return await chatService.getChats(payload);
} catch (error) {
return thunkAPI.rejectWithValue({ error });
}
@@ -194,7 +194,6 @@ const chatSlice = createSlice({
});
builder.addCase(loadNotifications.fulfilled, (state, action) => {
state.status = "idle";
console.log(action.payload);
if (action.payload.length === 0) {
state.notifications = [];
} else {

Laddar…
Avbryt
Spara