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

Updated chat schema #2466

Open
wants to merge 70 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 67 commits
Commits
Show all changes
70 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
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
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
d450059
Merge branch 'develop' into schema-update
disha1202 Sep 1, 2024
aad9ea2
Merge branch 'develop' of https://github.com/PalisadoesFoundation/tal…
disha1202 Sep 22, 2024
b5da053
Merge branch 'schema-update' of https://github.com/disha1202/talawa-a…
disha1202 Sep 22, 2024
50d579e
fix: failling tests
disha1202 Sep 22, 2024
99a24c2
removed unwanted code
disha1202 Sep 22, 2024
23ba0b5
Update tests/resolvers/Query/chatById.spec.ts
disha1202 Sep 22, 2024
c4f6cd6
fix: removed ignore statements
disha1202 Sep 22, 2024
3b0f12c
Merge branch 'schema-update' of https://github.com/disha1202/talawa-a…
disha1202 Sep 22, 2024
9f2f12d
Update schema.graphql
disha1202 Sep 22, 2024
a6b960f
fix: failing tests
disha1202 Sep 22, 2024
8548f25
Merge branch 'schema-update' of https://github.com/disha1202/talawa-a…
disha1202 Sep 22, 2024
bf38bc6
fix: removed eslint disabled statements
disha1202 Sep 22, 2024
d42aca6
updated tests and helper functions
disha1202 Sep 29, 2024
4124a3a
Merge branch 'develop' into schema-update
disha1202 Oct 6, 2024
7d5667d
reverted: unrelated changes
disha1202 Oct 6, 2024
9911641
Merge branch 'schema-update' of https://github.com/disha1202/talawa-a…
disha1202 Oct 6, 2024
3b4e431
reverted: unrelated changes
disha1202 Oct 6, 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
10 changes: 2 additions & 8 deletions codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,9 @@ const config: CodegenConfig = {

Community: "../models/Community#InterfaceCommunity",

DirectChat: "../models/DirectChat#InterfaceDirectChat",
Chat: "../models/Chat#InterfaceChat",

DirectChatMessage:
"../models/DirectChatMessage#InterfaceDirectChatMessage",
ChatMessage: "../models/ChatMessage#InterfaceChatMessage",

Donation: "../models/Donation#InterfaceDonation",

Expand All @@ -75,11 +74,6 @@ const config: CodegenConfig = {

Group: "../models/Group#InterfaceGroup",

GroupChat: "../models/GroupChat#InterfaceGroupChat",

GroupChatMessage:
"../models/GroupChatMessage#InterfaceGroupChatMessage",

// ImageHash: '../models/ImageHash#InterfaceImageHash',

Language: "../models/Language#InterfaceLanguage",
Expand Down
82 changes: 35 additions & 47 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,32 @@ input CampaignWhereInput {
organizationId: ID
}

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

type ChatMessage {
_id: ID!
chatMessageBelongsTo: Chat!
createdAt: DateTime!
deletedBy: [User]
messageContent: String!
replyTo: ChatMessage
disha1202 marked this conversation as resolved.
Show resolved Hide resolved
sender: User!
updatedAt: DateTime!
}

type CheckIn {
_id: ID!
createdAt: DateTime!
Expand Down Expand Up @@ -549,26 +575,6 @@ type DeletePayload {
success: Boolean!
}

type DirectChat {
_id: ID!
createdAt: DateTime!
creator: User
messages: [DirectChatMessage]
organization: Organization
updatedAt: DateTime!
users: [User!]!
}

type DirectChatMessage {
_id: ID!
createdAt: DateTime!
directChatMessageBelongsTo: DirectChat!
messageContent: String!
receiver: User!
sender: User!
updatedAt: DateTime!
}

type Donation {
_id: ID!
amount: Float!
Expand Down Expand Up @@ -932,26 +938,6 @@ type Group {
updatedAt: DateTime!
}

type GroupChat {
_id: ID!
createdAt: DateTime!
creator: User
messages: [GroupChatMessage]
organization: Organization!
title: String!
updatedAt: DateTime!
users: [User!]!
}

type GroupChatMessage {
_id: ID!
createdAt: DateTime!
groupChatMessageBelongsTo: GroupChat!
messageContent: String!
sender: User!
updatedAt: DateTime!
}

type InvalidCursor implements FieldError {
message: String!
path: [String!]!
Expand Down Expand Up @@ -1096,8 +1082,8 @@ type Mutation {
createAgendaCategory(input: CreateAgendaCategoryInput!): AgendaCategory!
createAgendaItem(input: CreateAgendaItemInput!): AgendaItem!
createAgendaSection(input: CreateAgendaSectionInput!): AgendaSection!
createChat(data: chatInput!): Chat
createComment(data: CommentInput!, postId: ID!): Comment
createDirectChat(data: createChatInput!): DirectChat!
createDonation(amount: Float!, nameOfOrg: String!, nameOfUser: String!, orgId: ID!, payPalId: ID!, userId: ID!): Donation!
createEvent(data: EventInput!, recurrenceRuleData: RecurrenceRuleInput): Event!
createEventVolunteer(data: EventVolunteerInput!): EventVolunteer!
Expand Down Expand Up @@ -1165,8 +1151,7 @@ type Mutation {
revokeRefreshTokenForUser: Boolean!
saveFcmToken(token: String): Boolean!
sendMembershipRequest(organizationId: ID!): MembershipRequest!
sendMessageToDirectChat(chatId: ID!, messageContent: String!): DirectChatMessage!
sendMessageToGroupChat(chatId: ID!, messageContent: String!): GroupChatMessage!
sendMessageToChat(chatId: ID!, messageContent: String!, replyTo: ID, type: String!): ChatMessage!
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use MessageType enum for type parameter in sendMessageToChat mutation.

Replacing the String type with the MessageType enum for the type parameter enhances validation and ensures only predefined message types are accepted.

Define the MessageType enum:

enum MessageType {
  TEXT
  IMAGE
  VIDEO
  FILE
}

Apply this diff:

 type Mutation {
-  sendMessageToChat(chatId: ID!, messageContent: String!, replyTo: ID, type: String!): ChatMessage!
+  sendMessageToChat(chatId: ID!, messageContent: String!, replyTo: ID, type: MessageType!): ChatMessage!
   ...
 }

signUp(data: UserInput!, file: String): AuthData!
togglePostPin(id: ID!, title: String): Post!
unassignUserTag(input: ToggleUserTagAssignInput!): User
Expand Down Expand Up @@ -1493,12 +1478,13 @@ type Query {
agendaItemByEvent(relatedEventId: ID!): [AgendaItem]
agendaItemByOrganization(organizationId: ID!): [AgendaItem]
agendaItemCategoriesByOrganization(organizationId: ID!): [AgendaCategory]
chatById(id: ID!): Chat!
chatsByUserId(id: ID!): [Chat]
checkAuth: User!
customDataByOrganization(organizationId: ID!): [UserCustomData!]!
customFieldsByOrganization(id: ID!): [OrganizationCustomField]
directChatById(id: ID!): DirectChat
directChatsByUserID(id: ID!): [DirectChat]
directChatsMessagesByChatID(id: ID!): [DirectChatMessage]
event(id: ID!): Event
eventVolunteersByEvent(id: ID!): [EventVolunteer]
eventsByOrganization(id: ID, orderBy: EventOrderByInput): [Event]
Expand Down Expand Up @@ -1629,8 +1615,7 @@ enum Status {

type Subscription {
directMessageChat: MessageChat
messageSentToDirectChat(userId: ID!): DirectChatMessage
messageSentToGroupChat(userId: ID!): GroupChatMessage
messageSentToChat(userId: ID!): ChatMessage @auth
onPluginUpdate: Plugin
}

Expand Down Expand Up @@ -2047,7 +2032,10 @@ enum WeekDays {
WEDNESDAY
}

input createChatInput {
input chatInput {
image: String
isGroup: Boolean!
name: String
Comment on lines +2035 to +2038
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Include 'organizationId' and 'userIds' in 'chatInput' for completeness

The chatInput type appears incomplete. To support organization-specific chats and specify participants, include organizationId and userIds fields.

Apply this diff:

 input chatInput {
   image: String
   isGroup: Boolean!
   name: String
+  organizationId: ID
+  userIds: [ID!]!
 }
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
input chatInput {
image: String
isGroup: Boolean!
name: String
input chatInput {
image: String
isGroup: Boolean!
name: String
organizationId: ID
userIds: [ID!]!
}

organizationId: ID
userIds: [ID!]!
}
Expand Down
1 change: 1 addition & 0 deletions setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { loadDefaultOrganiation } from "./src/utilities/loadDefaultOrg";
import { isMinioInstalled } from "./src/setup/isMinioInstalled";
import { installMinio } from "./src/setup/installMinio";


dotenv.config();

// Check if all the fields in .env.sample are present in .env
Expand Down
7 changes: 7 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ export const CHAT_NOT_FOUND_ERROR = Object.freeze({
PARAM: "chat",
});

export const MESSAGE_NOT_FOUND_ERROR = Object.freeze({
DESC: "Message not found",
CODE: "message.notFound",
MESSAGE: "message.notFound",
PARAM: "message",
});

export const VENUE_ALREADY_EXISTS_ERROR = Object.freeze({
DESC: "Venue already exists",
CODE: "venue.alreadyExists",
Expand Down
67 changes: 56 additions & 11 deletions src/models/DirectChat.ts → src/models/Chat.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,42 @@
import type { PopulatedDoc, Types, Document, Model } from "mongoose";
import { Schema, model, models } from "mongoose";
import type { InterfaceDirectChatMessage } from "./DirectChatMessage";
import type { InterfaceOrganization } from "./Organization";
import type { InterfaceUser } from "./User";
import { createLoggingMiddleware } from "../libraries/dbLogger";
import type { InterfaceChatMessage } from "./ChatMessage";
/**
* Interface representing a document for direct chat in MongoDB.
*/
export interface InterfaceDirectChat {
export interface InterfaceChat {
_id: Types.ObjectId;
isGroup: boolean;
name: string;
users: PopulatedDoc<InterfaceUser & Document>[];
messages: PopulatedDoc<InterfaceDirectChatMessage & Document>[];
messages: PopulatedDoc<InterfaceChatMessage & Document>[];
creatorId: PopulatedDoc<InterfaceUser & Document>;
organization: PopulatedDoc<InterfaceOrganization & Document>;
status: string;
admins: PopulatedDoc<InterfaceUser & Document>[];
createdAt: Date;
updatedAt: Date;
lastMessageId: string;
}

/**
* Mongoose schema for a direct chat.
* Mongoose schema for a chat.
* @param isGroup - Indicates if the chat is a group chat.
* @param name - Name of the chat if its a group chat.
* @param users - Users participating in the chat.
* @param messages - Messages in the chat.
* @param creatorId - Creator of the chat, reference to `User` model.
* @param admins - Admins of the chat if its a group chat, reference to `User` model.
* @param organization - Organization associated with the chat, reference to `Organization` model.
* @param status - Status of the chat (ACTIVE, BLOCKED, DELETED).
* @param createdAt - Timestamp of chat creation.
* @param updatedAt - Timestamp of chat update.
* @param lastMessageId - ID of the last message in the chat.
*/
const directChatSchema = new Schema(
const chatSchema = new Schema(
{
users: [
{
Expand All @@ -37,39 +45,76 @@ const directChatSchema = new Schema(
required: true,
},
],
isGroup: {
type: Boolean,
required: true,
},
name: {
type: String,
required: false,
},
image: {
type: String,
require: false,
Comment on lines +53 to +58
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use lowercase string for type consistency.

The String type should be replaced with string to adhere to TypeScript best practices.

Use this diff to fix the types:

-      type: String,
+      type: string,

Committable suggestion was skipped due to low confidence.

},
messages: [
{
type: Schema.Types.ObjectId,
ref: "DirectChatMessage",
ref: "ChatMessage",
},
],
creatorId: {
type: Schema.Types.ObjectId,
ref: "User",
required: true,
},
admins: [
{
type: Schema.Types.ObjectId,
ref: "User",
required: false,
},
],
status: {
type: String,
required: true,
enum: ["ACTIVE", "BLOCKED", "DELETED"],
default: "ACTIVE",
},
organization: {
type: Schema.Types.ObjectId,
ref: "Organization",
required: false,
},
createdAt: {
type: Date,
required: true,
},
updatedAt: {
type: Date,
required: true,
},
lastMessageId: {
type: String,
required: false,
},
},
{
timestamps: true,
},
);

// Add logging middleware for directChatSchema
createLoggingMiddleware(directChatSchema, "DirectChat");
createLoggingMiddleware(chatSchema, "Chat");

/**
* Retrieves or creates the Mongoose model for DirectChat.
* Prevents Mongoose OverwriteModelError during testing.
*/
const directChatModel = (): Model<InterfaceDirectChat> =>
model<InterfaceDirectChat>("DirectChat", directChatSchema);
const chatModel = (): Model<InterfaceChat> =>
model<InterfaceChat>("Chat", chatSchema);

// This syntax is needed to prevent Mongoose OverwriteModelError while running tests.
export const DirectChat = (models.DirectChat ||
directChatModel()) as ReturnType<typeof directChatModel>;
export const Chat = (models.Chat || chatModel()) as ReturnType<
typeof chatModel
>;
Loading
Loading