2019-11-23 21:16:03 +01:00
|
|
|
package org.mercury_im.messenger.data.mapping;
|
|
|
|
|
|
|
|
import org.mercury_im.messenger.data.model.DirectChatModel;
|
|
|
|
import org.mercury_im.messenger.entity.chat.DirectChat;
|
|
|
|
import org.mercury_im.messenger.entity.contact.Peer;
|
|
|
|
|
|
|
|
import javax.inject.Inject;
|
|
|
|
|
|
|
|
public class DirectChatMapping implements Mapping<DirectChat, DirectChatModel> {
|
|
|
|
|
2019-12-01 19:56:13 +01:00
|
|
|
private final AccountMapping accountMapping;
|
|
|
|
|
|
|
|
private final PeerMapping peerMapping;
|
2019-11-23 21:16:03 +01:00
|
|
|
|
|
|
|
@Inject
|
2019-12-01 19:56:13 +01:00
|
|
|
public DirectChatMapping(AccountMapping accountMapping, PeerMapping peerMapping) {
|
|
|
|
this.accountMapping = accountMapping;
|
|
|
|
this.peerMapping = peerMapping;
|
|
|
|
}
|
2019-11-23 21:16:03 +01:00
|
|
|
|
|
|
|
@Override
|
2019-11-25 15:17:49 +01:00
|
|
|
public DirectChatModel entityToModel(DirectChat entity, DirectChatModel model) {
|
2019-12-01 19:56:13 +01:00
|
|
|
if (entity == null) {
|
|
|
|
return null;
|
|
|
|
}
|
2019-11-25 15:17:49 +01:00
|
|
|
model.setPeer(peerMapping.entityToModel(entity.getPeer(), model.getPeer()));
|
2019-11-23 21:16:03 +01:00
|
|
|
return model;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-11-25 15:17:49 +01:00
|
|
|
public DirectChat modelToEntity(DirectChatModel model, DirectChat entity) {
|
2019-12-01 19:56:13 +01:00
|
|
|
if (model == null) {
|
|
|
|
return null;
|
|
|
|
}
|
2019-11-25 15:17:49 +01:00
|
|
|
entity.setId(model.getId());
|
|
|
|
Peer peer = peerMapping.modelToEntity(model.getPeer(), entity.getPeer());
|
2019-11-23 21:16:03 +01:00
|
|
|
entity.setPeer(peer);
|
|
|
|
entity.setAccount(peer.getAccount());
|
|
|
|
return entity;
|
|
|
|
}
|
|
|
|
}
|