提交 3c1517f5 编写于 作者: Huan (李卓桓)'s avatar Huan (李卓桓) 提交者: GitHub

Merge pull request #162 from lijiarui/master

enhance #155 fire `room-join` when someone joins from a QR Code
......@@ -64,9 +64,29 @@ test('parseRoomJoin()', t => {
]
, [
`你邀请"李佳芮"加入了群聊`
, ''
, `你`
, ['李佳芮']
]
, [
`"桔小秘"通过扫描你分享的二维码加入群聊`
, `你`
, ['桔小秘']
]
, [
`"桔小秘"通过扫描"李佳芮"分享的二维码加入群聊`
, `李佳芮`
, ['桔小秘']
]
, [
`"桔小秘" joined the group chat via your shared QR Code.`
, `your`
, ['桔小秘']
]
, [
`"桔小秘" joined the group chat via the QR Code shared by "李佳芮".`
, `李佳芮`
, ['桔小秘']
]
]
let result
......
......@@ -51,10 +51,17 @@ const regexConfig = {
, /^你已添加了(.+),现在可以开始聊天了。$/
]
, roomJoin: [
, roomJoinInvite: [
/^"?(.+?)"? invited "(.+)" to the group chat$/
, /^"?(.+?)"?邀请"(.+)"加入了群聊$/
]
, roomJoinQrcode: [
/^"(.+)" joined the group chat via the QR Code shared by "?(.+?)".$/
, /^"(.+)" joined the group chat via "?(.+?)"? shared QR Code.$/
, /^"(.+)"通过扫描"?(.+?)"?分享的二维码加入群聊$/
]
, roomLeave: [
/^You removed "(.+)" from the group chat$/
, /^你将"(.+)"移出了群聊$/
......@@ -133,17 +140,21 @@ async function checkFriendConfirm(m: Message) {
function parseRoomJoin(content: string): [string[], string] {
log.verbose('PuppetWebFirer', 'checkRoomJoin(%s)', content)
const reList = regexConfig.roomJoin
const reListInvite = regexConfig.roomJoinInvite
const reListQrcode = regexConfig.roomJoinQrcode
let found: string[]|null = []
reList.some(re => !!(found = content.match(re)))
if (!found || !found.length) {
let foundInvite: string[]|null = []
reListInvite.some(re => !!(foundInvite = content.match(re)))
let foundQrcode: string[]|null = []
reListQrcode.some(re => !!(foundQrcode = content.match(re)))
if ((!foundInvite || !foundInvite.length) && (!foundQrcode || !foundQrcode.length)) {
throw new Error('checkRoomJoin() not found matched re of ' + content)
}
const [inviter, inviteeStr] = [ found[1], found[2] ]
// "凌" invited "庆次、小桔妹" to the group chat
/**
* "凌" invited "庆次、小桔妹" to the group chat
* "桔小秘"通过扫描你分享的二维码加入群聊
*/
const [inviter, inviteeStr] = foundInvite ? [ foundInvite[1], foundInvite[2] ] : [ foundQrcode[2], foundQrcode[1] ]
const inviteeList = inviteeStr.split(/、/)
return [inviteeList, inviter] // put invitee at first place
......@@ -175,7 +186,7 @@ async function checkRoomJoin(m: Message): Promise<void> {
let inviteeContactList: Contact[] = []
try {
if (inviter === "You've" || inviter === '') {
if (inviter === "You've" || inviter === '' || inviter === 'your') {
inviterContact = Contact.load(this.userId)
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册