Version 4.1.19
This commit is contained in:
1 parent
28bd025b35
commit
2bd5025018
2674 files changed
+233518
-77766
No files matched your search
@@ -2,9 +2,9 @@
|
||||
/**
|
||||
* @brief Personal Conversation Model
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @package IPS Community Suite
|
||||
* @since 5 Jul 2013
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
@@ -115,7 +115,7 @@ class _Conversation extends \IPS\Content\Item
|
||||
* Can a given member create this type of content?
|
||||
*
|
||||
* @param \IPS\Member $member The member
|
||||
* @param int $container Container (e.g. forum) ID, if appropriate
|
||||
* @param \IPS\Node\Model $container Container (e.g. forum) ID, if appropriate
|
||||
* @param bool $showError If TRUE, rather than returning a boolean value, will display an error
|
||||
* @return bool
|
||||
*/
|
||||
@@ -139,7 +139,7 @@ class _Conversation extends \IPS\Content\Item
|
||||
}
|
||||
|
||||
/* Have we exceeded our limit for the day/minute? */
|
||||
if ( $member->group['g_pm_perday'] )
|
||||
if ( $member->group['g_pm_perday'] !== -1 )
|
||||
{
|
||||
$messagesSentToday = \IPS\Db::i()->select( 'COUNT(*) AS count, MAX(mt_date) AS max', 'core_message_topics', array( 'mt_starter_id=? AND mt_date>?', $member->member_id, \IPS\DateTime::create()->sub( new \DateInterval( 'P1D' ) )->getTimeStamp() ) )->first();
|
||||
if ( $messagesSentToday['count'] >= $member->group['g_pm_perday'] )
|
||||
@@ -154,7 +154,7 @@ class _Conversation extends \IPS\Content\Item
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
if ( $member->group['g_pm_flood_mins'] )
|
||||
if ( $member->group['g_pm_flood_mins'] !== -1 )
|
||||
{
|
||||
$messagesSentThisMinute = \IPS\Db::i()->select( 'COUNT(*)', 'core_message_topics', array( 'mt_starter_id=? AND mt_date>?', $member->member_id, \IPS\DateTime::create()->sub( new \DateInterval( 'PT1M' ) )->getTimeStamp() ) )->first();
|
||||
if ( $messagesSentThisMinute >= $member->group['g_pm_flood_mins'] )
|
||||
@@ -169,7 +169,7 @@ class _Conversation extends \IPS\Content\Item
|
||||
}
|
||||
|
||||
/* Is our inbox full? */
|
||||
if ( $member->group['g_max_messages'] )
|
||||
if ( $member->group['g_max_messages'] !== -1 )
|
||||
{
|
||||
$messagesInInbox = \IPS\Db::i()->select( 'COUNT(*)', 'core_message_topic_user_map', array( 'map_user_id=? AND map_user_active=1', $member->member_id ) )->first();
|
||||
if ( $messagesInInbox > $member->group['g_max_messages'] )
|
||||
@@ -213,36 +213,86 @@ class _Conversation extends \IPS\Content\Item
|
||||
$member = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
$return['to'] = new \IPS\Helpers\Form\Member( 'messenger_to', $member, TRUE, array( 'multiple' => ( \IPS\Member::loggedIn()->group['g_max_mass_pm'] == 0 ) ? NULL : \IPS\Member::loggedIn()->group['g_max_mass_pm'] ), function ( $members )
|
||||
|
||||
$return['to'] = new \IPS\Helpers\Form\Member( 'messenger_to', $member, TRUE, array( 'multiple' => ( \IPS\Member::loggedIn()->group['g_max_mass_pm'] == -1 ) ? NULL : \IPS\Member::loggedIn()->group['g_max_mass_pm'] ), function ( $members )
|
||||
{
|
||||
$messengerModule = \IPS\Application\Module::get( 'core', 'messaging' );
|
||||
|
||||
if ( $members instanceof \IPS\Member )
|
||||
if ( is_array( $members ) )
|
||||
{
|
||||
$members = array( $members );
|
||||
}
|
||||
|
||||
if ( !is_array( $members ) )
|
||||
{
|
||||
throw new \InvalidArgumentException( 'messenger_invalid_recipient' );
|
||||
}
|
||||
|
||||
foreach ( $members as $m )
|
||||
{
|
||||
if ( $m->members_disable_pm or !$m->canAccessModule( $messengerModule ) or ( ( $m->group['g_max_messages'] > 0 AND $m->msg_count_total >= $m->group['g_max_messages'] ) and !\IPS\Member::loggedIn()->group['gbw_pm_override_inbox_full'] ) or $m->isIgnoring( \IPS\Member::loggedIn(), 'messages' ) )
|
||||
foreach ( $members as $m )
|
||||
{
|
||||
throw new \InvalidArgumentException( \IPS\Member::loggedIn()->language()->addToStack('meesnger_err_bad_recipient', FALSE, array( 'sprintf' => array( $m->name ) ) ) );
|
||||
if ( !$m instanceof \IPS\Member OR !static::memberCanReceiveNewMessage( $m, \IPS\Member::loggedIn() ) )
|
||||
{
|
||||
throw new \InvalidArgumentException( \IPS\Member::loggedIn()->language()->addToStack('meesnger_err_bad_recipient', FALSE, array( 'sprintf' => array( $m->name ) ) ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( !$members instanceof \IPS\Member OR !$members->member_id OR !static::memberCanReceiveNewMessage( $members, \IPS\Member::loggedIn() ) )
|
||||
{
|
||||
throw new \InvalidArgumentException( \IPS\Member::loggedIn()->language()->addToStack('meesnger_err_bad_recipient', FALSE, array( 'sprintf' => array( ( $members instanceof \IPS\Member ) ? $members->name : $members ) ) ) );
|
||||
}
|
||||
}
|
||||
} );
|
||||
}
|
||||
}
|
||||
else if ( $k == 'content' )
|
||||
{
|
||||
if( isset( \IPS\Request::i()->to ) and \IPS\Request::i()->to )
|
||||
{
|
||||
$v->options['autoSaveKey'] = 'newMessageTo-' . \IPS\Request::i()->to;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Ensure that the autosave doesn't populate the editor witha previous PM which may be sent by accident */
|
||||
$v->options['autoSaveKey'] = 'newMessageTo-' . uniqid();
|
||||
}
|
||||
}
|
||||
|
||||
$return[ $k ] = $v;
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if a member can receive new messages
|
||||
*
|
||||
* @param \IPS\Member $member The member to check
|
||||
* @param \IPS\Member $sender The member sending the new message
|
||||
* @return array
|
||||
*/
|
||||
public static function memberCanReceiveNewMessage( \IPS\Member $member, \IPS\Member $sender )
|
||||
{
|
||||
/* Messenger is disabled */
|
||||
if ( $member->members_disable_pm )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Group can not use messenger */
|
||||
if ( !$member->canAccessModule( \IPS\Application\Module::get( 'core', 'messaging' ) ) )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Inbox is full */
|
||||
if ( ( $member->group['g_max_messages'] > 0 AND $member->msg_count_total >= $member->group['g_max_messages'] ) and !$sender->group['gbw_pm_override_inbox_full'] )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Is being ignored */
|
||||
if ( $member->isIgnoring( $sender, 'messages' ) )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process created object BEFORE the object has been created
|
||||
*
|
||||
@@ -251,6 +301,7 @@ class _Conversation extends \IPS\Content\Item
|
||||
*/
|
||||
protected function processBeforeCreate( $values )
|
||||
{
|
||||
$this->maps = array();
|
||||
$this->to_count = count( $values['messenger_to'] );
|
||||
|
||||
parent::processBeforeCreate( $values );
|
||||
@@ -315,6 +366,12 @@ class _Conversation extends \IPS\Content\Item
|
||||
/* Have we granted them temporary permission from the report center or a warning log? */
|
||||
if ( $member->modPermission('can_view_reports') )
|
||||
{
|
||||
/* If we are coming directly from a report, and the Report ID is different from what is stored in session, then we need to unset it so it can be reset */
|
||||
if ( isset( $_SESSION['report'] ) AND isset( \IPS\Request::i()->_report ) AND \IPS\Request::i()->_report != $_SESSION['report'] )
|
||||
{
|
||||
unset( $_SESSION['report'] );
|
||||
}
|
||||
|
||||
$report = isset( $_SESSION['report'] ) ? $_SESSION['report'] : ( isset( \IPS\Request::i()->_report ) ? \IPS\Request::i()->_report : NULL );
|
||||
if ( $report )
|
||||
{
|
||||
@@ -332,15 +389,26 @@ class _Conversation extends \IPS\Content\Item
|
||||
}
|
||||
if ( $member->modPermission('mod_see_warn') )
|
||||
{
|
||||
/* If we are coming directly from a warning, and the Warning ID is different from what is stored in session, then we need to unset it so it can be reset */
|
||||
if ( isset( $_SESSION['warning'] ) AND isset( \IPS\Request::i()->_warning ) AND \IPS\Request::i()->_warning != $_SESSION['warning'] )
|
||||
{
|
||||
unset( $_SESSION['warning'] );
|
||||
}
|
||||
|
||||
$warning = isset( $_SESSION['warning'] ) ? $_SESSION['warning'] : ( isset( \IPS\Request::i()->_warning ) ? \IPS\Request::i()->_warning : NULL );
|
||||
if ( $warning )
|
||||
{
|
||||
$warning = \IPS\Db::i()->select( '*', 'core_members_warn_logs', array( 'wl_id=? AND wl_content_app=? AND wl_content_module=? AND wl_content_id1=?', $member->member_id, 'core', 'messaging', $this->id ) )->first();
|
||||
if ( $warning )
|
||||
try
|
||||
{
|
||||
$_SESSION['report'] = $report->id;
|
||||
return TRUE;
|
||||
$warning = \IPS\core\Warnings\Warning::load( $warning );
|
||||
|
||||
if ( $warning->content_app == 'core' AND $warning->content_module == 'messaging-comment' AND $warning->content_id1 == $this->id )
|
||||
{
|
||||
$_SESSION['warning'] = $warning->id;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
catch( \OutOfRangeException $e ) { }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -466,10 +534,10 @@ class _Conversation extends \IPS\Content\Item
|
||||
*/
|
||||
public static function rebuildMessageCounts( \IPS\Member $member )
|
||||
{
|
||||
$total = \IPS\Db::i()->select( 'count(*)', 'core_message_topic_user_map', array( 'map_user_id=? AND map_user_active=1', $member->member_id ) )->first();
|
||||
$total = \IPS\Db::i()->select( 'count(*)', 'core_message_topic_user_map', array( 'map_user_id=? AND map_user_active=1', $member->member_id ), NULL, NULL, NULL, NULL, \IPS\Db::SELECT_FROM_WRITE_SERVER )->first();
|
||||
$member->msg_count_total = $total;
|
||||
|
||||
$new = \IPS\Db::i()->select( 'count(*)', 'core_message_topic_user_map', array( 'map_user_id=? AND map_user_active=1 AND map_has_unread=1 AND map_ignore_notification=0 AND map_last_topic_reply>?', $member->member_id, $member->msg_count_reset ) )->first();
|
||||
$new = \IPS\Db::i()->select( 'count(*)', 'core_message_topic_user_map', array( 'map_user_id=? AND map_user_active=1 AND map_has_unread=1 AND map_ignore_notification=0 AND map_last_topic_reply>?', $member->member_id, $member->msg_count_reset ), NULL, NULL, NULL, NULL, \IPS\Db::SELECT_FROM_WRITE_SERVER )->first();
|
||||
$member->msg_count_new = $new;
|
||||
|
||||
$member->save();
|
||||
@@ -532,7 +600,6 @@ class _Conversation extends \IPS\Content\Item
|
||||
if ( !$done )
|
||||
{
|
||||
/* Create map */
|
||||
$membersLastComment = $this->comments( 1, 0, 'date', 'desc', $member );
|
||||
$this->maps[ $member->member_id ] = array(
|
||||
'map_user_id' => $member->member_id,
|
||||
'map_topic_id' => $this->id,
|
||||
@@ -545,7 +612,7 @@ class _Conversation extends \IPS\Content\Item
|
||||
'map_is_starter' => ( $member->member_id == $this->starter_id ),
|
||||
'map_left_time' => 0,
|
||||
'map_ignore_notification' => FALSE,
|
||||
'map_last_topic_reply' => $membersLastComment ? $membersLastComment->date : time(),
|
||||
'map_last_topic_reply' => time(),
|
||||
);
|
||||
\IPS\Db::i()->insert( 'core_message_topic_user_map', $this->maps[ $member->member_id ] );
|
||||
}
|
||||
@@ -580,7 +647,9 @@ class _Conversation extends \IPS\Content\Item
|
||||
$members = is_array( $members ) ? $members : array( $members );
|
||||
foreach ( $members as $member )
|
||||
{
|
||||
unset( $this->maps[ $member->member_id ] );
|
||||
\IPS\Db::i()->update( 'core_message_topic_user_map', array( 'map_user_active' => 0, 'map_user_banned' => $banned ), array( 'map_user_id=? AND map_topic_id=?', $member->member_id, $this->id ) );
|
||||
\IPS\Db::i()->delete( 'core_notifications', array( 'notification_key=? AND item_id = ? AND member=?', 'new_private_message', $this->id, $member->member_id ) );
|
||||
static::rebuildMessageCounts( $member );
|
||||
}
|
||||
$this->rebuildParticipants();
|
||||
@@ -594,7 +663,7 @@ class _Conversation extends \IPS\Content\Item
|
||||
public function rebuildParticipants()
|
||||
{
|
||||
$activeParticipants = 0;
|
||||
foreach ( $this->maps( TRUE ) as $map )
|
||||
foreach ( $this->maps() as $map )
|
||||
{
|
||||
if ( $map['map_user_active'] )
|
||||
{
|
||||
@@ -683,5 +752,27 @@ class _Conversation extends \IPS\Content\Item
|
||||
|
||||
return $this->participantBlurb;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move a message to a different folder
|
||||
*
|
||||
* @param string $to Folder name
|
||||
* @param \IPS\Member|null $member Member object, or null to use logged in member
|
||||
* @return void
|
||||
* @throws \OutOfRangeException
|
||||
*/
|
||||
public function moveConversation( $to, $member=NULL )
|
||||
{
|
||||
$member = ( $member != NULL ) ? $member : \IPS\Member::loggedIn();
|
||||
|
||||
if ( in_array( $to, array_merge( array( 'myconvo' ), array_keys( json_decode( $member->pconversation_filters, TRUE ) ) ) ) )
|
||||
{
|
||||
\IPS\Db::i()->update( 'core_message_topic_user_map', array( 'map_folder_id' => $to ), array( 'map_user_id=? AND map_topic_id=?', $member->member_id, $this->id ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,9 +2,9 @@
|
||||
/**
|
||||
* @brief Personal Conversation Message Model
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @package IPS Community Suite
|
||||
* @since 8 Jul 2013
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
@@ -106,16 +106,18 @@ class _Message extends \IPS\Content\Comment implements \IPS\Content\ReportCenter
|
||||
/**
|
||||
* Create comment
|
||||
*
|
||||
* @param \IPS\Content\Item $item The content item just created
|
||||
* @param string $comment The comment
|
||||
* @param bool $first Is the first comment?
|
||||
* @param string $guestName If author is a guest, the name to use
|
||||
* @param \IPS\Content\Item $item The content item just created
|
||||
* @param string $comment The comment
|
||||
* @param bool $first Is the first comment?
|
||||
* @param string $guestName If author is a guest, the name to use
|
||||
* @param bool|NULL $incrementPostCount Increment post count? If NULL, will use static::incrementPostCount()
|
||||
* @param \IPS\Member|NULL $member The author of this comment. If NULL, uses currently logged in member.
|
||||
* @param \IPS\DateTime|NULL $time The time
|
||||
* @return \IPS\Content\Comment
|
||||
* @param string|NULL $ipAddress The IP address or NULL to detect automatically
|
||||
* @param int|NULL $hiddenStatus NULL to set automatically or override: 0 = unhidden; 1 = hidden, pending moderator approval; -1 = hidden (as if hidden by a moderator)
|
||||
* @return static
|
||||
*/
|
||||
public static function create( $item, $comment, $first=FALSE, $guestName=NULL, $incrementPostCount=NULL, $member=NULL, \IPS\DateTime $time=NULL )
|
||||
public static function create( $item, $comment, $first=FALSE, $guestName=NULL, $incrementPostCount=NULL, $member=NULL, \IPS\DateTime $time=NULL, $ipAddress=NULL, $hiddenStatus=NULL )
|
||||
{
|
||||
if ( $member === NULL )
|
||||
{
|
||||
@@ -144,11 +146,19 @@ class _Message extends \IPS\Content\Comment implements \IPS\Content\ReportCenter
|
||||
\IPS\Db::i()->update( 'core_message_topic_user_map', array( 'map_has_unread' => 0, 'map_last_topic_reply' => time(), 'map_read_time' => time() ), array( 'map_topic_id=? AND map_user_id=?', $this->item()->id, $this->author()->member_id ) );
|
||||
|
||||
$notification = new \IPS\Notification( \IPS\Application::load('core'), 'new_private_message', $this->item(), array( $this ) );
|
||||
foreach ( $this->item()->maps( TRUE ) as $map )
|
||||
$messengerModule = \IPS\Application\Module::get( 'core', 'messaging' );
|
||||
|
||||
foreach ( $this->item()->maps() as $map )
|
||||
{
|
||||
if ( $map['map_user_id'] !== $this->author()->member_id and $map['map_user_active'] and !$map['map_ignore_notification'] )
|
||||
{
|
||||
$member = \IPS\Member::load( $map['map_user_id'] );
|
||||
/* skip this for members which can't or don't want to use the messenger or for deleted users */
|
||||
if ( $member->members_disable_pm or !$member->canAccessModule( $messengerModule ) or !$member->member_id )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
\IPS\core\Messenger\Conversation::rebuildMessageCounts( $member );
|
||||
|
||||
$notification->recipients->attach( $member );
|
||||
@@ -163,4 +173,22 @@ class _Message extends \IPS\Content\Comment implements \IPS\Content\ReportCenter
|
||||
|
||||
$notification->send();
|
||||
}
|
||||
|
||||
/**
|
||||
* Move Comment to another item
|
||||
*
|
||||
* @param \IPS\Content\Item $item The item to move this comment too.
|
||||
* @return void
|
||||
*/
|
||||
public function move( \IPS\Content\Item $item )
|
||||
{
|
||||
/* Make sure all active participants in the old conversation are in the new one */
|
||||
$activeParticipants = array_keys( array_filter( $this->item()->maps( TRUE ), function ( $map ) {
|
||||
return $map['map_user_active'];
|
||||
} ) );
|
||||
|
||||
$item->authorize( $activeParticipants );
|
||||
|
||||
parent::move( $item );
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user