123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- <?php
- if (!defined('GNUSOCIAL')) { exit(1); }
- class DirectMessagePlugin extends Plugin
- {
- const PLUGIN_VERSION = '2.0.0';
- public function onCheckSchema()
- {
- $schema = Schema::get();
- $schema->ensureTable('message', Message::schemaDef());
- return true;
- }
- public function onRouterInitialized(URLMapper $m)
- {
-
- $m->connect('message/new', ['action' => 'newmessage']);
- $m->connect('message/new?to=:to',
- ['action' => 'newmessage'],
- ['to' => Nickname::DISPLAY_FMT]);
- $m->connect('message/:message',
- ['action' => 'showmessage'],
- ['message' => '[0-9]+']);
-
- $m->connect('api/direct_messages.:format',
- ['action' => 'ApiDirectMessage'],
- ['format' => '(xml|json|rss|atom)']);
- $m->connect('api/direct_messages/sent.:format',
- ['action' => 'ApiDirectMessage',
- 'sent' => true],
- ['format' => '(xml|json|rss|atom)']);
- $m->connect('api/direct_messages/new.:format',
- ['action' => 'ApiDirectMessageNew'],
- ['format' => '(xml|json)']);
- return true;
- }
- public function onAppendUserActivityStreamObjects(UserActivityStream $uas, array &$objs)
- {
-
- $msgMap = Message::listGet('from_profile', array($uas->getUser()->id));
- $messages = $msgMap[$uas->getUser()->id];
- if (!empty($uas->after)) {
- $messages = array_filter($messages, array($uas, 'createdAfter'));
- }
- foreach ($messages as $message) {
- $objs[] = clone($message);
- }
-
- $msgMap = Message::listGet('to_profile', array($uas->getUser()->id));
- $messages = $msgMap[$uas->getUser()->id];
- if (!empty($uas->after)) {
- $messages = array_filter($messages, array($uas, 'createdAfter'));
- }
- foreach ($messages as $message) {
- $objs[] = clone($message);
- }
- return true;
- }
-
- public function onCommandSupportedAPI(Command $cmd, &$supported)
- {
- $supported = $supported || $cmd instanceof MessageCommand;
- return true;
- }
-
- public function onStartInterpretCommand($cmd, $arg, $user, &$result)
- {
- $dm_cmds = array('d', 'dm');
- if ($result === false && in_array($cmd, $dm_cmds)) {
- if (!empty($arg)) {
- list($other, $extra) = CommandInterpreter::split_arg($arg);
- if (!empty($extra)) {
- $result = new MessageCommand($user, $other, $extra);
- }
- }
- return false;
- }
- return true;
- }
- public function onEndPersonalGroupNav(Menu $menu, Profile $target, Profile $scoped=null)
- {
- if ($scoped instanceof Profile && $scoped->id == $target->id
- && !common_config('singleuser', 'enabled')) {
- $menu->out->menuItem(common_local_url('inbox', array('nickname' =>
- $target->getNickname())),
-
- _m('MENU','Messages'),
-
- _('Your incoming messages'),
- $scoped->id === $target->id && $menu->actionName =='inbox');
- }
- }
- public function onEndProfilePageActionsElements(HTMLOutputter $out, Profile $profile)
- {
- $scoped = Profile::current();
- if (!$scoped instanceof Profile) {
- return true;
- }
- if ($profile->isLocal() && $scoped->mutuallySubscribed($profile)) {
- $out->elementStart('li', 'entity_send-a-message');
- $out->element('a', array('href' => common_local_url('newmessage', array('to' => $profile->id)),
-
- 'title' => _('Send a direct message to this user.')),
-
- _m('BUTTON','Message'));
- $out->elementEnd('li');
- }
- return true;
- }
- public function onProfileDeleteRelated(Profile $profile, &$related)
- {
- $msg = new Message();
- $msg->from_profile = $profile->id;
- $msg->delete();
- $msg = new Message();
- $msg->to_profile = $profile->id;
- $msg->delete();
- return true;
- }
- public function onPluginVersion(array &$versions)
- {
- $versions[] = array('name' => 'Direct Message',
- 'version' => self::PLUGIN_VERSION,
- 'author' => 'Mikael Nordfeldth',
- 'homepage' => 'http://gnu.io/',
- 'rawdescription' =>
-
- _m('Direct Message to other local users (broken out of core).'));
- return true;
- }
- }
|