feat: mute
This commit is contained in:
@@ -4,6 +4,8 @@ const initialState = {
|
||||
afterMid: 0,
|
||||
readUsers: {},
|
||||
readChannels: {},
|
||||
muteUsers: {},
|
||||
muteChannels: {},
|
||||
};
|
||||
const footprintSlice = createSlice({
|
||||
name: "footprint",
|
||||
@@ -18,8 +20,17 @@ const footprintSlice = createSlice({
|
||||
afterMid = 0,
|
||||
readUsers = {},
|
||||
readChannels = {},
|
||||
muteUsers = {},
|
||||
muteChannels = {},
|
||||
} = action.payload;
|
||||
return { usersVersion, afterMid, readUsers, readChannels };
|
||||
return {
|
||||
usersVersion,
|
||||
afterMid,
|
||||
readUsers,
|
||||
readChannels,
|
||||
muteUsers,
|
||||
muteChannels,
|
||||
};
|
||||
},
|
||||
updateUsersVersion(state, action) {
|
||||
const usersVersion = action.payload;
|
||||
@@ -29,6 +40,47 @@ const footprintSlice = createSlice({
|
||||
const afterMid = action.payload;
|
||||
state.afterMid = afterMid;
|
||||
},
|
||||
updateMute(state, action) {
|
||||
const payload = action.payload || {};
|
||||
Object.keys(payload).forEach((key) => {
|
||||
switch (key) {
|
||||
case "remove_users":
|
||||
{
|
||||
const uids = payload.remove_users;
|
||||
uids.forEach((id) => {
|
||||
delete state.muteUsers[id];
|
||||
});
|
||||
}
|
||||
break;
|
||||
case "remove_groups":
|
||||
{
|
||||
const gids = payload.remove_groups;
|
||||
gids.forEach((id) => {
|
||||
delete state.muteChannels[id];
|
||||
});
|
||||
}
|
||||
break;
|
||||
case "add_users":
|
||||
{
|
||||
const mutes = payload.add_users;
|
||||
mutes.forEach(({ uid, expired_in = null }) => {
|
||||
state.muteUsers[uid] = { expired_in };
|
||||
});
|
||||
}
|
||||
break;
|
||||
case "add_groups":
|
||||
{
|
||||
const mutes = payload.add_groups;
|
||||
mutes.forEach(({ gid, expired_in = null }) => {
|
||||
state.muteChannels[gid] = { expired_in };
|
||||
});
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
});
|
||||
},
|
||||
updateReadUsers(state, action) {
|
||||
const reads = action.payload || [];
|
||||
if (reads.length == 0) return;
|
||||
@@ -52,5 +104,6 @@ export const {
|
||||
updateUsersVersion,
|
||||
updateReadChannels,
|
||||
updateReadUsers,
|
||||
updateMute,
|
||||
} = footprintSlice.actions;
|
||||
export default footprintSlice.reducer;
|
||||
|
||||
Reference in New Issue
Block a user