-
Notifications
You must be signed in to change notification settings - Fork 11
/
extend.php
64 lines (56 loc) · 3.15 KB
/
extend.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
namespace Kyrne\Whisper;
use Flarum\Api\Controller;
use Flarum\Extend;
use Flarum\Formatter\Event\Configuring;
use Flarum\User\User;
use Flarum\Api\Serializer\ForumSerializer;
use Flarum\Api\Serializer\CurrentUserSerializer;
use Kyrne\Whisper\Api\Controllers;
use Kyrne\Whisper\Api\Serializers\ConversationRecipientSerializer;
use Kyrne\Whisper\Api\Serializers\ConversationSerializer;
return [
(new Extend\Frontend('admin'))
->js(__DIR__.'/js/dist/admin.js'),
(new Extend\Frontend('forum'))
->js(__DIR__.'/js/dist/forum.js')
->css(__DIR__.'/resources/less/extension.less')
->route('/whisper/messages/{id}', 'whisper.messages')
->route('/whisper/conversations', 'whisper.conversation'),
new Extend\Locales(__DIR__.'/resources/locale'),
(new Extend\Model(User::class))
->hasMany('conversations' ,ConversationUser::class, 'user_id'),
(new Extend\Routes('api'))
->get('/whisper/conversations', 'whisper.conversations.index', Controllers\ListConversationsController::class)
->get('/whisper/messages/{id}', 'whisper.messages.list', Controllers\ListMessagesController::class)
->post('/whisper/conversations', 'whisper.conversations.create', Controllers\CreateConversationController::class)
->post('/whisper/messages', 'whisper.messages.create', Controllers\CreateMessageController::class)
->post('/whisper/messages/typing', 'whisper.message.typing', Controllers\TypingPusherController::class)
->post('/whisper/messages/read', 'whisper.message.read', Controllers\ReadMessageController::class)
->delete('/whisper/messages{id}', 'whisper.messages.delete', Controllers\DeleteMessageController::class)
//->patch('/messages/{id}', 'messages.update', Controllers\UpdateMessageController::class)
//->delete('/messages/{id}', 'messages.delete', Controllers\DeleteMessageController::class)
->get('/whisper/conversations/{id}', 'whisper.conversations.show', Controllers\ShowConversationController::class),
(new Extend\ApiSerializer(ForumSerializer::class))
->attribute('canMessage', function (ForumSerializer $serializer) {
return $serializer->getActor()->can('startConversation');
}),
(new Extend\ApiSerializer(CurrentUserSerializer::class))
->attribute('unreadMessages', function (CurrentUserSerializer $serializer) {
return $serializer->getActor()->unread_messages;
}),
(new Extend\Settings())
->serializeToForum('whisperReturnKey', 'kyrne-whisper.return_key', function ($value) {
return (bool) $value;
}),
(new Extend\ApiSerializer(CurrentUserSerializer::class))
->hasMany('conversations', ConversationRecipientSerializer::class),
(new Extend\ApiController(Controller\ListUsersController::class))
->addInclude('conversations'),
(new Extend\ApiController(Controller\ShowUserController::class))
->addInclude('conversations'),
(new Extend\ApiController(Controller\CreateUserController::class))
->addInclude('conversations'),
(new Extend\ApiController(Controller\UpdateUserController::class))
->addInclude('conversations'),
];