Skip to content

Commit

Permalink
HF 30 - Private groups - Mentions, fix mark messages
Browse files Browse the repository at this point in the history
  • Loading branch information
1aerostorm committed Oct 17, 2024
1 parent 71e93e2 commit 11b7d29
Show file tree
Hide file tree
Showing 10 changed files with 147 additions and 61 deletions.
3 changes: 3 additions & 0 deletions src/components/modules/groups/GroupMembers.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import AccountName from 'app/components/elements/common/AccountName'
import Input from 'app/components/elements/common/Input';
import GroupMember from 'app/components/elements/groups/GroupMember'
import LoadingIndicator from 'app/components/elements/LoadingIndicator'
import MarkNotificationRead from 'app/components/elements/MarkNotificationRead'
import { getRoleInGroup, getGroupMeta, getGroupTitle } from 'app/utils/groups'

export async function validateMembersStep(values, errors) {
Expand Down Expand Up @@ -253,6 +254,8 @@ class GroupMembers extends React.Component {
{this._renderMemberTypeSwitch()}
</div>
</div>}
{(username && showPendings) ? <MarkNotificationRead fields='join_request' account={username}
/> : null}
</div>
}

Expand Down
5 changes: 5 additions & 0 deletions src/components/modules/groups/MyGroups.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import user from 'app/redux/UserReducer'
import DropdownMenu from 'app/components/elements/DropdownMenu'
import Icon from 'app/components/elements/Icon'
import LoadingIndicator from 'app/components/elements/LoadingIndicator'
import MarkNotificationRead from 'app/components/elements/MarkNotificationRead'
import { showLoginDialog } from 'app/components/dialogs/LoginDialog'
import { getGroupLogo, getGroupMeta, getRoleInGroup } from 'app/utils/groups'

Expand Down Expand Up @@ -244,13 +245,17 @@ class MyGroups extends React.Component {
</div>
}

const { username } = this.props

return <div className='MyGroups'>
<div className='row'>
<h3>{tt('my_groups_jsx.title')}</h3>
</div>
{button}
{groups}
{hasGroups ? <div style={{ height: '50px' }}></div> : null}
{username ? <MarkNotificationRead fields='group_member' account={username}
/> : null}
</div>
}
}
Expand Down
93 changes: 63 additions & 30 deletions src/components/pages/Messages.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import g from 'app/redux/GlobalReducer'
import transaction from 'app/redux/TransactionReducer'
import user from 'app/redux/UserReducer'
import { getRoleInGroup, opGroup } from 'app/utils/groups'
import { parseMentions } from 'app/utils/mentions'
import { getProfileImage, } from 'app/utils/NormalizeProfile';
import { normalizeContacts, normalizeMessages, cacheMyOwnMsg } from 'app/utils/Normalizators';
import { fitToPreview } from 'app/utils/ImageUtils';
Expand All @@ -53,7 +54,7 @@ class Messages extends React.Component {
};
this.cachedProfileImages = {};
this.windowFocused = true;
this.newMessages = 0;
this.newMessages = {}
if (process.env.MOBILE_APP) {
this.stopService()
}
Expand All @@ -71,47 +72,70 @@ class Messages extends React.Component {
return the_group ? the_group.name : ''
}

