@juzi/wechaty 1.0.3 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/dist/cjs/src/package-json.js +4 -4
  2. package/dist/cjs/src/package-json.js.map +1 -1
  3. package/dist/cjs/src/sayable/deliver-sayable.d.ts +2 -2
  4. package/dist/cjs/src/sayable/deliver-sayable.d.ts.map +1 -1
  5. package/dist/cjs/src/sayable/deliver-sayable.js +5 -2
  6. package/dist/cjs/src/sayable/deliver-sayable.js.map +1 -1
  7. package/dist/cjs/src/sayable/mod.d.ts +2 -2
  8. package/dist/cjs/src/sayable/mod.d.ts.map +1 -1
  9. package/dist/cjs/src/sayable/mod.js.map +1 -1
  10. package/dist/cjs/src/sayable/types.d.ts +9 -3
  11. package/dist/cjs/src/sayable/types.d.ts.map +1 -1
  12. package/dist/cjs/src/sayable/types.js +8 -0
  13. package/dist/cjs/src/sayable/types.js.map +1 -1
  14. package/dist/cjs/src/user-modules/contact.d.ts +2 -2
  15. package/dist/cjs/src/user-modules/contact.d.ts.map +1 -1
  16. package/dist/cjs/src/user-modules/contact.js +6 -2
  17. package/dist/cjs/src/user-modules/contact.js.map +1 -1
  18. package/dist/cjs/src/user-modules/message.d.ts +8 -1
  19. package/dist/cjs/src/user-modules/message.d.ts.map +1 -1
  20. package/dist/cjs/src/user-modules/message.js +32 -2
  21. package/dist/cjs/src/user-modules/message.js.map +1 -1
  22. package/dist/cjs/src/user-modules/room.d.ts +3 -1
  23. package/dist/cjs/src/user-modules/room.d.ts.map +1 -1
  24. package/dist/cjs/src/user-modules/room.js +24 -6
  25. package/dist/cjs/src/user-modules/room.js.map +1 -1
  26. package/dist/cjs/src/user-modules/room.spec.js +20 -0
  27. package/dist/cjs/src/user-modules/room.spec.js.map +1 -1
  28. package/dist/esm/src/package-json.js +4 -4
  29. package/dist/esm/src/package-json.js.map +1 -1
  30. package/dist/esm/src/sayable/deliver-sayable.d.ts +2 -2
  31. package/dist/esm/src/sayable/deliver-sayable.d.ts.map +1 -1
  32. package/dist/esm/src/sayable/deliver-sayable.js +5 -2
  33. package/dist/esm/src/sayable/deliver-sayable.js.map +1 -1
  34. package/dist/esm/src/sayable/mod.d.ts +2 -2
  35. package/dist/esm/src/sayable/mod.d.ts.map +1 -1
  36. package/dist/esm/src/sayable/mod.js.map +1 -1
  37. package/dist/esm/src/sayable/types.d.ts +9 -3
  38. package/dist/esm/src/sayable/types.d.ts.map +1 -1
  39. package/dist/esm/src/sayable/types.js +6 -1
  40. package/dist/esm/src/sayable/types.js.map +1 -1
  41. package/dist/esm/src/user-modules/contact.d.ts +2 -2
  42. package/dist/esm/src/user-modules/contact.d.ts.map +1 -1
  43. package/dist/esm/src/user-modules/contact.js +6 -2
  44. package/dist/esm/src/user-modules/contact.js.map +1 -1
  45. package/dist/esm/src/user-modules/message.d.ts +8 -1
  46. package/dist/esm/src/user-modules/message.d.ts.map +1 -1
  47. package/dist/esm/src/user-modules/message.js +32 -2
  48. package/dist/esm/src/user-modules/message.js.map +1 -1
  49. package/dist/esm/src/user-modules/room.d.ts +3 -1
  50. package/dist/esm/src/user-modules/room.d.ts.map +1 -1
  51. package/dist/esm/src/user-modules/room.js +24 -6
  52. package/dist/esm/src/user-modules/room.js.map +1 -1
  53. package/dist/esm/src/user-modules/room.spec.js +20 -0
  54. package/dist/esm/src/user-modules/room.spec.js.map +1 -1
  55. package/package.json +3 -3
  56. package/src/package-json.ts +4 -4
  57. package/src/sayable/deliver-sayable.ts +6 -2
  58. package/src/sayable/mod.ts +4 -0
  59. package/src/sayable/types.ts +21 -2
  60. package/src/user-modules/contact.ts +8 -1
  61. package/src/user-modules/message.ts +41 -3
  62. package/src/user-modules/room.spec.ts +24 -0
  63. package/src/user-modules/room.ts +36 -14
@@ -46,7 +46,7 @@ import {
46
46
  validationMixin,
47
47
  } from '../user-mixins/mod.js'
