Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
beta.php
1<?php
2
3
5
6
20
21class Beta extends Controller
22{
23 protected function processBeforeAction(Action $action): bool
24 {
25 if (!Loader::includeModule('im'))
26 {
27 $this->addError(new Error("Module IM is not installed"));
28
29 return false;
30 }
31
32 if (User::getInstance()->isExtranet())
33 {
34 $this->addError(new Error("You dont have access to this action"));
35
36 return false;
37 }
38
39 return true;
40 }
41
42 public function createRoomAction(CurrentUser $currentUser, string $dialogId = "0", int $chatId = 0)
43 {
44 if ($dialogId > 0)
45 {
46 $chatId = Dialog::getChatId($dialogId, $currentUser->getId());
47 }
48 if ($chatId <= 0)
49 {
50 $this->addError(new Error("You must be specified chatId or dialogId"));
51 return null;
52 }
53
54 $chat = Chat::getInstance($chatId);
55
56 if (!$chat->hasAccess())
57 {
58 $this->addError(new Error("You must be a member of the chat to call it"));
59
60 return null;
61 }
62
63 $roomId = $chatId.'_'. Alias::generateUnique();
64 $link = 'https://demo-stage.webrtc-test.bitrix.info/?roomId='.$roomId;
65
66 $text = Loc::getMessage("IM_CALL_BETA_INVITE", [
67 '#LINK#' => '[URL='.$link.']'.Loc::getMessage('IM_CALL_BETA_INVITE_BUTTON').'[/URL]',
68 ]);
69
70 $message = new Message();
71 $message->setMessage($text)->markAsImportant(true);
72 $message->getParams()
73 ->fill([
74 Params::COMPONENT_ID => 'CallInviteMessage',
75 Params::COMPONENT_PARAMS => [
76 'LINK' => $link
77 ]
78 ])
79 ->save()
80 ;
81 $chat->sendMessage($message);
82
83 return true;
84 }
85}
static generateUnique()
Definition alias.php:226
processBeforeAction(Action $action)
Definition beta.php:23
createRoomAction(CurrentUser $currentUser, string $dialogId="0", int $chatId=0)
Definition beta.php:42
static getChatId($dialogId, $userId=null)
Definition dialog.php:91
static getInstance($userId=null)
Definition user.php:44
static getInstance(?int $chatId)
Definition Chat.php:282
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29