fixup mapchat stuff
This commit is contained in:
parent
ea82a9df27
commit
8010e7d497
7 changed files with 30 additions and 58 deletions
|
@ -157,6 +157,7 @@ const ReactApp = {
|
||||||
getChatProps: function() {
|
getChatProps: function() {
|
||||||
const self = ReactApp
|
const self = ReactApp
|
||||||
return {
|
return {
|
||||||
|
unreadMessages: ChatView.unreadMessages,
|
||||||
conversationLive: ChatView.conversationLive,
|
conversationLive: ChatView.conversationLive,
|
||||||
isParticipating: ChatView.isParticipating,
|
isParticipating: ChatView.isParticipating,
|
||||||
onOpen: ChatView.onOpen,
|
onOpen: ChatView.onOpen,
|
||||||
|
|
|
@ -151,8 +151,6 @@ let Realtime = {
|
||||||
config: { DOUBLE_CLICK_TOLERANCE: 200 }
|
config: { DOUBLE_CLICK_TOLERANCE: 200 }
|
||||||
})
|
})
|
||||||
self.room.videoAdded(self.handleVideoAdded)
|
self.room.videoAdded(self.handleVideoAdded)
|
||||||
|
|
||||||
self.startActiveMap()
|
|
||||||
} // if Active.Mapper
|
} // if Active.Mapper
|
||||||
},
|
},
|
||||||
addJuntoListeners: function() {
|
addJuntoListeners: function() {
|
||||||
|
@ -201,9 +199,6 @@ let Realtime = {
|
||||||
self.leaveMap()
|
self.leaveMap()
|
||||||
$('.collabCompass').remove()
|
$('.collabCompass').remove()
|
||||||
if (self.room) self.room.leave()
|
if (self.room) self.room.leave()
|
||||||
ChatView.hide()
|
|
||||||
ChatView.close()
|
|
||||||
ChatView.reset()
|
|
||||||
Cable.unsubscribeFromMap()
|
Cable.unsubscribeFromMap()
|
||||||
},
|
},
|
||||||
turnOn: function(notify) {
|
turnOn: function(notify) {
|
||||||
|
@ -228,7 +223,6 @@ let Realtime = {
|
||||||
ChatView.setNewMap()
|
ChatView.setNewMap()
|
||||||
ChatView.addParticipant(self.activeMapper)
|
ChatView.addParticipant(self.activeMapper)
|
||||||
ChatView.addMessages(new DataModel.MessageCollection(DataModel.Messages), true)
|
ChatView.addMessages(new DataModel.MessageCollection(DataModel.Messages), true)
|
||||||
ChatView.show()
|
|
||||||
},
|
},
|
||||||
setupLocalEvents: function() {
|
setupLocalEvents: function() {
|
||||||
var self = Realtime
|
var self = Realtime
|
||||||
|
|
|
@ -14,10 +14,10 @@ import ReactApp from '../GlobalUI/ReactApp'
|
||||||
|
|
||||||
const ChatView = {
|
const ChatView = {
|
||||||
isOpen: false,
|
isOpen: false,
|
||||||
|
unreadMessages: 0,
|
||||||
messages: new Backbone.Collection(),
|
messages: new Backbone.Collection(),
|
||||||
conversationLive: false,
|
conversationLive: false,
|
||||||
isParticipating: false,
|
isParticipating: false,
|
||||||
mapChat: null,
|
|
||||||
domId: 'chat-box-wrapper',
|
domId: 'chat-box-wrapper',
|
||||||
init: function(urls) {
|
init: function(urls) {
|
||||||
const self = ChatView
|
const self = ChatView
|
||||||
|
@ -34,29 +34,32 @@ const ChatView = {
|
||||||
},
|
},
|
||||||
setNewMap: function() {
|
setNewMap: function() {
|
||||||
const self = ChatView
|
const self = ChatView
|
||||||
|
self.unreadMessages = 0
|
||||||
|
self.isOpen = false
|
||||||
self.conversationLive = false
|
self.conversationLive = false
|
||||||
self.isParticipating = false
|
self.isParticipating = false
|
||||||
self.alertSound = true // whether to play sounds on arrival of new messages or not
|
self.alertSound = true // whether to play sounds on arrival of new messages or not
|
||||||
self.cursorsShowing = true
|
self.cursorsShowing = true
|
||||||
self.videosShowing = true
|
self.videosShowing = true
|
||||||
self.participants = new Backbone.Collection()
|
self.participants = new Backbone.Collection()
|
||||||
|
self.messages = new Backbone.Collection()
|
||||||
self.render()
|
self.render()
|
||||||
},
|
},
|
||||||
show: () => {
|
|
||||||
$('#' + ChatView.domId).show()
|
|
||||||
},
|
|
||||||
hide: () => {
|
|
||||||
$('#' + ChatView.domId).hide()
|
|
||||||
},
|
|
||||||
render: () => {
|
render: () => {
|
||||||
if (!Active.Map) return
|
if (!Active.Map) return
|
||||||
const self = ChatView
|
const self = ChatView
|
||||||
ReactApp.render()
|
ReactApp.render()
|
||||||
},
|
},
|
||||||
onOpen: () => {
|
onOpen: () => {
|
||||||
|
const self = ChatView
|
||||||
|
self.isOpen = true
|
||||||
|
self.unreadMessages = 0
|
||||||
|
self.render()
|
||||||
$(document).trigger(ChatView.events.openTray)
|
$(document).trigger(ChatView.events.openTray)
|
||||||
},
|
},
|
||||||
onClose: () => {
|
onClose: () => {
|
||||||
|
const self = ChatView
|
||||||
|
self.isOpen = false
|
||||||
$(document).trigger(ChatView.events.closeTray)
|
$(document).trigger(ChatView.events.closeTray)
|
||||||
},
|
},
|
||||||
addParticipant: participant => {
|
addParticipant: participant => {
|
||||||
|
@ -102,12 +105,6 @@ const ChatView = {
|
||||||
ChatView.participants.forEach(p => p.set({isParticipating: false, isPending: false}))
|
ChatView.participants.forEach(p => p.set({isParticipating: false, isPending: false}))
|
||||||
ChatView.render()
|
ChatView.render()
|
||||||
},
|
},
|
||||||
close: () => {
|
|
||||||
ChatView.mapChat && ChatView.mapChat.close()
|
|
||||||
},
|
|
||||||
open: () => {
|
|
||||||
ChatView.mapChat && ChatView.mapChat.open()
|
|
||||||
},
|
|
||||||
videoToggleClick: function() {
|
videoToggleClick: function() {
|
||||||
ChatView.videosShowing = !ChatView.videosShowing
|
ChatView.videosShowing = !ChatView.videosShowing
|
||||||
$(document).trigger(ChatView.videosShowing ? ChatView.events.videosOn : ChatView.events.videosOff)
|
$(document).trigger(ChatView.videosShowing ? ChatView.events.videosOn : ChatView.events.videosOff)
|
||||||
|
@ -127,11 +124,10 @@ const ChatView = {
|
||||||
},
|
},
|
||||||
addMessage: (message, isInitial, wasMe) => {
|
addMessage: (message, isInitial, wasMe) => {
|
||||||
const self = ChatView
|
const self = ChatView
|
||||||
if (!isInitial) self.mapChat.newMessage()
|
if (!isInitial && !self.isOpen) self.unreadMessages += 1
|
||||||
if (!wasMe && !isInitial && self.alertSound) self.sound.play('receivechat')
|
if (!wasMe && !isInitial && self.alertSound) self.sound.play('receivechat')
|
||||||
self.messages.add(message)
|
self.messages.add(message)
|
||||||
self.render()
|
self.render()
|
||||||
if (!isInitial) self.mapChat.scroll()
|
|
||||||
},
|
},
|
||||||
sendChatMessage: message => {
|
sendChatMessage: message => {
|
||||||
var self = ChatView
|
var self = ChatView
|
||||||
|
@ -157,23 +153,9 @@ const ChatView = {
|
||||||
// passed to this function
|
// passed to this function
|
||||||
addMessages: (messages, isInitial, wasMe) => {
|
addMessages: (messages, isInitial, wasMe) => {
|
||||||
messages.models.forEach(m => ChatView.addMessage(m, isInitial, wasMe))
|
messages.models.forEach(m => ChatView.addMessage(m, isInitial, wasMe))
|
||||||
},
|
|
||||||
reset: () => {
|
|
||||||
ChatView.mapChat && ChatView.mapChat.reset()
|
|
||||||
ChatView.participants && ChatView.participants.reset()
|
|
||||||
ChatView.messages && ChatView.messages.reset()
|
|
||||||
ChatView.render()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ChatView.prototype.scrollMessages = function(duration) {
|
|
||||||
// duration = duration || 0
|
|
||||||
|
|
||||||
// this.$messages.animate({
|
|
||||||
// scrollTop: this.$messages[0].scrollHeight
|
|
||||||
// }, duration)
|
|
||||||
// }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @class
|
* @class
|
||||||
* @static
|
* @static
|
||||||
|
|
|
@ -43,7 +43,6 @@ const TopicCard = {
|
||||||
var self = TopicCard
|
var self = TopicCard
|
||||||
var topic = node.getData('topic')
|
var topic = node.getData('topic')
|
||||||
self.openTopic = topic
|
self.openTopic = topic
|
||||||
// populate the card that's about to show with the right topics data
|
|
||||||
self.render()
|
self.render()
|
||||||
$('.showcard').fadeIn('fast', () => {
|
$('.showcard').fadeIn('fast', () => {
|
||||||
$('.showcard').draggable({
|
$('.showcard').draggable({
|
||||||
|
|
|
@ -26,7 +26,6 @@ class MapChat extends Component {
|
||||||
super(props)
|
super(props)
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
unreadMessages: 0,
|
|
||||||
messageText: '',
|
messageText: '',
|
||||||
alertSound: true, // whether to play sounds on arrival of new messages or not
|
alertSound: true, // whether to play sounds on arrival of new messages or not
|
||||||
cursorsShowing: true,
|
cursorsShowing: true,
|
||||||
|
@ -34,9 +33,14 @@ class MapChat extends Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
componentDidUpdate(prevProps) {
|
||||||
|
const { messages } = this.props
|
||||||
|
const prevMessages = prevProps.messages
|
||||||
|
if (messages.length !== prevMessages.length) setTimeout(() => this.scroll(), 50)
|
||||||
|
}
|
||||||
|
|
||||||
reset = () => {
|
reset = () => {
|
||||||
this.setState({
|
this.setState({
|
||||||
unreadMessages: 0,
|
|
||||||
messageText: '',
|
messageText: '',
|
||||||
alertSound: true, // whether to play sounds on arrival of new messages or not
|
alertSound: true, // whether to play sounds on arrival of new messages or not
|
||||||
cursorsShowing: true,
|
cursorsShowing: true,
|
||||||
|
@ -46,22 +50,16 @@ class MapChat extends Component {
|
||||||
|
|
||||||
close = () => {
|
close = () => {
|
||||||
this.props.onClose()
|
this.props.onClose()
|
||||||
this.messageInput.blur()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
open = () => {
|
open = () => {
|
||||||
this.scroll()
|
|
||||||
this.setState({unreadMessages: 0})
|
|
||||||
this.props.onOpen()
|
this.props.onOpen()
|
||||||
this.messageInput.focus()
|
setTimeout(() => this.scroll(), 50)
|
||||||
}
|
|
||||||
|
|
||||||
newMessage = () => {
|
|
||||||
if (!this.state.open) this.setState({unreadMessages: this.state.unreadMessages + 1})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
scroll = () => {
|
scroll = () => {
|
||||||
this.messagesDiv.scrollTop = this.messagesDiv.scrollHeight
|
// hack: figure out how to do this right
|
||||||
|
this.messagesDiv.scrollTop = this.messagesDiv.scrollHeight + 100
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleDrawer = () => {
|
toggleDrawer = () => {
|
||||||
|
@ -99,14 +97,10 @@ class MapChat extends Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
focusMessageInput = () => {
|
|
||||||
if (!this.messageInput) return
|
|
||||||
this.messageInput.focus()
|
|
||||||
}
|
|
||||||
|
|
||||||
render = () => {
|
render = () => {
|
||||||
const { chatOpen, conversationLive, isParticipating, participants, messages, inviteACall, inviteToJoin } = this.props
|
const { unreadMessages, chatOpen, conversationLive,
|
||||||
const { videosShowing, cursorsShowing, alertSound, unreadMessages } = this.state
|
isParticipating, participants, messages, inviteACall, inviteToJoin } = this.props
|
||||||
|
const { videosShowing, cursorsShowing, alertSound } = this.state
|
||||||
const rightOffset = chatOpen ? '0' : '-300px'
|
const rightOffset = chatOpen ? '0' : '-300px'
|
||||||
return (
|
return (
|
||||||
<div id="chat-box-wrapper">
|
<div id="chat-box-wrapper">
|
||||||
|
@ -153,7 +147,7 @@ class MapChat extends Component {
|
||||||
handleChange={this.handleChange('messageText')}
|
handleChange={this.handleChange('messageText')}
|
||||||
textAreaProps={{
|
textAreaProps={{
|
||||||
className: 'chat-input',
|
className: 'chat-input',
|
||||||
ref: textarea => { this.messageInput = textarea },
|
ref: textarea => { textarea && textarea.focus() },
|
||||||
placeholder: 'Send a message...',
|
placeholder: 'Send a message...',
|
||||||
onKeyUp: this.handleTextareaKeyUp,
|
onKeyUp: this.handleTextareaKeyUp,
|
||||||
onFocus: this.props.inputFocus,
|
onFocus: this.props.inputFocus,
|
||||||
|
@ -167,6 +161,7 @@ class MapChat extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
MapChat.propTypes = {
|
MapChat.propTypes = {
|
||||||
|
unreadMessages: PropTypes.number,
|
||||||
chatOpen: PropTypes.bool,
|
chatOpen: PropTypes.bool,
|
||||||
conversationLive: PropTypes.bool,
|
conversationLive: PropTypes.bool,
|
||||||
isParticipating: PropTypes.bool,
|
isParticipating: PropTypes.bool,
|
||||||
|
|
|
@ -42,6 +42,7 @@ class MapView extends Component {
|
||||||
this.setState({
|
this.setState({
|
||||||
chatOpen: false
|
chatOpen: false
|
||||||
})
|
})
|
||||||
|
this.mapChat.reset()
|
||||||
this.props.endActiveMap()
|
this.props.endActiveMap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,7 +83,7 @@ class MapView extends Component {
|
||||||
filterBoxHtml={filterBoxHtml} />
|
filterBoxHtml={filterBoxHtml} />
|
||||||
<DataVis />
|
<DataVis />
|
||||||
<TopicCard {...this.props} />
|
<TopicCard {...this.props} />
|
||||||
{currentUser && <MapChat {...this.props} onOpen={onChatOpen} onClose={onChatClose} chatOpen={chatOpen} />}
|
{currentUser && <MapChat {...this.props} onOpen={onChatOpen} onClose={onChatClose} chatOpen={chatOpen} ref={x => this.mapChat = x} />}
|
||||||
<MapControls onClickZoomExtents={onZoomExtents}
|
<MapControls onClickZoomExtents={onZoomExtents}
|
||||||
onClickZoomIn={onZoomIn}
|
onClickZoomIn={onZoomIn}
|
||||||
onClickZoomOut={onZoomOut} />
|
onClickZoomOut={onZoomOut} />
|
||||||
|
|
Loading…
Add table
Reference in a new issue