1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- /**
- * 客户端App状态库。
- *
- * 客户端App状态对每个用户来讲只保存一个,不区分设备。
- * 因此当用户从iOS切换至Android平台时,先前的状态将被新的替换。
- *
- * author: Sand
- * since: 12/14/2016
- */
- "use strict";
- var imDb = require("./db/im.db.js");
- class AppStatusRepo {
- constructor() {
- }
- /**
- * 查找客户端App状态。
- *
- * @param userId
- * @param handler
- */
- static findOne(userId, handler) {
- let sql = "SELECT platform, token, client_id, app_in_bg, last_login_time " +
- "FROM app_status WHERE user_id = ?";
- imDb.execQuery({
- "sql": sql,
- "args": [userId],
- "handler": handler
- });
- };
- /**
- * 保存App的最新状态。
- *
- * @param userId
- * @param token
- * @param client_id
- * @param platform
- * @param handler
- */
- static save(userId, token, client_id, platform, handler) {
- imDb.execQuery({
- "sql": "INSERT INTO app_status (user_id, platform, token, client_id, app_in_bg, last_login_time) VALUES (?,?,?,?,1,1) ON" +
- " DUPLICATE KEY UPDATE token=?,client_id=?,platform=?,is_online=1,status=1",
- "args": [userId, token, client_id, platform, token, client_id, platform],
- "handler": handler
- });
- };
- /**
- * 更新App前后台状态。
- *
- * @param userId
- * @param appInBg
- * @param handler
- */
- static updateStatus(userId, appInBg, handler) {
- imDb.execQuery({
- "sql": "UPDATE user SET app_in_bg = ? WHERE user_id = ",
- "args": [appInBg, userId],
- "handler": handler
- });
- };
- static delete(token, handler) {
- imDb.execQuery({
- "sql": "DELETE FROM user WHERE token=?",
- "args": [token],
- "handler": handler
- });
- };
- }
- module.exports = AppStatusRepo;
|