示例#1
0
 static function send($user, $group, $text)
 {
     if (!$user->hasRight(Right::NEWMESSAGE)) {
         // XXX: maybe break this out into a separate right
         // TRANS: Exception thrown when trying to send group private message without having the right to do that.
         // TRANS: %s is a user nickname.
         throw new Exception(sprintf(_m('User %s is not allowed to send private messages.'), $user->nickname));
     }
     Group_privacy_settings::ensurePost($user, $group);
     $text = $user->shortenLinks($text);
     // We use the same limits as for 'regular' private messages.
     if (Message::contentTooLong($text)) {
         // TRANS: Exception thrown when trying to send group private message that is too long.
         // TRANS: %d is the maximum meggage length.
         throw new Exception(sprintf(_m('That\'s too long. Maximum message size is %d character.', 'That\'s too long. Maximum message size is %d characters.', Message::maxContent()), Message::maxContent()));
     }
     // Valid! Let's do this thing!
     $gm = new Group_message();
     $gm->id = UUID::gen();
     $gm->uri = common_local_url('showgroupmessage', array('id' => $gm->id));
     $gm->from_profile = $user->id;
     $gm->to_group = $group->id;
     $gm->content = $text;
     // XXX: is this cool?!
     $gm->rendered = common_render_text($text);
     $gm->url = $gm->uri;
     $gm->created = common_sql_now();
     // This throws a conniption if there's a problem
     $gm->insert();
     $gm->distribute();
     return $gm;
 }