Skip to content

Commit

Permalink
[FIX] handling error and not showing InputBox when not authenticated (#…
Browse files Browse the repository at this point in the history
…107)

* handling error and hiding input when cookies not present

* added an optional chaining if the array is present or not
  • Loading branch information
sidmohanty11 committed Mar 29, 2022
1 parent be23250 commit 4beb2e4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion app/components/inappchat/helpers/sortMessagesByDate.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export default function messagesSortedByDate(messagesArray) {
return messagesArray.sort(function (a, b) {
return messagesArray?.sort(function (a, b) {
return a.ts < b.ts ? -1 : a.ts > b.ts ? 1 : 0;
});
};
22 changes: 13 additions & 9 deletions app/components/inappchat/inappchat.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,18 @@ const InAppChat = ({ closeChat, cookies, rid }) => {

useEffect(() => {
const runRealtime = async (token, rid) => {
await rcClient.connect({ host: rcURL.host, useSsl });
await rcClient.resume({ token });
await rcClient.subscribe("stream-room-messages", rid);
rcClient.onMessage(() => {
// TODO: add the animate function here,
// and check if that corresponds to any of the emoji that we want to animate then animate()
getData();
});
try {
await rcClient.connect({ host: rcURL.host, useSsl });
await rcClient.resume({ token });
await rcClient.subscribe("stream-room-messages", rid);
rcClient.onMessage(() => {
// TODO: add the animate function here,
// and check if that corresponds to any of the emoji that we want to animate then animate()
getData();
});
} catch(err) {
console.log(err.message);
}
};
async function getData() {
const data = await getMessages(rid, cookies);
Expand Down Expand Up @@ -94,7 +98,7 @@ const InAppChat = ({ closeChat, cookies, rid }) => {
)}
</Box>
</div>
<InappchatTextInput sendMsg={sendMsg} />
{cookies.rc_token && cookies.rc_uid && <InappchatTextInput sendMsg={sendMsg} />}
</div>
);
};
Expand Down

0 comments on commit 4beb2e4

Please sign in to comment.