Skip to content
This repository was archived by the owner on Feb 27, 2023. It is now read-only.

Commit 1a56785

Browse files
guidotaJulieta11
andauthored
fix: channels feature integration (#557)
Co-authored-by: Julieta11 <millochjuli@gmail.com> Co-authored-by: Juli Milloch <42394626+Julieta11@users.noreply.github.com>
1 parent 88795bf commit 1a56785

13 files changed

Lines changed: 324 additions & 113 deletions

File tree

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
"dcl-catalyst-client": "^13.0.7",
8686
"dcl-quests-client": "^2.10.0",
8787
"dcl-scene-writer": "^1.1.2",
88-
"dcl-social-client": "^1.14.1",
88+
"dcl-social-client": "^1.14.2",
8989
"decentraland-ecs": "^6.0.4",
9090
"decentraland-rpc": "^3.1.9",
9191
"devtools-protocol": "0.0.615714",

packages/shared/chat/sagas.ts

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import { store } from 'shared/store/isolatedStore'
3131
import { waitForRendererInstance } from 'shared/renderer/sagas-helper'
3232
import { getUsedComponentVersions } from 'shared/rolloutVersions'
3333
import { SocialAPI } from 'dcl-social-client'
34-
import { joinOrCreateChannel, leaveChannel } from 'shared/friends/actions'
34+
import { joinOrCreateChannel, leaveChannel, sendChannelMessage } from 'shared/friends/actions'
3535

3636
interface IChatCommand {
3737
name: string
@@ -92,10 +92,12 @@ function* handleReceivedMessage(action: MessageReceived) {
9292
}
9393

9494
function* handleSendMessage(action: SendMessage) {
95-
const { body: message } = action.payload
95+
const { body: message, messageType, recipient } = action.payload
9696

9797
let entry: ChatMessage | null = null
9898

99+
// When there is a recipient, it means is a message sent to a channel
100+
const isChannel = messageType === ChatMessageType.PUBLIC && recipient
99101
// Check if message is a command
100102
if (message[0] === '/') {
101103
entry = handleChatCommand(message)
@@ -118,17 +120,35 @@ function* handleSendMessage(action: SendMessage) {
118120
} else {
119121
// If the message was not a command ("/cmdname"), then send message through wire
120122
const currentUserId = yield select(getCurrentUserId)
121-
if (!currentUserId) throw new Error('cannotGetCurrentUser')
122-
123-
entry = {
124-
messageType: ChatMessageType.PUBLIC,
125-
messageId: uuid(),
126-
timestamp: Date.now(),
127-
sender: currentUserId,
128-
body: message
123+
if (!currentUserId) {
124+
defaultLogger.error('Could not get the current user id.')
125+
trackEvent('error', {
126+
message: 'error trying to get the current user id.',
127+
context: 'kernel#chatSaga',
128+
stack: 'handleSendMessage'
129+
})
130+
return
131+
}
132+
if (isChannel) {
133+
entry = {
134+
messageType: ChatMessageType.PUBLIC,
135+
messageId: uuid(),
136+
sender: currentUserId,
137+
recipient,
138+
body: message,
139+
timestamp: Date.now()
140+
}
141+
yield put(sendChannelMessage(recipient, message))
142+
} else {
143+
entry = {
144+
messageType: ChatMessageType.PUBLIC,
145+
messageId: uuid(),
146+
timestamp: Date.now(),
147+
sender: currentUserId,
148+
body: message
149+
}
150+
sendPublicChatMessage(entry.messageId, entry.body)
129151
}
130-
131-
sendPublicChatMessage(entry.messageId, entry.body)
132152
}
133153

134154
yield call(waitForRendererInstance)
@@ -473,10 +493,8 @@ function initChatCommands() {
473493
}
474494
}
475495

476-
const ownId = client.getUserId()
477-
478496
// Join or create channel
479-
store.dispatch(joinOrCreateChannel(channelId, [ownId]))
497+
store.dispatch(joinOrCreateChannel(channelId, []))
480498

481499
return {
482500
messageId: uuid(),

packages/shared/friends/actions.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,8 @@ export type JoinOrCreateChannel = ReturnType<typeof joinOrCreateChannel>
3131
export const LEAVE_CHANNEL = 'Leave channel'
3232
export const leaveChannel = (channelId: string) => action(LEAVE_CHANNEL, { channelId })
3333
export type LeaveChannel = ReturnType<typeof leaveChannel>
34+
35+
export const SEND_CHANNEL_MESSAGE = '[Request] Send channel message'
36+
export const sendChannelMessage = (channelId: string, message: string) =>
37+
action(SEND_CHANNEL_MESSAGE, { channelId, message })
38+
export type SendChannelMessage = ReturnType<typeof sendChannelMessage>

0 commit comments

Comments
 (0)