Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mutations to mark chat messages as read, update message, update group chat info, add user to group chat, share images in chats, and create dedicated group chats for events #2625

Open
wants to merge 72 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
a8c02f8
Updated subscriptions and added mutations for directChat and groupChat
disha1202 Jul 15, 2024
fe6907d
Update index.ts
disha1202 Jul 16, 2024
3a9799d
Update messageSentToDirectChat.ts
disha1202 Jul 16, 2024
2fa65b1
Update createDirectChat.spec.ts
disha1202 Jul 16, 2024
f68bb01
Update createDirectChat.spec.ts
disha1202 Jul 16, 2024
f7089b9
fix: linting errors
disha1202 Jul 16, 2024
2fe5353
fix: lint errors
disha1202 Jul 16, 2024
7e31c14
fix: formatting issues
disha1202 Jul 16, 2024
0bf28a2
Merge branch 'develop' into chat-feature
disha1202 Jul 16, 2024
9c44ea4
fix: formatting issues
disha1202 Jul 16, 2024
fa5f6ec
fix: test cases
disha1202 Jul 16, 2024
3db8381
fix test cases
disha1202 Jul 16, 2024
a1379bf
Update messageSentToDirectChat.ts
disha1202 Jul 18, 2024
bd98a6b
Update messageSentToDirectChat.ts
disha1202 Jul 18, 2024
7ec1773
added test cases for query directChatById
Jul 18, 2024
3781ede
Update directChatById.spec.ts
disha1202 Jul 18, 2024
8aaf5f3
Update directChatById.spec.ts
disha1202 Jul 18, 2024
e83657d
Update directChatById.spec.ts
disha1202 Jul 18, 2024
23a9676
Added test cases
disha1202 Jul 18, 2024
9576d4a
fix: test cases
disha1202 Jul 18, 2024
c2af22d
fix: tests
disha1202 Jul 18, 2024
ad48619
fix test cases
disha1202 Jul 18, 2024
77c7fde
Merge branch 'chat-feature' of https://github.com/disha1202/talawa-ap…
disha1202 Jul 18, 2024
d18843a
added support to reply to direct chat and group chat
disha1202 Jul 24, 2024
cf27ca6
Merge branch 'develop' of https://github.com/disha1202/talawa-api int…
disha1202 Jul 24, 2024
8469653
fix: test cases
disha1202 Jul 24, 2024
87ad70f
updated schema for chat
disha1202 Jul 28, 2024
33535ac
Added tests for chat
disha1202 Aug 8, 2024
98d06a7
fix format
disha1202 Aug 8, 2024
5a61b43
fix test cases
disha1202 Aug 8, 2024
a84f1c6
fix tests
disha1202 Aug 8, 2024
4d65b03
fix tests
disha1202 Aug 8, 2024
c23008b
fix: test cases
disha1202 Aug 9, 2024
a539e3e
fix: test cases
disha1202 Aug 9, 2024
074b79c
fix: test cases
disha1202 Aug 10, 2024
9926e63
Merge branch 'develop' of https://github.com/PalisadoesFoundation/tal…
disha1202 Aug 10, 2024
1586732
added test cases
disha1202 Aug 15, 2024
8b873ea
Merge branch 'schema-update' of https://github.com/disha1202/talawa-a…
disha1202 Aug 15, 2024
6cb5dcc
feat: added unread msgs feature
disha1202 Aug 17, 2024
15d6bed
removed unwanted code
disha1202 Aug 18, 2024
46d4f5f
Removed unwanted code
disha1202 Aug 18, 2024
ce20fe0
Merge branch 'develop' into schema-update
disha1202 Aug 18, 2024
dcd6006
fix: lint errors
disha1202 Aug 18, 2024
ea23279
Merge branch 'schema-update' of https://github.com/disha1202/talawa-a…
disha1202 Aug 18, 2024
dca6cf3
sort chats by updatedAt field
disha1202 Aug 18, 2024
d33aada
fix: formatting issues
disha1202 Aug 18, 2024
56cd761
fix: chat updation
disha1202 Aug 18, 2024
ff1987f
Merge branch 'develop' into schema-update
disha1202 Aug 21, 2024
7cd8040
Merge branch 'develop' into schema-update
disha1202 Aug 21, 2024
f29ac65
Merge branch 'develop' into schema-update
disha1202 Aug 23, 2024
a440bad
fix: chat documentation
disha1202 Aug 23, 2024
615a5ac
Merge branch 'schema-update' of https://github.com/disha1202/talawa-a…
disha1202 Aug 23, 2024
5ad1d76
Merge branch 'develop' into schema-update
disha1202 Aug 24, 2024
c2d831a
added test cases
disha1202 Aug 24, 2024
bac5283
Merge branch 'schema-update' of https://github.com/disha1202/talawa-a…
disha1202 Aug 24, 2024
a2e5141
fix: formatting issues
disha1202 Aug 24, 2024
39d9086
fix: failed test cases
disha1202 Aug 24, 2024
69ee5c0
Merge branch 'develop' of https://github.com/PalisadoesFoundation/tal…
disha1202 Aug 24, 2024
cb9bd96
Merge branch 'schema-update' of https://github.com/disha1202/talawa-a…
disha1202 Aug 24, 2024
c90b208
added logic to filter chats
disha1202 Aug 25, 2024
4caa252
implemented mutation to add user to group chat
disha1202 Sep 7, 2024
e609503
feat: implemented mutation to update groupChat
disha1202 Sep 8, 2024
fdb0420
feat: implemented functionality to send media in chat
disha1202 Sep 9, 2024
8125136
feat: implemented update chat functionality
disha1202 Oct 7, 2024
b75cfc0
feat: logic to create automated group chats
disha1202 Oct 16, 2024
85b5c6e
Merge branch 'develop' of https://github.com/PalisadoesFoundation/tal…
disha1202 Oct 29, 2024
27afed4
added: ts doc comment
disha1202 Oct 29, 2024
8ef79b3
Merge branch 'develop' of https://github.com/PalisadoesFoundation/tal…
disha1202 Oct 29, 2024
1e030e1
fix: linting error
disha1202 Oct 29, 2024
6e45396
fix: formatting issue
disha1202 Oct 29, 2024
9e3c75e
fix: failing test
disha1202 Oct 29, 2024
ac4256c
fix: failing tests
disha1202 Oct 29, 2024
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
30 changes: 28 additions & 2 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ type Chat {
messages: [ChatMessage]
name: String
organization: Organization
unseenMessagesByUsers: JSON
updatedAt: DateTime!
users: [User!]!
}
Expand All @@ -215,12 +216,18 @@ type ChatMessage {
chatMessageBelongsTo: Chat!
createdAt: DateTime!
deletedBy: [User]
media: String
messageContent: String!
replyTo: ChatMessage
sender: User!
updatedAt: DateTime!
}

