Skip to content

Commit

Permalink
fized message bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Tzikas committed Jun 24, 2021
1 parent 79b05e5 commit faa545f
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 33 deletions.
8 changes: 4 additions & 4 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ DEV_ELECTRON_WEBPACK_APP_JITSI_URL=https://jitsi.local.cowbell.club:8443
#ELECTRON_WEBPACK_APP_API_URL=https://local.plshelp.live:5001
#ELECTRON_WEBPACK_APP_JITSI_URL=https://jitsi.local.plshelp.live:8443

#ELECTRON_WEBPACK_APP_API_URL=https://local.cowbell.club:5001
#ELECTRON_WEBPACK_APP_JITSI_URL=https://jitsi.local.cowbell.club:8443
ELECTRON_WEBPACK_APP_API_URL=https://local.cowbell.club:5001
ELECTRON_WEBPACK_APP_JITSI_URL=https://jitsi.local.cowbell.club:8443

ELECTRON_WEBPACK_APP_API_URL=https://cowbell.club
ELECTRON_WEBPACK_APP_JITSI_URL=https://jitsi.cowbell.club
#ELECTRON_WEBPACK_APP_API_URL=https://cowbell.club
#ELECTRON_WEBPACK_APP_JITSI_URL=https://jitsi.cowbell.club

ELECTRON_WEBPACK_APP_VAPID_PUBLICKEY=BG2QxzujwzP60oqKoT0ZxArqtcI-d1k6CWjhFrfdd2HWh7SLQDAyYjavm7cfvVrkzd_2pMRBcOuPVDpWaB_vKYk
3 changes: 3 additions & 0 deletions frontend/src/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ const actions = {

saveReaction: async (emojis, messageId) => {
return await API.post(`/save-reaction?messageId=${messageId}`, emojis, resetHead())
},
findPreviousChat: async (users) => {
return await API.post(`/find-previous-chat`, users, resetHead())
}

}
Expand Down
55 changes: 27 additions & 28 deletions frontend/src/components/NewMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function NewMessage(props) {
const { user, history } = useContext(TheContext)
const refInput = useRef();

const [channel, setChannel] = useState({ message: '' })
const [channel, setChannel] = useState(null)
const [allUsers, setAllUsers] = useState([])
const [selectedUsers, setSelectedUsers] = useState([])
let [message, setMessage] = useState('')
Expand Down Expand Up @@ -43,9 +43,7 @@ function NewMessage(props) {

let selectUserId = new URLSearchParams(history.location.search).get('user')
if (selectUserId) {
setSelectedUsers([res.data.find(user => user._id === selectUserId)])


handleClick([res.data.find(user => user._id === selectUserId)])
}
setAllUsers(res.data)

Expand All @@ -63,25 +61,39 @@ function NewMessage(props) {
}
//Create Channel

actions
.addMessage({ message: selectedUsers.map(u => u.name).join(' & '), members: selectedUsers })
.then(res => {
console.log('then ', res.data)

// actions
// .addMessage({ message: selectedUsers.map(u => u.name).join(' & '), members: selectedUsers })
// .then(res => {
// console.log('then ', res.data)

//I think res.data.post is channel
actions.addMessage({ message, channel: res.data.post }).then(res => {
history.push(`/chat/${res.data.post?._id}`)
setMessage('')
}).catch(console.error)
actions.addMessage({ message, channel, members: selectedUsers }).then(res => {
history.push(`/chat/${res.data.post?._id}`)
setMessage('')
}).catch(console.error)


}).catch(console.error)
// }).catch(console.error)
}



const handleClick = (users) => {
setSelectedUsers(users)
setUserQuery('')
actions.findPreviousChat(users).then(res => {
console.log(res, 'prev chat')
setChannel(res.data)
})
}


const showSelectedUsers = () => {
console.log(selectedUsers, 'setSelectedUsers')
if (selectedUsers) {
return selectedUsers.map(sUser =>
<li onClick={() => { setSelectedUsers(selectedUsers.filter(u => u._id != sUser._id)); setUserQuery('') }}>
<li onClick={() => { handleClick(selectedUsers.filter(u => u._id != sUser._id)) }}>
<Image avatar src={sUser.avatar} style={{ background: "white" }} />
<span>{sUser.name}</span>

Expand All @@ -91,7 +103,7 @@ function NewMessage(props) {

const showUsers = () => {
return allUsers.filter(u => u.name.toLowerCase().includes(userQuery) && !selectedUsers.some(one => one._id == u._id) && u._id != user._id).map(user =>
<li onClick={() => { setSelectedUsers([...selectedUsers, user]); setUserQuery('') }}>
<li onClick={() => { handleClick([...selectedUsers, user]) }}>
<Image avatar src={user.avatar} style={{ background: "white" }} />
<span>{user.name}</span>

Expand Down Expand Up @@ -142,20 +154,7 @@ function NewMessage(props) {
<button id="addMessage" disabled={false}><Icon name="chat" /> <label>Send</label></button>
</form>
</div>
{/* : null} */}

{/* <h1>{selectedUsers.map(u => u.name).join(' & ')}</h1> */}

{/* <div className="controls">
<button onClick={() => gotoRoom(channel._id, channel)}>
<Icon name="video" /> Video
</button>
<button onClick={() => gotoRoom(channel._id, channel)}>
<Icon name="laptop" /> Screen
</button>

</div> */}
{/* <h1>{channel.message}</h1> */}

</header>
<div className="moreUsers">
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/components/VideoPreview/VideoPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ export default function VideoPreview({ setLittleVideo }) {
const ref = createRef()

useEffect(() => {
console.log(window, ' window')
const api = window.jitsiMeetExternalAPI

if (api) {
const listeners = {
speakerChanged: (evt) => {
console.log('evt', evt)
const largeVideo = api._getLargeVideo()
console.log(largeVideo, 'largeVideo')
setHasVideo(largeVideo)
Expand Down Expand Up @@ -62,7 +64,7 @@ export default function VideoPreview({ setLittleVideo }) {

}, [stream, transform])

// console.log('stream', stream)
console.log('stream', stream)

return (
<div className="videobottomright">
Expand Down

0 comments on commit faa545f

Please sign in to comment.