Version 5.0.0 beta 1
This commit is contained in:
1 parent
25ddeb65d6
commit
15c7beabc5
6736 files changed
+627902
-497943
No files matched your search
@@ -11,58 +11,74 @@
|
||||
namespace IPS\core\Messenger;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use IPS\Application;
|
||||
use IPS\Application\Module;
|
||||
use IPS\Content\Comment;
|
||||
use IPS\Content\EditHistory;
|
||||
use IPS\Content\Item;
|
||||
use IPS\Content\Reportable;
|
||||
use IPS\DateTime;
|
||||
use IPS\Db;
|
||||
use IPS\Member;
|
||||
use IPS\Node\Model;
|
||||
use IPS\Notification;
|
||||
use IPS\Platform\Bridge;
|
||||
use function defined;
|
||||
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Personal Conversation Message
|
||||
*/
|
||||
class _Message extends \IPS\Content\Comment
|
||||
class Message extends Comment
|
||||
{
|
||||
use \IPS\Content\Reportable;
|
||||
use Reportable,
|
||||
EditHistory;
|
||||
|
||||
/**
|
||||
* @brief Application
|
||||
*/
|
||||
public static $application = 'core';
|
||||
public static string $application = 'core';
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Database Table
|
||||
*/
|
||||
public static $databaseTable = 'core_message_posts';
|
||||
public static ?string $databaseTable = 'core_message_posts';
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Database Prefix
|
||||
*/
|
||||
public static $databasePrefix = 'msg_';
|
||||
public static string $databasePrefix = 'msg_';
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Multiton Store
|
||||
*/
|
||||
protected static $multitons;
|
||||
protected static array $multitons;
|
||||
|
||||
/**
|
||||
* @brief [Content\Comment] Title
|
||||
*/
|
||||
public static $title = 'personal_conversation_message';
|
||||
public static string $title = 'personal_conversation_message';
|
||||
|
||||
/**
|
||||
* @brief [Content\Comment] Icon
|
||||
*/
|
||||
public static $icon = 'envelope';
|
||||
public static string $icon = 'envelope';
|
||||
|
||||
/**
|
||||
* @brief [Content\Comment] Item Class
|
||||
*/
|
||||
public static $itemClass = 'IPS\core\Messenger\Conversation';
|
||||
public static string $itemClass = 'IPS\core\Messenger\Conversation';
|
||||
|
||||
/**
|
||||
* @brief [Content\Comment] Database Column Map
|
||||
*/
|
||||
public static $databaseColumnMap = array(
|
||||
public static array $databaseColumnMap = array(
|
||||
'item' => 'topic_id',
|
||||
'date' => 'date',
|
||||
'content' => 'post',
|
||||
@@ -74,26 +90,26 @@ class _Message extends \IPS\Content\Comment
|
||||
/**
|
||||
* @brief [Content\Comment] Language prefix for forms
|
||||
*/
|
||||
public static $formLangPrefix = 'messenger_';
|
||||
public static string $formLangPrefix = 'messenger_';
|
||||
|
||||
/**
|
||||
* @brief [Content\Comment] The ignore type
|
||||
*/
|
||||
public static $ignoreType = 'messages';
|
||||
public static string $ignoreType = 'messages';
|
||||
|
||||
/**
|
||||
* Should this comment be ignored?
|
||||
* Override so that the person who starts the conversation sees all messages - if you send a
|
||||
* message to someone, you're always going to want to be able to see their replies.
|
||||
*
|
||||
* @param \IPS\Member|null $member The member to check for - NULL for currently logged in member
|
||||
* @param Member|null $member The member to check for - NULL for currently logged in member
|
||||
* @return bool
|
||||
*/
|
||||
public function isIgnored( $member=NULL )
|
||||
public function isIgnored( Member $member=null ): bool
|
||||
{
|
||||
if ( $member === NULL )
|
||||
{
|
||||
$member = \IPS\Member::loggedIn();
|
||||
$member = Member::loggedIn();
|
||||
}
|
||||
|
||||
if ( $this->item()->author()->member_id == $member->member_id )
|
||||
@@ -107,51 +123,40 @@ class _Message extends \IPS\Content\Comment
|
||||
/**
|
||||
* Should posting this increment the poster's post count?
|
||||
*
|
||||
* @param \IPS\Node\Model|NULL $container Container
|
||||
* @return void
|
||||
* @param Model|NULL $container Container
|
||||
* @return bool
|
||||
*/
|
||||
public static function incrementPostCount( \IPS\Node\Model $container = NULL )
|
||||
public static function incrementPostCount( Model $container = NULL ): bool
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Can promote this comment/item?
|
||||
*
|
||||
* @param \IPS\Member|NULL $member The member to check for (NULL for currently logged in member)
|
||||
* @return boolean
|
||||
*/
|
||||
public function canPromoteToSocialMedia( $member=NULL )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 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
|
||||
* @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)
|
||||
* @param int|NULL $anonymous NULL for no value, 0 or 1 for a value (0=no, 1=yes)
|
||||
* @return static
|
||||
* @param Item $item The content item just created
|
||||
* @param string $comment The comment
|
||||
* @param bool $first Is the first comment?
|
||||
* @param string|null $guestName If author is a guest, the name to use
|
||||
* @param bool|null $incrementPostCount Increment post count? If NULL, will use static::incrementPostCount()
|
||||
* @param Member|null $member The author of this comment. If NULL, uses currently logged in member.
|
||||
* @param DateTime|null $time The time
|
||||
* @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)
|
||||
* @param int|null $anonymous NULL for no value, 0 or 1 for a value (0=no, 1=yes)
|
||||
* @return Message|null
|
||||
*/
|
||||
public static function create( $item, $comment, $first=FALSE, $guestName=NULL, $incrementPostCount=NULL, $member=NULL, \IPS\DateTime $time=NULL, $ipAddress=NULL, $hiddenStatus=NULL, $anonymous=NULL )
|
||||
public static function create( Item $item, string $comment, bool $first=false, string|null $guestName=null, bool|null $incrementPostCount= null, Member|null $member= null, DateTime|null $time= null, string|null $ipAddress= null, int|null $hiddenStatus= null, int|null $anonymous= null ): static|null
|
||||
{
|
||||
if ( $member === NULL )
|
||||
{
|
||||
$member = \IPS\Member::loggedIn();
|
||||
$member = Member::loggedIn();
|
||||
}
|
||||
|
||||
$comment = parent::create( $item, $comment, $first, $guestName, $incrementPostCount, $member, $time, $ipAddress, $hiddenStatus, $anonymous );
|
||||
|
||||
/* Mark unread for this person */
|
||||
\IPS\Db::i()->update( 'core_message_topic_user_map', array( 'map_has_unread' => FALSE, 'map_read_time' => time() ), array( 'map_user_id=? AND map_topic_id=?', $member->member_id, $item->id ) );
|
||||
Db::i()->update( 'core_message_topic_user_map', array( 'map_has_unread' => FALSE, 'map_read_time' => time() ), array( 'map_user_id=? AND map_topic_id=?', $member->member_id, $item->id ) );
|
||||
|
||||
return $comment;
|
||||
}
|
||||
@@ -161,29 +166,31 @@ class _Message extends \IPS\Content\Comment
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function sendNotifications()
|
||||
public function sendNotifications(): void
|
||||
{
|
||||
/* Update topic maps for other participants */
|
||||
\IPS\Db::i()->update( 'core_message_topic_user_map', array( 'map_has_unread' => 1, 'map_last_topic_reply' => time() ), array( 'map_topic_id=? AND map_user_id!=?', $this->item()->id, $this->author()->member_id ) );
|
||||
Db::i()->update( 'core_message_topic_user_map', array( 'map_has_unread' => 1, 'map_last_topic_reply' => time() ), array( 'map_topic_id=? AND map_user_id!=?', $this->item()->id, $this->author()->member_id ) );
|
||||
|
||||
/* Update topic map for this author */
|
||||
\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 ) );
|
||||
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 ) );
|
||||
$messengerModule = \IPS\Application\Module::get( 'core', 'messaging', 'front' );
|
||||
$notification = new Notification( Application::load('core'), 'new_private_message', $this->item(), array( $this ) );
|
||||
$messengerModule = Module::get( 'core', 'messaging', 'front' );
|
||||
|
||||
$memberIds = [];
|
||||
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'] );
|
||||
$member = 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 == 2 or !$member->canAccessModule( $messengerModule ) or !$member->member_id )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
\IPS\core\Messenger\Conversation::rebuildMessageCounts( $member );
|
||||
$memberIds[] = $member->member_id;
|
||||
Conversation::rebuildMessageCounts( $member );
|
||||
|
||||
$notification->recipients->attach( $member );
|
||||
|
||||
@@ -195,17 +202,23 @@ class _Message extends \IPS\Content\Comment
|
||||
}
|
||||
}
|
||||
|
||||
/* Send the notification event on cloud where we don't use long polling */
|
||||
if ( Bridge::i()->featureIsEnabled( 'realtime' ) and count( $memberIds ) )
|
||||
{
|
||||
Bridge::i()->publishRealtimeEvent( 'notifications_available', location: $memberIds, locationAsMember: true );
|
||||
}
|
||||
|
||||
$notification->send();
|
||||
}
|
||||
|
||||
/**
|
||||
* Move Comment to another item
|
||||
*
|
||||
* @param \IPS\Content\Item $item The item to move this comment to
|
||||
* @param bool $skip Skip rebuilding new/old content item data (used for multimod where we can do it in one go after)
|
||||
* @param Item $item The item to move this comment to
|
||||
* @param bool $skip Skip rebuilding new/old content item data (used for multimod where we can do it in one go after)
|
||||
* @return void
|
||||
*/
|
||||
public function move( \IPS\Content\Item $item, $skip=FALSE )
|
||||
public function move( Item $item, bool $skip=FALSE ): void
|
||||
{
|
||||
/* 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 ) {
|
||||
|
||||
Reference in new issue
Block a user