Skip to content

Commit

Permalink
HF 30
Browse files Browse the repository at this point in the history
  • Loading branch information
1aerostorm committed Sep 13, 2024
1 parent dc5fd41 commit eb1958f
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 9 deletions.
16 changes: 14 additions & 2 deletions src/components/elements/messages/ConversationListItem/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ export default class ConversationListItem extends React.Component {
constructor(props) {
super(props);
this.state = {
avatarSrc: require('app/assets/images/user.png'),
//avatarSrc: require('app/assets/images/user.png'),
avatarSrc: null,
};
}

Expand Down Expand Up @@ -50,6 +51,17 @@ export default class ConversationListItem extends React.Component {
}
};

_renderAvatar = () => {
const defaultRender = (src) => {
return <img className='conversation-photo' src={src} alt={''} />
}
const { renderConversationAvatar } = this.props
if (!renderConversationAvatar) {
return defaultRender(this.state.avatarSrc)
}
return renderConversationAvatar(this.props.data, defaultRender)
}

render() {
const { selected } = this.props;
const { avatar, isSystemMessage, contact, last_message, size, unread_donate } = this.props.data;
Expand Down Expand Up @@ -89,7 +101,7 @@ export default class ConversationListItem extends React.Component {

return (
<Link to={isSystemMessage ? null : link} className={'conversation-list-item' + (selected ? ' selected' : '')}>
<img className='conversation-photo' src={this.state.avatarSrc} alt={''} />
{this._renderAvatar()}
<div className='conversation-info'>
<h1 className='conversation-title'>{contact}{checkmark}</h1>
<div className='conversation-snippet'>{last_body && truncate(last_body, {length: 30})}
Expand Down
3 changes: 2 additions & 1 deletion src/components/modules/messages/ConversationList/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import './ConversationList.css';
export default class ConversationList extends React.Component {
render() {
const { topLeft, topRight,
conversationSelected, conversationLinkPattern, onConversationSearch,
conversationSelected, conversationLinkPattern, renderConversationAvatar, onConversationSearch,
onConversationSelect,
isSmall } = this.props;
return (
Expand All @@ -26,6 +26,7 @@ export default class ConversationList extends React.Component {
data={conversation}
selected={conversationSelected === conversation.contact}
conversationLinkPattern={conversationLinkPattern}
renderConversationAvatar={renderConversationAvatar}
onConversationSelect={onConversationSelect}
/>
)
Expand Down
3 changes: 2 additions & 1 deletion src/components/modules/messages/Messenger/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default class Messages extends React.Component {

render() {
const { account, to, toNew,
contacts, conversationTopLeft, conversationTopRight, conversationLinkPattern,
contacts, conversationTopLeft, conversationTopRight, conversationLinkPattern, renderConversationAvatar,
onConversationSearch, onConversationSelect,
messagesTopLeft, messagesTopCenter, messagesTopRight, messages, renderMessages,
replyingMessage, onCancelReply, onSendMessage,
Expand Down Expand Up @@ -71,6 +71,7 @@ export default class Messages extends React.Component {
conversations={contacts}
conversationSelected={to}
conversationLinkPattern={conversationLinkPattern}
renderConversationAvatar={renderConversationAvatar}
onConversationSearch={onConversationSearch}
onConversationSelect={onConversationSelect}
/>
Expand Down
16 changes: 14 additions & 2 deletions src/components/pages/Messages.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import NotifiCounter from 'app/components/elements/NotifiCounter'
import DialogManager from 'app/components/elements/common/DialogManager'
import AddImageDialog from 'app/components/dialogs/AddImageDialog'
import ChatError from 'app/components/elements/messages/ChatError'
import LetteredAvatar from 'app/components/elements/messages/LetteredAvatar'
import PageFocus from 'app/components/elements/messages/PageFocus'
import { renderStubs } from 'app/components/elements/Stub'
import Userpic from 'app/components/elements/Userpic'
Expand Down Expand Up @@ -378,7 +379,10 @@ class Messages extends React.Component {
continue;
}
account.contact = account.name;
account.avatar = getProfileImage(account, this.cachedProfileImages);
const { url, isDefault } = getProfileImage(account, this.cachedProfileImages)
if (!isDefault) {
account.avatar = url
}
contacts.push(account);
}
if (contacts.length === 0) {
Expand Down Expand Up @@ -1032,6 +1036,14 @@ class Messages extends React.Component {
if (contact.kind === 'group') return '/*'
return '/@*'
}}
renderConversationAvatar={(contact, defaultRender) => {
if (contact.avatar) {
return defaultRender(contact.avatar)
}
return <span className='conversation-photo'>
<LetteredAvatar name={contact.contact} size={50} />
</span>
}}
onConversationSearch={this.onConversationSearch}
messages={this.state.messages}
messagesTopLeft={this._renderMessagesTopLeft()}
Expand Down Expand Up @@ -1205,7 +1217,7 @@ export default withRouter(connect(
}]]
}

if (!editInfo && !group) {
if (!editInfo) {
sendOffchainMessage(opData).catch(err => {
console.error('sendOffchainMessage', err)
if (notifyAbort) {
Expand Down
10 changes: 9 additions & 1 deletion src/utils/Normalizators.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,15 @@ export async function normalizeContacts(contacts, accounts, currentUser, cachedP
let messages = []
for (let contact of contactsCopy) {
let account = accounts && accounts[contact.contact];
contact.avatar = getProfileImageLazy(account, cachedProfileImages);

if (contact.kind === 'group') {
contact.avatar = require('app/assets/images/user.png')
} else {
const { url, isDefault } = getProfileImageLazy(account, cachedProfileImages)
if (!isDefault) {
contact.avatar = url
}
}

if (contact.last_message.create_date.startsWith('1970')) {
contact.last_message.message = { body: '', };
Expand Down
4 changes: 2 additions & 2 deletions src/utils/NormalizeProfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ export function getProfileImage(account, size = 48) {
if (url && /^(https?:)\/\//.test(url)) {
size = size > 75 ? '200x200' : '75x75';
url = proxifyImageUrl(url, size);
return url;
return { url }
}
}
} catch (e) {
console.error(e);
}
}
return require('app/assets/images/user.png');
return { url: require('app/assets/images/user.png'), isDefault: true }
}

/**
Expand Down

0 comments on commit eb1958f

Please sign in to comment.