Skip to content

Commit

Permalink
HF 30 - Private groups - Avatars
Browse files Browse the repository at this point in the history
  • Loading branch information
1aerostorm committed Sep 5, 2024
1 parent 67201a4 commit 51a90de
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 9 deletions.
14 changes: 9 additions & 5 deletions src/components/elements/messages/Compose/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,15 @@ export default class Compose extends React.Component {

const selectedMessages = Object.entries(this.props.selectedMessages);
let selectedMessagesCount = 0;
let selectedEditablesCount = 0;
let selectedEditables = 0
let selectedDeletables = 0
for (let [nonce, info] of selectedMessages) {
selectedMessagesCount++;
if (info.editable) {
selectedEditablesCount++;
selectedEditables++;
}
if (info.deletable) {
selectedDeletables++
}
}

Expand Down Expand Up @@ -271,11 +275,11 @@ export default class Compose extends React.Component {
<Icon name='cross' />
<span>{tt('g.cancel')}</span>
</button>
<button className='button hollow small alert delete-button' onClick={onPanelDeleteClick}>
{selectedDeletables === selectedMessagesCount ? <button className='button hollow small alert delete-button' onClick={onPanelDeleteClick}>
<Icon name='ionicons/trash-outline' />
<span>{tt('g.delete') + ' (' + selectedMessagesCount + ')'}</span>
</button>
{(selectedMessagesCount === 1 && selectedEditablesCount === 1) ? (<button className='button hollow small edit-button' onClick={onPanelEditClick}>
</button> : null}
{(selectedMessagesCount === 1 && selectedEditables === 1) ? (<button className='button hollow small edit-button' onClick={onPanelEditClick}>
<Icon name='pencil' />
<span>{tt('g.edit')}</span>
</button>) : null}
Expand Down
5 changes: 5 additions & 0 deletions src/components/elements/messages/Message/Message.css
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
display: flex;
}

.msgs-message .bubble-container .avatar {
width: 42px;
margin-top: 14px;
}

.msgs-message .bubble-container a {
color: #007aff;
text-decoration: underline;
Expand Down
14 changes: 13 additions & 1 deletion src/components/elements/messages/Message/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import tt from 'counterpart';
import { Asset } from 'golos-lib-js/lib/utils'

import Donating from 'app/components/elements/messages/Donating'
import Userpic from 'app/components/elements/Userpic'
import { displayQuoteMsg } from 'app/utils/MessageUtils';
import { proxifyImageUrl } from 'app/utils/ProxifyUrl';
import './Message.css';
Expand Down Expand Up @@ -36,7 +37,7 @@ export default class Message extends React.Component {

const unread = data.unread ? (<div className={'unread' + loading}></div>) : null;

const { message } = data;
const { message, group, from} = data;

let content;
if (message.type === 'image') {
Expand Down Expand Up @@ -100,6 +101,16 @@ export default class Message extends React.Component {
adds.unshift(unread)
}

let avatar
if (!isMine && group) {
if (startsSequence) {
avatar = <Userpic account={from} title={'@' + from} width={32} height={32} />
}
avatar = <div className='avatar'>
{avatar}
</div>
}

return (
<div className={[
'msgs-message',
Expand All @@ -115,6 +126,7 @@ export default class Message extends React.Component {
}

<div className={'bubble-container' + (selected ? ' selected' : '')}>
{avatar}
{isMine ? adds : null}
<div className={'bubble' + loading} onClick={(event) => this.onMessageSelect(idx, event)} title={friendlyDate + (modified ? tt('g.modified') : '')}>
{ quoteHeader }
Expand Down
20 changes: 18 additions & 2 deletions src/components/pages/Messages.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import MessagesTopCenter from 'app/components/modules/MessagesTopCenter'
import g from 'app/redux/GlobalReducer'
import transaction from 'app/redux/TransactionReducer'
import user from 'app/redux/UserReducer'
import { getRoleInGroup } from 'app/utils/groups'
import { getProfileImage, } from 'app/utils/NormalizeProfile';
import { normalizeContacts, normalizeMessages } from 'app/utils/Normalizators';
import { fitToPreview } from 'app/utils/ImageUtils';
Expand Down Expand Up @@ -447,7 +448,20 @@ class Messages extends React.Component {
let selectedMessages = {...this.state.selectedMessages};

let selectMessage = (msg, idx) => {
const isMine = account.name === msg.from;
const isMine = account.name === msg.from
let canIEdit = isMine
let canIDelete = true
if (this.isGroup()) {
const { the_group } = this.props
const { amModer, amMember, amBanned } = getRoleInGroup(the_group, account.name)
if (amModer) {
canIEdit = true
} else if (amBanned || (the_group.privacy !== 'public_group' && !amModer && !amMember)) {
canIEdit = false
}
canIDelete = canIEdit
}

let isImage = false;
let isInvalid = true;
const { message } = msg;
Expand All @@ -456,7 +470,9 @@ class Messages extends React.Component {
isInvalid = !!message.invalid;
}
selectedMessages[msg.nonce] = {
editable: isMine && !isImage && !isInvalid, idx };
editable: canIEdit && !isImage && !isInvalid,
deletable: canIDelete,
idx };
};

if (event.shiftKey) {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/Normalizators.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export async function normalizeMessages(messages, accounts, currentUser, to) {
}
}
}
msg.decrypt_date = null
//msg.decrypt_date = null

if (loadFromCache(msg)) {
results.push(msg)
Expand Down

0 comments on commit 51a90de

Please sign in to comment.