markMessages() {
const { messages } = this.state;
if (!messages.length) return;
markMessages = () => {
const { messages } = this.props
if (!messages || !messages.size) return

const msgs = messages.toJS()

const { account, accounts, } = this.props;
const to = this.getToAcc()

let OPERATIONS = golos.messages.makeDatedGroups(messages, (message_object, idx) => {
return message_object.toMark && !message_object._offchain;
const isGroup = this.isGroup()

let OPERATIONS = golos.messages.makeDatedGroups(msgs, (msg, idx) => {
if (msg._offchain) return false
if (msg.read_date.startsWith('19')) {
if (!isGroup) {
return msg.to === account.name
} else {
if (msg.to === account.name) return true
}
}
if (isGroup && msg.mentions.includes(account.name)) {
return true
}
return false
}, (group, indexes, results) => {
const json = JSON.stringify(['private_mark_message', {
from: accounts[to].name,
to: account.name,
const op = {
from: isGroup ? '' : accounts[to].name,
to: isGroup ? '' : account.name,
...group,
}]);
}
if (isGroup) {
op.extensions = [[0, {
group: to,
requester: account.name,
}]]
}
const json = JSON.stringify(['private_mark_message', op])
return ['custom_json',
{
id: 'private_message',
required_posting_auths: [account.name],
json,
}
];
}, messages.length - 1, -1);
}, 0, msgs.length);

this.props.sendOperations(account, accounts[to], OPERATIONS);
}

markMessages2 = debounce(this.markMessages, 1000);
markMessages2 = debounce(this.markMessages, 1000)

flashMessage() {
++this.newMessages;
flashMessage(nonce) {
this.newMessages[nonce] = true

let title = this.newMessages;
const plural = this.newMessages % 10;
const count = Object.keys(this.newMessages).length
let title = count
const plural = count % 10

if (plural === 1) {
if (this.newMessages === 11)
if (count === 11)
title += tt('messages.new_message5');
else
title += tt('messages.new_message1');
} else if ((plural === 2 || plural === 3 || plural === 4) && (this.newMessages < 10 || this.newMessages > 20)) {
} else if ((plural === 2 || plural === 3 || plural === 4) && (count < 10 || count > 20)) {
title += tt('messages.new_message234');
} else {
title += tt('messages.new_message5');
Expand Down Expand Up @@ -220,18 +244,20 @@ class Messages extends React.Component {
//alert(scope + ' ' + type + op +' ' + timestamp)
const isDonate = type === 'donate'
const toAcc = this.getToAcc()
const group = opGroup(op)
const { group } = opGroup(op)
let updateMessage = group === this.state.to || (!group && (op.from === toAcc ||
op.to === toAcc))
const isMine = username === op.from;
if (type === 'private_message') {
if (op.update) {
this.props.messageEdited(op, timestamp, updateMessage, isMine);
} else if (this.nonce !== op.nonce) {
} else {
this.props.messaged(op, timestamp, updateMessage, isMine);
this.nonce = op.nonce
if (!isMine && !this.windowFocused) {
this.flashMessage();
if (this.nonce !== op.nonce) {
this.nonce = op.nonce
if (!isMine && !this.windowFocused) {
this.flashMessage(op.nonce)
}
}
}
} else if (type === 'private_delete_message') {
Expand Down Expand Up @@ -357,6 +383,7 @@ class Messages extends React.Component {
}
updateData()
}
this.markMessages2()
}

componentWillUnmount() {
Expand Down Expand Up @@ -808,7 +835,7 @@ class Messages extends React.Component {
<Icon name="new/more" />
</div>
<div className='TopRightMenu__notificounter'>
<NotifiCounter fields='mention,donate,send,receive,fill_order,delegate_vs,new_sponsor,sponsor_inactive,nft_receive,nft_token_sold,nft_buy_offer,referral' />
<NotifiCounter fields='mention,donate,send,receive,fill_order,delegate_vs,new_sponsor,sponsor_inactive,nft_receive,nft_token_sold,nft_buy_offer,referral,join_request,group_member' />
</div>
</div>
</a>
Expand Down Expand Up @@ -864,7 +891,7 @@ class Messages extends React.Component {
}

let user_menu = [
{link: '#', onClick: openMyGroups, icon: 'voters', value: tt('g.groups') + (isSmall ? (' @' + username) : '') },
{link: '#', onClick: openMyGroups, icon: 'voters', value: tt('g.groups') + (isSmall ? (' @' + username) : ''), addon: <NotifiCounter fields='join_request,group_member' /> },
{link: accountLink, extLink: 'blogs', icon: 'new/blogging', value: tt('g.blog'), addon: <NotifiCounter fields='new_sponsor,sponsor_inactive,referral' />},
{link: mentionsLink, extLink: 'blogs', icon: 'new/mention', value: tt('g.mentions'), addon: <NotifiCounter fields='mention' />},
{link: donatesLink, extLink: 'wallet', icon: 'editor/coin', value: tt('g.rewards'), addon: <NotifiCounter fields='donate' />},
Expand Down Expand Up @@ -906,7 +933,7 @@ class Messages extends React.Component {
<div className='msgs-curruser-notify-sink'>
<Userpic account={username} title={isSmall ? username : null} width={40} height={40} />
<div className='TopRightMenu__notificounter'>
<NotifiCounter fields='mention,donate,send,receive,fill_order,delegate_vs,new_sponsor,sponsor_inactive,nft_receive,nft_token_sold,nft_buy_offer,referral' />
<NotifiCounter fields='mention,donate,send,receive,fill_order,delegate_vs,new_sponsor,sponsor_inactive,nft_receive,nft_token_sold,nft_buy_offer,referral,join_request,group_member' />
</div>
</div>
{!isSmall ? <div className='msgs-curruser-name'>
Expand Down Expand Up @@ -953,11 +980,11 @@ class Messages extends React.Component {
handleFocusChange = isFocused => {
this.windowFocused = isFocused;
if (!isFocused) {
if (this.newMessages) {
if (Object.keys(this.newMessages).length) {
flash();
}
} else {
this.newMessages = 0;
this.newMessages = {}
unflash();
}
}
Expand Down Expand Up @@ -1191,6 +1218,11 @@ export default withRouter(connect(
message = {...message, ...replyingMessage};
}

let mentions = []
if (group) {
mentions = parseMentions(message)
}

let data = null
try {
data = await golos.messages.encodeMsg({ group,
Expand All @@ -1214,7 +1246,6 @@ export default withRouter(connect(
update: editInfo ? true : false,
encrypted_message: data.encrypted_message,
}
//alert(JSON.stringify(opData))

if (group) {
let requester
Expand All @@ -1226,9 +1257,11 @@ export default withRouter(connect(

opData.extensions = [[0, {
group: group.name,
requester
requester,
mentions
}]]
}
//alert(JSON.stringify(opData))

cacheMyOwnMsg(opData, group, message)

Expand Down
3 changes: 3 additions & 0 deletions src/redux/FetchDataSaga.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,9 @@ export function* fetchMyGroups({ payload: { account } }) {
}
})
groups = [...groupsOwn, ...groups]
groups.sort((a, b) => {
return b.pendings - a.pendings
})

yield put(g.actions.receiveMyGroups({ groups }))
} catch (err) {
Expand Down
16 changes: 7 additions & 9 deletions src/redux/GlobalReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@ export default createModule({
message.donates = '0.000 GOLOS'
message.donates_uia = 0
}
const group = opGroup(message)
const { group, mentions } = opGroup(message)
message.group = group
message.mentions = mentions

let new_state = state;
let messages_update = message.nonce;
Expand Down Expand Up @@ -199,15 +200,14 @@ export default createModule({
) => {
let new_state = state;
let messages_update = message.nonce || Math.random();
const { requester } = opGroup(message)
if (updateMessage) {
new_state = new_state.updateIn(['messages'],
List(),
messages => {
return processDatedGroup(message, messages, (messages, idx) => {
let msg = messages.get(idx)
return processDatedGroup(message, messages, (msg, idx) => {
msg = msg.set('read_date', timestamp)
const msgs = messages.set(idx, msg)
return { msgs }
return { updated: msg }
});
});
}
Expand Down Expand Up @@ -260,10 +260,8 @@ export default createModule({
new_state = new_state.updateIn(['messages'],
List(),
messages => {
return processDatedGroup(message, messages, (messages, idx) => {
let msg = messages.get(idx)
const msgs = messages.delete(idx)
return { msgs, fixIdx: idx - 1 }
return processDatedGroup(message, messages, (msg, idx) => {
return { updated: null, fixIdx: idx - 1 }
});
})
}
Expand Down
4 changes: 3 additions & 1 deletion src/redux/TransactionSaga.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,16 @@ function* preBroadcast_custom_json({operation}) {
const idx = msgs.findIndex(i => i.get('nonce') === json[1].nonce);
if (idx === -1) {
let group = ''
let mentions = []
const exts = json[1].extensions || []
for (const [key, val ] of exts) {
if (key === 0) {
group = val.group
mentions = val.mentions
break
}
}
const newMsg = messageOpToObject(json[1], group)
const newMsg = messageOpToObject(json[1], group, mentions)
msgs = msgs.insert(0, fromJS(newMsg))
} else {
messages_update = json[1].nonce;
Expand Down
26 changes: 19 additions & 7 deletions src/utils/MessageUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,20 @@ export function displayQuoteMsg(body) {
}

export function processDatedGroup(group, messages, for_each) {
let deleteIt
if (group.nonce) {
const idx = messages.findIndex(i => i.get('nonce') === group.nonce);
if (idx !== -1) {
messages = messages.update(idx, (msg) => {
return for_each(msg, idx);
});
const { updated, fixIdx } = for_each(msg, idx)
if (!updated) {
deleteIt = idx
}
return updated || msg
})
if (deleteIt !== undefined) {
messages = messages.delete(idx)
}
}
} else {
let inRange = false;
Expand All @@ -26,15 +34,19 @@ export function processDatedGroup(group, messages, for_each) {
break;
}
if (inRange) {
const updated = for_each(messages, idx)
if (updated) {
const { msgs, fixIdx } = updated
if (msgs) {
messages = msgs
deleteIt = undefined
messages = messages.update(idx, (msg) => {
const { updated, fixIdx } = for_each(msg, idx)
if (!updated) {
deleteIt = idx
}
if (fixIdx !== undefined) {
idx = fixIdx
}
return updated || msg
})
if (deleteIt !== undefined) {
messages = messages.delete(idx)
}
}
}
Expand Down
Loading

0 comments on commit 11b7d29

Please sign in to comment.