aboutsummaryrefslogtreecommitdiff
path: root/src/java/com/juick/api/Others.java
blob: 25df5bf46b507c74a12429221b9320b141283ca3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package com.juick.api;

import com.juick.server.PMQueries;
import java.io.IOException;
import java.sql.Connection;
import java.util.ArrayList;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author ugnich
 */
public class Others {

    Connection sql;

    public Others(Connection sql) {
        this.sql = sql;
    }

    public void doGetGroupsPMs(HttpServletRequest request, HttpServletResponse response, int vuid) throws ServletException, IOException {
        int cnt = 5;
        try {
            String cntStr = request.getParameter("cnt");
            cnt = Integer.parseInt(cntStr);
            if (cnt < 3) {
                cnt = 3;
            }
            if (cnt > 10) {
                cnt = 10;
            }
        } catch (Exception e) {
        }

        ArrayList<com.juick.User> lastconv = PMQueries.getPMLastConversationsUsers(sql, vuid, cnt);
        if (lastconv != null && !lastconv.isEmpty()) {
            String json = "{\"pms\":" + com.juick.json.Users.arrayToString(lastconv) + "}";
            Main.replyJSON(request, response, json);
        } else {
            response.sendError(404);
        }
    }
}