1
0
forked from PGL/Clyde

adding timestamp

This commit is contained in:
Debucquoy Anthony 2024-04-02 11:08:58 +02:00
parent 2b9bdf8dac
commit 7ca5c34afe
Signed by: tonitch
GPG Key ID: A78D6421F083D42E
3 changed files with 21 additions and 4 deletions

View File

@ -4,6 +4,7 @@ import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import ovh.herisson.Clyde.Tables.User; import ovh.herisson.Clyde.Tables.User;
import ovh.herisson.Clyde.Tables.Msg.Message; import ovh.herisson.Clyde.Tables.Msg.Message;
import java.util.Date;
@Data @Data
@AllArgsConstructor @AllArgsConstructor
@ -12,12 +13,13 @@ public class MessagesDTO {
private String content; private String content;
private User author; private User author;
private boolean sender; private boolean sender;
private Date created;
//TODO: Attachment //TODO: Attachment
public static MessagesDTO construct(Message m, User user){ public static MessagesDTO construct(Message m, User user){
boolean sender = false; boolean sender = false;
if(m.getAuthor().equals(user)) if(m.getAuthor().equals(user))
sender = true; sender = true;
return new MessagesDTO(m.getId(), m.getContent(), m.getAuthor(), sender); return new MessagesDTO(m.getId(), m.getContent(), m.getAuthor(), sender, m.getCreated());
} }
} }

View File

@ -1,8 +1,13 @@
package ovh.herisson.Clyde.Tables.Msg; package ovh.herisson.Clyde.Tables.Msg;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
import java.util.Date;
import jakarta.persistence.CascadeType; import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue; import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType; import jakarta.persistence.GenerationType;
@ -10,6 +15,9 @@ import jakarta.persistence.Id;
import jakarta.persistence.ManyToOne; import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany; import jakarta.persistence.OneToMany;
import jakarta.persistence.OneToOne; import jakarta.persistence.OneToOne;
import jakarta.persistence.PrePersist;
import jakarta.persistence.Temporal;
import jakarta.persistence.TemporalType;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
@ -28,6 +36,10 @@ public class Message {
private long id; private long id;
private String content; private String content;
@CreationTimestamp
@Column(nullable = false)
private Date created;
@ManyToOne @ManyToOne
private User author; private User author;
@ -42,5 +54,4 @@ public class Message {
@JsonIgnore @JsonIgnore
private Discussion discussion; private Discussion discussion;
//TODO: Attachment
} }

View File

@ -12,6 +12,10 @@
const msgContent = ref(""); const msgContent = ref("");
const addMember = ref(false); const addMember = ref(false);
function formatTime(date){
return date.getHours() + ":" + date.getMinutes() + " " + date.getDate() + "/" + date.getMonth();
}
</script> </script>
<template> <template>
@ -25,7 +29,7 @@
<div id=msgs> <div id=msgs>
<div class="msg" v-for="msg in currentDiscussion.msgs" :sender="msg.sender" :key="msg.id"> <div class="msg" v-for="msg in currentDiscussion.msgs" :sender="msg.sender" :key="msg.id">
{{ msg.content }}<br/> {{ msg.content }}<br/>
<span class="sender" v-if="!msg.sender">{{msg.author.firstName}}</span> <span class="sender"><span v-if="!msg.sender">{{ msg.author.firstName }} {{ msg.author.lastName.toUpperCase() }}</span> {{formatTime(new Date(msg.created))}}</span>
</div> </div>
</div> </div>
<div id=messageBox> <div id=messageBox>