Skip to content

Commit db67b8c

Browse files
authored
Fix coco 4272 fix null user in from message when deleted user (#794)
fix(conversation): #COCO-4272 add default user when user is null in from of messages
1 parent cda6959 commit db67b8c

File tree

1 file changed

+17
-0
lines changed
  • conversation/backend/src/main/java/org/entcore/conversation/util

1 file changed

+17
-0
lines changed

conversation/backend/src/main/java/org/entcore/conversation/util/MessageUtil.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import io.vertx.core.eventbus.EventBus;
3434
import io.vertx.core.json.JsonArray;
3535
import io.vertx.core.json.JsonObject;
36+
import org.entcore.common.utils.StringUtils;
3637

3738
/**
3839
* Utility class for handling messages, particularly for decoding display names stored in the database,
@@ -45,9 +46,11 @@ public class MessageUtil {
4546
final static public String RECIPIENT_ID = "id";
4647
final static public String RECIPIENT_NAME = "displayName";
4748
final static public String MSG_FROM = "from";
49+
final static public String MSG_FROM_NAME = "fromName";
4850
final static public String MSG_TO = "to";
4951
final static public String MSG_CC = "cc";
5052
final static public String MSG_CCI = "cci";
53+
final static public String FROM_DELETED_ID = "FROM_DELETED_ID";
5154

5255
/**
5356
* Extracts users and groups from a message loaded from the database and populates the user and group indices.
@@ -64,6 +67,14 @@ static public void computeUsersAndGroupsDisplayNames(
6467
final Boolean notIsSender = (!userId.equals(message.getString(MSG_FROM)));
6568
final List<String> userGroups = getOrElse(userInfos.getGroupsIds(), new ArrayList<>());
6669

70+
if(StringUtils.isEmpty(message.getString(MSG_FROM))) {
71+
userIndex.put(
72+
FROM_DELETED_ID,
73+
JsonObject.of(RECIPIENT_ID, FROM_DELETED_ID, RECIPIENT_NAME, message.getString(MSG_FROM_NAME))
74+
);
75+
message.put(MSG_FROM, FROM_DELETED_ID);
76+
}
77+
6778
// Add connected user to index
6879
userIndex.put(
6980
userId,
@@ -131,7 +142,13 @@ static public void computeUsersAndGroupsDisplayNames(
131142
*/
132143
static public void formatRecipients(JsonObject message, final JsonObject userIndex, final JsonObject groupIndex) {
133144
final String from = message.getString(MSG_FROM);
145+
boolean isDeleted = message.getString(MSG_FROM).equals(FROM_DELETED_ID);
134146
message.put(MSG_FROM, userIndex.getJsonObject(from));
147+
if(isDeleted) {
148+
JsonObject fromUser = userIndex.getJsonObject(from);
149+
fromUser.put(RECIPIENT_ID, "");
150+
message.put(MSG_FROM, fromUser);
151+
}
135152

136153
Stream.of(MSG_TO, MSG_CC, MSG_CCI).forEach(key -> {
137154
JsonArray recipients = (JsonArray) message.remove(key);

0 commit comments

Comments
 (0)