Skip to content

Commit

Permalink
Feat: updated chat related functionality to work with the updated cha…
Browse files Browse the repository at this point in the history
…t schema (#2286)

* Initial commit

* Updated the UI of chat screen

* feat: added support to create group chat

* implemented group chats

* Implemented logic to send messages in group chat

* refactor chat functionality

* fix format

* refactor code

* fix failing tests

* removed unwanted code

* fix: formatting issues and reverted unwanted changes

* removed unwanted code

* implemented reply functionality for direct chat

* implemented reply functionality

* Updated chat schema

* fix: contact card ui

* removed unwanted code

* fix: create group chat functionality

* fix: formatting issues

* fix: formatting issue

* fix: formatting issue

* fix: type errors

* fix: tsdoc error

* fix: formatting errors

* improve code coverage

* improved code coverage

* Update Chat.tsx
  • Loading branch information
disha1202 authored Oct 20, 2024
1 parent a2b0167 commit 036b92e
Show file tree
Hide file tree
Showing 17 changed files with 3,959 additions and 4,767 deletions.
38 changes: 38 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,32 @@ enum MaritalStatus {
WIDOWED
}

type Chat {
_id: ID!
isGroup: Boolean!
name: String
createdAt: DateTime!
creator: User
messages: [ChatMessage]
organization: Organization
updatedAt: DateTime!
users: [User!]!
admins: [User]
lastMessageId: String
}

type ChatMessage {
_id: ID!
createdAt: DateTime!
chatMessageBelongsTo: Chat!
messageContent: String!
type: String!
replyTo: ChatMessage
sender: User!
deletedBy: [User]
updatedAt: DateTime!
}

type MaximumLengthError implements FieldError {
message: String!
path: [String!]!
Expand Down Expand Up @@ -665,6 +691,7 @@ type Mutation {
): Advertisement!
createAgendaCategory(input: CreateAgendaCategoryInput!): AgendaCategory!
createComment(data: CommentInput!, postId: ID!): Comment
createChat(data: chatInput!): Chat!
createDirectChat(data: createChatInput!): DirectChat!
createDonation(
amount: Float!
Expand Down Expand Up @@ -739,6 +766,7 @@ type Mutation {
revokeRefreshTokenForUser: Boolean!
saveFcmToken(token: String): Boolean!
sendMembershipRequest(organizationId: ID!): MembershipRequest!
sendMessageToChat(chatId: ID!, messageContent: String!, type: String!, replyTo: ID): ChatMessage!
sendMessageToDirectChat(
chatId: ID!
messageContent: String!
Expand Down Expand Up @@ -1066,6 +1094,8 @@ type Query {
checkAuth: User!
customDataByOrganization(organizationId: ID!): [UserCustomData!]!
customFieldsByOrganization(id: ID!): [OrganizationCustomField]
chatById(id: ID!): Chat!
chatsByUserId(id: ID!): [Chat]
directChatsByUserID(id: ID!): [DirectChat]
directChatsMessagesByChatID(id: ID!): [DirectChatMessage]
directChatById(id: ID!): DirectChat
Expand Down Expand Up @@ -1166,6 +1196,7 @@ enum Status {

type Subscription {
directMessageChat: MessageChat
messageSentToChat(userId: ID!): ChatMessage
messageSentToDirectChat(userId: ID!): DirectChatMessage
messageSentToGroupChat(userId: ID!): GroupChatMessage
onPluginUpdate: Plugin
Expand Down Expand Up @@ -1593,3 +1624,10 @@ input createUserFamilyInput {
title: String!
userIds: [ID!]!
}

input chatInput {
isGroup: Boolean!
organizationId: ID
userIds: [ID!]!
name: String
}
139 changes: 135 additions & 4 deletions src/GraphQl/Mutations/OrganizationMutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,93 @@ export const CREATE_DIRECT_CHAT = gql`
}
`;

export const CREATE_CHAT = gql`
mutation createChat(
$userIds: [ID!]!
$organizationId: ID
$isGroup: Boolean!
$name: String
) {
createChat(
data: {
userIds: $userIds
organizationId: $organizationId
isGroup: $isGroup
name: $name
}
) {
_id
}
}
`;

export const SEND_MESSAGE_TO_CHAT = gql`
mutation sendMessageToChat(
$chatId: ID!
$replyTo: ID
$messageContent: String!
$type: String!
) {
sendMessageToChat(
chatId: $chatId
replyTo: $replyTo
messageContent: $messageContent
type: $type
) {
_id
createdAt
messageContent
replyTo {
_id
createdAt
messageContent
sender {
_id
firstName
lastName
}
updatedAt
}
sender {
_id
firstName
lastName
}
updatedAt
}
}
`;

export const SEND_MESSAGE_TO_DIRECT_CHAT = gql`
mutation sendMessageToDirectChat($chatId: ID!, $messageContent: String!) {
sendMessageToDirectChat(chatId: $chatId, messageContent: $messageContent) {
mutation sendMessageToDirectChat(
$chatId: ID!
$replyTo: ID
$messageContent: String!
) {
sendMessageToDirectChat(
chatId: $chatId
replyTo: $replyTo
messageContent: $messageContent
) {
_id
createdAt
messageContent
replyTo {
_id
createdAt
messageContent
receiver {
_id
firstName
lastName
}
sender {
_id
firstName
lastName
}
updatedAt
}
receiver {
_id
firstName
Expand All @@ -107,11 +188,30 @@ export const SEND_MESSAGE_TO_DIRECT_CHAT = gql`
`;

export const SEND_MESSAGE_TO_GROUP_CHAT = gql`
mutation sendMessageToGroupChat($chatId: ID!, $messageContent: String!) {
sendMessageToGroupChat(chatId: $chatId, messageContent: $messageContent) {
mutation sendMessageToGroupChat(
$chatId: ID!
$replyTo: ID
$messageContent: String!
) {
sendMessageToGroupChat(
chatId: $chatId
replyTo: $replyTo
messageContent: $messageContent
) {
_id
createdAt
messageContent
replyTo {
_id
createdAt
messageContent
sender {
_id
firstName
lastName
}
updatedAt
}
sender {
_id
firstName
Expand Down Expand Up @@ -164,6 +264,37 @@ export const MESSAGE_SENT_TO_DIRECT_CHAT = gql`
}
`;

export const MESSAGE_SENT_TO_CHAT = gql`
subscription messageSentToChat($userId: ID!) {
messageSentToChat(userId: $userId) {
_id
createdAt
chatMessageBelongsTo {
_id
}
messageContent
replyTo {
_id
createdAt
messageContent
sender {
_id
firstName
lastName
}
updatedAt
}
type
sender {
_id
firstName
lastName
}
updatedAt
}
}
`;

export const MESSAGE_SENT_TO_GROUP_CHAT = gql`
subscription messageSentToGroupChat($userId: ID!) {
messageSentToGroupChat(userId: $userId) {
Expand Down
Loading

0 comments on commit 036b92e

Please sign in to comment.