Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.2k views
in Technique[技术] by (71.8m points)

社交平台消息通知设置?求思路

image
image


社交产品中的消息推送设置

1.平台所有用户默认打开接受推送通知

2.如个别用户关闭某个消息设置,则不产生跟他相关的消息推送

问:
这块业务功能怎么实现,有sf小伙伴能提下实现思路的没? 谢过 ^_^


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

假设有10个配置项,id是从1到10,数据库只存用户操作过的数据,一个id是一条数据

typeuser_idactive
110
310
610

那么查询这个用户的数据库数据得到

const userSwitches = [
    {"type": 1, "active": 0},
    {"type": 3, "active": 0},
    {"type": 6, "active": 0},
];

组装数据

const switches = Array.from({length: 10}, (v, index) => {
    const type = index + 1;
    return userSwitches.find(item => item.type === type) 
        || {type, "active": 1},
});

就能得到数据

[
    {"type": 1, "active": 0},
    {"type": 2, "active": 1},
    {"type": 3, "active": 0},
    {"type": 4, "active": 1},
    {"type": 5, "active": 1},
    {"type": 6, "active": 0},
    {"type": 7, "active": 1},
    {"type": 8, "active": 1},
    {"type": 9, "active": 1},
    {"type": 10, "active": 1},
]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...