finish mails?
This commit is contained in:
@@ -296,4 +296,16 @@ public final class Config {
|
||||
NOTIFICATIONFORMAT = getString("settings.blockedmessage-notification", NOTIFICATIONFORMAT);
|
||||
}
|
||||
|
||||
public static String mailHeader = "===== List Mails ====='";
|
||||
public static String mailBody = "<white>From:</white> <staffprefix><sender> <white>on:<date></white>\n<message>";
|
||||
public static String mailFooter = "======================";
|
||||
public static String mailNoUser = "<red>A player with this name hasn't logged in recently.";
|
||||
public static List<String> mailCommandAlias = new ArrayList<>();
|
||||
private static void mailSettings() {
|
||||
mailHeader = getString("settings.mail.header", mailHeader);
|
||||
mailBody = getString("settings.mail.message", mailBody);
|
||||
mailFooter = getString("settings.mail.footer", mailFooter);
|
||||
mailCommandAlias = getList("settings.mail.command-aliases", Lists.newArrayList("gmail"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,10 +9,7 @@ import com.alttd.chat.objects.PartyUser;
|
||||
import com.alttd.chat.objects.channels.Channel;
|
||||
import com.alttd.chat.util.ALogger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
|
||||
@@ -25,7 +22,7 @@ public class Queries {
|
||||
tables.add("CREATE TABLE IF NOT EXISTS ignored_users (`uuid` VARCHAR(36) NOT NULL, `ignored_uuid` VARCHAR(36) NOT NULL, PRIMARY KEY (`uuid`, `ignored_uuid`))");
|
||||
tables.add("CREATE TABLE IF NOT EXISTS parties (`id` INT NOT NULL AUTO_INCREMENT, `owner_uuid` VARCHAR(36) NOT NULL, `party_name` VARCHAR(36) NOT NULL, `password` VARCHAR(36), PRIMARY KEY (`id`))");
|
||||
tables.add("CREATE TABLE IF NOT EXISTS chat_users (`uuid` VARCHAR(36) NOT NULL, `party_id` INT NOT NULL, `toggled_channel` VARCHAR(36) NULL DEFAULT NULL, PRIMARY KEY (`uuid`))");
|
||||
tables.add("CREATE TABLE IF NOT EXISTS mails (`id` INT NOT NULL AUTO_INCREMENT, `uuid` VARCHAR(36) NOT NULL, `from` VARCHAR(36) NOT NULL, `message` VARCHAR(256) NOT NULL, `sendtime` BIGINT default 0, `readtime` BIGINT default 0, PRIMARY KEY (`id`))");
|
||||
tables.add("CREATE TABLE IF NOT EXISTS mails (`id` INT NOT NULL AUTO_INCREMENT, `uuid` VARCHAR(36) NOT NULL, `sender` VARCHAR(36) NOT NULL, `message` VARCHAR(256) NOT NULL, `sendtime` BIGINT default 0, `readtime` BIGINT default 0, PRIMARY KEY (`id`))");
|
||||
|
||||
try {
|
||||
Connection connection = DatabaseConnection.getConnection();
|
||||
@@ -412,11 +409,12 @@ public class Queries {
|
||||
|
||||
ResultSet resultSet = statement.executeQuery();
|
||||
while (resultSet.next()) {
|
||||
UUID fromUUID = UUID.fromString(resultSet.getString("from"));
|
||||
int id = resultSet.getInt("id");
|
||||
UUID fromUUID = UUID.fromString(resultSet.getString("sender"));
|
||||
String message = resultSet.getString("message");
|
||||
long sendTime = resultSet.getLong("sendtime");
|
||||
long readTime = resultSet.getLong("readtime");
|
||||
mails.add(new Mail(uuid, fromUUID, sendTime, readTime, message));
|
||||
mails.add(new Mail(id, uuid, fromUUID, sendTime, readTime, message));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
@@ -504,4 +502,47 @@ public class Queries {
|
||||
}
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public static int insertMail(Mail mail) {
|
||||
String query = "INSERT INTO mails (uuid , sender, message, sendtime, readtime) VALUES (?, ?, ?, ?, ?)";
|
||||
int id = 0;
|
||||
try {
|
||||
Connection connection = DatabaseConnection.getConnection();
|
||||
PreparedStatement statement = connection.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);
|
||||
statement.setString(1, mail.getUuid().toString());
|
||||
statement.setString(2, mail.getSender().toString());
|
||||
statement.setString(3, mail.getMessage());
|
||||
statement.setLong(4, mail.getSendTime());
|
||||
statement.setLong(5, mail.getReadTime());
|
||||
|
||||
statement.execute();
|
||||
|
||||
ResultSet rs = statement.getGeneratedKeys();
|
||||
if (rs.next()) {
|
||||
id = rs.getInt(1);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
public static void markMailRead(Mail mail) {
|
||||
String query = "INSERT INTO mails (Id, uuid , sender, message, sendtime, readtime) VALUES (?, ?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE readtime = ?";
|
||||
try {
|
||||
Connection connection = DatabaseConnection.getConnection();
|
||||
PreparedStatement statement = connection.prepareStatement(query);
|
||||
statement.setInt(1, mail.getId());
|
||||
statement.setString(2, mail.getUuid().toString());
|
||||
statement.setString(3, mail.getSender().toString());
|
||||
statement.setString(4, mail.getMessage());
|
||||
statement.setLong(5, mail.getSendTime());
|
||||
statement.setLong(6, mail.getReadTime());
|
||||
statement.setLong(7, mail.getReadTime());
|
||||
|
||||
statement.execute();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,10 +27,4 @@ public final class ChatUserManager {
|
||||
return chatUsers.computeIfAbsent(uuid, k -> Queries.loadChatUser(uuid));
|
||||
}
|
||||
|
||||
public List<Mail> getUnReadMail(ChatUser user) {
|
||||
return user.getMails().stream()
|
||||
.filter(Mail::isUnRead)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import net.kyori.adventure.text.Component;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ChatUser {
|
||||
private final UUID uuid; // player uuid
|
||||
@@ -108,6 +109,12 @@ public class ChatUser {
|
||||
return mails;
|
||||
}
|
||||
|
||||
public List<Mail> getUnReadMail() {
|
||||
return getMails().stream()
|
||||
.filter(Mail::isUnRead)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public void addMail(Mail mail) {
|
||||
mails.add(mail);
|
||||
}
|
||||
|
||||
@@ -1,16 +1,20 @@
|
||||
package com.alttd.chat.objects;
|
||||
|
||||
import com.alttd.chat.database.Queries;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class Mail {
|
||||
|
||||
private final int id;
|
||||
private final UUID uuid;
|
||||
private final UUID sender;
|
||||
private final long sendTime;
|
||||
private long readTime;
|
||||
private final String message;
|
||||
|
||||
public Mail(UUID player, UUID sender, long sendTime, long readTime, String message) {
|
||||
public Mail(int id, UUID player, UUID sender, long sendTime, long readTime, String message) {
|
||||
this.id = id;
|
||||
this.uuid = player;
|
||||
this.sender = sender;
|
||||
this.sendTime = sendTime;
|
||||
@@ -21,9 +25,15 @@ public class Mail {
|
||||
public Mail(UUID player, UUID sender, String message) {
|
||||
this.uuid = player;
|
||||
this.sender = sender;
|
||||
this.sendTime = System.currentTimeMillis();
|
||||
this.readTime = System.currentTimeMillis();
|
||||
long time = System.currentTimeMillis();
|
||||
this.sendTime = time;
|
||||
this.readTime = time;
|
||||
this.message = message;
|
||||
this.id = Queries.insertMail(this);
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public UUID getUuid() {
|
||||
@@ -35,7 +45,7 @@ public class Mail {
|
||||
}
|
||||
|
||||
public boolean isUnRead() {
|
||||
return getSendTime() != getReadTime();
|
||||
return getSendTime() == getReadTime();
|
||||
}
|
||||
|
||||
public long getSendTime() {
|
||||
|
||||
Reference in New Issue
Block a user