Do not count system messages for unread
This commit is contained in:
parent
cb61490db1
commit
03aa7696ba
@ -24,8 +24,8 @@
|
|||||||
"lint": "eslint .",
|
"lint": "eslint .",
|
||||||
"lint:fix": "eslint . --fix",
|
"lint:fix": "eslint . --fix",
|
||||||
"ci": "npm run lint && npm run test:coverage && npm run build",
|
"ci": "npm run lint && npm run test:coverage && npm run build",
|
||||||
"ts:watch": "tsc --build . --watch --preserveWatchOutput",
|
"ts:watch": "tsc -p . --watch --preserveWatchOutput",
|
||||||
"ts": "tsc --build .",
|
"ts": "tsc -p .",
|
||||||
"clean": "rimraf lib/ tsconfig.tsbuildinfo build/*"
|
"clean": "rimraf lib/ tsconfig.tsbuildinfo build/*"
|
||||||
},
|
},
|
||||||
"babel": {
|
"babel": {
|
||||||
|
|||||||
@ -107,8 +107,8 @@ describe('PeerActions', () => {
|
|||||||
const payload = 'test'
|
const payload = 'test'
|
||||||
const object = JSON.stringify({ payload })
|
const object = JSON.stringify({ payload })
|
||||||
peer.emit('data', Buffer.from(object, 'utf-8'))
|
peer.emit('data', Buffer.from(object, 'utf-8'))
|
||||||
const { messages } = store.getState()
|
const { list } = store.getState().messages
|
||||||
expect(messages[messages.length - 1]).toEqual({
|
expect(list[list.length - 1]).toEqual({
|
||||||
userId: 'user2',
|
userId: 'user2',
|
||||||
timestamp: jasmine.any(String),
|
timestamp: jasmine.any(String),
|
||||||
image: undefined,
|
image: undefined,
|
||||||
|
|||||||
@ -19,6 +19,7 @@ export interface AppProps {
|
|||||||
init: () => void
|
init: () => void
|
||||||
notifications: Record<string, Notification>
|
notifications: Record<string, Notification>
|
||||||
messages: Message[]
|
messages: Message[]
|
||||||
|
messagesCount: number
|
||||||
peers: Record<string, Peer.Instance>
|
peers: Record<string, Peer.Instance>
|
||||||
sendMessage: (message: TextMessage) => void
|
sendMessage: (message: TextMessage) => void
|
||||||
streams: Record<string, AddStreamPayload>
|
streams: Record<string, AddStreamPayload>
|
||||||
@ -62,6 +63,7 @@ export default class App extends React.PureComponent<AppProps, AppState> {
|
|||||||
dismissAlert,
|
dismissAlert,
|
||||||
notifications,
|
notifications,
|
||||||
messages,
|
messages,
|
||||||
|
messagesCount,
|
||||||
onSendFile,
|
onSendFile,
|
||||||
peers,
|
peers,
|
||||||
sendMessage,
|
sendMessage,
|
||||||
@ -75,7 +77,7 @@ export default class App extends React.PureComponent<AppProps, AppState> {
|
|||||||
<div className="app">
|
<div className="app">
|
||||||
<Toolbar
|
<Toolbar
|
||||||
chatVisible={this.state.chatVisible}
|
chatVisible={this.state.chatVisible}
|
||||||
messages={messages}
|
messagesCount={messagesCount}
|
||||||
onToggleChat={this.handleToggleChat}
|
onToggleChat={this.handleToggleChat}
|
||||||
onSendFile={onSendFile}
|
onSendFile={onSendFile}
|
||||||
stream={streams[constants.ME]}
|
stream={streams[constants.ME]}
|
||||||
|
|||||||
@ -1,8 +1,9 @@
|
|||||||
import classnames from 'classnames'
|
import Input from './Input'
|
||||||
|
import PropTypes from 'prop-types'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
|
import classnames from 'classnames'
|
||||||
import { Message as MessageType } from '../actions/ChatActions'
|
import { Message as MessageType } from '../actions/ChatActions'
|
||||||
import { TextMessage } from '../actions/PeerActions'
|
import { TextMessage } from '../actions/PeerActions'
|
||||||
import Input from './Input'
|
|
||||||
|
|
||||||
export interface MessageProps {
|
export interface MessageProps {
|
||||||
message: MessageType
|
message: MessageType
|
||||||
|
|||||||
@ -21,7 +21,7 @@ describe('components/Toolbar', () => {
|
|||||||
chatVisible={this.props.chatVisible}
|
chatVisible={this.props.chatVisible}
|
||||||
onToggleChat={this.props.onToggleChat}
|
onToggleChat={this.props.onToggleChat}
|
||||||
onSendFile={this.props.onSendFile}
|
onSendFile={this.props.onSendFile}
|
||||||
messages={this.props.messages}
|
messagesCount={this.props.messagesCount}
|
||||||
stream={this.state.stream || this.props.stream}
|
stream={this.state.stream || this.props.stream}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
@ -44,7 +44,7 @@ describe('components/Toolbar', () => {
|
|||||||
chatVisible
|
chatVisible
|
||||||
onToggleChat={onToggleChat}
|
onToggleChat={onToggleChat}
|
||||||
onSendFile={onSendFile}
|
onSendFile={onSendFile}
|
||||||
messages={[]}
|
messagesCount={1}
|
||||||
stream={{ userId: '', stream: mediaStream, url }}
|
stream={{ userId: '', stream: mediaStream, url }}
|
||||||
/>,
|
/>,
|
||||||
div,
|
div,
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
import React, { ReactEventHandler, ChangeEvent } from 'react'
|
|
||||||
import classnames from 'classnames'
|
import classnames from 'classnames'
|
||||||
|
import React from 'react'
|
||||||
import screenfull from 'screenfull'
|
import screenfull from 'screenfull'
|
||||||
import { Message } from '../actions/ChatActions'
|
|
||||||
import { AddStreamPayload } from '../actions/StreamActions'
|
import { AddStreamPayload } from '../actions/StreamActions'
|
||||||
|
|
||||||
const hidden = {
|
const hidden = {
|
||||||
@ -9,7 +8,7 @@ const hidden = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface ToolbarProps {
|
export interface ToolbarProps {
|
||||||
messages: Message[]
|
messagesCount: number
|
||||||
stream: AddStreamPayload
|
stream: AddStreamPayload
|
||||||
onToggleChat: () => void
|
onToggleChat: () => void
|
||||||
onSendFile: (file: File) => void
|
onSendFile: (file: File) => void
|
||||||
@ -30,7 +29,7 @@ extends React.PureComponent<ToolbarProps, ToolbarState> {
|
|||||||
constructor(props: ToolbarProps) {
|
constructor(props: ToolbarProps) {
|
||||||
super(props)
|
super(props)
|
||||||
this.state = {
|
this.state = {
|
||||||
readMessages: props.messages.length,
|
readMessages: props.messagesCount,
|
||||||
camDisabled: false,
|
camDisabled: false,
|
||||||
micMuted: false,
|
micMuted: false,
|
||||||
fullScreenEnabled: false,
|
fullScreenEnabled: false,
|
||||||
@ -79,12 +78,12 @@ extends React.PureComponent<ToolbarProps, ToolbarState> {
|
|||||||
}
|
}
|
||||||
handleToggleChat = () => {
|
handleToggleChat = () => {
|
||||||
this.setState({
|
this.setState({
|
||||||
readMessages: this.props.messages.length,
|
readMessages: this.props.messagesCount,
|
||||||
})
|
})
|
||||||
this.props.onToggleChat()
|
this.props.onToggleChat()
|
||||||
}
|
}
|
||||||
render () {
|
render () {
|
||||||
const { messages, stream } = this.props
|
const { messagesCount, stream } = this.props
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="toolbar active">
|
<div className="toolbar active">
|
||||||
@ -93,7 +92,7 @@ extends React.PureComponent<ToolbarProps, ToolbarState> {
|
|||||||
on: this.props.chatVisible,
|
on: this.props.chatVisible,
|
||||||
})}
|
})}
|
||||||
data-blink={!this.props.chatVisible &&
|
data-blink={!this.props.chatVisible &&
|
||||||
messages.length > this.state.readMessages}
|
messagesCount > this.state.readMessages}
|
||||||
title="Chat"
|
title="Chat"
|
||||||
>
|
>
|
||||||
<span className="icon icon-question_answer" />
|
<span className="icon icon-question_answer" />
|
||||||
|
|||||||
@ -13,7 +13,8 @@ function mapStateToProps (state: State) {
|
|||||||
peers: state.peers,
|
peers: state.peers,
|
||||||
alerts: state.alerts,
|
alerts: state.alerts,
|
||||||
notifications: state.notifications,
|
notifications: state.notifications,
|
||||||
messages: state.messages,
|
messages: state.messages.list,
|
||||||
|
messagesCount: state.messages.count,
|
||||||
active: state.active,
|
active: state.active,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,7 +12,7 @@ describe('reducers/messages', () => {
|
|||||||
}
|
}
|
||||||
let state = messages(undefined, {type: 'test'} as any)
|
let state = messages(undefined, {type: 'test'} as any)
|
||||||
state = messages(state, ChatActions.addMessage(payload))
|
state = messages(state, ChatActions.addMessage(payload))
|
||||||
expect(state).toEqual([payload])
|
expect(state.list).toEqual([payload])
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@ -2,9 +2,15 @@ import * as constants from '../constants'
|
|||||||
import { Message, MessageAddAction } from '../actions/ChatActions'
|
import { Message, MessageAddAction } from '../actions/ChatActions'
|
||||||
import { NotificationAddAction } from '../actions/NotifyActions'
|
import { NotificationAddAction } from '../actions/NotifyActions'
|
||||||
|
|
||||||
export type MessagesState = Message[]
|
export interface MessagesState {
|
||||||
|
list: Message[]
|
||||||
|
count: number
|
||||||
|
}
|
||||||
|
|
||||||
const defaultState: MessagesState = []
|
const defaultState: MessagesState = {
|
||||||
|
list: [],
|
||||||
|
count: 0,
|
||||||
|
}
|
||||||
|
|
||||||
function convertNotificationToMessage(action: NotificationAddAction): Message {
|
function convertNotificationToMessage(action: NotificationAddAction): Message {
|
||||||
return {
|
return {
|
||||||
@ -19,12 +25,15 @@ export default function messages (
|
|||||||
): MessagesState {
|
): MessagesState {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case constants.NOTIFY:
|
case constants.NOTIFY:
|
||||||
return [
|
return {
|
||||||
...state,
|
...state,
|
||||||
convertNotificationToMessage(action),
|
list: [...state.list, convertNotificationToMessage(action)],
|
||||||
]
|
}
|
||||||
case constants.MESSAGE_ADD:
|
case constants.MESSAGE_ADD:
|
||||||
return [...state, action.payload]
|
return {
|
||||||
|
count: state.count + 1,
|
||||||
|
list: [...state.list, action.payload],
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
return state
|
return state
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"composite": true,
|
"composite": false,
|
||||||
"declaration": true,
|
"declaration": true,
|
||||||
"declarationMap": true,
|
"declarationMap": true,
|
||||||
"inlineSourceMap": true,
|
"inlineSourceMap": true,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user