added thymeleaf template logic for active users in chat page

This commit is contained in:
Rohan Sircar 2019-11-13 19:40:02 +05:30
parent e85650d499
commit 74396ccd68
4 changed files with 25 additions and 6 deletions

View File

@ -10,6 +10,7 @@ import java.util.stream.Collectors;
import javax.validation.Valid;
import org.ros.chatto.dto.ActiveUserDTO;
import org.ros.chatto.dto.ChatMessageDTO;
import org.ros.chatto.dto.MessageCipherDTO;
import org.ros.chatto.error.ErrorModel;
@ -130,6 +131,11 @@ public class ChatMessageController {
public List<String> getAllOtherUsers(Principal principal) {
return userService.findAllOtherUsers(principal.getName());
}
@GetMapping("/get/active-users")
public List<ActiveUserDTO> getAllOtherActiveUsers(Principal principal) {
return userService.getOtherActiveUsers(principal.getName());
}
}
//public ResponseEntity<List<ChatMessage>> getMessages(@PathVariable String userName, Principal principal) {

View File

@ -83,7 +83,7 @@ public class Home {
boolean isAdmin = authentication.getAuthorities().stream()
.anyMatch(r -> r.getAuthority().equals("ROLE_ADMIN") || r.getAuthority().equals("ROLE_SUPER_USER"));
System.out.println("Is admin? " + isAdmin);
modelAndView.addObject("userNames", userService.findAllOtherUsers(principal.getName()));
modelAndView.addObject("activeUsers", userService.getOtherActiveUsers(principal.getName()));
return modelAndView;
}
// public String showHome(Model model)

View File

@ -175,7 +175,7 @@ html {
color: white;
}
.user_info p {
.user_info p, .user_info p span {
font-size: 10px;
color: rgba(255, 255, 255, 0.6);
}

View File

@ -73,16 +73,29 @@
</li>
</ui>
<ui class="contacts">
<th:block th:each="userName: ${userNames}">
<th:block th:each="au: ${activeUsers}">
<li name="user-box" class="user-box">
<div class="d-flex bd-highlight">
<div class="img_cont">
<img src="https://static.turbosquid.com/Preview/001292/481/WV/_D.jpg" class="rounded-circle user_img">
<span class="online_icon"></span>
<span th:if="${au.online == true}" class="online_icon"></span>
</div>
<div class="user_info">
<span th:text="${userName}">Khalid</span>
<p th:text="${userName} + ' is online'">Kalid is online</p>
<span th:text="${au.userName}">Khalid</span>
<div th:switch="${au.online}">
<p th:case="true" th:text="${au.userName} + ' is online'">Khalid is online</p>
<th:block th:case="false">
<th:block th:if="${au.lastActive == null}" >
<p th:text="'User has not logged in yet'"></p>
</th:block>
<th:block th:if="${au.lastActive != null}">
<p th:text="'Last active = ' + ${au.lastActive}">Last active 3 hours ago</p>
</th:block>
<!-- <p th:case="${au.online == true}" th:text="${au.userName} + ' is online'">Khalid is online</p>
<p th:if="${au.online == false}" th:text="${au.userName} + ' is offline' + ' Last active = ' + ${au.lastActive}">Khalid is offline. -->
<!-- <span th:text="'Last active = ' + ${au.lastActive}"></span> -->
</th:block>
</div>
</div>
<div class="d-flex flex-column ml-auto">
<div class="text-right">Dec 25</div>