work on real time for message actions

This commit is contained in:
2025-08-08 12:04:28 +03:30
parent e2e4bab029
commit a900c66eac
8 changed files with 264 additions and 29 deletions
@@ -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}
}
}