IMPL server-side recover message history API
This commit is contained in:
parent
f2d3c948bf
commit
fdedd75807
2 changed files with 19 additions and 3 deletions
|
@ -1,5 +1,6 @@
|
||||||
package me.imsonmia.epqapi.controller;
|
package me.imsonmia.epqapi.controller;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.springframework.messaging.handler.annotation.MessageMapping;
|
import org.springframework.messaging.handler.annotation.MessageMapping;
|
||||||
|
@ -24,9 +25,16 @@ public class MessageController {
|
||||||
// Forward message to subscribers of Stomp endpoint
|
// Forward message to subscribers of Stomp endpoint
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
@GetMapping("/chat/history/{from}")
|
@GetMapping("/api/v1/chat/history/{from}")
|
||||||
public ArrayList<Message> getMessagesFromTimestamp(@PathVariable(value = "from") Long fromTimestamp) {
|
public ArrayList<Message> getMessagesFromTimestamp(@PathVariable(value = "from") long fromTimestamp) {
|
||||||
return new ArrayList<Message>();
|
ArrayList<Message> messages = new ArrayList<>();
|
||||||
|
Instant targetInstant = Instant.ofEpochMilli(fromTimestamp);
|
||||||
|
for (Message msg : repository.findAll()) {
|
||||||
|
Instant t = Instant.ofEpochMilli(msg.getTimestamp());
|
||||||
|
if (t.isBefore(targetInstant)) {continue;}
|
||||||
|
messages.add(msg);
|
||||||
|
}
|
||||||
|
return messages;
|
||||||
}
|
}
|
||||||
// @GetMapping("/msg/{id}")
|
// @GetMapping("/msg/{id}")
|
||||||
// public ChatMessage getMessageById(@PathVariable(value = "id") Long id) {
|
// public ChatMessage getMessageById(@PathVariable(value = "id") Long id) {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package me.imsonmia.epqapi.model;
|
package me.imsonmia.epqapi.model;
|
||||||
|
|
||||||
|
|
||||||
import jakarta.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import jakarta.persistence.GeneratedValue;
|
import jakarta.persistence.GeneratedValue;
|
||||||
import jakarta.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
|
@ -14,6 +15,7 @@ public class Message {
|
||||||
private String from;
|
private String from;
|
||||||
private String to;
|
private String to;
|
||||||
private String content;
|
private String content;
|
||||||
|
private Long timestamp;
|
||||||
public Long getId() {
|
public Long getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
@ -35,4 +37,10 @@ public class Message {
|
||||||
public void setContent(String content) {
|
public void setContent(String content) {
|
||||||
this.content = content;
|
this.content = content;
|
||||||
}
|
}
|
||||||
|
public Long getTimestamp() {
|
||||||
|
return timestamp;
|
||||||
|
}
|
||||||
|
public void setTimestamp(Long timestamp) {
|
||||||
|
this.timestamp = timestamp;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue