提交 8cf61158 编写于 作者: Huan (李卓桓)'s avatar Huan (李卓桓)

code clean

上级 ab37155a
......@@ -214,6 +214,10 @@ export interface Sayable {
say(text: string, replyTo?: any|any[]): Promise<void>
}
// http://jkorpela.fi/chars/spaces.html
// String.fromCharCode(8197)
export const FOUR_PER_EM_SPACE = String.fromCharCode(0x2005)
export {
log,
Raven,
......
......@@ -2,7 +2,7 @@
import {
MessagePayload,
// MessageType,
MessageType,
} from '../../puppet/'
import {
......@@ -35,9 +35,21 @@ export function messageRawPayloadParser(
const payloadBase = {
id : rawPayload.msg_id,
timestamp : rawPayload.timestamp, // Padchat message timestamp is seconds
timestamp : rawPayload.timestamp, // Padchat message timestamp is seconds
type : type,
filename : messageFileName(rawPayload) || undefined,
} as {
id : string,
timestamp : number,
type : MessageType,
filename? : string,
}
if ( type === MessageType.Image
|| type === MessageType.Audio
|| type === MessageType.Video
|| type === MessageType.Attachment
) {
payloadBase.filename = messageFileName(rawPayload) || undefined
}
let fromId: undefined | string = undefined
......
......@@ -22,7 +22,6 @@ import {
FileBox,
} from 'file-box'
// tslint:disable-next-line
import Wechat4u from 'wechat4u'
import { Misc } from '../misc'
......@@ -96,7 +95,7 @@ export type ScanFoodType = 'scan' | 'login' | 'logout'
// }
// MemoryCard Slot Name
const SYNC_DATA_SLOT = 'wechat4u-sync-data'
const MEMORY_SLOT_NAME = 'puppet-wechat4u'
export class PuppetWechat4u extends Puppet {
......@@ -111,7 +110,7 @@ export class PuppetWechat4u extends Puppet {
private scanQrCode?: string
public readonly cacheMessageRawPayload : LRU.Cache<string, WebMessageRawPayload>
public readonly cacheMessageRawPayload: LRU.Cache<string, WebMessageRawPayload>
constructor(
public options: PuppetOptions,
......@@ -127,7 +126,7 @@ export class PuppetWechat4u extends Puppet {
maxAge: 1000 * 60 * 60,
}
this.cacheMessageRawPayload = new LRU<string, WebMessageRawPayload>(lruOptions)
this.cacheMessageRawPayload = new LRU<string, WebMessageRawPayload>(lruOptions)
}
public async start(): Promise<void> {
......@@ -135,7 +134,7 @@ export class PuppetWechat4u extends Puppet {
this.state.on('pending')
const syncData = await this.options.memory.get(SYNC_DATA_SLOT)
const syncData = await this.options.memory.get(MEMORY_SLOT_NAME)
if (syncData) {
this.wechat4u = new Wechat4u(syncData)
} else {
......@@ -183,7 +182,7 @@ export class PuppetWechat4u extends Puppet {
}
await this.login(userId)
// 保存数据,将数据序列化之后保存到任意位置
await this.options.memory.set(SYNC_DATA_SLOT, wechat4u.botData)
await this.options.memory.set(MEMORY_SLOT_NAME, wechat4u.botData)
await this.options.memory.save()
})
/**
......@@ -194,7 +193,7 @@ export class PuppetWechat4u extends Puppet {
await this.logout()
}
// 清除数据
await this.options.memory.delete(SYNC_DATA_SLOT)
await this.options.memory.delete(MEMORY_SLOT_NAME)
await this.options.memory.save()
})
/**
......@@ -524,7 +523,8 @@ export class PuppetWechat4u extends Puppet {
): Promise<void> {
log.verbose('PuppetWechat4u', 'messageSend(%s, %s)', receiver, text)
const id = receiver.contactId || receiver.roomId
// room first
const id = receiver.roomId || receiver.contactId
if (!id) {
throw new Error('no id')
......@@ -547,6 +547,7 @@ export class PuppetWechat4u extends Puppet {
): Promise<void> {
log.verbose('PuppetWechat4u', 'messageSend(%s, %s)', receiver, file)
// room first
const id = receiver.roomId || receiver.contactId
if (!id) {
......@@ -597,7 +598,7 @@ export class PuppetWechat4u extends Puppet {
throw new Error('no rawPayload')
}
const id = receiver.contactId || receiver.roomId
const id = receiver.roomId || receiver.contactId
if (!id) {
throw new Error('no id')
......
......@@ -20,7 +20,7 @@ export interface MessagePayloadBase {
export interface MessagePayloadRoom {
fromId? : string,
mentionIdList? : string[], // Mentioned Contacts' Ids
// mentionIdList? : string[], // Mentioned Contacts' Ids
roomId : string,
toId? : string, // if to is not set, then room must be set
}
......
......@@ -29,7 +29,8 @@ import {
import {
log,
Sayable,
} from '../config'
FOUR_PER_EM_SPACE,
} from '../config'
import {
Accessory,
} from '../accessory'
......@@ -460,7 +461,8 @@ export class Message extends Accessory implements Sayable {
}
// define magic code `8197` to identify @xxx
const AT_SEPRATOR = String.fromCharCode(8197)
// const AT_SEPRATOR = String.fromCharCode(8197)
const AT_SEPRATOR = FOUR_PER_EM_SPACE
const atList = this.text().split(AT_SEPRATOR)
// console.log('atList: ', atList)
......
......@@ -29,6 +29,7 @@ import {
Raven,
Sayable,
log,
FOUR_PER_EM_SPACE,
} from '../config'
import {
Accessory,
......@@ -341,7 +342,9 @@ export class Room extends Accessory implements Sayable {
if (typeof textOrContactOrFile === 'string') {
if (replyToList.length > 0) {
const AT_SEPRATOR = String.fromCharCode(8197)
// const AT_SEPRATOR = String.fromCharCode(8197)
const AT_SEPRATOR = FOUR_PER_EM_SPACE
const mentionList = replyToList.map(c => '@' + c.name()).join(AT_SEPRATOR)
text = mentionList + ' ' + textOrContactOrFile
} else {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册