12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- /**
- * 客户端App状态库。
- *
- * 客户端App状态对每个用户来讲只保存一个,不区分设备。
- * 因此当用户从iOS切换至Android平台时,先前的状态将被新的替换。
- *
- * author: Sand
- * since: 12/14/2016
- */
- "use strict";
- let 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 deviceToken
- * @param client_id
- * @param platform
- * @param handler
- */
- static save(userId, deviceToken, client_id, platform, handler) {
- let sql = "INSERT INTO APP_STATUS (USER_ID, PLATFORM, TOKEN, CLIENT_ID, APP_IN_BG, LAST_LOGIN_TIME) " +
- "VALUES (?, ?, ?, ?, 0, NOW()) " +
- "ON DUPLICATE KEY UPDATE PLATFORM=?, TOKEN=?, CLIENT_ID=?, APP_IN_BG=0,LAST_LOGIN_TIME=NOW()";
- ImDb.execQuery({
- sql: sql,
- args: [userId, platform, deviceToken, client_id, platform, deviceToken, client_id],
- handler: function(err,res){
- handler(err,res);
- }
- });
- };
- /**
- * 更新App前后台状态。
- *
- * @param userId
- * @param appInBg
- * @param handler
- */
- static updateStatus(userId, appInBg, handler) {
- ImDb.execQuery({
- "sql": "UPDATE APP_STATUS SET APP_IN_BG = ? WHERE USER_ID = ",
- "args": [appInBg, userId],
- "handler": handler
- });
- };
- /**
- * 销毁用户状态
- *
- * @param userId
- * @param handler
- */
- static destroy(userId, handler) {
- ImDb.execQuery({
- "sql": "DELETE FROM APP_STATUS WHERE USER_ID = ?",
- "args": [userId],
- "handler": handler
- });
- };
- }
- module.exports = AppStatusRepo;
|