Switched to instant from string for active users
This commit is contained in:
parent
f6576026a2
commit
16c937d137
@ -1,10 +1,12 @@
|
|||||||
package org.ros.chatto.dto;
|
package org.ros.chatto.dto;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class ActiveUserDTO {
|
public class ActiveUserDTO {
|
||||||
private String userName;
|
private String userName;
|
||||||
private Boolean online;
|
private Boolean online;
|
||||||
private String lastActive;
|
private Instant lastActive;
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
|
||||||
//private PostDto convertToDto(Post post) {
|
//private PostDto convertToDto(Post post) {
|
||||||
// PostDto postDto = modelMapper.map(post, PostDto.class);
|
// PostDto postDto = modelMapper.map(post, PostDto.class);
|
||||||
// postDto.setSubmissionDate(post.getSubmissionDate(),
|
// postDto.setSubmissionDate(post.getSubmissionDate(),
|
||||||
@ -38,52 +37,72 @@ import org.springframework.stereotype.Service;
|
|||||||
public class MyConversionService {
|
public class MyConversionService {
|
||||||
@Autowired
|
@Autowired
|
||||||
ModelMapper modelMapper;
|
ModelMapper modelMapper;
|
||||||
|
|
||||||
public ChatMessageDTO convertToChatMessageDTO(final ChatMessage chatMessage) {
|
public ChatMessageDTO convertToChatMessageDTO(
|
||||||
final ChatMessageDTO chatMessageDTO = modelMapper.map(chatMessage, ChatMessageDTO.class);
|
final ChatMessage chatMessage) {
|
||||||
|
final ChatMessageDTO chatMessageDTO = modelMapper.map(chatMessage,
|
||||||
|
ChatMessageDTO.class);
|
||||||
return chatMessageDTO;
|
return chatMessageDTO;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ChatMessage convertToChatMessage(final ChatMessageDTO chatMessageDTO) {
|
public ChatMessage convertToChatMessage(
|
||||||
final ChatMessage chatMessage = modelMapper.map(chatMessageDTO, ChatMessage.class);
|
final ChatMessageDTO chatMessageDTO) {
|
||||||
|
final ChatMessage chatMessage = modelMapper.map(chatMessageDTO,
|
||||||
|
ChatMessage.class);
|
||||||
return chatMessage;
|
return chatMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MessageCipher convertToMessageCipher(final MessageCipherDTO messageCipherDTO) {
|
public MessageCipher convertToMessageCipher(
|
||||||
final MessageCipher messageCipher = modelMapper.map(messageCipherDTO, MessageCipher.class);
|
final MessageCipherDTO messageCipherDTO) {
|
||||||
|
final MessageCipher messageCipher = modelMapper.map(messageCipherDTO,
|
||||||
|
MessageCipher.class);
|
||||||
return messageCipher;
|
return messageCipher;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ChatMessageDTO> convertToChatMessageDTOs(final List<ChatMessage> chatMessages) {
|
public List<ChatMessageDTO> convertToChatMessageDTOs(
|
||||||
return chatMessages.stream().map(chatMessage -> convertToChatMessageDTO(chatMessage))
|
final List<ChatMessage> chatMessages) {
|
||||||
.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()
|
return chatMessages.stream()
|
||||||
.map(chatMessage -> convertToChatMessageDTO(chatMessage))
|
.map(chatMessage -> convertToChatMessageDTO(chatMessage))
|
||||||
.collect(Collectors.toList());
|
.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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -87,7 +87,7 @@ public class UserServiceImpl implements UserService {
|
|||||||
activeUserDTO.setLastActive(null);
|
activeUserDTO.setLastActive(null);
|
||||||
if (us != null) {
|
if (us != null) {
|
||||||
activeUserDTO.setOnline(us.isOnline());
|
activeUserDTO.setOnline(us.isOnline());
|
||||||
activeUserDTO.setLastActive(toLastActiveString(us.getTimeStamp()));
|
activeUserDTO.setLastActive(us.getTimeStamp());
|
||||||
}
|
}
|
||||||
|
|
||||||
activeUserDTOs.add(activeUserDTO);
|
activeUserDTOs.add(activeUserDTO);
|
||||||
|
@ -31,11 +31,11 @@ export class UserController {
|
|||||||
const activeUsersMock: ActiveUserViewModel[] = [];
|
const activeUsersMock: ActiveUserViewModel[] = [];
|
||||||
let activeUserViewModelMock = new ActiveUserViewModel();
|
let activeUserViewModelMock = new ActiveUserViewModel();
|
||||||
activeUserViewModelMock.userName = "some user";
|
activeUserViewModelMock.userName = "some user";
|
||||||
activeUserViewModelMock.lastActive = "3 hrs ago";
|
// activeUserViewModelMock.lastActive = "3 hrs ago";
|
||||||
activeUserViewModelMock.online = true;
|
activeUserViewModelMock.online = true;
|
||||||
activeUsersMock.push(activeUserViewModelMock);
|
activeUsersMock.push(activeUserViewModelMock);
|
||||||
activeUserViewModelMock = new ActiveUserViewModel();
|
activeUserViewModelMock = new ActiveUserViewModel();
|
||||||
activeUserViewModelMock.lastActive = "3 hrs ago";
|
// activeUserViewModelMock.lastActive = "3 hrs ago";
|
||||||
activeUserViewModelMock.online = true;
|
activeUserViewModelMock.online = true;
|
||||||
activeUserViewModelMock.userName = "some user 2";
|
activeUserViewModelMock.userName = "some user 2";
|
||||||
activeUsersMock.push(activeUserViewModelMock);
|
activeUsersMock.push(activeUserViewModelMock);
|
||||||
|
@ -75,6 +75,10 @@ export class UserModel implements Subject<ActiveUserViewModel> {
|
|||||||
// sessionStorage.setItem('activeUsers', JSON.stringify(data));
|
// sessionStorage.setItem('activeUsers', JSON.stringify(data));
|
||||||
// log.trace(sessionStorage.getItem('activeUsers'));
|
// log.trace(sessionStorage.getItem('activeUsers'));
|
||||||
log.info(`Subject: received ajax active users`);
|
log.info(`Subject: received ajax active users`);
|
||||||
|
data.map((d: any) => {
|
||||||
|
d.lastActive = new Date(d.lastActive)
|
||||||
|
return d;
|
||||||
|
});
|
||||||
this._activeUsersList = data;
|
this._activeUsersList = data;
|
||||||
this.notify();
|
this.notify();
|
||||||
})
|
})
|
||||||
@ -98,8 +102,9 @@ export class UserModel implements Subject<ActiveUserViewModel> {
|
|||||||
let data = await response.json();
|
let data = await response.json();
|
||||||
// return data;
|
// return data;
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (data != null)
|
if (data != null) {
|
||||||
resolve(data)
|
resolve(data)
|
||||||
|
}
|
||||||
else
|
else
|
||||||
reject('Response data null')
|
reject('Response data null')
|
||||||
})
|
})
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
export class ActiveUserViewModel {
|
export class ActiveUserViewModel {
|
||||||
userName: string | undefined;
|
userName: string | undefined;
|
||||||
online: boolean | undefined;
|
online: boolean | undefined;
|
||||||
lastActive: string| undefined;
|
lastActive: Date | undefined;
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user