refactor: reaction

This commit is contained in:
zerosoul
2022-05-27 16:46:57 +08:00
parent 84f9998277
commit d9d3cb661e
8 changed files with 114 additions and 19 deletions
+9 -1
View File
@@ -20,11 +20,18 @@ const reactionMessageSlice = createSlice({
});
},
toggleReactionMessage(state, action) {
const { from_uid, mid, action: reaction } = action.payload;
// rid: reaction's mid, mid: which message append to
const { from_uid, mid, rid, action: reaction } = action.payload;
console.log("msg reaction", mid, from_uid, reaction);
const ridExisted = state[rid] || false;
// 已经塞过了
if (ridExisted) return;
console.log("ssss");
// 还未塞过任何一表情
if (!state[mid]) {
state[mid] = {};
}
// 存在该表情数据
if (state[mid][reaction]) {
const reactionUids = state[mid][reaction];
const idx = reactionUids.findIndex((id) => id == from_uid);
@@ -40,6 +47,7 @@ const reactionMessageSlice = createSlice({
} else {
state[mid][reaction] = [from_uid];
}
state[rid] = true;
},
},
});