Skip to content

Commit

Permalink
fix: added modify stream (#1159)
Browse files Browse the repository at this point in the history
  • Loading branch information
mishramonalisha76 authored Mar 8, 2024
1 parent fe36df2 commit 15a3771
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const ChatViewComponentTest = () => {
<ChatView
onVerificationFail={() => console.log("Verification Failed")}

chatId='0x56A734ba4C7c7b117774C9aAcCEf521eBE66d65b'
chatId='bd01307fa75e738842b474e0c0aa00385e9aa886ebd33ed246182141f377be5f'
chatProfileLeftHelperComponent={<img src={Img} onClick={()=>console.debug('clicked')}/>}
chatProfileRightHelperComponent={<div>right component</div>}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -513,14 +513,13 @@ export const GroupInfoModal = ({
const {
chatAcceptStream,
chatRejectStream,
chatRequestStream,
participantRemoveStream,
participantLeaveStream,
participantJoinStream,
groupUpdateStream,
participantRoleChangeStream,
} = usePushChatStream();


//stream listeners
useEffect(() => {
if (
Expand Down Expand Up @@ -562,7 +561,6 @@ export const GroupInfoModal = ({
})();

}, [participantJoinStream]);

useEffect(() => {
if (
Object.keys(groupUpdateStream).length > 0 &&
Expand All @@ -571,6 +569,13 @@ export const GroupInfoModal = ({
transformGroupDetails(groupUpdateStream);
}, [groupUpdateStream]);

useEffect(() => {
if (
Object.keys(participantRoleChangeStream).length > 0 &&
participantRoleChangeStream.constructor === Object
)
transformRoleChange(participantRoleChangeStream);
}, [participantRoleChangeStream]);
useEffect(() => {
(async () => {
const count = await fetchMembersCount({ chatId: groupInfo!.chatId! });
Expand Down Expand Up @@ -713,6 +718,14 @@ export const GroupInfoModal = ({
),
}));
};
const memberRoleChange = (item:any): void => {
const acceptedMember:ChatMemberProfile[] = groupMembers?.accepted.map(member => member.address == item.to[0] ? {...member, role:item.newRole} : member);
console.debug(acceptedMember)
setGroupMembers((prevMembers: MembersType) => ({
...prevMembers,
accepted: acceptedMember,
}));
};

const transformAcceptedRequest = (item: any): void => {
if (item?.meta?.group && groupInfo?.chatId === item?.chatId) {
Expand Down Expand Up @@ -766,18 +779,24 @@ export const GroupInfoModal = ({
// }
// };

const transformRoleChange = (item: any): void => {
if ( groupInfo?.chatId === item?.chatId) {
memberRoleChange(item)

}
};
const transformGroupDetails = (item: any): void => {
if ( groupInfo?.chatId === item?.chatId) {
const updatedGroupInfo = groupInfo;
// console.debug(updatedGroupInfo)
// if(updatedGroupInfo){
// updatedGroupInfo.groupName= item?.meta?.name;
// updatedGroupInfo.groupDescription=item?.meta?.description;
// updatedGroupInfo.groupImage=item?.meta?.image;
// updatedGroupInfo.groupCreator=item?.meta?.owner;
// updatedGroupInfo.isPublic=!item?.meta?.private;
// setGroupInfo(updatedGroupInfo);
// }
if(updatedGroupInfo){
updatedGroupInfo.groupName= item?.meta?.name;
updatedGroupInfo.groupDescription=item?.meta?.description;
updatedGroupInfo.groupImage=item?.meta?.image;
updatedGroupInfo.groupCreator=item?.meta?.owner;
updatedGroupInfo.isPublic=!item?.meta?.private;
updatedGroupInfo.rules=item?.meta?.rules;
setGroupInfo(updatedGroupInfo);
}

}
};
Expand Down
9 changes: 7 additions & 2 deletions packages/uiweb/src/lib/hooks/chat/usePushChatStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ export const usePushChatStream = () => {
const [chatRejectStream, setChatRejectStream] = useState<any>({}); // to track any rejected request

const [chatRequestStream, setChatRequestStream] = useState<any>({}); // any message in request
const [participantRoleChangeStream, setParticipantRoleChangeStream] = useState<any>({}); // to track if a participant role is changed in a group

const [participantRemoveStream, setParticipantRemoveStream] = useState<any>({}); // to track if a participant is removed from group
const [participantLeaveStream, setParticipantLeaveStream] = useState<any>({}); // to track if a participant leaves a group
const [participantJoinStream, setParticipantJoinStream] = useState<any>({}); // to track if a participant joins a group
const [groupCreateStream, setGroupCreateStream] = useState<any>({}); // to track if group is created

const [groupUpdateStream, setGroupUpdateStream] = useState<any>({}); //group updation stream
console.debug('in stream')
const attachListenersAndConnect = async (stream: any) => {
stream?.on(CONSTANTS.STREAM.CONNECT, (err: Error) => {
console.debug(' stream connected .........',err)
Expand Down Expand Up @@ -56,6 +57,9 @@ console.debug('in stream')
else if (message.event === 'chat.group.participant.join') {
setParticipantJoinStream(message);
}
else if (message.event === 'chat.group.participant.role'){
setParticipantRoleChangeStream(message);
}

else if (message.event === 'chat.message') {
setChatStream(message);
Expand All @@ -64,13 +68,13 @@ console.debug('in stream')

// Listen for group info
stream?.on(CONSTANTS.STREAM.CHAT_OPS, (chatops: any) => {
console.debug(chatops)
if (chatops.event === 'chat.group.update') {
setGroupUpdateStream(chatops);
}
else if (chatops.event === 'chat.group.create') {
setGroupCreateStream(chatops);
}

});

console.debug('stream listeners attached');
Expand Down Expand Up @@ -138,6 +142,7 @@ console.debug('in stream')
participantRemoveStream,
participantLeaveStream,
participantJoinStream,
participantRoleChangeStream,
groupCreateStream
};
};

0 comments on commit 15a3771

Please sign in to comment.