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

feat: functionality to view unread messages and mark messages as read. #2353

Open
wants to merge 40 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
1ca936b
Initial commit
disha1202 Jun 8, 2024
c42da5e
Updated the UI of chat screen
disha1202 Jun 27, 2024
3742346
feat: added support to create group chat
disha1202 Jun 30, 2024
06f4af4
implemented group chats
disha1202 Jul 2, 2024
c18b97b
Implemented logic to send messages in group chat
disha1202 Jul 7, 2024
cbde8f7
refactor chat functionality
disha1202 Jul 12, 2024
9950269
fix format
disha1202 Jul 12, 2024
77a392c
refactor code
disha1202 Jul 13, 2024
eb54545
fix failing tests
disha1202 Jul 15, 2024
09427e6
Merge branch 'develop' of https://github.com/PalisadoesFoundation/tal…
disha1202 Jul 15, 2024
6fbaaa2
removed unwanted code
disha1202 Jul 15, 2024
8fffdc5
fix: formatting issues and reverted unwanted changes
disha1202 Jul 15, 2024
f76dc3e
removed unwanted code
disha1202 Jul 15, 2024
d4864a8
implemented reply functionality for direct chat
disha1202 Jul 20, 2024
75fa6c3
implemented reply functionality
disha1202 Jul 27, 2024
58086e2
Updated chat schema
disha1202 Jul 28, 2024
4d6f9a6
fix: contact card ui
disha1202 Jul 31, 2024
a68dcb4
removed unwanted code
disha1202 Jul 31, 2024
3df2541
feat: implemented unseen message functionality
disha1202 Aug 15, 2024
15385ae
fix: create group chat functionality
disha1202 Aug 18, 2024
1ee07f3
Merge branch 'develop' into schema-update
disha1202 Sep 21, 2024
4525924
fix: formatting issues
disha1202 Sep 21, 2024
f4b6fd0
fix: formatting issue
disha1202 Sep 21, 2024
74899fd
fix: formatting issue
disha1202 Sep 21, 2024
450b587
fix: type errors
disha1202 Sep 21, 2024
b1790e2
fix: tsdoc error
disha1202 Sep 21, 2024
fe66f0a
fix: formatting errors
disha1202 Sep 21, 2024
352b6b5
improve code coverage
disha1202 Sep 21, 2024
9a661e5
improved code coverage
disha1202 Sep 22, 2024
580260a
Merge branch 'develop' of https://github.com/disha1202/talawa-admin i…
disha1202 Sep 22, 2024
182eded
Merge branch 'develop' into schema-update
disha1202 Oct 17, 2024
e6e5c24
Update Chat.tsx
disha1202 Oct 17, 2024
426f34c
Merge branch 'schema-update' of https://github.com/disha1202/talawa-a…
disha1202 Oct 19, 2024
11265e0
fix: failing test cases
disha1202 Oct 20, 2024
85f698c
Merge branch 'develop' of https://github.com/PalisadoesFoundation/tal…
disha1202 Oct 20, 2024
d541812
Merge branch 'develop' of https://github.com/PalisadoesFoundation/tal…
disha1202 Oct 23, 2024
635a115
fix: failing tests
disha1202 Oct 25, 2024
9d581e8
Merge branch 'develop' of https://github.com/PalisadoesFoundation/tal…
disha1202 Oct 25, 2024
4b3850a
reverted unwanted changes
disha1202 Oct 25, 2024
da51531
revert unwanted changes
disha1202 Oct 25, 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
9 changes: 7 additions & 2 deletions public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -1159,14 +1159,19 @@
"endOfResults": "endOfResults"
},
"userChat": {
"add": "Add",
"chat": "Chat",
"search": "Search",
"messages": "Messages",
"contacts": "Contacts"
"contacts": "Contacts",
"create": "Create",
"newChat": "New Chat",
"newGroupChat": "New Group Chat"
},
"userChatRoom": {
"selectContact": "Select a contact to start conversation",
"sendMessage": "Send Message"
"sendMessage": "Send Message",
"reply": "Reply"
},
"orgProfileField": {
"loading": "Loading...",
Expand Down
9 changes: 7 additions & 2 deletions public/locales/fr/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -1159,14 +1159,19 @@
"endOfResults": "Fin des résultats"
},
"userChat": {
"add": "Ajouter",
"chat": "Chat",
"contacts": "Contacts",
"search": "rechercher",
"messages": "messages"
"messages": "messages",
"create": "créer",
"newChat": "nouvelle discussion",
"newGroupChat": "Nouvelle discussion de groupe"
},
"userChatRoom": {
"selectContact": "Sélectionnez un contact pour démarrer la conversation",
"sendMessage": "Envoyer le message"
"sendMessage": "Envoyer le message",
"reply": "répondre"
},
"orgProfileField": {
"loading": "Chargement...",
Expand Down
9 changes: 7 additions & 2 deletions public/locales/hi/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -1159,14 +1159,19 @@
"endOfResults": "परिणाम समाप्त"
},
"userChat": {
"add": "जोड़ें",
"chat": "बात करना",
"contacts": "संपर्क",
"search": "खोज",
"messages": "संदेश"
"messages": "संदेश",
"create": "बनाएं",
"newChat": "नई चैट",
"newGroupChat": "नया समूह चैट"
},
"userChatRoom": {
"selectContact": "बातचीत शुरू करने के लिए एक संपर्क चुनें",
"sendMessage": "मेसेज भेजें"
"sendMessage": "मेसेज भेजें",
"reply": "जवाब"
},
"orgProfileField": {
"loading": "लोड हो रहा है...",
Expand Down
9 changes: 7 additions & 2 deletions public/locales/sp/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -1160,14 +1160,19 @@
"createAdvertisement": "Crear publicidad"
},
"userChat": {
"add": "Agregar",
"chat": "Charlar",
"search": "Buscar",
"contacts": "Contactos",
"messages": "Mensajes"
"messages": "Mensajes",
"create": "crear",
"newChat": "nueva charla",
"newGroupChat": "Nuevo chat grupal"
},
"userChatRoom": {
"selectContact": "Seleccione un contacto para iniciar una conversación",
"sendMessage": "Enviar mensaje"
"sendMessage": "Enviar mensaje",
"reply": "responder"
},
"orgProfileField": {
"loading": "Cargando..",
Expand Down
9 changes: 7 additions & 2 deletions public/locales/zh/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -1159,14 +1159,19 @@
"endOfResults": "结果结束"
},
"userChat": {
"add": "添加",
"chat": "聊天",
"contacts": "联系方式",
"search": "搜索",
"messages": "消息"
"messages": "消息",
"create": "创造",
"newChat": "新聊天",
"newGroupChat": "新群聊"
},
"userChatRoom": {
"selectContact": "选择联系人开始对话",
"sendMessage": "发信息"
"sendMessage": "发信息",
"reply": "回复"
},
"orgProfileField": {
"loading": "加载中...",
Expand Down
14 changes: 2 additions & 12 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,6 @@ type ChatMessage {
createdAt: DateTime!
chatMessageBelongsTo: Chat!
messageContent: String!
type: String!
replyTo: ChatMessage
sender: User!
deletedBy: [User]
Expand Down Expand Up @@ -692,7 +691,6 @@ type Mutation {
createAgendaCategory(input: CreateAgendaCategoryInput!): AgendaCategory!
createComment(data: CommentInput!, postId: ID!): Comment
createChat(data: chatInput!): Chat!
createDirectChat(data: createChatInput!): DirectChat!
createDonation(
amount: Float!
nameOfOrg: String!
Expand All @@ -706,7 +704,6 @@ type Mutation {
recurrenceRuleData: RecurrenceRuleInput
): Event!
createEventVolunteer(data: EventVolunteerInput!): EventVolunteer!
createGroupChat(data: createGroupChatInput!): GroupChat!
createMember(input: UserAndOrganizationInput!): Organization!
createMessageChat(data: MessageChatInput!): MessageChat!
createOrganization(data: OrganizationInput, file: String): Organization!
Expand Down Expand Up @@ -766,15 +763,8 @@ 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!
): DirectChatMessage!
sendMessageToGroupChat(
chatId: ID!
messageContent: String!
): GroupChatMessage!
sendMessageToChat(chatId: ID!, messageContent: String!, replyTo: ID): ChatMessage!
markChatMessagesAsRead(chatId: ID!, userId: ID!): Chat
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Missing read status tracking fields in Chat and ChatMessage types

The mutation markChatMessagesAsRead is added but the schema doesn't have the necessary fields to track message read status. The Chat and ChatMessage types should include fields to store which messages have been read by which users.

Suggested additions needed:

  • Add a field in ChatMessage type to track read status (e.g., readBy: [User!])
  • Or add a separate type for tracking message read status with references to both User and ChatMessage
🔗 Analysis chain

LGTM! Added mutation for marking messages as read.

The new mutation properly handles message read status tracking by taking both chatId and userId parameters, which is essential for multi-user chat scenarios.

Let's verify the mutation is properly integrated with the Chat type:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify Chat type has necessary fields for read status tracking
ast-grep --pattern 'type Chat {
  $$$
  lastMessageId: String
  $$$
}'

Length of output: 72


Script:

#!/bin/bash
# Let's try a more specific search for the Chat type definition
rg "type Chat \{" -A 20 schema.graphql

Length of output: 425


Script:

#!/bin/bash
# Let's check if there are any read status related fields in the schema
rg "read|unread" -i schema.graphql

Length of output: 93

signUp(data: UserInput!, file: String): AuthData!
togglePostPin(id: ID!, title: String): Post!
unassignUserTag(input: ToggleUserTagAssignInput!): User
Expand Down
37 changes: 9 additions & 28 deletions src/GraphQl/Mutations/OrganizationMutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,34 +57,6 @@ export const REMOVE_SAMPLE_ORGANIZATION_MUTATION = gql`
* @returns The created direct chat object.
*/

export const CREATE_GROUP_CHAT = gql`
mutation createGroupChat(
$userIds: [ID!]!
$organizationId: ID!
$title: String!
) {
createGroupChat(
data: {
userIds: $userIds
organizationId: $organizationId
title: $title
}
) {
_id
}
}
`;

export const CREATE_DIRECT_CHAT = gql`
mutation createDirectChat($userIds: [ID!]!, $organizationId: ID) {
createDirectChat(
data: { userIds: $userIds, organizationId: $organizationId }
) {
_id
}
}
`;

export const CREATE_CHAT = gql`
mutation createChat(
$userIds: [ID!]!
Expand All @@ -105,6 +77,14 @@ export const CREATE_CHAT = gql`
}
`;

export const MARK_CHAT_MESSAGES_AS_READ = gql`
mutation markChatMessagesAsRead($chatId: ID!, $userId: ID!) {
markChatMessagesAsRead(chatId: $chatId, userId: $userId) {
_id
}
Comment on lines +82 to +84
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider expanding the mutation return fields.

The mutation currently returns only the _id. Consider returning additional fields that could be useful for UI updates, such as updatedAt or a boolean indicating success.

 markChatMessagesAsRead(chatId: $chatId, userId: $userId) {
   _id
+  updatedAt
+  isRead
 }

Committable suggestion was skipped due to low confidence.

}
`;

export const SEND_MESSAGE_TO_CHAT = gql`
mutation sendMessageToChat(
$chatId: ID!
Expand Down Expand Up @@ -178,6 +158,7 @@ export const MESSAGE_SENT_TO_CHAT = gql`
}
updatedAt
}
type
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

The 'type' field in the subscription needs to be documented in the schema

The type field is being used in the MESSAGE_SENT_TO_CHAT subscription but it's not defined in any of the Message types in the schema. This could lead to confusion about its purpose and valid values.

  • Add the type field to the Message or MessageChat type in schema.graphql
  • Document the possible values for this field
🔗 Analysis chain

Document the purpose of the 'type' field.

The new 'type' field has been added to the subscription, but its purpose and possible values are not documented.

Let's check the GraphQL schema for the possible values of this field:


Let me search for more context about the type field in the codebase:


Let me check the actual content of those files that might contain message type definitions:


Let me check the subscription definition in the mutations file:


Let me check the schema for the message type field:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for the Message type definition and possible type values
rg -A 10 "type Message" || rg -A 10 "enum MessageType"

Length of output: 663


Script:

#!/bin/bash
# Search for message type related fields or enums in the schema
rg -l "type.*Message|enum.*Message" 

# Search for type field usage in mutations/subscriptions
rg -A 5 "type:.*Message" || rg -A 5 "type.*Message.*subscription"

# Look for message type related constants or enums in the codebase
rg -A 5 "MessageType|MESSAGE_TYPE"

Length of output: 241


Script:

#!/bin/bash
# Check content of the identified files for message type related code
echo "=== ChatRoom.tsx ===="
cat src/components/UserPortal/ChatRoom/ChatRoom.tsx

echo -e "\n=== Chat.tsx ===="
cat src/screens/UserPortal/Chat/Chat.tsx

# Also check the subscription definition
echo -e "\n=== Subscription definition ===="
rg -A 10 "MESSAGE_SENT_TO_CHAT" schema.graphql

Length of output: 24582


Script:

#!/bin/bash
# Check the mutation file for MESSAGE_SENT_TO_CHAT subscription
cat src/GraphQl/Mutations/OrganizationMutations.ts

Length of output: 5999


Script:

#!/bin/bash
# Look for message type related enums or type definitions in schema
rg -B 5 -A 5 "type Message|enum.*Message|type.*message" schema.graphql

Length of output: 386

sender {
_id
firstName
Expand Down
1 change: 0 additions & 1 deletion src/GraphQl/Mutations/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,6 @@ export {
// Changes the role of a user in an organization
export {
ADD_CUSTOM_FIELD,
CREATE_DIRECT_CHAT,
CREATE_SAMPLE_ORGANIZATION_MUTATION,
JOIN_PUBLIC_ORGANIZATION,
PLUGIN_SUBSCRIPTION,
Expand Down
2 changes: 2 additions & 0 deletions src/GraphQl/Queries/PlugInQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ export const CHAT_BY_ID = gql`
lastName
email
}
unseenMessagesByUsers
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Based on the search results, I can now provide a final response about the type information for unseenMessagesByUsers:

The type for unseenMessagesByUsers should be string in the GraphQL query

From the codebase analysis:

  • In src/screens/UserPortal/Chat/Chat.tsx, it's typed as string and used with JSON.parse()
  • In src/components/UserPortal/ChatRoom/ChatRoom.tsx, it's typed as JSON
  • The actual data structure is a stringified object mapping user IDs to numbers, as seen in test files: { '1': number, '2': number }
🔗 Analysis chain

Consider adding type information for unseenMessagesByUsers.

The type of unseenMessagesByUsers is not immediately clear from the query. This could lead to type safety issues in the consuming components.

Let's verify the type definition in the schema:

Also applies to: 191-191


Let me search for the GraphQL schema definition to understand the type information better.


Let me try to read the schema file directly and look for Chat type definitions.


Let me check the TypeScript interfaces or types since we found the Chat types but not the unseenMessagesByUsers field.


Let me try one more search without file type restriction since the typescript flag isn't working.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for type definitions related to unseenMessagesByUsers
rg -A 5 "type.*Chat.*{" 
rg "unseenMessagesByUsers"

Length of output: 10851


Script:

#!/bin/bash
# Search for GraphQL schema files and type definitions
fd schema.graphql
fd "schema.*" --extension graphql
rg -A 5 "type.*Chat" --type graphql

Length of output: 155


Script:

#!/bin/bash
# Read the schema file and look for Chat type definitions
cat schema.graphql | grep -A 10 "type.*Chat"

# Also search for unseenMessagesByUsers in the schema
cat schema.graphql | grep -A 3 -B 3 "unseenMessagesByUsers"

Length of output: 1470


Script:

#!/bin/bash
# Search for TypeScript interfaces or types related to Chat
rg -t typescript "interface.*Chat|type.*Chat" -A 10

# Search for unseenMessagesByUsers in TypeScript files
rg -t typescript "unseenMessagesByUsers.*:" -A 2

Length of output: 174


Script:

#!/bin/bash
# Search for TypeScript interfaces or types related to Chat
rg "interface.*Chat|type.*Chat" --type ts -A 10

# Look at the actual usage of unseenMessagesByUsers in the code
rg "unseenMessagesByUsers.*:" -B 2 -A 2

Length of output: 45404

}
}
`;
Expand Down Expand Up @@ -187,6 +188,7 @@ export const CHATS_LIST = gql`
email
image
}
unseenMessagesByUsers
}
}
`;
Expand Down
Loading
Loading