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;
|