3 * GNU Social - a federating social network
4 * Copyright (C) 2014, Free Software Foundation, Inc.
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 if (!defined('GNUSOCIAL')) { exit(1); }
23 * @maintainer Mikael Nordfeldth <mmn@hethane.se>
25 class DirectMessagePlugin extends Plugin
27 public function onCheckSchema()
29 $schema = Schema::get();
30 $schema->ensureTable('message', Message::schemaDef());
34 public function onRouterInitialized(URLMapper $m)
36 // web front-end actions
37 $m->connect('message/new', array('action' => 'newmessage'));
38 $m->connect('message/new?to=:to', array('action' => 'newmessage'), array('to' => Nickname::DISPLAY_FMT));
39 $m->connect('message/:message',
40 array('action' => 'showmessage'),
41 array('message' => '[0-9]+'));
44 $m->connect('api/direct_messages.:format',
45 array('action' => 'ApiDirectMessage',
46 'format' => '(xml|json|rss|atom)'));
47 $m->connect('api/direct_messages/sent.:format',
48 array('action' => 'ApiDirectMessage',
49 'format' => '(xml|json|rss|atom)',
51 $m->connect('api/direct_messages/new.:format',
52 array('action' => 'ApiDirectMessageNew',
53 'format' => '(xml|json)'));
58 public function onAppendUserActivityStreamObjects(UserActivityStream $uas, array &$objs)
60 // Messages _from_ the user
61 $msgMap = Message::listGet('from_profile', array($this->user->id));
62 $messages = $msgMap[$uas->user->id];
63 if (!empty($uas->after)) {
64 $messages = array_filter($messages, array($uas, 'createdAfter'));
68 // Messages _to_ the user
69 $msgMap = Message::listGet('to_profile', array($this->user->id));
70 $messages = $msgMap[$uas->user->id];
71 if (!empty($uas->after)) {
72 $messages = array_filter($messages, array($uas, 'createdAfter'));
79 public function onEndPersonalGroupNav(Menu $menu, Profile $target, Profile $scoped=null)
81 if ($scoped instanceof Profile && $scoped->id == $target->id
82 && !common_config('singleuser', 'enabled')) {
84 $menu->out->menuItem(common_local_url('inbox', array('nickname' =>
85 $target->getNickname())),
86 // TRANS: Menu item in personal group navigation menu.
87 _m('MENU','Messages'),
88 // TRANS: Menu item title in personal group navigation menu.
89 _('Your incoming messages'),
90 $scoped->id === $target->id && $menu->actionName =='inbox');
94 public function onEndProfilePageActionsElements(HTMLOutputter $out, Profile $profile)
96 $scoped = Profile::current();
97 if (!$scoped instanceof Profile) {
101 if ($profile->isLocal() && $scoped->mutuallySubscribed($profile)) {
102 $out->elementStart('li', 'entity_send-a-message');
103 $out->element('a', array('href' => common_local_url('newmessage', array('to' => $profile->id)),
104 // TRANS: Link title for link on user profile.
105 'title' => _('Send a direct message to this user.')),
106 // TRANS: Link text for link on user profile.
107 _m('BUTTON','Message'));
108 $out->elementEnd('li');
113 public function onProfileDeleteRelated(Profile $profile, &$related)
115 $msg = new Message();
116 $msg->from_profile = $profile->id;
119 $msg = new Message();
120 $msg->to_profile = $profile->id;
125 public function onPluginVersion(array &$versions)
127 $versions[] = array('name' => 'Direct Message',
128 'version' => GNUSOCIAL_VERSION,
129 'author' => 'Mikael Nordfeldth',
130 'homepage' => 'http://gnu.io/',
132 // TRANS: Plugin description.
133 _m('Direct Message to other local users (broken out of core).'));