Skip to content
Snippets Groups Projects
Commit 242a23e0 authored by Benoit Lavenier's avatar Benoit Lavenier
Browse files

- Add id to USerEvent object sent by websocket

parent fb96b2a7
No related branches found
No related tags found
No related merge requests found
......@@ -57,6 +57,7 @@ public class UserEvent extends Record {
return new Builder(type, code, message, params);
}
public static final String PROPERTY_ID="id";
public static final String PROPERTY_TYPE="type";
public static final String PROPERTY_CODE="code";
public static final String PROPERTY_MESSAGE="message";
......@@ -67,6 +68,8 @@ public class UserEvent extends Record {
public static final String PROPERTY_READ_SIGNATURE="readSignature";
private String id;
private EventType type;
private String recipient;
......@@ -167,6 +170,14 @@ public class UserEvent extends Record {
this.readSignature = readSignature;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
@JsonIgnore
public String toJson() {
try {
......
......@@ -27,23 +27,18 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.google.common.base.Preconditions;
import com.google.gson.JsonSyntaxException;
import org.apache.commons.collections4.MapUtils;
import org.duniter.core.exception.TechnicalException;
import org.duniter.core.service.CryptoService;
import org.duniter.core.service.MailService;
import org.duniter.core.util.StringUtils;
import org.duniter.core.util.crypto.CryptoUtils;
import org.duniter.core.util.crypto.KeyPair;
import org.duniter.core.util.websocket.WebsocketClientEndpoint;
import org.duniter.elasticsearch.PluginSettings;
import org.duniter.elasticsearch.exception.InvalidFormatException;
import org.duniter.elasticsearch.exception.InvalidSignatureException;
import org.duniter.elasticsearch.exception.NotFoundException;
import org.duniter.elasticsearch.service.AbstractService;
import org.duniter.elasticsearch.service.BlockchainService;
import org.duniter.elasticsearch.threadpool.ThreadPool;
import org.duniter.elasticsearch.user.model.UserEvent;
import org.duniter.elasticsearch.user.model.UserEventCodes;
import org.duniter.elasticsearch.user.model.UserProfile;
import org.elasticsearch.action.bulk.BulkRequestBuilder;
import org.elasticsearch.action.index.IndexResponse;
......@@ -57,7 +52,8 @@ import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.query.*;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.SearchHit;
import org.nuiton.i18n.I18n;
......@@ -412,20 +408,25 @@ public class UserEventService extends AbstractService {
indexEventAndNotifyListener(locale, event);
}
private void indexEventAndNotifyListener(Locale locale, UserEvent event) {
private String indexEventAndNotifyListener(final Locale locale, final UserEvent event) {
// Add new event to index
indexEvent(locale, event);
final String eventId = indexEvent(locale, event);
final UserEvent eventCopy = new UserEvent(event);
eventCopy.setId(eventId);
// Notify listeners
threadPool.schedule(() -> {
synchronized (LISTENERS) {
LISTENERS.values().stream().forEach(listener -> {
if (event.getRecipient().equals(listener.getPubkey())) {
listener.onEvent(event);
listener.onEvent(eventCopy);
}
});
}
});
return eventId;
}
private void doDeleteEventsByReference(final UserEvent.Reference reference) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment