Skip to content

Commit bcfaf41

Browse files
Merge pull request #267 from cabal-club/add-moderation-messages
Add moderation system messages
2 parents 7dc7d77 + c7e077c commit bcfaf41

File tree

6 files changed

+67
-36
lines changed

6 files changed

+67
-36
lines changed

app/actions.js

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,7 @@ const initializeCabal = ({ addr, username, settings }) => async dispatch => {
697697
]
698698
cabalDetailsEvents.forEach((event) => {
699699
cabalDetails.on(event.name, throttle((data) => {
700+
// console.log('Event', event.name, data)
700701
event.action(data)
701702
}), event.throttleDelay || 200, { leading: true, trailing: true })
702703
})
@@ -756,42 +757,43 @@ const generateUniqueName = () => {
756757
return `${randomItem(adjectives)}-${randomItem(nouns)}`
757758
}
758759

759-
export const moderationHide = ({ addr, channel, reason, userKey }) => async dispatch => {
760-
const cabalDetails = client.getDetails(addr)
761-
cabalDetails.moderation.hide([[userKey, reason]], { channel, reason } )
760+
export const moderationHide = (props) => async dispatch => {
761+
dispatch(moderationAction('hide', props))
762762
}
763763

764-
export const moderationUnhide = ({ addr, channel, reason, userKey }) => async dispatch => {
765-
const cabalDetails = client.getDetails(addr)
766-
cabalDetails.moderation.unhide([[userKey, reason]], { channel, reason } )
764+
export const moderationUnhide = (props) => async dispatch => {
765+
dispatch(moderationAction('unhide', props))
767766
}
768767

769-
export const moderationBlock = ({ addr, channel, reason, userKey }) => async dispatch => {
770-
const cabalDetails = client.getDetails(addr)
771-
cabalDetails.moderation.block([[userKey, reason]], { channel, reason } )
768+
export const moderationBlock = (props) => async dispatch => {
769+
dispatch(moderationAction('block', props))
772770
}
773771

774-
export const moderationUnblock = ({ addr, channel, reason, userKey }) => async dispatch => {
775-
const cabalDetails = client.getDetails(addr)
776-
cabalDetails.moderation.unblock([[userKey, reason]], { channel, reason } )
772+
export const moderationUnblock = (props) => async dispatch => {
773+
dispatch(moderationAction('unblock', props))
777774
}
778775

779-
export const moderationAddMod = ({ addr, channel, reason, userKey }) => async dispatch => {
780-
const cabalDetails = client.getDetails(addr)
781-
cabalDetails.moderation.addMod([[userKey, reason]], { channel, reason } )
776+
export const moderationAddMod = (props) => async dispatch => {
777+
dispatch(moderationAction('addMod', props))
782778
}
783779

784-
export const moderationRemoveMod = ({ addr, channel, reason, userKey }) => async dispatch => {
785-
const cabalDetails = client.getDetails(addr)
786-
cabalDetails.moderation.removeMod([[userKey, reason]], { channel, reason } )
780+
export const moderationRemoveMod = (props) => async dispatch => {
781+
dispatch(moderationAction('removeMod', props))
787782
}
788783

789-
export const moderationAddAdmin = ({ addr, channel, reason, userKey }) => async dispatch => {
790-
const cabalDetails = client.getDetails(addr)
791-
cabalDetails.moderation.addAdmin([[userKey, reason]], { channel, reason } )
784+
export const moderationAddAdmin = (props) => async dispatch => {
785+
dispatch(moderationAction('addAdmin', props))
786+
}
787+
788+
export const moderationRemoveAdmin = (props) => async dispatch => {
789+
dispatch(moderationAction('removeAdmin', props))
792790
}
793791

794-
export const moderationRemoveAdmin = ({ addr, channel, reason, userKey }) => async dispatch => {
792+
export const moderationAction = (action, { addr, channel, reason, userKey}) => async dispatch => {
795793
const cabalDetails = client.getDetails(addr)
796-
cabalDetails.moderation.removeAdmin([[userKey, reason]], { channel, reason } )
794+
await cabalDetails.moderation[action](userKey, { channel, reason })
795+
setTimeout(() => {
796+
const users = cabalDetails.getUsers()
797+
dispatch({ type: 'UPDATE_CABAL', addr, users })
798+
}, 500)
797799
}

app/containers/messages.js

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ function MessagesContainer (props) {
4545
</div>
4646
)
4747
} else {
48+
const defaultSystemName = 'Cabalbot'
4849
let prevMessage = {}
4950
return (
5051
<div className='messages'>
@@ -71,7 +72,6 @@ function MessagesContainer (props) {
7172
let item = (<div />)
7273
prevMessage = message
7374
if (message.type === 'status') {
74-
const defaultSystemName = 'Cabalbot'
7575
item = (
7676
<div className='messages__item messages__item--system'>
7777
<div className='messages__item__avatar'>
@@ -86,6 +86,35 @@ function MessagesContainer (props) {
8686
</div>
8787
)
8888
}
89+
if (message.type === 'chat/moderation') {
90+
const { role, type, issuerid, receiverid, reason } = message.content
91+
const issuer = props.getUsers({ addr: props.addr })[issuerid]
92+
const receiver = props.getUsers({ addr: props.addr })[receiverid]
93+
const issuerName = issuer && issuer.name ? issuer.name : issuerid.slice(0, 8)
94+
const receiverName = receiver && receiver.name ? receiver.name : receiverid.slice(0, 8)
95+
item = (
96+
<div className='messages__item messages__item--system'>
97+
<div className='messages__item__avatar'>
98+
<div className='messages__item__avatar__img'>
99+
<Avatar name={message.key || defaultSystemName} />
100+
</div>
101+
</div>
102+
<div className='messages__item__metadata'>
103+
<div className='messages__item__metadata__name'>{message.name || defaultSystemName}{renderDate(formattedTime)}</div>
104+
<div className='text'>
105+
Moderation:
106+
{role === 'hide' &&
107+
<span><span onClick={onClickProfile.bind(this, issuer)}>{issuerName}</span> {(type === 'add' ? 'hid' : 'unhid')} <span onClick={onClickProfile.bind(this, receiver)}>{receiverName}</span></span>}
108+
{role !== 'hide' &&
109+
<span><span onClick={onClickProfile.bind(this, issuer)}>{issuerName}</span> {(type === 'add' ? 'added' : 'removed')} <span onClick={onClickProfile.bind(this, receiver)}>{receiverName}</span> as {role}</span>}
110+
{!!reason &&
111+
<span>({reason})</span>
112+
}
113+
</div>
114+
</div>
115+
</div>
116+
)
117+
}
89118
if (message.type === 'chat/text') {
90119
item = (
91120
<div className='messages__item'>

app/containers/sidebar.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@ class SidebarScreen extends React.Component {
181181
const deduplicatedNicks = []
182182
users && users.forEach((user) => {
183183
const userIndex = deduplicatedNicks.findIndex((u) => u.name === user.name)
184-
if (user.name && userIndex > -1) {
184+
const moderated = user.isHidden || user.isAdmin || user.isModerator
185+
if (user.name && userIndex > -1 && !moderated) {
185186
deduplicatedNicks[userIndex].users.push(user)
186187
} else {
187188
deduplicatedNicks.push({
@@ -311,6 +312,7 @@ class SidebarScreen extends React.Component {
311312
const isAdmin = peer.users.some((u) => u.isAdmin())
312313
const isModerator = peer.users.some((u) => u.isModerator())
313314
const isHidden = peer.users.some((u) => u.isHidden())
315+
const name = isHidden ? peer.name.substring(0, 3) + peer.key.substring(0, 6) : peer.name
314316
return (
315317
<div
316318
key={index}
@@ -327,7 +329,7 @@ class SidebarScreen extends React.Component {
327329
</div>
328330
<div className={`collection__item__content ${(peer.online && !isHidden) ? 'active' : ''}`}>
329331
<span className='name'>
330-
{peer.name || peer.key.substring(0, 6)}
332+
{peer.name ? name : peer.key.substring(0, 6)}
331333
{peer.users.length > 1 && <span className='collection__item__count'>({peer.users.length})</span>}
332334
</span>
333335
{!isAdmin && !isModerator && isHidden && <span className='sigil hidden'>HIDDEN</span>}

app/styles/style.scss

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -949,8 +949,6 @@ form {
949949
border: 2px solid rgba(0, 0, 0, 0.25);
950950
border-radius: 3px;
951951
transition: all 0.1s ease-in-out;
952-
padding: .5rem 0;
953-
min-height: 48px;
954952

955953
&:hover, &:focus {
956954
border-color: rgba(0, 0, 0, 0.5);
@@ -967,13 +965,13 @@ form {
967965

968966
.composer__input {
969967
width: 100%;
970-
padding: 0 1rem;
971968
}
972969

973970
.composer__input form {
974971
width: 100%;
975972
display: flex;
976973
align-content: center;
974+
padding: 0.5rem;
977975
}
978976

979977
.composer__input textarea {
@@ -995,7 +993,7 @@ form {
995993
}
996994

997995
.composer__other {
998-
align-self: flex-end;
996+
align-self: center;
999997
display: table-cell;
1000998
width: 3rem;
1001999
height: 1.5rem;

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cabal-desktop",
3-
"version": "6.0.1",
3+
"version": "6.0.2",
44
"description": "Cabal p2p offline-first desktop application",
55
"scripts": {
66
"build": "cross-env NODE_ENV=production webpack",
@@ -51,7 +51,7 @@
5151
"@babel/runtime": "^7.7.7",
5252
"@reduxjs/toolkit": "^1.3.5",
5353
"babel-runtime": "^6.26.0",
54-
"cabal-client": "^6.0.0",
54+
"cabal-client": "6.1.0",
5555
"collect-stream": "^1.2.1",
5656
"dat-encoding": "^5.0.1",
5757
"debug": "^4.1.1",

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2359,10 +2359,10 @@ bulk-write-stream@^1.1.3:
23592359
inherits "^2.0.1"
23602360
readable-stream "^2.1.4"
23612361

2362-
cabal-client@^6.0.0:
2363-
version "6.0.0"
2364-
resolved "https://registry.yarnpkg.com/cabal-client/-/cabal-client-6.0.0.tgz#081f64f839116e681447dbeb5ac72ee5c649945a"
2365-
integrity sha512-Fb357yv3TzcEH0fX1crtx2m4Ua+WF0HqFznnu9mEZUaGk8BCKv9Sk+g2QXc2BdqJ59mjlTRvflFio1UzFzfqJw==
2362+
cabal-client@6.1.0:
2363+
version "6.1.0"
2364+
resolved "https://registry.yarnpkg.com/cabal-client/-/cabal-client-6.1.0.tgz#5e350c836d5c46bbf55ef032897ed8dd948531e7"
2365+
integrity sha512-y/8CJBR4+f8MIdwXCfKevYzkV7Jdnb19WDixFValn6U180zKIA4dWkoWaD0B1Kr9PNy2bKLT1/ixG2Tsn76e/g==
23662366
dependencies:
23672367
cabal-core "^13.0.0"
23682368
collect-stream "^1.2.1"

0 commit comments

Comments
 (0)