-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
feat: implemented Reply functionality for chat #2584
Merged
DMills27
merged 52 commits into
PalisadoesFoundation:develop
from
disha1202:reply-functionality
Oct 21, 2024
Merged
Changes from all commits
Commits
Show all changes
52 commits
Select commit
Hold shift + click to select a range
a8c02f8
Updated subscriptions and added mutations for directChat and groupChat
disha1202 fe6907d
Update index.ts
disha1202 3a9799d
Update messageSentToDirectChat.ts
disha1202 2fa65b1
Update createDirectChat.spec.ts
disha1202 f68bb01
Update createDirectChat.spec.ts
disha1202 f7089b9
fix: linting errors
disha1202 2fe5353
fix: lint errors
disha1202 7e31c14
fix: formatting issues
disha1202 0bf28a2
Merge branch 'develop' into chat-feature
disha1202 9c44ea4
fix: formatting issues
disha1202 fa5f6ec
fix: test cases
disha1202 3db8381
fix test cases
disha1202 a1379bf
Update messageSentToDirectChat.ts
disha1202 bd98a6b
Update messageSentToDirectChat.ts
disha1202 7ec1773
added test cases for query directChatById
3781ede
Update directChatById.spec.ts
disha1202 8aaf5f3
Update directChatById.spec.ts
disha1202 e83657d
Update directChatById.spec.ts
disha1202 23a9676
Added test cases
disha1202 9576d4a
fix: test cases
disha1202 c2af22d
fix: tests
disha1202 ad48619
fix test cases
disha1202 77c7fde
Merge branch 'chat-feature' of https://github.com/disha1202/talawa-ap…
disha1202 d18843a
added support to reply to direct chat and group chat
disha1202 cf27ca6
Merge branch 'develop' of https://github.com/disha1202/talawa-api int…
disha1202 8469653
fix: test cases
disha1202 f936adc
removed console logs
disha1202 babf1c0
Merge branch 'develop' into reply-functionality
disha1202 c84f33a
Merge branch 'develop' into reply-functionality
disha1202 ef2d45d
Merge branch 'develop' into reply-functionality
disha1202 a2ccfb0
Removed unwanted code
disha1202 52165f1
Merge branch 'reply-functionality' of https://github.com/disha1202/ta…
disha1202 369a81d
Merge branch 'develop' into reply-functionality
disha1202 979bf37
Merge branch 'develop' into reply-functionality
disha1202 dd9120f
Merge branch 'develop' into reply-functionality
disha1202 08a6fed
Merge branch 'develop' into reply-functionality
disha1202 b6fa93e
added test cases
disha1202 0e0b1d3
Merge branch 'reply-functionality' of https://github.com/disha1202/ta…
disha1202 4f9ea48
removed unwanted comments
disha1202 7baed1d
Merge branch 'develop' into reply-functionality
disha1202 b3032db
Merge branch 'develop' into reply-functionality
disha1202 d0b54f6
Merge branch 'develop' into reply-functionality
disha1202 670f79e
Merge branch 'develop' of https://github.com/PalisadoesFoundation/tal…
disha1202 b66d394
Merge branch 'reply-functionality' of https://github.com/disha1202/ta…
disha1202 03a26d8
fix: linting errors'
disha1202 45f663f
Merge branch 'develop' into reply-functionality
disha1202 eb66ac0
fix: eslint errors
disha1202 da87a78
fix: removed unused imports
disha1202 08ad877
Merge branch 'develop' into reply-functionality
disha1202 6d9ca1f
Update eslint.config.mjs
disha1202 fad02e3
fix: formatting issues
disha1202 66719d5
Merge branch 'develop' into reply-functionality
DMills27 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
import type { DirectChatMessageResolvers } from "../../types/generatedGraphQLTypes"; | ||
import { directChatMessageBelongsTo } from "./directChatMessageBelongsTo"; | ||
import { receiver } from "./receiver"; | ||
import { replyTo } from "./replyTo"; | ||
import { sender } from "./sender"; | ||
|
||
export const DirectChatMessage: DirectChatMessageResolvers = { | ||
directChatMessageBelongsTo, | ||
receiver, | ||
sender, | ||
replyTo, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import type { DirectChatMessageResolvers } from "../../types/generatedGraphQLTypes"; | ||
import { DirectChatMessage } from "../../models"; | ||
import { MESSAGE_NOT_FOUND_ERROR } from "../../constants"; | ||
import { errors, requestContext } from "../../libraries"; | ||
/** | ||
* This resolver function will fetch and return the reply to message of the Direct chat from the database. | ||
* @param parent - An object that is the return value of the resolver for this field's parent. | ||
* @returns An `object` that contains User's data. | ||
*/ | ||
export const replyTo: DirectChatMessageResolvers["replyTo"] = async ( | ||
parent, | ||
) => { | ||
if (parent.replyTo) { | ||
const result = await DirectChatMessage.findOne({ | ||
_id: parent.replyTo, | ||
}).lean(); | ||
|
||
if (result) { | ||
return result; | ||
} else { | ||
throw new errors.NotFoundError( | ||
requestContext.translate(MESSAGE_NOT_FOUND_ERROR.MESSAGE), | ||
MESSAGE_NOT_FOUND_ERROR.CODE, | ||
MESSAGE_NOT_FOUND_ERROR.PARAM, | ||
); | ||
} | ||
} else { | ||
return null; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
import type { GroupChatMessageResolvers } from "../../types/generatedGraphQLTypes"; | ||
import { groupChatMessageBelongsTo } from "./groupChatMessageBelongsTo"; | ||
import { replyTo } from "./replyTo"; | ||
import { sender } from "./sender"; | ||
|
||
export const GroupChatMessage: GroupChatMessageResolvers = { | ||
groupChatMessageBelongsTo, | ||
sender, | ||
replyTo, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import type { GroupChatMessageResolvers } from "../../types/generatedGraphQLTypes"; | ||
import { GroupChatMessage } from "../../models"; | ||
import { MESSAGE_NOT_FOUND_ERROR } from "../../constants"; | ||
import { errors, requestContext } from "../../libraries"; | ||
/** | ||
* This resolver function will fetch and return the replied-to message in a group chat from the database. | ||
* @param parent - An object that is the return value of the resolver for this field's parent. | ||
* @returns An `object` that contains User's data. | ||
*/ | ||
export const replyTo: GroupChatMessageResolvers["replyTo"] = async (parent) => { | ||
if (parent.replyTo) { | ||
const result = await GroupChatMessage.findOne({ | ||
_id: parent.replyTo, | ||
}).lean(); | ||
|
||
if (result) { | ||
return result; | ||
} else { | ||
throw new errors.NotFoundError( | ||
requestContext.translate(MESSAGE_NOT_FOUND_ERROR.MESSAGE), | ||
MESSAGE_NOT_FOUND_ERROR.CODE, | ||
MESSAGE_NOT_FOUND_ERROR.PARAM, | ||
); | ||
} | ||
} else { | ||
return null; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Consider adding validation for the
replyTo
field.While the implementation of the reply functionality is correct, it might benefit from additional validation to ensure data integrity and prevent potential misuse. Consider adding checks to verify that:
replyTo
message exists.replyTo
message belongs to the same group chat.This could be implemented before creating the new message, for example:
This additional check would ensure that users can only reply to existing messages within the same group chat.