33
33
import io .vertx .core .eventbus .EventBus ;
34
34
import io .vertx .core .json .JsonArray ;
35
35
import io .vertx .core .json .JsonObject ;
36
+ import org .entcore .common .utils .StringUtils ;
36
37
37
38
/**
38
39
* Utility class for handling messages, particularly for decoding display names stored in the database,
@@ -45,9 +46,11 @@ public class MessageUtil {
45
46
final static public String RECIPIENT_ID = "id" ;
46
47
final static public String RECIPIENT_NAME = "displayName" ;
47
48
final static public String MSG_FROM = "from" ;
49
+ final static public String MSG_FROM_NAME = "fromName" ;
48
50
final static public String MSG_TO = "to" ;
49
51
final static public String MSG_CC = "cc" ;
50
52
final static public String MSG_CCI = "cci" ;
53
+ final static public String FROM_DELETED_ID = "FROM_DELETED_ID" ;
51
54
52
55
/**
53
56
* 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(
64
67
final Boolean notIsSender = (!userId .equals (message .getString (MSG_FROM )));
65
68
final List <String > userGroups = getOrElse (userInfos .getGroupsIds (), new ArrayList <>());
66
69
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
+
67
78
// Add connected user to index
68
79
userIndex .put (
69
80
userId ,
@@ -131,7 +142,13 @@ static public void computeUsersAndGroupsDisplayNames(
131
142
*/
132
143
static public void formatRecipients (JsonObject message , final JsonObject userIndex , final JsonObject groupIndex ) {
133
144
final String from = message .getString (MSG_FROM );
145
+ boolean isDeleted = message .getString (MSG_FROM ).equals (FROM_DELETED_ID );
134
146
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
+ }
135
152
136
153
Stream .of (MSG_TO , MSG_CC , MSG_CCI ).forEach (key -> {
137
154
JsonArray recipients = (JsonArray ) message .remove (key );
0 commit comments