Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: chat and agent issue #228

Merged
merged 1 commit into from
Mar 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const DeleteGroupPopup = ({
const history = useHistory();
const handleDelete = async () => {
setProcessing(true);
const groupId = history.location.pathname.split("/")[3];
const groupId = history.location.pathname.split("/")[2];
deleteGroup(groupId);
setConfirmAction(false);
amplitude.getInstance().logEvent("Delete group click", {});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,10 @@ export const GroupChatsViewSection = ({
const messagesEndRef: any = useCallback(
(node: any) => {
/// Wait 1 sec for design Rendering and then scroll
setTimeout(() => {
node.scrollIntoView({ block: "end" });
}, 1000);
if (node)
setTimeout(() => {
node.scrollIntoView({ block: "end" });
}, 1000);
},
[messages]
);
Expand Down
61 changes: 43 additions & 18 deletions packages/extension/src/stores/chats/messages-slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { CHAT_PAGE_COUNT, GROUP_PAGE_COUNT } from "../../config.ui.var";

interface State {
groups: Groups;
agents: Groups;
groupsPagination: Pagination;
chats: Chats;
blockedAddress: BlockedAddressState;
Expand All @@ -20,6 +21,7 @@ interface State {

const initialState: State = {
groups: {},
agents: {},
groupsPagination: {
page: -1,
pageCount: GROUP_PAGE_COUNT,
Expand All @@ -38,8 +40,26 @@ export const messagesSlice = createSlice({
reducers: {
setGroups: (state, action) => {
const { groups, pagination } = action.payload;
state.groups = { ...state.groups, ...groups };
state.groupsPagination = pagination;

const chatGroup = Object.keys(groups)
.filter((key) => !key.includes("agent"))
.reduce((obj: Groups, key: string) => {
obj[key] = groups[key];
return obj;
}, {});
if (Object.keys(chatGroup).length > 0)
state.groups = { ...state.groups, ...chatGroup };

const chatAgent = Object.keys(groups)
.filter((key) => key.includes("agent"))
.reduce((obj: Groups, key: string) => {
obj[key] = groups[key];
return obj;
}, {});

if (Object.keys(chatAgent).length > 0)
state.agents = { ...state.agents, ...chatAgent };
},
updateChatList: (state, action) => {
const { userAddress, messages, pagination } = action.payload;
Expand Down Expand Up @@ -79,7 +99,7 @@ export const messagesSlice = createSlice({
},
updateGroupsData: (state: any, action: PayloadAction<any>) => {
const group = action.payload;
let key;
let key: string;
if (group.isDm) {
key = group?.userAddress;
} else {
Expand All @@ -89,11 +109,28 @@ export const messagesSlice = createSlice({
const updatedGroup = {
[key]: group,
};
state.groups = { ...state.groups, ...updatedGroup };
const chatGroup = Object.keys(updatedGroup)
.filter((key) => !key.includes("agent"))
.reduce((obj: Groups, key: string) => {
obj[key] = updatedGroup[key];
return obj;
}, {});
if (Object.keys(chatGroup).length > 0)
state.groups = { ...state.groups, ...chatGroup };

const chatAgent = Object.keys(updatedGroup)
.filter((key) => key.includes("agent"))
.reduce((obj: Groups, key: string) => {
obj[key] = updatedGroup[key];
return obj;
}, {});
if (Object.keys(chatAgent).length > 0)
state.agents = { ...state.agents, ...chatAgent };
},
removeGroup: (state: any, action: PayloadAction<any>) => {
const groupId = action.payload;
delete state.groups[groupId];
if (state.groups.hasOwnProperty(groupId)) delete state.groups[groupId];
if (state.agents.hasOwnProperty(groupId)) delete state.agents[groupId];
},
updateLatestSentMessage: (state: any, action: PayloadAction<Message>) => {
const { target, id, groupId } = action.payload;
Expand Down Expand Up @@ -157,20 +194,8 @@ export const {
setIsChatSubscriptionActive,
} = messagesSlice.actions;

export const userChatGroups = (state: any) =>
Object.keys(state.messages.groups)
.filter((key) => !key.includes("agent"))
.reduce((obj: Groups, key: string) => {
obj[key] = state.messages.groups[key];
return obj;
}, {});
export const userChatAgents = (state: any) =>
Object.keys(state.messages.groups)
.filter((key) => key.includes("agent"))
.reduce((obj: Groups, key: string) => {
obj[key] = state.messages.groups[key];
return obj;
}, {});
export const userChatGroups = (state: any) => state.messages.groups;
export const userChatAgents = (state: any) => state.messages.agents;
export const userChatGroupPagination = (state: any) =>
state.messages.groupsPagination;

Expand Down