Skip to content

Commit

Permalink
fix room user for other type
Browse files Browse the repository at this point in the history
  • Loading branch information
jinqiming committed Mar 31, 2019
1 parent da157bb commit 3c8ad7a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/msghandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ function getChatroomUser (chatroom, username) {
}

function parseContentIfChatroom (fromType, fromUser, msg) {
if (fromType === UserTypes.USER_TYPE_CHATROOM && MsgTypes.MSGTYPE_TEXT === msg.MsgType) {
if (fromType === UserTypes.USER_TYPE_CHATROOM) {
let group = /(@[0-9a-z]*?):<br\/>(.*)$/.exec(msg.Content)
if (group) {
msg.Content = group[2]
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chatwe",
"version": "1.0.3",
"version": "1.0.4",
"description": "this is a wechat client sdk. using the protocol of web wechat.",
"main": "index.js",
"scripts": {
Expand Down
32 changes: 32 additions & 0 deletions test/test-fillRoomUserIfChatroom.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,38 @@ test('wechat parseContentIfChatroom 1', async function (t) {
t.equal(undefined, msg.IsAtMe)
})

test('wechat parseContentIfChatroom 2', async function (t) {
wechat.loginInfo['url'] = Config.BASE_URL
wechat.loginInfo['User'] = { 'UserName': 'yizhiren', 'NickName': 'sb' }

let msg = { MsgType: 2, Content: '@12345:<br/>hi' }
wechat.parseContentIfChatroom(UserTypes.USER_TYPE_CHATROOM, {
MemberList: [
{ UserName: '@12345', Tag: 'X' },
{ UserName: 'yizhiren', Tag: 'Y' }
]
}, msg)
t.equal('X', msg.ChatRoomUser.Tag)
t.equal('hi', msg.Content)
t.equal(undefined, msg.IsAtMe)
})

test('wechat parseContentIfChatroom 3', async function (t) {
wechat.loginInfo['url'] = Config.BASE_URL
wechat.loginInfo['User'] = { 'UserName': 'yizhiren', 'NickName': 'sb' }

let msg = { MsgType: 3, Content: '@12345:<br/>hi' }
wechat.parseContentIfChatroom(UserTypes.USER_TYPE_CHATROOM, {
MemberList: [
{ UserName: '@12345', Tag: 'X' },
{ UserName: 'yizhiren', Tag: 'Y' }
]
}, msg)
t.equal('X', msg.ChatRoomUser.Tag)
t.equal('hi', msg.Content)
t.equal(undefined, msg.IsAtMe)
})

test('cleanup', function (t) {
t.end()
})

0 comments on commit 3c8ad7a

Please sign in to comment.