work on real time for message actions
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package org.to.telegramfinalproject.Database;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
@@ -44,4 +46,31 @@ public class MessageReactionDatabase {
|
||||
}
|
||||
return reactions;
|
||||
}
|
||||
public static JSONObject getCountsAsJson(UUID messageId) {
|
||||
String sql = """
|
||||
SELECT emoji, COUNT(*) AS c
|
||||
FROM message_reactions
|
||||
WHERE message_id = ?
|
||||
GROUP BY emoji
|
||||
""";
|
||||
|
||||
JSONObject counts = new JSONObject();
|
||||
|
||||
try (Connection conn = ConnectionDb.connect();
|
||||
PreparedStatement ps = conn.prepareStatement(sql)) {
|
||||
|
||||
ps.setObject(1, messageId);
|
||||
try (ResultSet rs = ps.executeQuery()) {
|
||||
while (rs.next()) {
|
||||
String emoji = rs.getString("emoji");
|
||||
int c = rs.getInt("c");
|
||||
counts.put(emoji, c);
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return counts; // مثال: {"❤️":2,"👍":1}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user