Made making message timestamp

This commit is contained in:
ChronosX88 2019-03-26 21:08:03 +04:00
parent 18c06d1b5a
commit b0b4a0fc33
2 changed files with 13 additions and 5 deletions

View File

@ -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<ChatEntity> 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;
}
}

View File

@ -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;
}