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: getchannelavatarurl function in chatHeader and RoomInformation to Reflect Updated Avatar Changes. #888

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
28 changes: 22 additions & 6 deletions packages/react/src/views/ChatHeader/ChatHeader.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import React, { useCallback, useEffect, useMemo } from 'react';
import React, {
useCallback,
useEffect,
useMemo,
useState,
useContext,
} from 'react';
import { css } from '@emotion/react';
import PropTypes from 'prop-types';
import {
Expand All @@ -11,7 +17,7 @@ import {
useTheme,
Avatar,
} from '@embeddedchat/ui-elements';
import { useRCContext } from '../../context/RCInstance';
import RCContext from '../../context/RCInstance';
import {
useUserStore,
useMessageStore,
Expand Down Expand Up @@ -78,7 +84,7 @@ const ChatHeader = ({
);
const workspaceLevelRoles = useUserStore((state) => state.roles);

const { RCInstance, ECOptions } = useRCContext();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any specific reason for removing this and using useContext here ?

const { RCInstance, ECOptions } = useContext(RCContext);
const { channelName, anonymousMode, showRoles } = ECOptions ?? {};

const isUserAuthenticated = useUserStore(
Expand Down Expand Up @@ -117,10 +123,20 @@ const ChatHeader = ({
);
const setShowAllFiles = useFileStore((state) => state.setShowAllFiles);
const setShowMentions = useMentionsStore((state) => state.setShowMentions);
const getChannelAvatarURL = (channelname) => {

const getChannelAvatarURL = (RoomId) => {
const host = RCInstance.getHost();
return `${host}/avatar/${channelname}`;
const etag =
channelInfo && channelInfo.avatarETag
? `?etag=${channelInfo.avatarETag}`
: '';
const res = RCInstance.channelInfo();
const channelAvatarUrl = `${host}/avatar/room/${encodeURIComponent(
RoomId
)}${etag}`;
return channelAvatarUrl;
};

const handleGoBack = async () => {
if (isUserAuthenticated) {
getMessagesAndRoles();
Expand Down Expand Up @@ -369,7 +385,7 @@ const ChatHeader = ({
<Avatar
size="36px"
style={{ marginRight: '6px' }}
url={getChannelAvatarURL(channelInfo.name)}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question here

url={getChannelAvatarURL(RCInstance.rid)}
/>
<Box>
<Box
Expand Down
15 changes: 11 additions & 4 deletions packages/react/src/views/RoomInformation/RoomInformation.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useContext } from 'react';
import React, { useContext, useState } from 'react';
import { css } from '@emotion/react';
import {
Box,
Expand All @@ -21,9 +21,16 @@ const Roominfo = () => {
const { variantOverrides } = useComponentOverrides('RoomMember');
const viewType = variantOverrides.viewType || 'Sidebar';
const setExclusiveState = useSetExclusiveState();
const getChannelAvatarURL = (channelname) => {
const getChannelAvatarURL = (RoomId) => {
const host = RCInstance.getHost();
return `${host}/avatar/${channelname}`;
const etag =
channelInfo && channelInfo.avatarETag
? `?etag=${channelInfo.avatarETag}`
: '';
const channelAvatarUrl = `${host}/avatar/room/${encodeURIComponent(
RoomId
)}${etag}`;
return channelAvatarUrl;
};

const ViewComponent = viewType === 'Popup' ? Popup : Sidebar;
Expand Down Expand Up @@ -54,7 +61,7 @@ const Roominfo = () => {
justify-content: center;
`}
>
<Avatar size="100%" url={getChannelAvatarURL(channelInfo.name)} />
<Avatar size="100%" url={getChannelAvatarURL(RCInstance.rid)} />
</Box>
<Box css={styles.infoContainer}>
<Box css={styles.infoHeader}>
Expand Down