Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public async Task<Result<ChatDto>> Handle(CreateChatCommand request, Cancellatio
AvatarLink = avatarLink,
MembersCount = 1,
CanSendMedia = true,
OwnerId = requester.Id,
IsOwner = true,
IsMember = true
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public async Task<Result<ChatDto>> Handle(JoinToChatCommand request, Cancellatio
? chat.LastMessage.Owner.DisplayName
: null,
LastMessageDateOfCreate = chat.LastMessage?.DateOfCreate,
OwnerId = chat.OwnerId,
IsOwner = chat.OwnerId == request.RequesterId,
IsMember = true,
MembersCount = memberCount,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public async Task<Result<ChatDto>> Handle(LeaveFromChatCommand request, Cancella
: null,
LastMessageDateOfCreate = chatUser.Chat.LastMessage?.DateOfCreate,
CanSendMedia = chatUser.CanSendMedia,
OwnerId = chatUser.Chat.OwnerId,
IsOwner = chatUser.Chat.OwnerId == request.RequesterId,
IsMember = false,
MuteDateOfExpire = chatUser.MuteDateOfExpire,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public async Task<Result<ChatDto>> Handle(UpdateChatAvatarCommand request, Cance
? chatUserByRequester.Chat.LastMessage.Owner.DisplayName
: null,
LastMessageDateOfCreate = chatUserByRequester.Chat.LastMessage?.DateOfCreate,
OwnerId = chatUserByRequester.Chat.OwnerId,
IsOwner = chatUserByRequester.Chat.OwnerId == request.RequesterId,
IsMember = true,
MuteDateOfExpire = chatUserByRequester.MuteDateOfExpire,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public async Task<Result<ChatDto>> Handle(UpdateChatDataCommand request, Cancell
LastMessageDateOfCreate = chatUserByRequester.Chat.LastMessage?.DateOfCreate,
MembersCount = chatUserByRequester.Chat.ChatUsers.Count,
CanSendMedia = chatUserByRequester.CanSendMedia,
OwnerId = chatUserByRequester.Chat.OwnerId,
IsOwner = chatUserByRequester.Chat.OwnerId == request.RequesterId,
IsMember = true,
MuteDateOfExpire = chatUserByRequester.MuteDateOfExpire,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ where EF.Functions.Like(chat.Title, $"%{request.SearchText}%") ||
LastMessageDateOfCreate = chat.LastMessage != null ? chat.LastMessage.DateOfCreate : null,
MembersCount = chat.ChatUsers.Count,
CanSendMedia = chatUsersItem != null && chatUsersItem.CanSendMedia,
OwnerId = chat.OwnerId,
IsOwner = chat.OwnerId == request.RequesterId,
IsMember = chatUsersItem != null,
MuteDateOfExpire = chatUsersItem != null ? chatUsersItem.MuteDateOfExpire : null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ orderby chat.LastMessage.DateOfCreate descending
LastMessageDateOfCreate = chat.LastMessage != null ? chat.LastMessage.DateOfCreate : null,
MembersCount = chat.ChatUsers.Count,
CanSendMedia = chatUsersItem.CanSendMedia,
OwnerId = chat.OwnerId,
IsOwner = chat.OwnerId == request.RequesterId,
IsMember = chatUsersItem != null,
MuteDateOfExpire = chatUsersItem != null ? chatUsersItem.MuteDateOfExpire : null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ from banUserByChatItem in banUserByChatEnumerable.DefaultIfEmpty()
LastMessageDateOfCreate = chat.LastMessage != null ? chat.LastMessage.DateOfCreate : null,
MembersCount = chat.ChatUsers.Count,
CanSendMedia = chatUsersItem != null && chatUsersItem.CanSendMedia,
OwnerId = chat.OwnerId,
IsOwner = chat.OwnerId == request.RequesterId,
IsMember = chatUsersItem != null,
MuteDateOfExpire = chatUsersItem != null ? chatUsersItem.MuteDateOfExpire : null,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using MediatR;
using Messenger.BusinessLogic.Models;
using Messenger.BusinessLogic.Responses;

namespace Messenger.BusinessLogic.ApiQueries.Conversations;

public record GetUserPermissionsQuery(Guid ChatId, Guid UserId) : IRequest<Result<PermissionDto>>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using MediatR;
using Messenger.BusinessLogic.Models;
using Messenger.BusinessLogic.Responses;
using Messenger.Persistence;
using Microsoft.EntityFrameworkCore;

namespace Messenger.BusinessLogic.ApiQueries.Conversations;

public class GetUserPermissionsQueryHandler : IRequestHandler<GetUserPermissionsQuery, Result<PermissionDto>>
{
private readonly DatabaseContext _context;

public GetUserPermissionsQueryHandler(DatabaseContext context)
{
_context = context;
}

public async Task<Result<PermissionDto>> Handle(GetUserPermissionsQuery request, CancellationToken cancellationToken)
{
var userPermissions = await _context.ChatUsers
.Where(x => x.UserId == request.UserId && x.ChatId == request.ChatId)
.Select(c => new PermissionDto(c))
.FirstOrDefaultAsync(cancellationToken);

if (userPermissions == null)
{
return new Result<PermissionDto>(new DbEntityNotFoundError("user permissions not found"));
}

return new Result<PermissionDto>(userPermissions);
}
}
2 changes: 2 additions & 0 deletions Messenger.BusinessLogic/Models/ChatDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public class ChatDto

public bool CanSendMedia { get; init; }

public Guid? OwnerId { get; set; }

public bool IsOwner { get; init; }

public bool IsMember { get; init; }
Expand Down
10 changes: 8 additions & 2 deletions Messenger.BusinessLogic/Models/PermissionDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@ namespace Messenger.BusinessLogic.Models;

public class PermissionDto
{
public bool CanSendMedia { get; set; }
public Guid UserId { get; private set; }

public DateTime? MuteDateOfExpire { get; set; }
public Guid ChatId { get; private set; }

public bool CanSendMedia { get; private set; }

public DateTime? MuteDateOfExpire { get; private set; }

public PermissionDto(ChatUserEntity chatUser)
{
UserId = chatUser.UserId;
ChatId = chatUser.ChatId;
CanSendMedia = chatUser.CanSendMedia;
MuteDateOfExpire = chatUser.MuteDateOfExpire;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Messenger.Domain.Enums;

namespace Messenger.BusinessLogic.Models.Requests;

public class CreateOrUpdateRoleUserRequest
{
public Guid ChatId { get; set; }

public Guid UserId { get; set; }

public string RoleTitle { get; set; }

public RoleColor RoleColor { get; set; }

public bool CanBanUser { get; set; }

public bool CanChangeChatData { get; set; }

public bool CanAddAndRemoveUserToConversation { get; set; }

public bool CanGivePermissionToUser { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Messenger.BusinessLogic.Models.Requests;

public class CreatePermissionsUserInConversationRequest
{
public Guid ChatId { get; set; }
public Guid UserId { get; set; }
public bool CanSendMedia { get; set; }
public int? MuteMinutes { get; set; }
}
22 changes: 20 additions & 2 deletions Messenger.Client/src/App.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ body {
$light-grey-border: rgb(185, 185, 185);
$grey-font-page:rgb(56, 56, 56);
$light-grey-font-page:rgb(150, 150, 150);
$light-grey: #efefef;
$light-grey: #f5f5f5;
$light-grey-for-session-item: rgb(92, 90, 90);

$grey: #dbdbdb;
Expand Down Expand Up @@ -43,4 +43,22 @@ $purple-transparent-button-hover: #9533e6b7;

$pink-transparent: rgba(243, 237, 245, 0.781);

$blue-transparent-for-session-item: rgb(174, 180, 243);
$blue-transparent-for-session-item: rgb(174, 180, 243);

$role-color-blue: rgba(0, 4, 255, 0.13);
$role-color-blue-hover: rgba(0, 4, 255, 0.18);

$role-color-green: rgba(81, 255, 0, 0.13);
$role-color-green-hover: rgba(81, 255, 0, 0.18);

$role-color-cyan: rgba(0, 255, 234, 0.13);
$role-color-cyan-hover: rgba(0, 255, 234, 0.25);

$role-color-red: rgba(255, 0, 0, 0.08);
$role-color-red-hover: rgba(255, 0, 0, 0.13);

$role-color-yellow: rgba(255, 251, 0, 0.17);
$role-color-yellow-hover: rgba(255, 251, 0, 0.13);

$role-color-orange: rgba(255, 174, 0, 0.2);
$role-color-orange-hover: rgba(255, 196, 0, 0.15);
48 changes: 0 additions & 48 deletions Messenger.Client/src/components/chatInfo/ChatInfo.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@
overflow-y: scroll;
width: 100%;
height: 400px;
border-radius: 0 0 20px 0;

&::-webkit-scrollbar {
width: 2px;
Expand All @@ -150,53 +149,6 @@
}
}

.memberItem {
display: flex;
border-bottom: 2px solid $grey;
transition: 0.2s;
cursor: pointer;

&:hover {
background-color: $light-grey
}
}

.memberItemAvatar {
width: 40px;
height: 40px;
border-radius: 100%;
margin: 5px;
margin-left: 10px;
flex-shrink: 0;
object-fit: cover;
}

.memberItemContainer {
position: relative;
width: 100%;
height: 100%;
margin-left: 5px;
}

.memberItemDisplayName {
font-size: 15px;
margin-top: 5px;
}

.memberItemBio {
font-size: 12px;
margin-top: 5px;
color: $light-grey-font-page;
}

.memberItemRole {
position: absolute;
right: 5px;
top: 5px;
font-size: 12px;
color: $grey-font-page;
}

.okButton {
width: 25px;
height: 25px;
Expand Down
41 changes: 2 additions & 39 deletions Messenger.Client/src/components/chatInfo/ChatInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ import { currentChatState } from "../../state/CurrentChatState";
import { chatListWithMessagesState } from "../../state/ChatListWithMessagesState";
import { useNavigate } from "react-router-dom";
import { blackCoverState } from "../../state/BlackCoverState";
import { authorizationState } from "../../state/AuthorizationState";
import { currentProfileState } from "../../state/CurrentProfileState";
import { useDebouncedCallback } from "use-debounce";
import { motion } from "framer-motion";
import RouteConstants from "../../constants/RouteConstants";
import MemberListItem from "../memberListItem/MemberListItem";

const ChatInfo = observer(() => {
const [updateMode, setUpdateMode] = useState<boolean>(false);
Expand Down Expand Up @@ -106,20 +105,6 @@ const ChatInfo = observer(() => {
blackCoverState.setImage(currentChatState.chat?.avatarLink ?? nonAvatar);
};

const showProfileByMessage = async (userId: string) => {
if (userId === authorizationState.data?.id) {
currentProfileState.setProfileNull();

return navigate(RouteConstants.Layout, { replace: true });
}

await currentProfileState
.getUserAsync(userId)
.catch((error: any) => { if (error.response.status !== 401) alert(error.response.data.message); });

return navigate(RouteConstants.Layout, { replace: true });
};

const onClickShowMemberListHandler = async () => {
if (!currentChatStateChat) return;

Expand Down Expand Up @@ -266,29 +251,7 @@ const ChatInfo = observer(() => {
showMemberList && (
<div className={styles.memberList} id="memberList" onScroll={getMembers}>
{currentChatState.chat?.members.map((i) => (
<motion.div
initial={{ opacity: 0.7 }}
animate={{ opacity: 1 }}
transition={{ type: "Inertia", duration: .15 }}
className={styles.memberItem} key={i.id}
onClick={() => showProfileByMessage(i.id)}>
<img
className={styles.memberItemAvatar}
src={i.avatarLink ?? nonAvatar}
alt=""
/>
<div className={styles.memberItemContainer}>
<p className={styles.memberItemDisplayName}>{i.displayName}</p>
<p className={styles.memberItemBio}>{i.bio}</p>
<p className={styles.memberItemRole}>
{
currentChatState.chat?.usersWithRole.find(
(u) => u.userId === i.id
)?.roleTitle
}
</p>
</div>
</motion.div>
<MemberListItem {...i} key={i.id}/>
))}
</div>
)
Expand Down
Loading