input ChatWhereInput {
name_contains: String
user: UserWhereInput
}

type CheckIn {
_id: ID!
createdAt: DateTime!
Expand Down Expand Up @@ -700,6 +707,7 @@ input EventAttendeeInput {

input EventInput {
allDay: Boolean!
createChat: Boolean!
description: String!
endDate: Date!
endTime: Time
Expand Down Expand Up @@ -1067,6 +1075,7 @@ type Mutation {
addPledgeToFundraisingCampaign(campaignId: ID!, pledgeId: ID!): FundraisingCampaignPledge!
addUserCustomData(dataName: String!, dataValue: Any!, organizationId: ID!): UserCustomData!
addUserImage(file: String!): User!
addUserToGroupChat(chatId: ID!, userId: ID!): Chat
addUserToUserFamily(familyId: ID!, userId: ID!): UserFamily!
assignToUserTags(input: TagActionsInput!): UserTag
assignUserTag(input: ToggleUserTagAssignInput!): User
Expand Down Expand Up @@ -1114,6 +1123,7 @@ type Mutation {
likePost(id: ID!): Post
login(data: LoginInput!): AuthData!
logout: Boolean!
markChatMessagesAsRead(chatId: ID!, userId: ID!): Chat
otp(data: OTPInput!): OtpData!
recaptcha(data: RecaptchaVerification!): Boolean!
refreshToken(refreshToken: String!): ExtendSession!
Expand Down Expand Up @@ -1147,7 +1157,7 @@ type Mutation {
revokeRefreshTokenForUser: Boolean!
saveFcmToken(token: String): Boolean!
sendMembershipRequest(organizationId: ID!): MembershipRequest!
sendMessageToChat(chatId: ID!, messageContent: String!, replyTo: ID): ChatMessage!
sendMessageToChat(chatId: ID!, media: String, messageContent: String, replyTo: ID): ChatMessage!
signUp(data: UserInput!, file: String): AuthData!
togglePostPin(id: ID!, title: String): Post!
unassignUserTag(input: ToggleUserTagAssignInput!): User
Expand All @@ -1161,6 +1171,8 @@ type Mutation {
updateAgendaCategory(id: ID!, input: UpdateAgendaCategoryInput!): AgendaCategory
updateAgendaItem(id: ID!, input: UpdateAgendaItemInput!): AgendaItem
updateAgendaSection(id: ID!, input: UpdateAgendaSectionInput!): AgendaSection
updateChat(input: UpdateChatInput!): Chat!
updateChatMessage(input: UpdateChatMessageInput!): ChatMessage!
updateCommunity(data: UpdateCommunityInput!): Boolean!
updateEvent(data: UpdateEventInput!, id: ID!, recurrenceRuleData: RecurrenceRuleInput, recurringEventUpdateType: RecurringEventMutationType): Event!
updateEventVolunteer(data: UpdateEventVolunteerInput, id: ID!): EventVolunteer!
Expand Down Expand Up @@ -1476,7 +1488,7 @@ type Query {
agendaItemByOrganization(organizationId: ID!): [AgendaItem]
agendaItemCategoriesByOrganization(organizationId: ID!): [AgendaCategory]
chatById(id: ID!): Chat!
chatsByUserId(id: ID!): [Chat]
chatsByUserId(id: ID!, where: ChatWhereInput): [Chat]
checkAuth: User!
customDataByOrganization(organizationId: ID!): [UserCustomData!]!
customFieldsByOrganization(id: ID!): [OrganizationCustomField]
Expand All @@ -1500,9 +1512,11 @@ type Query {
getFundById(id: ID!, orderBy: CampaignOrderByInput, where: CampaignWhereInput): Fund!
getFundraisingCampaignPledgeById(id: ID!): FundraisingCampaignPledge!
getFundraisingCampaigns(campaignOrderby: CampaignOrderByInput, pledgeOrderBy: PledgeOrderByInput, where: CampaignWhereInput): [FundraisingCampaign]!
getGroupChatsByUserId: [Chat]
getNoteById(id: ID!): Note!
getPledgesByUserId(orderBy: PledgeOrderByInput, userId: ID!, where: PledgeWhereInput): [FundraisingCampaignPledge]
getPlugins: [Plugin]
getUnreadChatsByUserId: [Chat]
getUserTag(id: ID!): UserTag
getUserTagAncestors(id: ID!): [UserTag]
getVenueByOrgId(first: Int, orderBy: VenueOrderByInput, orgId: ID!, skip: Int, where: VenueWhereInput): [Venue]
Expand Down Expand Up @@ -1696,6 +1710,18 @@ input UpdateAgendaSectionInput {
sequence: Int
}

input UpdateChatInput {
_id: ID!
image: String
name: String
}

input UpdateChatMessageInput {
chatId: ID!
messageContent: String!
messageId: ID!
}

input UpdateCommunityInput {
logo: String!
name: String!
Expand Down
4 changes: 3 additions & 1 deletion src/helpers/event/createEventHelpers/createRecurringEvent.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type mongoose from "mongoose";
import type { InterfaceEvent } from "../../../models";
import type { InterfaceChat, InterfaceEvent } from "../../../models";
import { Event } from "../../../models";
import type { MutationCreateEventArgs } from "../../../types/generatedGraphQLTypes";
import {
Expand Down Expand Up @@ -37,6 +37,7 @@ export const createRecurringEvent = async (
creatorId: string,
organizationId: string,
session: mongoose.ClientSession,
chat: InterfaceChat | null,
): Promise<InterfaceEvent> => {
// Extract event data and recurrence rule information from arguments
const { data } = args;
Expand Down Expand Up @@ -69,6 +70,7 @@ export const createRecurringEvent = async (
creatorId,
admins: [creatorId],
organization: organizationId,
chat: chat?._id,
},
],
{ session }, // Use the provided session if available
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export const createRecurringEventInstancesDuringQuery = async (
// Prepare input data for generating recurring event instances
const currentInputData: InterfaceRecurringEvent = {
...data,
createChat: false,
organizationId: recurrenceRule.organizationId.toString(),
};

Expand Down
4 changes: 3 additions & 1 deletion src/helpers/event/createEventHelpers/createSingleEvent.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type mongoose from "mongoose";
import type { InterfaceEvent } from "../../../models";
import type { InterfaceChat, InterfaceEvent } from "../../../models";
import { AppUserProfile, Event, EventAttendee, User } from "../../../models";
import type { MutationCreateEventArgs } from "../../../types/generatedGraphQLTypes";
import { cacheEvents } from "../../../services/EventCache/cacheEvents";
Expand Down Expand Up @@ -31,6 +31,7 @@ export const createSingleEvent = async (
creatorId: string,
organizationId: string,
session: mongoose.ClientSession,
chat: InterfaceChat | null,
): Promise<InterfaceEvent> => {
// Create the single event in the database
const createdEvent = await Event.create(
Expand All @@ -40,6 +41,7 @@ export const createSingleEvent = async (
creatorId,
admins: [creatorId],
organization: organizationId,
chat: chat?._id,
},
],
{ session },
Expand Down
2 changes: 2 additions & 0 deletions src/helpers/event/updateEventHelpers/getEventData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ export const getEventData = (
longitude: event.longitude,
creatorId: event.creatorId,
organizationId: event.organization,
chat: event.chat,
};

// Step 2: Update the current data with the input data (if provided).
const updatedEventData: InterfaceRecurringEvent = {
...eventCurrentData,
...(updateEventInputData as Partial<InterfaceRecurringEvent>),
createChat: event.chat ? true : false,
};

return updatedEventData;
Expand Down
8 changes: 7 additions & 1 deletion src/models/Chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface InterfaceChat {
_id: Types.ObjectId;
isGroup: boolean;
name: string;
image: string;
users: PopulatedDoc<InterfaceUser & Document>[];
messages: PopulatedDoc<InterfaceChatMessage & Document>[];
creatorId: PopulatedDoc<InterfaceUser & Document>;
Expand All @@ -20,6 +21,7 @@ export interface InterfaceChat {
createdAt: Date;
updatedAt: Date;
lastMessageId: string;
unseenMessagesByUsers: JSON;
}

/**
Expand Down Expand Up @@ -98,9 +100,13 @@ const chatSchema = new Schema(
type: String,
required: false,
},
unseenMessagesByUsers: {
type: JSON,
required: true,
},
},
{
timestamps: true,
timestamps: false,
},
);

Expand Down
7 changes: 6 additions & 1 deletion src/models/ChatMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface InterfaceChatMessage {
sender: PopulatedDoc<InterfaceUser & Document>;
replyTo: PopulatedDoc<InterfaceChatMessage & Document>;
messageContent: string;
media: string;
status: string;
deletedBy: PopulatedDoc<InterfaceUser & Document>[];
createdAt: Date;
Expand Down Expand Up @@ -66,7 +67,11 @@ const chatMessageSchema = new Schema(
},
messageContent: {
type: String,
required: true,
required: false,
},
media: {
type: String,
required: false,
},
status: {
type: String,
Expand Down
7 changes: 7 additions & 0 deletions src/models/Event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { createLoggingMiddleware } from "../libraries/dbLogger";
import type { InterfaceEventVolunteerGroup } from "./EventVolunteerGroup";
import type { InterfaceRecurrenceRule } from "./RecurrenceRule";
import type { InterfaceAgendaItem } from "./AgendaItem";
import type { InterfaceChat } from "./Chat";

/**
* Represents a document for an event in the MongoDB database.
Expand Down Expand Up @@ -39,6 +40,7 @@ export interface InterfaceEvent {
updatedAt: Date;
volunteerGroups: PopulatedDoc<InterfaceEventVolunteerGroup & Document>[];
agendaItems: PopulatedDoc<InterfaceAgendaItem & Document>[];
chat: PopulatedDoc<InterfaceChat & Document>;
}

/**
Expand Down Expand Up @@ -178,6 +180,11 @@ const eventSchema = new Schema(
ref: "Organization",
required: true,
},
chat: {
type: Schema.Types.ObjectId,
ref: "Chat",
required: false,
},
volunteerGroups: [
{
type: Schema.Types.ObjectId,
Expand Down
2 changes: 1 addition & 1 deletion src/resolvers/Chat/admins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type { ChatResolvers } from "../../types/generatedGraphQLTypes";
export const admins: ChatResolvers["users"] = async (parent) => {
return await User.find({
_id: {
$in: parent.users,
$in: parent.admins,
},
}).lean();
};
16 changes: 14 additions & 2 deletions src/resolvers/Chat/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,22 @@
* @param parent - An object that is the return value of the resolver for this field's parent.
* @returns An `object` that contains the list of messages.
*/
export const messages: ChatResolvers["messages"] = async (parent) => {
return await ChatMessage.find({
export const messages: ChatResolvers["messages"] = async (
parent,
_args,
context,
) => {
let messages = await ChatMessage.find({
_id: {
$in: parent.messages,
},
}).lean();

messages = messages.map((message) => {
if (message.media) {
return { ...message, media: `${context.apiRootUrl}${message.media}` };
}
return message;

Check warning on line 23 in src/resolvers/Chat/messages.ts

View check run for this annotation

Codecov / codecov/patch

src/resolvers/Chat/messages.ts#L23

Added line #L23 was not covered by tests
});
return messages;
};
Loading
Loading