diff --git a/app/src/main/java/io/github/chronosx88/influence/helpers/LocalDBWrapper.java b/app/src/main/java/io/github/chronosx88/influence/helpers/LocalDBWrapper.java index e04b0a0..5061110 100644 --- a/app/src/main/java/io/github/chronosx88/influence/helpers/LocalDBWrapper.java +++ b/app/src/main/java/io/github/chronosx88/influence/helpers/LocalDBWrapper.java @@ -4,6 +4,7 @@ import android.util.Log; import net.tomp2p.peers.PeerAddress; +import java.util.Date; import java.util.List; import io.github.chronosx88.influence.models.roomEntities.ChatEntity; @@ -30,14 +31,21 @@ public class LocalDBWrapper { return true; } + /** + * Creating a message entry in the local database + * @param type Message type + * @param chatID ID of the chat in which need to create a message + * @param sender Message sender (username) + * @param text Message text (or technical info if technical message type) + * @return + */ public static boolean createMessageEntry(int type, String chatID, String sender, String text) { List chatEntities = AppHelper.getChatDB().chatDao().getChatByChatID(chatID); if(chatEntities.size() < 1) { Log.e(LOG_TAG, "Failed to create message entry because chat " + chatID + " doesn't exists!"); return false; } - // TODO: Make message timestamp - dbInstance.messageDao().insertMessage(new MessageEntity(type, chatID, sender, "", text)); + dbInstance.messageDao().insertMessage(new MessageEntity(type, chatID, sender, new Date().getTime(), text)); return true; } } diff --git a/app/src/main/java/io/github/chronosx88/influence/models/roomEntities/MessageEntity.java b/app/src/main/java/io/github/chronosx88/influence/models/roomEntities/MessageEntity.java index 6874255..86a85be 100644 --- a/app/src/main/java/io/github/chronosx88/influence/models/roomEntities/MessageEntity.java +++ b/app/src/main/java/io/github/chronosx88/influence/models/roomEntities/MessageEntity.java @@ -11,10 +11,10 @@ public class MessageEntity { @ColumnInfo public int type; @ColumnInfo public String chatID; @ColumnInfo public String sender; - @ColumnInfo public String timestamp; + @ColumnInfo public long timestamp; @ColumnInfo public String text; - public MessageEntity(int type, String chatID, String sender, String timestamp, String text) { + public MessageEntity(int type, String chatID, String sender, long timestamp, String text) { this.type = type; this.chatID = chatID; this.sender = sender; @@ -32,7 +32,7 @@ public class MessageEntity { return chatID; } - public String getTimestamp() { + public long getTimestamp() { return timestamp; }