48
48
  import {
49
- deliverSayableConversationPuppet,
49
+ deliverSayableConversationPuppet, SayOptions, SayOptionsObject,
50
50
  } from '../sayable/mod.js'
51
51
  import type {
52
52
  SayableSayer,
@@ -61,6 +61,7 @@ import {
61
61
  import type {
62
62
  MessageInterface,
63
63
  } from './message.js'
64
+ import { isSayOptionsObject } from '../sayable/types.js'
64
65
 
65
66
  const MixinBase = wechatifyMixin(
66
67
  poolifyMixin(
@@ -355,7 +356,8 @@ class RoomMixin extends MixinBase implements SayableSayer {
355
356
  }
356
357
 
357
358
  say (sayable: Sayable) : Promise<void | MessageInterface>
358
- say (text: string, ...mentionList: ContactInterface[]) : Promise<void | MessageInterface>
359
+ say (text: string, options?: SayOptions): Promise<void | MessageInterface>
360
+ say (text: string, ...options: SayOptions[]): Promise<void | MessageInterface>
359
361
  say (textList: TemplateStringsArray, ...varList: any[]) : Promise<void | MessageInterface>
360
362
 
361
363
  // Huan(202006): allow fall down to the defination to get more flexibility.
@@ -463,19 +465,27 @@ class RoomMixin extends MixinBase implements SayableSayer {
463
465
  /**
464
466
  * 1. string
465
467
  */
466
- let mentionList: ContactInterface[] = []
468
+ let mentionList: (ContactInterface | '@all')[] = []
469
+ let quoteMessage: MessageInterface | undefined
470
+ let options: SayOptionsObject
467
471
 
468
472
  if (varList.length > 0) {
469
- const allIsContact = varList.every(c => ContactImpl.valid(c))
473
+ if (isSayOptionsObject(varList[0])) {
474
+ options = varList[0] as SayOptionsObject
475
+ mentionList = options.mentionList || []
476
+ quoteMessage = options.quoteMessage
477
+ } else {
478
+ mentionList = varList as ContactInterface[]
479
+ }
480
+
481
+ const allIsContact = mentionList.every(c => ContactImpl.valid(c) || (c as string) === '@all')
470
482
  if (!allIsContact) {
471
483
  throw new Error('mentionList must be contact when not using TemplateStringsArray function call.')
472
484
  }
473
485
 
474
- mentionList = [...varList as any]
475
-
476
486
  const AT_SEPARATOR = FOUR_PER_EM_SPACE
477
487
  const mentionAlias = await Promise.all(mentionList.map(async contact =>
478
- '@' + (await this.alias(contact) || contact.name()),
488
+ '@' + (contact === '@all' ? 'all' : await this.alias(contact) || contact.name()),
479
489
  ))
480
490
  const mentionText = mentionAlias.join(AT_SEPARATOR)
481
491
 
@@ -487,11 +497,23 @@ class RoomMixin extends MixinBase implements SayableSayer {
487
497
  // contactId : (mentionList.length && mentionList[0].id) || undefined,
488
498
  // roomId : this.id,
489
499
  // }
490
- msgId = await this.wechaty.puppet.messageSendText(
491
- this.id,
492
- text,
493
- mentionList.map(c => c.id),
494
- )
500
+ if (quoteMessage) {
501
+ msgId = await this.wechaty.puppet.messageSendText(
502
+ this.id,
503
+ text,
504
+ {
505
+ mentionIdList: mentionList.map(c => c === '@all' ? '@all' : c.id),
506
+ quoteId: quoteMessage.id,
507
+ },
508
+ )
509
+ } else {
510
+ msgId = await this.wechaty.puppet.messageSendText(
511
+ this.id,
512
+ text,
513
+ mentionList.map(c => c === '@all' ? '@all' : c.id),
514
+ )
515
+ }
516
+
495
517
  } else {
496
518
  msgId = await deliverSayableConversationPuppet(this.wechaty.puppet)(this.id)(sayable)
497
519
  }
@@ -506,7 +528,7 @@ class RoomMixin extends MixinBase implements SayableSayer {
506
528
  textList: TemplateStringsArray,
507
529
  ...varList: unknown[]
508
530
  ) {
509
- const mentionList = varList.filter(c => ContactImpl.valid(c)) as ContactInterface[]
531
+ const mentionList = varList.filter(c => ContactImpl.valid(c) || c === '@all') as (ContactInterface | '@all')[]
510
532
 
511
533
  // const receiver = {
512
534
  // contactId : (mentionList.length && mentionList[0].id) || undefined,
@@ -561,7 +583,7 @@ class RoomMixin extends MixinBase implements SayableSayer {
561
583
  return this.wechaty.puppet.messageSendText(
562
584
  this.id,
563
585
  finalText,
564
- mentionList.map(c => c.id),
586
+ mentionList.map(c => c === '@all' ? '@all' : c.id),
565
587
  )
566
588
  }
567
589
  }