Skip to content

Commit

Permalink
forward emoji
Browse files Browse the repository at this point in the history
  • Loading branch information
trazyn committed Aug 7, 2017
1 parent 5c8b211 commit a1f0186
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 34 deletions.
6 changes: 4 additions & 2 deletions README.MD
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# weweChat
Unofficial WeChat client built with React, MobX and Electron.
Unofficial WeChat client built with React, MobX and Electron.

## Feature
- Work on desktop
Expand Down Expand Up @@ -46,7 +46,9 @@ $ npm run dev
- [x] Send text message
- [ ] Send file
- [ ] Send image
- [ ] Send emoji
- [x] Forward text message
- [x] Forward emoji
- [ ] Forward image
- [x] Search chat set
- [x] Search and create chat room
- [x] Keep online(bug)
Expand Down
5 changes: 4 additions & 1 deletion src/js/pages/Footer/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ export default class Input extends Component {
handleEnter(e) {
if (e.charCode !== 13) return;

this.props.sendMessage(this.props.user, this.refs.input.value);
this.props.sendMessage(this.props.user, {
content: this.refs.input.value,
type: 1,
});
this.refs.input.value = '';
}

Expand Down
4 changes: 2 additions & 2 deletions src/js/pages/Home/ChatContent/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ export default class ChatContent extends Component {
}

showMessageAction(message) {
var caniforward = [1, 3].includes(message.MsgType);
var caniforward = [1, 3, 47].includes(message.MsgType);
var templates = [
{
label: 'Delete',
Expand All @@ -322,7 +322,7 @@ export default class ChatContent extends Component {
templates.unshift({
label: 'Forward',
click: () => {
this.props.showForward(true, message);
this.props.showForward(message);
}
});
}
Expand Down
17 changes: 17 additions & 0 deletions src/js/pages/Home/ChatContent/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,23 @@
}
}

.message.isme.isEmoji {
& > div {
display: flex;
padding: 16px 31px 0 0;
justify-content: flex-end;
}

& .avatar {
left: auto;
right: -16px;
}

& .content {
text-align: right;
}
}

.invalidEmoji {
position: relative;
margin-top: -30px;
Expand Down
109 changes: 90 additions & 19 deletions src/js/stores/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,39 +302,110 @@ class Chat {
self.messages.set(from, list);
}

@action async sendMessage(user, content) {
var id = (+new Date() * 1000) + Math.random().toString().substr(2, 4);
var auth = await storage.get('auth');
var from = session.user.User.UserName;
var to = user.UserName;
@action async sendTextMessage(auth, message) {
var response = await axios.post(`/cgi-bin/mmwebwx-bin/webwxsendmsg`, {
BaseRequest: {
Sid: auth.wxsid,
Uin: auth.wxuin,
Skey: auth.skey,
},
Msg: {
Content: content,
FromUserName: from,
ToUserName: to,
ClientMsgId: id,
LocalID: id,
Content: message.content,
FromUserName: message.from,
ToUserName: message.to,
ClientMsgId: message.ClientMsgId,
LocalID: message.LocalID,
Type: 1,
},
Scene: 0,
});
var res = {
data: response.data,

if (+response.data.BaseResponse.Ret === 0) {
// Sent success
let list = self.messages.get(to);

list.data.push({
item: {
isme: true,
Content: content,
Content: message.content,
MsgType: 1,
CreateTime: +new Date() / 1000,
HeadImgUrl: session.user.User.HeadImgUrl,
},
};

if (res.data.BaseResponse.Ret !== 0) {
console.error('Failed to send message: %o', response.data);
}

return res;
}

@action async sendEmojiMessage(auth, message) {
var response = await axios.post(`/cgi-bin/mmwebwx-bin/webwxsendemoticon?fun=sys&lang=en_US&pass_ticket=${auth.passTicket}`, {
BaseRequest: {
Sid: auth.wxsid,
Uin: auth.wxuin,
Skey: auth.skey,
},
Msg: {
FromUserName: message.from,
ToUserName: message.to,
ClientMsgId: message.ClientMsgId,
LocalID: message.LocalID,
Type: 47,
EMoticonMd5: message.emoji.md5,
},
Scene: 2,
});
var res = {
data: response.data,

item: Object.assign({}, message, {
isme: true,
CreateTime: +new Date() / 1000,
HeadImgUrl: session.user.User.HeadImgUrl,
}),
};

if (res.data.BaseResponse.Ret !== 0) {
console.error('Failed to send emoji: %o', response.data);
}

return res;
}

@action async sendMessage(user, message) {
var id = (+new Date() * 1000) + Math.random().toString().substr(2, 4);
var auth = await storage.get('auth');
var from = session.user.User.UserName;
var to = user.UserName;
var res;

if (message.type === 1) {
res = await self.sendTextMessage(auth, {
content: message.content,
from,
to,
ClientMsgId: id,
LocalID: id,
});
} else if (message.type === 47) {
res = await self.sendEmojiMessage(auth, Object.assign({}, message, {
content: message.content,
from,
to,
ClientMsgId: message.MsgId,
LocalID: id,
}));
} else {
return false;
}

var { data, item } = res;

if (data.BaseResponse.Ret === 0) {
// Sent success
let list = self.messages.get(to);

list.data.push(item);

if (!helper.isChatRoom(user.UserName)
&& !user.isFriend) {
Expand All @@ -348,11 +419,11 @@ class Chat {
self.markedRead(to);
self.messages.set(to, list);
self.chatTo(user);
} else {
console.error('Failed to send message: %o', response.data);

return true;
}

return +response.data.BaseResponse.Ret === 0;
return false;
}

@action async sendImage(user, content, isForward) {
Expand Down
15 changes: 5 additions & 10 deletions src/js/stores/forward.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import pinyin from 'han';

import contacts from './contacts';
import chat from './chat';
import helper from 'utils/helper';

class Forward {
@observable show = false;
Expand Down Expand Up @@ -45,16 +44,12 @@ class Forward {
var message = self.message;
var user = await contacts.getUser(userid);

switch (message.MsgType) {
case 1:
// Text Message
chat.sendMessage(user, message.Content);
break;
message = Object.assign(message, {
content: message.Content,
type: message.MsgType,
});

case 3:
chat.sendImage(user, helper.decodeHTML(message.Content), true);
break;
}
chat.sendMessage(user, message);
}
}

Expand Down

0 comments on commit a1f0186

Please sign in to comment.