mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
messagepad (react is great!)
This commit is contained in:
1 parent
39ea30664d
commit
560e920624
13 files changed
+146
-279
No files matched your search
@@ -26,7 +26,7 @@ export default function reducer(state = null, action) {
|
||||
return action.payload;
|
||||
}
|
||||
case 'DIALOGUES_POST_SEND_FULFILLED': {
|
||||
return action.payload.mdoc._id;
|
||||
return action.meta.dialogueId;
|
||||
}
|
||||
default:
|
||||
return state;
|
||||
|
||||
@@ -3,79 +3,48 @@ import _ from 'lodash';
|
||||
export default function reducer(state = {}, action) {
|
||||
switch (action.type) {
|
||||
case 'DIALOGUES_LOAD_DIALOGUES_FULFILLED': {
|
||||
const { messages, udict } = action.payload;
|
||||
return _.keyBy(
|
||||
_.filter(
|
||||
_.map(messages, (m) => ({
|
||||
to_udoc: udict[m.to],
|
||||
from_udoc: udict[m.from],
|
||||
...m,
|
||||
})),
|
||||
(m) => m.to_udoc && m.from_udoc,
|
||||
),
|
||||
'_id',
|
||||
);
|
||||
const { messages } = action.payload;
|
||||
return _.keyBy(messages, 'udoc._id');
|
||||
}
|
||||
case 'DIALOGUES_CREATE': {
|
||||
const { id, user } = action.payload;
|
||||
const { user } = action.payload;
|
||||
return {
|
||||
...state,
|
||||
[id]: {
|
||||
_id: id,
|
||||
from: UserContext._id,
|
||||
to: user._id,
|
||||
to_udoc: { ...user },
|
||||
reply: [],
|
||||
isPlaceholder: true,
|
||||
},
|
||||
};
|
||||
}
|
||||
case 'DIALOGUES_POST_REPLY_FULFILLED': {
|
||||
const id = action.meta.dialogueId;
|
||||
const { reply } = action.payload;
|
||||
return {
|
||||
...state,
|
||||
[id]: {
|
||||
...state[id],
|
||||
reply: [
|
||||
...state[id].reply,
|
||||
reply,
|
||||
],
|
||||
[user._id]: {
|
||||
_id: user._id,
|
||||
udoc: { ...user },
|
||||
messages: [],
|
||||
},
|
||||
};
|
||||
}
|
||||
case 'DIALOGUES_POST_SEND_FULFILLED': {
|
||||
const { placeholderId } = action.meta;
|
||||
const id = action.meta.dialogueId;
|
||||
const { mdoc } = action.payload;
|
||||
return {
|
||||
..._.omit(state, placeholderId),
|
||||
[action.payload.mdoc._id]: action.payload.mdoc,
|
||||
...state,
|
||||
[id]: {
|
||||
...state[id],
|
||||
messages: [
|
||||
...state[id].messages,
|
||||
mdoc,
|
||||
],
|
||||
},
|
||||
};
|
||||
}
|
||||
case 'DIALOGUES_MESSAGE_PUSH': {
|
||||
const { type, data } = action.payload;
|
||||
const id = data._id;
|
||||
if (type === 'new') {
|
||||
return {
|
||||
...state,
|
||||
[id]: data,
|
||||
};
|
||||
} if (type === 'reply') {
|
||||
if (state[id] === undefined) {
|
||||
window.location.reload();
|
||||
return state;
|
||||
}
|
||||
return {
|
||||
...state,
|
||||
[id]: {
|
||||
...state[id],
|
||||
reply: [
|
||||
...state[id].reply,
|
||||
data.reply[0],
|
||||
],
|
||||
},
|
||||
};
|
||||
}
|
||||
return state;
|
||||
const { mdoc, udoc } = action.payload;
|
||||
const to = mdoc.from === UserContext._id ? mdoc.to : mdoc.from;
|
||||
return {
|
||||
...state,
|
||||
[to]: {
|
||||
...state[to] || {},
|
||||
udoc,
|
||||
messages: [
|
||||
...state[to]?.messages || [],
|
||||
mdoc,
|
||||
],
|
||||
},
|
||||
};
|
||||
}
|
||||
default:
|
||||
return state;
|
||||
|
||||
@@ -7,10 +7,10 @@ export default function reducer(state = {}, action) {
|
||||
return _.fromPairs(_.map(dialogues, (d) => [d._id, '']));
|
||||
}
|
||||
case 'DIALOGUES_CREATE': {
|
||||
const { id } = action.payload;
|
||||
const { user } = action.payload;
|
||||
return {
|
||||
...state,
|
||||
[id]: '',
|
||||
[user._id]: '',
|
||||
};
|
||||
}
|
||||
case 'DIALOGUES_INPUT_CHANGED': {
|
||||
@@ -20,27 +20,19 @@ export default function reducer(state = {}, action) {
|
||||
[id]: action.payload,
|
||||
};
|
||||
}
|
||||
case 'DIALOGUES_POST_REPLY_FULFILLED': {
|
||||
case 'DIALOGUES_POST_SEND_FULFILLED': {
|
||||
const id = action.meta.dialogueId;
|
||||
return {
|
||||
...state,
|
||||
[id]: '',
|
||||
};
|
||||
}
|
||||
case 'DIALOGUES_POST_SEND_FULFILLED': {
|
||||
const { placeholderId } = action.meta;
|
||||
return {
|
||||
..._.omit(state, placeholderId),
|
||||
[action.payload.mdoc._id]: '',
|
||||
};
|
||||
}
|
||||
case 'DIALOGUES_MESSAGE_PUSH': {
|
||||
const { type, data } = action.payload;
|
||||
const id = data._id;
|
||||
if (type === 'new') {
|
||||
const { udoc } = action.payload;
|
||||
if (!state[udoc._id]) {
|
||||
return {
|
||||
...state,
|
||||
[id]: '',
|
||||
[udoc._id]: '',
|
||||
};
|
||||
}
|
||||
return state;
|
||||
|
||||
@@ -8,66 +8,40 @@ export default function reducer(state = {}, action) {
|
||||
return _.fromPairs(_.map(dialogues, (d) => [d._id, false]));
|
||||
}
|
||||
case 'DIALOGUES_CREATE': {
|
||||
const { id } = action.payload;
|
||||
const { user } = action.payload;
|
||||
return {
|
||||
...state,
|
||||
[id]: false,
|
||||
[user._id]: false,
|
||||
};
|
||||
}
|
||||
case 'DIALOGUES_POST_REPLY_PENDING': {
|
||||
case 'DIALOGUES_POST_SEND_PENDING': {
|
||||
const id = action.meta.dialogueId;
|
||||
return {
|
||||
...state,
|
||||
[id]: true,
|
||||
};
|
||||
}
|
||||
case 'DIALOGUES_POST_REPLY_REJECTED': {
|
||||
Notification.error(action.payload.message);
|
||||
const id = action.meta.dialogueId;
|
||||
return {
|
||||
...state,
|
||||
[id]: false,
|
||||
};
|
||||
}
|
||||
case 'DIALOGUES_POST_REPLY_FULFILLED': {
|
||||
const id = action.meta.dialogueId;
|
||||
return {
|
||||
...state,
|
||||
[id]: false,
|
||||
};
|
||||
}
|
||||
case 'DIALOGUES_POST_SEND_PENDING': {
|
||||
const { placeholderId } = action.meta;
|
||||
return {
|
||||
...state,
|
||||
[placeholderId]: true,
|
||||
};
|
||||
}
|
||||
case 'DIALOGUES_POST_SEND_REJECTED': {
|
||||
Notification.error(action.payload.message);
|
||||
const { placeholderId } = action.meta;
|
||||
const id = action.meta.dialogueId;
|
||||
return {
|
||||
...state,
|
||||
[placeholderId]: false,
|
||||
[id]: false,
|
||||
};
|
||||
}
|
||||
case 'DIALOGUES_POST_SEND_FULFILLED': {
|
||||
const { placeholderId } = action.meta;
|
||||
const id = action.meta.dialogueId;
|
||||
return {
|
||||
..._.omit(state, placeholderId),
|
||||
[action.payload.mdoc._id]: false,
|
||||
...state,
|
||||
[id]: false,
|
||||
};
|
||||
}
|
||||
case 'DIALOGUES_MESSAGE_PUSH': {
|
||||
const { type, data } = action.payload;
|
||||
const id = data._id;
|
||||
if (type === 'new') {
|
||||
return {
|
||||
...state,
|
||||
[id]: false,
|
||||
};
|
||||
}
|
||||
return state;
|
||||
const { udoc } = action.payload;
|
||||
return {
|
||||
...state,
|
||||
[udoc._id]: false,
|
||||
};
|
||||
}
|
||||
default:
|
||||
return state;
|
||||
|
||||
Reference in new issue
Block a user