-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed some unused Imports, Provided MessageManagerInterface, fixed ti…
…tle of messageCenter
- Loading branch information
1 parent
67ab77d
commit 5f6ac41
Showing
11 changed files
with
194 additions
and
104 deletions.
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,63 @@ | ||
package model.service.message; | ||
|
||
public class MessageManager { | ||
import model.DAO.DAOMessage; | ||
import model.entity.Message; | ||
import model.entity.User; | ||
import model.service.user.UserData; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class MessageManager implements MessageManagerInterface { | ||
private int userId; | ||
private int unreadMessages; | ||
private final Map<Integer, List<Message>> conversations = new HashMap<>(); //Integer è l'ID dell'Utente con cui chatta. La lista dei messaggi è la lista dei messaggi con quell'utente | ||
DAOMessage db = new DAOMessage(); | ||
|
||
public int getUserId() { | ||
return userId; | ||
} | ||
|
||
public MessageManager(){} | ||
|
||
public void markMessagesAsRead(int senderId, int recipientId) { | ||
db.markMessagesAsRead(senderId, recipientId); | ||
} | ||
|
||
public int countReceivedMessages(int recipientId) { | ||
return db.countReceivedMessages(recipientId); | ||
} | ||
|
||
public void sendMessage(int sender, int recipientId, String text) { | ||
db.sendMessage(sender, recipientId, text); | ||
} | ||
public List<Message> retrieveMessages(int userId, int contact) { | ||
return db.retrieveMessages(userId, contact); | ||
} | ||
public int getUnreadMessagesForConversation(int userId, int contact){ | ||
int unreadCounter = 0; | ||
List<Message> messages = db.retrieveMessages(userId, contact); | ||
for (Message message : messages) { | ||
if (message.getRecipient() == userId && !message.isRead()) { | ||
unreadCounter++; | ||
} | ||
} | ||
return unreadCounter; | ||
} | ||
|
||
public List<Integer> retrieveAllTheContacts(int userId){ | ||
List<Integer> contacts = new ArrayList<>(); | ||
UserData check = new UserData(); | ||
User user = check.getUserByIdOrEmail(userId); | ||
if(check.isTherapist(user)) { | ||
contacts.addAll(db.retrieveUserIdsByTherapist(userId)); | ||
} | ||
else { //se è un paziente | ||
contacts.add(user.getIdTherapist()); | ||
} | ||
contacts.add(0); //Notifications | ||
return contacts; | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
src/main/java/model/service/message/MessageManagerInterface.java
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,60 @@ | ||
package model.service.message; | ||
|
||
import model.entity.Message; | ||
|
||
import java.util.List; | ||
|
||
public interface MessageManagerInterface { | ||
|
||
/** | ||
* Marks the messages between a sender and a recipient as read in the database. | ||
* This method updates the 'Read' field of the messages from the sender to the recipient to TRUE. | ||
* | ||
* @param senderId the ID of the sender | ||
* @param recipientId the ID of the recipient | ||
*/ | ||
void markMessagesAsRead(int senderId, int recipientId); | ||
|
||
/** | ||
* Counts the number of received messages for a given recipient. | ||
* | ||
* @param recipientId the ID of the recipient | ||
* @return the number of received messages for the recipient | ||
*/ | ||
int countReceivedMessages(int recipientId); | ||
|
||
/** | ||
* Sends a message from a sender to a recipient by inserting it into the database. | ||
* | ||
* @param sender the ID of the sender | ||
* @param recipientId the ID of the recipient | ||
* @param text the content of the message | ||
*/ | ||
void sendMessage(int sender, int recipientId, String text); | ||
|
||
/** | ||
* Retrieves the messages between a user and a contact. | ||
* | ||
* @param userId the ID of the user | ||
* @param contact the ID of the contact | ||
* @return the list of messages between the user and the contact | ||
*/ | ||
List<Message> retrieveMessages(int userId, int contact); | ||
|
||
/** | ||
* Retrieves the number of unread messages for a specific conversation between a user and a contact. | ||
* | ||
* @param userId the ID of the user | ||
* @param contact the ID of the contact | ||
* @return the number of unread messages for the conversation | ||
*/ | ||
int getUnreadMessagesForConversation(int userId, int contact); | ||
|
||
/** | ||
* Retrieves all the contacts of a user. | ||
* | ||
* @param userId the ID of the user | ||
* @return a list of integers representing the IDs of the contacts | ||
*/ | ||
List<Integer> retrieveAllTheContacts(int userId); | ||
} |
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.