Overview
TheMessageManager class handles all messaging operations in Threadly, including sending messages, retrieving conversations, uploading media in messages, managing message status, and handling message deletion. All methods are static for convenient access throughout the application.
Methods
sendMessage
Sends a message to another user.Message object containing sender, receiver, content, and metadata
senderUUId(String) - Sender’s unique identifierrecieverUUId(String) - Receiver’s unique identifiermessage(String) - Message contenttype(String) - Message type (text, image, video, etc.)MsgUid(String) - Unique message identifier
Example
getaAndUpdatePendingMessagesFromServer
Retrieves and stores pending messages from a specific sender.UUID of the sender whose messages to retrieve
- Fetches pending messages from the server
- Stores them in the local database
- Updates conversation history
- Automatically handles message synchronization
Example
checkAndGetPendingMessages
Checks for pending messages from all conversations and retrieves them.- Checks all active conversations for new messages
- Automatically fetches pending messages
- Updates local storage
- Should be called periodically or on app resume
Example
setSeenMessage
Marks messages as seen/read.List of message UIDs to mark as seen
UUID of the message sender
UUID of the message receiver (current user)
Callback interface to handle the response
Example
UploadMsgMedia
Uploads media files (images, videos) to be sent in messages.Media file to upload
Unique tag to identify and potentially cancel the upload
Callback interface to handle upload progress and response
Contains the uploaded media URL and metadata
Example
CancelMessageMediaUploadRequest
Cancels an ongoing media upload.Tag of the upload request to cancel (same tag used in UploadMsgMedia)
Example
GetAllChatsAssociatedWithUser
Retrieves all chat conversations for the current user.Callback interface to handle the response
Array of conversation objects with last message, participant info, and unread count
Example
DeleteMessageForLoggedInUser
Deletes a message for the current user only (other participant can still see it).Unique identifier of the message to delete
User’s role in the conversation (“sender” or “receiver”)
Callback interface to handle the response
Example
unSendMessage
Unsends a message, removing it for both sender and receiver.Unique identifier of the message to unsend
UUID of the message receiver
Callback interface to handle the response
Example
Message Model Structure
Messages follow the structure defined in MessageSchema.java:8:messageUid(String) - Unique message identifierconversationId(String) - Conversation identifierreplyToMsgId(String) - ID of message being replied to (if any)senderId(String) - Sender’s UUIDreceiverId(String) - Receiver’s UUIDmsg(String) - Message contenttype(String) - Message type (text, image, video, post)timestamp(String) - Message timestamp in ISO 8601 formatdeliveryStatus(int) - Delivery status code (0=pending, 1=sent, 2=delivered, 3=seen)isDeleted(boolean) - Whether message is deletedpostId(int) - ID of shared post (if type is post)postLink(String) - Link to shared post
Delivery Status Codes
0- Pending (queued for sending)1- Sent (delivered to server)2- Delivered (received by recipient’s device)3- Seen (read by recipient)
API Endpoints Used
POST /api/messages/send- Send messagePOST /api/messages/pending- Get pending messages from senderGET /api/messages/check-pending- Check for pending messagesPOST /api/messages/seen- Mark messages as seenPOST /api/messages/upload-media- Upload message mediaGET /api/messages/chats- Get all chatsPATCH /api/messages/delete- Delete message for userPATCH /api/messages/unsend- Unsend message
Related Components
- ProfileManager - User profile information
- PostsManager - Share posts in messages
- See MessageManager.java:34 for implementation details