feature/bugs-message_positioning nach development vor 3 Jahren zusammengeführt
| { | { | ||||
| await Groups.AddToGroupAsync(Context.ConnectionId, userConnection.RoomId); | await Groups.AddToGroupAsync(Context.ConnectionId, userConnection.RoomId); | ||||
| _connections[Context.ConnectionId] = userConnection; | _connections[Context.ConnectionId] = userConnection; | ||||
| await Clients.Group(userConnection.RoomId).ReceiveMessage(new ChatMessage { UserId = userConnection.UserId, User = userConnection.UserId, RoomId = userConnection.RoomId, Message = $"{userConnection.Username} has joined room", ConnId = Context.ConnectionId }); | |||||
| await Clients.Group(userConnection.RoomId).ReceiveMessage(new ChatMessage { UserId = userConnection.UserId, User = userConnection.UserId, RoomId = userConnection.RoomId, Message = $"{userConnection.Username} has joined room", ConnId = Context.ConnectionId,IsAccessMessage = true }); | |||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| { | { | ||||
| // Find user connection in connections dictionary and delete it | // Find user connection in connections dictionary and delete it | ||||
| _connections.Remove(Context.ConnectionId); | _connections.Remove(Context.ConnectionId); | ||||
| await Clients.OthersInGroup(room.RoomId).ReceiveMessage(new ChatMessage { UserId = room.UserId, User = room.UserId, Message = $"{room.Username} has left room", RoomId = room.RoomId }); | |||||
| await Clients.OthersInGroup(room.RoomId).ReceiveMessage(new ChatMessage { UserId = room.UserId, User = room.UserId, Message = $"{room.Username} has left room", RoomId = room.RoomId,IsAccessMessage = true }); | |||||
| await _mediator.Send(new RemoveUserFromGroupCommand(room.RoomId, room.UserId)); | await _mediator.Send(new RemoveUserFromGroupCommand(room.RoomId, room.UserId)); | ||||
| } | } | ||||
| } | } |
| public string Message { get; set; } | public string Message { get; set; } | ||||
| public DateTime Created { get; set; } = DateTime.Now; | public DateTime Created { get; set; } = DateTime.Now; | ||||
| public Attachment? Attachment { get; set; } | public Attachment? Attachment { get; set; } | ||||
| public bool IsAccessMessage { get; set; } = false; | |||||
| // Context.ConnectionId generated by SignalR | // Context.ConnectionId generated by SignalR | ||||
| public string ConnId { get; set; } | public string ConnId { get; set; } | ||||
| public string RoomId { get; set; } | public string RoomId { get; set; } |
| ? dispatch(fetchSupportRoomsAsync(user.id)) | ? dispatch(fetchSupportRoomsAsync(user.id)) | ||||
| : user !== null && dispatch(fetchChatRoomsAsync(user.id)); | : user !== null && dispatch(fetchChatRoomsAsync(user.id)); | ||||
| dispatch(fetchRequestsAsync()); | dispatch(fetchRequestsAsync()); | ||||
| }, [dispatch, user]); | |||||
| }, [dispatch]); | |||||
| useEffect(() => { | useEffect(() => { | ||||
| if (requests && rooms) { | if (requests && rooms) { | ||||
| dispatch( | dispatch( | ||||
| chatActions.saveContextId({ connId: data.connId, userId: user.id }) | chatActions.saveContextId({ connId: data.connId, userId: user.id }) | ||||
| ); | ); | ||||
| console.log("Join room",data) | |||||
| setChatMessage(data); | setChatMessage(data); | ||||
| } | } | ||||
| }); | }); | ||||
| chatActions.saveContextId({ connId: data.connId, userId: user.id }) | chatActions.saveContextId({ connId: data.connId, userId: user.id }) | ||||
| ); | ); | ||||
| } | } | ||||
| console.log("Send group message",data) | |||||
| setChatMessage(data); | setChatMessage(data); | ||||
| }); | }); | ||||
| } | } | ||||
| }, [myConnection, dispatch, user]); | |||||
| }, [myConnection, dispatch]); | |||||
| // Maybe don't work | // Maybe don't work | ||||
| useEffect(() => { | useEffect(() => { | ||||
| createdAtUtc: new Date(), | createdAtUtc: new Date(), | ||||
| deletedAtUtc: null, | deletedAtUtc: null, | ||||
| id: null, | id: null, | ||||
| senderId: user.id, | |||||
| senderId: chatMessage.userId, | |||||
| updatedAtUtc: null, | updatedAtUtc: null, | ||||
| username: user.username, | username: user.username, | ||||
| isAccessMessage: chatMessage.isAccessMessage | |||||
| }) | }) | ||||
| ); | ); | ||||
| } | } | ||||
| }, [chatMessage, dispatch, user, activeRoom]); | |||||
| }, [chatMessage, dispatch]); | |||||
| // Maybe don't work | // Maybe don't work | ||||
| useEffect(() => { | useEffect(() => { | ||||
| } | } | ||||
| } | } | ||||
| setNotificationRoom(null); | setNotificationRoom(null); | ||||
| }, [notificationRoom, activeRoom, dispatch, user]); | |||||
| }, [notificationRoom, dispatch]); | |||||
| const openModal = (n) => { | const openModal = (n) => { | ||||
| setShowModal(true); | setShowModal(true); |
| <div className="messages p-3 border d-flex flex-column-reverse"> | <div className="messages p-3 border d-flex flex-column-reverse"> | ||||
| {/* mapirane poruke */} | {/* mapirane poruke */} | ||||
| {messages | |||||
| {user && messages | |||||
| .map((n, index) => ( | .map((n, index) => ( | ||||
| <div | <div | ||||
| key={index} | key={index} | ||||
| className={ | className={ | ||||
| n.senderId === user.id | |||||
| n.isAccessMessage === true ? | |||||
| "d-flex flex-column align-items-center" : | |||||
| (n.senderId === user.id | |||||
| ? "d-flex flex-column align-items-end" | ? "d-flex flex-column align-items-end" | ||||
| : "d-flex flex-column align-items-start" | |||||
| : "d-flex flex-column align-items-start") | |||||
| } | } | ||||
| > | > | ||||
| {console.log("Message",n,"User id",user.id)} | |||||
| <p | <p | ||||
| className={`p-2 px-4 mb-0 rounded message ${ | className={`p-2 px-4 mb-0 rounded message ${ | ||||
| n.senderId !== user.id | n.senderId !== user.id | ||||
| : "bg-light text-dark" | : "bg-light text-dark" | ||||
| }`} | }`} | ||||
| > | > | ||||
| {/* {n.message} */} | |||||
| {n.content} | {n.content} | ||||
| </p> | </p> | ||||
| <p className="text-muted small m-0 p-0 mb-4"> | <p className="text-muted small m-0 p-0 mb-4"> | ||||
| ) : ( | ) : ( | ||||
| "" | "" | ||||
| )} | )} | ||||
| {n.username} | |||||
| {n.isAccessMessage !== true && n.username} | |||||
| </p> | </p> | ||||
| </div> | </div> | ||||
| )) | )) |