You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

183 lines
4.5 KiB

4 years ago
4 years ago
  1. <?php
  2. use App\Reported;
  3. use App\Url;
  4. use Moxl\Xec\Action\Message\Moderate;
  5. use Moxl\Xec\Action\Message\Retract;
  6. include_once WIDGETS_PATH.'ContactActions/ContactActions.php';
  7. class ChatActions extends \Movim\Widget\Base
  8. {
  9. public function load()
  10. {
  11. $this->addjs('chatactions.js');
  12. $this->addcss('chatactions.css');
  13. }
  14. /**
  15. * @brief Get a Drawer view of a contact
  16. */
  17. public function ajaxGetContact(string $jid)
  18. {
  19. $c = new ContactActions;
  20. $c->ajaxGetDrawer($jid);
  21. }
  22. /**
  23. * @brief Block the contact
  24. */
  25. public function ajaxBlockContact(string $jid)
  26. {
  27. $r = Reported::firstOrCreate(['id' => $jid]);
  28. $this->user->reported()->syncWithoutDetaching([$r->id]);
  29. $this->user->refreshBlocked();
  30. Toast::send($this->__('blocked.account_blocked'));
  31. $this->rpc('Chats_ajaxClose', $jid, true);
  32. }
  33. /**
  34. * @brief Unblock the contact
  35. */
  36. public function ajaxUnblockContact(string $jid)
  37. {
  38. $this->user->reported()->detach($jid);
  39. $this->user->refreshBlocked();
  40. Toast::send($this->__('blocked.account_unblocked'));
  41. }
  42. /**
  43. * @brief Display the message dialog
  44. */
  45. public function ajaxShowMessageDialog(string $mid)
  46. {
  47. $message = $this->user->messages()
  48. ->where('mid', $mid)
  49. ->first();
  50. if ($message && $message->isClassic()) {
  51. $view = $this->tpl();
  52. $view->assign('message', $message);
  53. if ($message->isMuc()) {
  54. $view->assign('conference', $this->user->session->conferences()
  55. ->where('conference', $message->jidfrom)
  56. ->with('info')
  57. ->first());
  58. } else {
  59. $view->assign('conference', null);
  60. }
  61. $this->rpc('ChatActions.setMessage', $message);
  62. Dialog::fill($view->draw('_chatactions_message'));
  63. }
  64. }
  65. public function ajaxCopiedMessageText()
  66. {
  67. Toast::send($this->__('chatactions.copied_text'));
  68. }
  69. /**
  70. * @brief Edit a message
  71. */
  72. /*public function ajaxEditMessage($mid)
  73. {
  74. $this->rpc('Dialog.clear');
  75. $this->rpc('Chat.editMessage', $mid);
  76. }*/
  77. /**
  78. * @brief Retract a message
  79. *
  80. * @param string $mid
  81. * @return void
  82. */
  83. public function ajaxHttpDaemonRetract($mid)
  84. {
  85. $retract = $this->user->messages()
  86. ->where('mid', $mid)
  87. ->first();
  88. if ($retract && $retract->originid) {
  89. $this->rpc('Dialog.clear');
  90. $r = new Retract;
  91. $r->setTo($retract->jidto)
  92. ->setOriginid($retract->originid)
  93. ->request();
  94. $retract->retract();
  95. $retract->save();
  96. $packet = new \Moxl\Xec\Payload\Packet;
  97. $packet->content = $retract;
  98. $c = new Chat;
  99. $c->onMessage($packet, false, true);
  100. }
  101. }
  102. /**
  103. * @brief Moderate a message
  104. *
  105. * @param string $mid
  106. * @return void
  107. */
  108. public function ajaxHttpDaemonModerate($mid)
  109. {
  110. $retract = $this->user->messages()
  111. ->where('mid', $mid)
  112. ->first();
  113. if ($retract && $retract->stanzaid) {
  114. $this->rpc('Dialog.clear');
  115. $r = new Moderate;
  116. $r->setTo($retract->jidfrom)
  117. ->setStanzaid($retract->stanzaid)
  118. ->request();
  119. }
  120. }
  121. /**
  122. * @brief Try to resolve a message URL
  123. */
  124. public function ajaxHttpResolveMessage($mid)
  125. {
  126. $message = $this->user->messages()
  127. ->where('mid', $mid)
  128. ->first();
  129. if ($message && $message->resolved == false) {
  130. try {
  131. $url = new Url;
  132. $url->resolve(trim($message->body));
  133. $message->urlid = $url->id;
  134. if ($url->file) {
  135. $message->file = (array)$url->file;
  136. }
  137. $this->rpc('Chat.refreshMessage', $message->mid);
  138. } catch (\Exception $e) {}
  139. $message->resolved = true;
  140. $message->save();
  141. }
  142. }
  143. /**
  144. * @brief Resolve a URL
  145. */
  146. public function ajaxHttpResolveUrl(string $url)
  147. {
  148. try {
  149. (new Url)->resolve(trim($url));
  150. } catch (\Exception $e) {}
  151. $this->rpc('Chat.disableSending');
  152. }
  153. }