Skip to content

Commit

Permalink
dang it, location didn't work
Browse files Browse the repository at this point in the history
  • Loading branch information
lhr0909 committed Mar 18, 2019
1 parent 45e4e0b commit ddb3b40
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 28 deletions.
50 changes: 26 additions & 24 deletions src/puppet-padpro.ts
Expand Up @@ -1211,8 +1211,9 @@ export class PuppetPadpro extends Puppet {
)
} else if (payload.type === MessageType.Video) {
await this.forwardVideo(receiver, messageId)
} else if (payload.type === MessageType.Location) {
await this.forwardLocation(receiver, messageId)
// commenting this out because currently there is no way to directly send location
// } else if (payload.type === MessageType.Location) {
// await this.forwardLocation(receiver, messageId)
} else if (
payload.type === MessageType.Attachment ||
payload.type === MessageType.ChatHistory
Expand All @@ -1226,34 +1227,35 @@ export class PuppetPadpro extends Puppet {
}
}

private async forwardLocation (
receiver: Receiver,
messageId: string,
): Promise<void> {
if (!this.padproManager) {
throw new Error('no padpro manager')
}
// commenting this out because currently there is no way to directly send location
// private async forwardLocation (
// receiver: Receiver,
// messageId: string,
// ): Promise<void> {
// if (!this.padproManager) {
// throw new Error('no padpro manager')
// }

const rawPayload = await this.messageRawPayload(messageId)
// const rawPayload = await this.messageRawPayload(messageId)

// Send to the Room if there's a roomId
const id = receiver.roomId || receiver.contactId
// // Send to the Room if there's a roomId
// const id = receiver.roomId || receiver.contactId

if (!id) {
throw new Error('There is no receiver id when trying to forward location.')
}
const locationPayload = await locationPayloadParser(rawPayload)
if (locationPayload === null) {
throw new Error('Can not forward location, failed to parse xml message.')
}
// if (!id) {
// throw new Error('There is no receiver id when trying to forward location.')
// }
// const locationPayload = await locationPayloadParser(rawPayload)
// if (locationPayload === null) {
// throw new Error('Can not forward location, failed to parse xml message.')
// }

locationPayload.fromUsername = this.selfId()
// locationPayload.fromUsername = this.selfId()

log.silly(PRE, `forwardLocation(${JSON.stringify(locationPayload)})`)
// log.silly(PRE, `forwardLocation(${JSON.stringify(locationPayload)})`)

const content = generateLocationMessage(locationPayload)
await this.padproManager.GrpcSendApp(id, content)
}
// const content = generateLocationMessage(locationPayload)
// await this.padproManager.GrpcSendApp(id, content)
// }

private async forwardAttachment (
receiver: Receiver,
Expand Down
6 changes: 3 additions & 3 deletions src/pure-function-helpers/message-location-payload-parser.ts
Expand Up @@ -35,11 +35,11 @@ export async function locationPayloadParser (rawPayload: PadproMessagePayload):

const data = jsonPayload.msg.location.$
const result: PadproLocationMessagePayload = {
x: parseInt(data.x, 10),
y: parseInt(data.y, 10),
x: parseFloat(data.x),
y: parseFloat(data.y),
scale: parseInt(data.scale, 10),
label: data.label,
mapType: parseInt(data.maptype, 10),
mapType: data.maptype,
poiName: data.poiname,
poiId: data.poiid,
fromUsername: data.fromusername,
Expand Down
2 changes: 1 addition & 1 deletion src/schemas/padpro-schemas.ts
Expand Up @@ -231,7 +231,7 @@ export interface PadproLocationMessagePayload {
x: number,
y: number,
scale: number,
mapType: number,
mapType: string,
label: string,
poiId: string,
poiName: string,
Expand Down

0 comments on commit ddb3b40

Please sign in to comment.