Switched to instant from string for active users

This commit is contained in:
Rohan Sircar 2020-02-01 14:34:42 +05:30
parent f6576026a2
commit 16c937d137
6 changed files with 68 additions and 42 deletions

View File

@ -1,10 +1,12 @@
package org.ros.chatto.dto;
import java.time.Instant;
import lombok.Data;
@Data
public class ActiveUserDTO {
private String userName;
private Boolean online;
private String lastActive;
private Instant lastActive;
}

View File

@ -13,7 +13,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
//private PostDto convertToDto(Post post) {
// PostDto postDto = modelMapper.map(post, PostDto.class);
// postDto.setSubmissionDate(post.getSubmissionDate(),
@ -38,52 +37,72 @@ import org.springframework.stereotype.Service;
public class MyConversionService {
@Autowired
ModelMapper modelMapper;
public ChatMessageDTO convertToChatMessageDTO(final ChatMessage chatMessage) {
final ChatMessageDTO chatMessageDTO = modelMapper.map(chatMessage, ChatMessageDTO.class);
public ChatMessageDTO convertToChatMessageDTO(
final ChatMessage chatMessage) {
final ChatMessageDTO chatMessageDTO = modelMapper.map(chatMessage,
ChatMessageDTO.class);
return chatMessageDTO;
}
public ChatMessage convertToChatMessage(final ChatMessageDTO chatMessageDTO) {
final ChatMessage chatMessage = modelMapper.map(chatMessageDTO, ChatMessage.class);
public ChatMessage convertToChatMessage(
final ChatMessageDTO chatMessageDTO) {
final ChatMessage chatMessage = modelMapper.map(chatMessageDTO,
ChatMessage.class);
return chatMessage;
}
public MessageCipher convertToMessageCipher(final MessageCipherDTO messageCipherDTO) {
final MessageCipher messageCipher = modelMapper.map(messageCipherDTO, MessageCipher.class);
public MessageCipher convertToMessageCipher(
final MessageCipherDTO messageCipherDTO) {
final MessageCipher messageCipher = modelMapper.map(messageCipherDTO,
MessageCipher.class);
return messageCipher;
}
public List<ChatMessageDTO> convertToChatMessageDTOs(final List<ChatMessage> chatMessages) {
return chatMessages.stream().map(chatMessage -> convertToChatMessageDTO(chatMessage))
.collect(Collectors.toList());
}
public ReencryptionDTO convertToReencryptionDTO(final ChatMessage chatMessage) {
final ReencryptionDTO reencryptionDTO = modelMapper.map(chatMessage, ReencryptionDTO.class);
return reencryptionDTO;
}
public ChatMessage convertToChatMessage(final ReencryptionDTO reencryptionDTO) {
final ChatMessage chatMessage = modelMapper.map(reencryptionDTO, ChatMessage.class);
return chatMessage;
}
public List<ReencryptionDTO> convertToReencryptionDTOs(final List<ChatMessage> chatMessages) {
return chatMessages.stream().map(chatMessage -> convertToReencryptionDTO(chatMessage))
.collect(Collectors.toList());
}
public Iterable<ChatMessage> convertoToChatMessages(final List<ChatMessageDTO> chatMessageDTOs) {
return chatMessageDTOs.stream().map(chatMessageDTO -> convertToChatMessage(chatMessageDTO))
.collect(Collectors.toList());
}
public List<ChatMessageDTO> convertToChatMessageDTOs(final Page<ChatMessage> chatMessages)
{
public List<ChatMessageDTO> convertToChatMessageDTOs(
final List<ChatMessage> chatMessages) {
return chatMessages.stream()
.map(chatMessage -> convertToChatMessageDTO(chatMessage))
.collect(Collectors.toList());
}
public ReencryptionDTO convertToReencryptionDTO(
final ChatMessage chatMessage) {
final ReencryptionDTO reencryptionDTO = modelMapper.map(chatMessage,
ReencryptionDTO.class);
return reencryptionDTO;
}
public ChatMessage convertToChatMessage(
final ReencryptionDTO reencryptionDTO) {
final ChatMessage chatMessage = modelMapper.map(reencryptionDTO,
ChatMessage.class);
return chatMessage;
}
public List<ReencryptionDTO> convertToReencryptionDTOs(
final List<ChatMessage> chatMessages) {
return chatMessages.stream()
.map(chatMessage -> convertToReencryptionDTO(chatMessage))
.collect(Collectors.toList());
}
public Iterable<ChatMessage> convertoToChatMessages(
final List<ChatMessageDTO> chatMessageDTOs) {
return chatMessageDTOs.stream()
.map(chatMessageDTO -> convertToChatMessage(chatMessageDTO))
.collect(Collectors.toList());
}
public List<ChatMessageDTO> convertToChatMessageDTOs(
final Page<ChatMessage> chatMessages) {
return chatMessages.stream()
.map(chatMessage -> convertToChatMessageDTO(chatMessage))
.collect(Collectors.toList());
}
public <T, O> O convert(T obj, Class<O> clazz) {
return modelMapper.map(obj, clazz);
}
}

View File

@ -87,7 +87,7 @@ public class UserServiceImpl implements UserService {
activeUserDTO.setLastActive(null);
if (us != null) {
activeUserDTO.setOnline(us.isOnline());
activeUserDTO.setLastActive(toLastActiveString(us.getTimeStamp()));
activeUserDTO.setLastActive(us.getTimeStamp());
}
activeUserDTOs.add(activeUserDTO);

View File

@ -31,11 +31,11 @@ export class UserController {
const activeUsersMock: ActiveUserViewModel[] = [];
let activeUserViewModelMock = new ActiveUserViewModel();
activeUserViewModelMock.userName = "some user";
activeUserViewModelMock.lastActive = "3 hrs ago";
// activeUserViewModelMock.lastActive = "3 hrs ago";
activeUserViewModelMock.online = true;
activeUsersMock.push(activeUserViewModelMock);
activeUserViewModelMock = new ActiveUserViewModel();
activeUserViewModelMock.lastActive = "3 hrs ago";
// activeUserViewModelMock.lastActive = "3 hrs ago";
activeUserViewModelMock.online = true;
activeUserViewModelMock.userName = "some user 2";
activeUsersMock.push(activeUserViewModelMock);

View File

@ -75,6 +75,10 @@ export class UserModel implements Subject<ActiveUserViewModel> {
// sessionStorage.setItem('activeUsers', JSON.stringify(data));
// log.trace(sessionStorage.getItem('activeUsers'));
log.info(`Subject: received ajax active users`);
data.map((d: any) => {
d.lastActive = new Date(d.lastActive)
return d;
});
this._activeUsersList = data;
this.notify();
})
@ -98,8 +102,9 @@ export class UserModel implements Subject<ActiveUserViewModel> {
let data = await response.json();
// return data;
return new Promise((resolve, reject) => {
if (data != null)
if (data != null) {
resolve(data)
}
else
reject('Response data null')
})

View File

@ -1,5 +1,5 @@
export class ActiveUserViewModel {
userName: string | undefined;
online: boolean | undefined;
lastActive: string| undefined;
lastActive: Date | undefined;
}