aboutsummaryrefslogtreecommitdiff
path: root/src/com
diff options
context:
space:
mode:
authorGravatar Ugnich Anton2014-01-26 03:23:57 +0700
committerGravatar Ugnich Anton2014-01-26 03:23:57 +0700
commita6a3f6c811395d148a0b8d571d721443e6f121c2 (patch)
tree97546466555b1383c71e8c67f3c7409c1ae436a6 /src/com
parenta6b3956014a894ff4e8e1d9194c10869e5911e34 (diff)
getLastPMMessages
Diffstat (limited to 'src/com')
-rw-r--r--src/com/juick/server/PMQueries.java29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/com/juick/server/PMQueries.java b/src/com/juick/server/PMQueries.java
index b0c2911a..651524ee 100644
--- a/src/com/juick/server/PMQueries.java
+++ b/src/com/juick/server/PMQueries.java
@@ -242,4 +242,33 @@ public class PMQueries {
return msgs;
}
+
+ public static ArrayList<com.juick.Message> getLastPMMessages(Connection sql, int uid) {
+ ArrayList<com.juick.Message> msgs = new ArrayList<com.juick.Message>(20);
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = sql.prepareStatement("SELECT pm.user_id,users.nick,pm.txt,TIMESTAMPDIFF(MINUTE,pm.ts,NOW()),DATE_FORMAT(pm.ts,'%Y-%m-%d %H:%i:%s') FROM pm INNER JOIN users ON pm.user_id=users.id WHERE pm.user_id_to=? ORDER BY pm.ts DESC LIMIT 20");
+ stmt.setInt(1, uid);
+ rs = stmt.executeQuery();
+ rs.beforeFirst();
+ while (rs.next()) {
+ com.juick.Message msg = new com.juick.Message();
+ msg.User = new com.juick.User();
+ msg.User.UID = rs.getInt(1);
+ msg.User.UName = rs.getString(2);
+ msg.Text = rs.getString(3);
+ msg.TimeAgo = rs.getInt(4);
+ msg.TimestampString = rs.getString(5);
+ msgs.add(0, msg);
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+
+ return msgs;
+ }
}