--[[ 推送Model ]] local Notification_Model = {} local private = {} local JSON = require("cjson") local base_opt = require 'Proto/base_opt_pb' local EventSystem = require('Event/EventSystem') Notification_Model.ConstPushID = { TiLi = 1, --体力值满 GuaJi = 2, --挂机收益 Mine = 3, --矿战 } Notification_Model.PushType = { TiLi = 1, -- 体力值满 GuaJi = 2, -- 挂机收益 Activity = 3, -- 活动类型 Custom_Time = 4, -- 自定义时间类型 日/周 HeroMatch1v1 = 5, -- 天地群雄 FairSoloTournament = 6, --天下会武 HeroMatch3v3 = 7, --天地群雄3v3 TeamFairChampionship = 8, --天下会武3V3 Mine = 9, -- 矿战 ServerNotice = 10, --服务器推送 只用于设置界面显示 } function Notification_Model.OnStartup() NetManager.RegisterMsgCB(MessageEnums.MessageAppPushReward, private.OnGetNotificationReward) NetManager.RegisterMsgCB(MessageEnums.MessageGetAppPushSwitchInfo, private.OnGetAppPushSwitchInfo) NetManager.RegisterMsgCB(MessageEnums.MessageUpdateAppPushSwitch, private.OnUpdateAppPushSwitch) private.isHasGetNotificationReward = false --key:pushCfgId value:0,1 private.notificationData = {} private.LoadNotificationData() private.serverNotificationData = {} end function private.OnGetNotificationReward(msgResp) logging.log(LTAG.YL, "UseItemByCfgIdResponse") end function Notification_Model.ReqNotificationReward() local msg = base_opt.AppPushRewardReq() NetManager.SendMessage(MessageEnums.MessageAppPushReward, msg) end function Notification_Model.SetHasGetNotificationReward(isHas) private.isHasGetNotificationReward = isHas end function Notification_Model.GetHasGetNotificationReward() return private.isHasGetNotificationReward end function private.LoadNotificationData() private.InitDefaultData() local jsonNotificationStr = PersistentData.DeviceData:Get(LuaConst.SettingKeyEnum.NotificationSettingStr) or "" if not string.isNilOrEmpty(jsonNotificationStr) then local notificationData = JSON.decode(jsonNotificationStr); if type(notificationData) == 'table' then for pushId, isPushInt in pairs(notificationData) do if private.notificationData[pushId] ~= nil then private.notificationData[pushId] = isPushInt end end end end end function private.InitDefaultData() for __, pushCfgData in DataSheetManager.AppPush:GetEnumerator() do if pushCfgData.IsShow == 1 and pushCfgData.ShowOrNot == 1 then if pushCfgData.Class ~= MDL.Notification.PushType.ServerNotice then private.notificationData[pushCfgData.ID] = 1 end end end end function Notification_Model.SaveNotificationData() local saveData = private.notificationData if saveData ~= nil then local jsonNotificationStr = JSON.encode(private.notificationData); PersistentData.DeviceData:Set(LuaConst.SettingKeyEnum.NotificationSettingStr, jsonNotificationStr, true) else logging.error(LTAG.ERROR,"错误 不能在推送存储数据为空的情况下还尝试保存") end end function Notification_Model.SetNotificationEnabled(pushCfgId, isEnabled) local _, pushCfgData = DataSheetManager.AppPush:TryGetDataByID(pushCfgId) if pushCfgData and pushCfgData.Class == MDL.Notification.PushType.ServerNotice then Notification_Model.UpdateAppPushSwitchReq(pushCfgId, isEnabled) else private.notificationData[pushCfgId] = isEnabled and 1 or 0 end end function Notification_Model.UpdateAppPushSwitchReq(id, isEnabled) local msg = NetManager.GetPB("app_push_opt_bp").UpdateAppPushSwitchReq() msg.id = id msg.is_open = isEnabled NetManager.SendMessage(MessageEnums.MessageUpdateAppPushSwitch, msg) end function Notification_Model.GetNotificationEnabled(pushCfgId) local _, pushCfgData = DataSheetManager.AppPush:TryGetDataByID(pushCfgId) if pushCfgData and pushCfgData.Class == MDL.Notification.PushType.ServerNotice then return private.serverNotificationData[pushCfgId] end return private.notificationData[pushCfgId] and private.notificationData[pushCfgId] == 1 end function private.OnGetAppPushSwitchInfo(msgResp) if msgResp.Resp.Code == 0 then for i,v in ipairs(msgResp.SwitchInfo) do private.serverNotificationData[v.id] = v.is_open end EventSystem.Dispatch(EventID.UI_ServerNotificationStateChange) end end function private.OnUpdateAppPushSwitch(msgResp) if msgResp.Resp.Code == 0 then private.serverNotificationData[msgResp.SwitchInfo.id] = msgResp.SwitchInfo.is_open EventSystem.Dispatch(EventID.UI_ServerNotificationStateChange) end end function Notification_Model.GetAppPushSwitchInfoReq() local msg = NetManager.GetPB("app_push_opt_bp").GetAppPushSwitchInfoReq() NetManager.SendMessage(MessageEnums.MessageGetAppPushSwitchInfo, msg) end return Notification_Model