Skip to content

Commit

Permalink
HF 30 - Private groups - ability to view group
Browse files Browse the repository at this point in the history
  • Loading branch information
1aerostorm committed Jul 21, 2024
1 parent e3ac7e6 commit bdb9b8a
Show file tree
Hide file tree
Showing 11 changed files with 124 additions and 25 deletions.
15 changes: 12 additions & 3 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const cors = require('@koa/cors')
const coBody = require('co-body')
const config = require('config')
const git = require('git-rev-sync')
const fs = require('fs')
const path = require('path')
const { convertEntriesToArrays, } = require('./utils/misc')

Expand Down Expand Up @@ -70,14 +71,22 @@ if (env === 'production') {
}

if (env === 'production') {
const buildPath = path.join(__dirname, '../build')
app.use(async (ctx, next) => {
if (ctx.path.startsWith('/@')) {
ctx.url = '/'
const parts = ctx.path.split('/')
// /
// /@user
// /group
if (parts.length === 2 && parts[1] !== 'api') {
const filePath = path.join(buildPath, parts[1])
if (!fs.existsSync(filePath)) {
ctx.url = '/'
}
}
await next()
})
const cacheOpts = { maxage: 0, gzip: true }
app.use(static(path.join(__dirname, '../build'), cacheOpts))
app.use(static(buildPath, cacheOpts))
}

app.use(router.routes())
Expand Down
1 change: 1 addition & 0 deletions src/assets/icons/golos.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/components/elements/Icon.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const icons = new Map([
// ['clock', require('app/assets/icons/clock.svg')],
// ['copy', require('app/assets/icons/copy.svg')],
// ['extlink', require('app/assets/icons/extlink.svg')],
// ['golos', require('app/assets/icons/golos.svg')],
['golos', require('app/assets/icons/golos.svg')],
['dropdown-arrow', require('app/assets/icons/dropdown-arrow.svg')],
// ['printer', require('app/assets/icons/printer.svg')],
// ['search', require('app/assets/icons/search.svg')],
Expand Down
6 changes: 6 additions & 0 deletions src/components/elements/messages/ChatError/ChatError.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.ChatError {
position: absolute;
top: 50%;
transform: translateX(-50%) translateY(-50%);
left: 50%;
}
18 changes: 18 additions & 0 deletions src/components/elements/messages/ChatError/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react'
import tt from 'counterpart'

import Icon from 'app/components/elements/Icon'
import './ChatError.scss'

class ChatError extends React.Component {
render() {
const { isGroup } = this.props
return <div className='ChatError'>
<center><Icon name='golos' size='3x' /></center>
<h5 style={{ marginTop: '0.5rem' }}>{isGroup ? tt('msgs_chat_error.404_group') : tt('msgs_chat_error.404_acc')}</h5>
<div>{tt('msgs_chat_error.404_but')}</div>
</div>
}
}

export default ChatError
10 changes: 9 additions & 1 deletion src/components/modules/messages/MessageList/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,15 @@ export default class MessageList extends React.Component {
}

renderMessages = () => {
const { to, renderEmpty, messages, selectedMessages, onMessageSelect } = this.props;
const { to, renderEmpty, renderMessages, messages, selectedMessages, onMessageSelect } = this.props;

let renderRes = false
if (renderMessages) {
renderRes = renderMessages({})
}
if (renderRes !== false) {
return renderRes
}

if (!to && renderEmpty) {
return renderEmpty()
Expand Down
6 changes: 4 additions & 2 deletions src/components/modules/messages/Messenger/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ export default class Messages extends React.Component {
}

render() {
const { account, to,
const { account, to, toNew,
contacts, conversationTopLeft, conversationTopRight, conversationLinkPattern,
onConversationSearch, onConversationSelect,
messagesTopLeft, messagesTopCenter, messagesTopRight, messages, replyingMessage, onCancelReply, onSendMessage,
messagesTopLeft, messagesTopCenter, messagesTopRight, messages, renderMessages,
replyingMessage, onCancelReply, onSendMessage,
onButtonImageClicked, onImagePasted,
selectedMessages, onMessageSelect, onPanelDeleteClick, onPanelReplyClick, onPanelEditClick, onPanelCloseClick,
composeRef
Expand Down Expand Up @@ -86,6 +87,7 @@ export default class Messages extends React.Component {
if ((localStorage.getItem('msgr_auth') && !account) || process.env.MOBILE_APP) return null
return <StartPanel />
}}
renderMessages={renderMessages}
messages={messages}
replyingMessage={replyingMessage}
onCancelReply={onCancelReply}
Expand Down
48 changes: 39 additions & 9 deletions src/components/pages/Messages.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import MarkNotificationRead from 'app/components/elements/MarkNotificationRead'
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 PageFocus from 'app/components/elements/messages/PageFocus'
import TimeAgoWrapper from 'app/components/elements/TimeAgoWrapper'
import Userpic from 'app/components/elements/Userpic'
Expand Down Expand Up @@ -56,11 +57,18 @@ class Messages extends React.Component {
this.composeRef = React.createRef()
}

getToAcc = () => {
let { to } = this.props
if (to) to = to.replace('@', '')
return to
}

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

const { account, accounts, to } = this.props;
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;
Expand Down Expand Up @@ -390,7 +398,8 @@ class Messages extends React.Component {

onSendMessage = (message, event) => {
if (!message.length) return;
const { to, account, accounts, currentUser, messages } = this.props;
const { account, accounts, currentUser, messages } = this.props;
const to = this.getToAcc()
const private_key = currentUser.getIn(['private_keys', 'memo_private']);

let editInfo;
Expand Down Expand Up @@ -480,7 +489,8 @@ class Messages extends React.Component {
onPanelDeleteClick = (event) => {
const { messages } = this.state;

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

// TODO: works wrong if few messages have same create_time
/*let OPERATIONS = golos.messages.makeDatedGroups(messages, (message_object, idx) => {
Expand Down Expand Up @@ -597,7 +607,8 @@ class Messages extends React.Component {
if (!url)
return;

const { to, account, accounts, currentUser, messages } = this.props;
const { account, accounts, currentUser, messages } = this.props;
const to = this.getToAcc()
const private_key = currentUser.getIn(['private_keys', 'memo_private']);
this.props.sendMessage({
senderAcc: account, memoKey: private_key, toAcc: accounts[to],
Expand Down Expand Up @@ -746,7 +757,8 @@ class Messages extends React.Component {

_renderMessagesTopCenter = ({ isSmall }) => {
let messagesTopCenter = [];
const { to, accounts } = this.props;
const { accounts } = this.props;
const to = this.getToAcc()
if (accounts[to]) {
let checkmark
if (to === 'notify') {
Expand Down Expand Up @@ -862,6 +874,21 @@ class Messages extends React.Component {
</LinkWithDropdown>);
};

_renderMessages = ({ }) => {
const { to, the_group, accounts } = this.props

if (to) {
const isGroup = !to.startsWith('@')
if (isGroup && the_group === null) {
return <ChatError isGroup={isGroup} />
} else if (!isGroup && !accounts[this.getToAcc()]) {
return <ChatError isGroup={isGroup} />
}
}

return false
}

handleFocusChange = isFocused => {
this.windowFocused = isFocused;
if (!isFocused) {
Expand Down Expand Up @@ -915,7 +942,7 @@ class Messages extends React.Component {
}

render() {
const { contacts, account, to, nodeError } = this.props;
const { contacts, account, to, the_group, nodeError } = this.props;
let bbc, auc
if (process.env.MOBILE_APP) {
bbc = <BackButtonController goHome={!to} />
Expand All @@ -934,6 +961,8 @@ class Messages extends React.Component {
conversationTopLeft={this._renderConversationTopLeft}
/>
</div>);
const toAcc = this.getToAcc()

return (
<div>
{bbc}
Expand All @@ -946,7 +975,7 @@ class Messages extends React.Component {
</PageFocus>
{Messenger ? (<Messenger
account={this.props.account}
to={to}
to={toAcc}
contacts={this.state.searchContacts || this.state.contacts}
conversationTopLeft={this._renderConversationTopLeft}
conversationTopRight={this._renderConversationTopRight}
Expand All @@ -956,6 +985,7 @@ class Messages extends React.Component {
messagesTopLeft={this._renderMessagesTopLeft()}
messagesTopCenter={this._renderMessagesTopCenter}
messagesTopRight={this._renderMessagesTopRight}
renderMessages={this._renderMessages}
replyingMessage={this.state.replyingMessage}
onCancelReply={this.onCancelReply}
onSendMessage={this.onSendMessage}
Expand Down Expand Up @@ -987,7 +1017,6 @@ export default withRouter(connect(
const username = state.user.getIn(['current', 'username'])

let to = ownProps.match.params.to
if (to) to = to.replace('@', '')

let memo_private = null
if (currentUser) {
Expand All @@ -1001,6 +1030,7 @@ export default withRouter(connect(
contacts: contacts,
messages: messages,
messages_update,
the_group: state.global.get('the_group'),
account: currentUser && accounts && accounts.toJS()[currentUser.get('username')],
currentUser,
memo_private,
Expand Down Expand Up @@ -1035,7 +1065,7 @@ export default withRouter(connect(
showMyGroups: () => dispatch(user.actions.showMyGroups()),

fetchState: (to) => {
const pathname = '/' + (to ? ('@' + to) : '');
const pathname = '/' + (to || '')
dispatch({type: 'FETCH_STATE', payload: {
location: {
pathname
Expand Down
5 changes: 5 additions & 0 deletions src/locales/ru-RU.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@
"start_chat": "Начать чат",
"create_group": "Создать группу"
},
"msgs_chat_error": {
"404_group": "Такой группы у нас нет",
"404_acc": "Такого пользователя нет",
"404_but": "Но у нас есть много интересного..."
},
"create_group_jsx": {
"title": "Название",
"name": "Ссылка chat.golos.app/",
Expand Down
36 changes: 27 additions & 9 deletions src/redux/FetchDataSaga.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,33 @@ export function* fetchState(location_change_action) {
state.contacts = yield callSafe(state, [], 'getContactsAsync', [api, api.getContactsAsync], account, 'unknown', 100, 0)
if (hasErr) return

if (parts[1]) {
const to = parts[1].replace('@', '');
accounts.add(to);

state.messages = yield callSafe(state, [], 'getThreadAsync', [api, api.getThreadAsync], account, to, {});
if (hasErr) return

if (state.messages.length) {
state.messages_update = state.messages[state.messages.length - 1].nonce;
const path = parts[1]
if (path) {
if (path.startsWith('@')) {
const to = path.replace('@', '');
accounts.add(to);

state.messages = yield callSafe(state, [], 'getThreadAsync', [api, api.getThreadAsync], account, to, {});
if (hasErr) return

if (state.messages.length) {
state.messages_update = state.messages[state.messages.length - 1].nonce;
}
} else {
let the_group = yield callSafe(state, [], 'getGroupsAsync', [api, api.getGroupsAsync], {
start_group: path,
limit: 1,
with_members: {
accounts: [account]
}
})
if (hasErr) return
if (the_group[0] && the_group[0].name === path) {
the_group = the_group[0]
} else {
the_group = null
}
state.the_group = the_group
}
}
for (let contact of state.contacts) {
Expand Down
2 changes: 2 additions & 0 deletions src/utils/Normalizators.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ export function normalizeContacts(contacts, accounts, currentUser, preDecoded, c
}

export function normalizeMessages(messages, accounts, currentUser, to, preDecoded) {
if (to) to = to.replace('@', '')

if (!to || !accounts[to]) {
return [];
}
Expand Down

0 comments on commit bdb9b8a

Please sign in to comment.