Skip to content

Commit

Permalink
Merge pull request trazyn#153 from trazyn/dev
Browse files Browse the repository at this point in the history
Fix bug
  • Loading branch information
trazyn authored Jul 25, 2018
2 parents 0b9c50e + 3fc8f56 commit d6fc8a0
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 68 deletions.
2 changes: 2 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,8 @@ function updateTray(unread = 0) {
tray.setContextMenu(contextmenu);
});
} else {
if (!tray) return;

tray.destroy();
tray = null;
}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"linux": {
"icon": "../resource",
"category": "Chat",
"executableName": "weweChat",
"target": [
"deb",
"rpm",
Expand Down
5 changes: 3 additions & 2 deletions src/js/components/Avatar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ export default class Avatar extends Component {
<img
className={`Avatar fade fadein ${this.props.className}`}
onClick={this.props.onClick}
onError={e => this.handleError(e)}
onLoad={e => this.handleLoad(e)}
src={this.props.src} />
onError={e => this.handleError(e)}
src={this.props.src}
/>
);
}
}
117 changes: 74 additions & 43 deletions src/js/components/MessageInput/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,61 +24,61 @@ export default class MessageInput extends Component {
canisend() {
var user = this.props.user;

if (this.blocking) {
return false;
}

if (user.length === 1
&& user.slice(-1).pop().UserName === this.props.me.UserName) {
if (
true
&& user.length === 1
&& user.slice(-1).pop().UserName === this.props.me.UserName
) {
this.props.showMessage('Can\'t send message to yourself.');
return false;
}

return true;
}

// Prevent duplicate message
blocking = false;

async handleEnter(e) {
var message = this.refs.input.value.trim();
var user = this.props.user;
var batch = user.length > 1;

if (!this.canisend()
if (
false
|| !this.canisend()
|| !message
|| e.charCode !== 13) return;

this.blocking = true;
|| e.charCode !== 13
) return;

// You can not send message to yourself
await Promise.all(
user.filter(e => e.UserName !== this.props.me.UserName).map(async e => {
let res = await this.props.sendMessage(e, {
content: message,
type: 1,
}, true);

this.refs.input.value = '';

if (!res) {
await this.props.showMessage(batch ? `Send message to ${e.NickName} is failed!` : 'Failed to send message.');
Promise.all(
user.filter(e => e.UserName !== this.props.me.UserName).map(
async e => {
let res = await this.props.sendMessage(
e,
{
content: message,
type: 1,
},
true
);

if (!res) {
await this.props.showMessage(batch ? `Send message to ${e.NickName} is failed!` : 'Failed to send message.');
}

return true;
}

return true;
})
)
);
this.blocking = false;

this.refs.input.value = '';
}

state = {
showEmoji: false
};

toggleEmoji(show = !this.state.showEmoji) {
this.setState({
showEmoji: show,
});
this.setState({ showEmoji: show });
}

writeEmoji(emoji) {
Expand Down Expand Up @@ -141,38 +141,66 @@ export default class MessageInput extends Component {
}
}

componentWillReceiveProps(nextProps) {
var input = this.refs.input;

// When user has changed clear the input
if (
true
&& input
&& input.value
&& this.props.user.map(e => e.UserName).join() !== nextProps.user.map(e => e.UserName).join()
) {
input.value = '';
}
}

render() {
var canisend = !!this.props.user.length;

return (
<div className={clazz(classes.container, this.props.className, {
[classes.shouldSelectUser]: !canisend,
})}>
<div
className={
clazz(
classes.container,
this.props.className,
{
[classes.shouldSelectUser]: !canisend,
}
)
}
>
<div
className={classes.tips}>
className={classes.tips}
>
You should choice a contact at first.
</div>

<input
id="messageInput"
onPaste={e => this.handlePaste(e)}
onKeyPress={e => this.handleEnter(e)}
ref="input"
type="text"
placeholder="Type something to send..."
readOnly={!canisend}
ref="input"
type="text" />
onPaste={e => this.handlePaste(e)}
onKeyPress={e => this.handleEnter(e)}
/>

<div className={classes.action}>
<i
className="icon-ion-android-attach"
id="showUploader"
onClick={e => canisend && this.refs.uploader.click()} />
onClick={e => canisend && this.refs.uploader.click()}
/>

<i
className="icon-ion-ios-heart"
id="showEmoji"
onClick={e => canisend && this.toggleEmoji(true)}
style={{
color: 'red',
}} />
}}
/>

<input
onChange={e => {
Expand All @@ -183,11 +211,14 @@ export default class MessageInput extends Component {
style={{
display: 'none',
}}
type="file" />
type="file"
/>

<Emoji
close={e => setTimeout(() => this.toggleEmoji(false), 100)}
output={emoji => this.writeEmoji(emoji)}
show={this.state.showEmoji} />
show={this.state.showEmoji}
/>
</div>
</div>
);
Expand Down
12 changes: 8 additions & 4 deletions src/js/pages/Home/ChatContent/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ import { on, off } from 'utils/event';
showAddFriend: (user) => stores.addfriend.toggle(true, user),
recallMessage: stores.chat.recallMessage,
downloads: stores.settings.downloads,
remeberConversation: stores.settings.remeberConversation,
rememberConversation: stores.settings.rememberConversation,
showConversation: stores.chat.showConversation,
toggleConversation: stores.chat.toggleConversation,
}))
Expand Down Expand Up @@ -304,9 +304,13 @@ export default class ChatContent extends Component {
<Avatar
src={message.isme ? message.HeadImgUrl : user.HeadImgUrl}
className={classes.avatar}
onClick={ev => this.props.showUserinfo(message.isme, user)} />
onClick={ev => this.props.showUserinfo(message.isme, user)}
/>

<p className={classes.username} dangerouslySetInnerHTML={{__html: user.NickName}} />
<p
className={classes.username}
dangerouslySetInnerHTML={{__html: user.DisplayName || user.RemarkName || user.NickName}}
/>

<div className={classes.content}>
<p
Expand Down Expand Up @@ -540,7 +544,7 @@ export default class ChatContent extends Component {
}

componentWillUnmount() {
!this.props.remeberConversation && this.props.reset();
!this.props.rememberConversation && this.props.reset();
}

componentDidUpdate() {
Expand Down
4 changes: 3 additions & 1 deletion src/js/pages/Home/Chats/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ export default class Chats extends Component {
})}>
<img
className="disabledDrag"
src={e.HeadImgUrl} />
src={e.HeadImgUrl}
onError={e => (e.target.src = 'assets/images/user-fallback.png')}
/>
</div>

<div className={classes.info}>
Expand Down
18 changes: 9 additions & 9 deletions src/js/pages/Settings/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import helper from 'utils/helper';
setConfirmImagePaste: stores.settings.setConfirmImagePaste,
blockRecall: stores.settings.blockRecall,
setBlockRecall: stores.settings.setBlockRecall,
remeberConversation: stores.settings.remeberConversation,
setRemeberConversation: stores.settings.setRemeberConversation,
rememberConversation: stores.settings.rememberConversation,
setRememberConversation: stores.settings.setRememberConversation,
showRedIcon: stores.settings.showRedIcon,
setShowRedIcon: stores.settings.setShowRedIcon,

Expand Down Expand Up @@ -56,8 +56,8 @@ export default class Settings extends Component {
setConfirmImagePaste,
blockRecall,
setBlockRecall,
remeberConversation,
setRemeberConversation,
rememberConversation,
setRememberConversation,
showRedIcon,
setShowRedIcon,
user,
Expand Down Expand Up @@ -131,12 +131,12 @@ export default class Settings extends Component {
</li>

<li>
<label htmlFor="remeberConversation">
<span>Remeber the last Conversation</span>
<label htmlFor="rememberConversation">
<span>Remember the last Conversation</span>
<Switch
checked={remeberConversation}
id="remeberConversation"
onChange={e => setRemeberConversation(e.target.checked)} />
checked={rememberConversation}
id="rememberConversation"
onChange={e => setRememberConversation(e.target.checked)} />
</label>
</li>

Expand Down
18 changes: 9 additions & 9 deletions src/js/stores/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Settings {
@observable confirmImagePaste = true;
@observable startup = false;
@observable blockRecall = false;
@observable remeberConversation = false;
@observable rememberConversation = false;
@observable showRedIcon = true;
@observable downloads = '';

Expand All @@ -26,8 +26,8 @@ class Settings {
self.save();
}

@action setRemeberConversation(remeberConversation) {
self.remeberConversation = remeberConversation;
@action setRememberConversation(rememberConversation) {
self.rememberConversation = rememberConversation;
self.save();
}

Expand Down Expand Up @@ -63,7 +63,7 @@ class Settings {

@action async init() {
var settings = await storage.get('settings');
var { alwaysOnTop, showOnTray, showNotification, blockRecall, remeberConversation, showRedIcon, startup, downloads } = self;
var { alwaysOnTop, showOnTray, showNotification, blockRecall, rememberConversation, showRedIcon, startup, downloads } = self;

if (settings && Object.keys(settings).length) {
// Use !! force convert to a bool value
Expand All @@ -73,7 +73,7 @@ class Settings {
self.confirmImagePaste = !!settings.confirmImagePaste;
self.startup = !!settings.startup;
self.blockRecall = !!settings.blockRecall;
self.remeberConversation = !!settings.remeberConversation;
self.rememberConversation = !!settings.rememberConversation;
self.showRedIcon = !!settings.showRedIcon;
self.downloads = settings.downloads;
} else {
Expand All @@ -84,7 +84,7 @@ class Settings {
startup,
downloads,
blockRecall,
remeberConversation,
rememberConversation,
showRedIcon,
});
}
Expand All @@ -104,7 +104,7 @@ class Settings {
}

save() {
var { alwaysOnTop, showOnTray, showNotification, confirmImagePaste, blockRecall, remeberConversation, showRedIcon, startup, downloads } = self;
var { alwaysOnTop, showOnTray, showNotification, confirmImagePaste, blockRecall, rememberConversation, showRedIcon, startup, downloads } = self;

storage.set('settings', {
alwaysOnTop,
Expand All @@ -114,7 +114,7 @@ class Settings {
startup,
downloads,
blockRecall,
remeberConversation,
rememberConversation,
showRedIcon,
});

Expand All @@ -127,7 +127,7 @@ class Settings {
startup,
downloads,
blockRecall,
remeberConversation,
rememberConversation,
showRedIcon,
}
});
Expand Down

0 comments on commit d6fc8a0

Please sign in to comment.