Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions Sources/Actions/PersonalMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -497,12 +497,18 @@ public function applyActions(): void
}

// Are we labeling anything?
// Only ever our own copy: the other recipients of a PM keep their own
// labels on it, and these are our labels, not theirs.
if (!empty($to_label) && $this->folder === 'inbox') {
foreach (Received::loadByPm(array_keys($to_label)) as $received) {
if ($label_type[$received->id] === 'add') {
$received->addLabel($to_label[$received->id]);
} elseif ($label_type[$received->id] === 'rem') {
$received->removeLabel($to_label[$received->id]);
foreach (Received::loadByPm(array_keys($to_label)) as $pm => $recipients) {
if (!isset($recipients[User::$me->id])) {
continue;
}

if ($label_type[$pm] === 'add') {
$recipients[User::$me->id]->addLabel($to_label[$pm]);
} elseif ($label_type[$pm] === 'rem') {
$recipients[User::$me->id]->removeLabel($to_label[$pm]);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/PersonalMessage/PM.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class PM implements \ArrayAccess
/**
* @var array
*
* Data about received copies of this PM.
* Data about received copies of this PM, keyed by the recipient's ID.
*/
public array $received = [];

Expand Down Expand Up @@ -229,7 +229,7 @@ public function __construct(int $id, array $props = [])
{
$this->id = $id;
$this->set($props);
$this->received = Received::loadByPm($this->id);
$this->received = Received::loadByPm($this->id)[$this->id] ?? [];
$this->folder = $this->member_from !== User::$me->id ? 'inbox' : 'sent';
self::$loaded[$id] = $this;
}
Expand Down
13 changes: 8 additions & 5 deletions Sources/PersonalMessage/Received.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,9 @@ public function __set(string $prop, mixed $value): void
* for future reference.
*
* @param int|array $ids The IDs of one or more personal messages.
* @return array The newly loaded instances of this class.
* @return array The newly loaded instances of this class, keyed first by
* the PM's ID and then by the recipient's ID. A PM has one of these per
* person it was sent to.
*/
public static function loadByPm(int|array $ids): array
{
Expand All @@ -326,9 +328,7 @@ public static function loadByPm(int|array $ids): array
// Have we already loaded these?
foreach ($ids as $key => $id) {
if (isset(self::$loaded[$id])) {
foreach (self::$loaded[$id] as $received) {
$loaded[$id] = $received;
}
$loaded[$id] = self::$loaded[$id];

unset($ids[$key]);
}
Expand Down Expand Up @@ -358,8 +358,11 @@ public static function loadByPm(int|array $ids): array
'ids' => $ids,
];

// One row per recipient, so the member has to be part of the key here.
// Keying on the PM alone leaves only whichever recipient the database
// happened to hand over last.
foreach (self::queryData($selects, $params, $joins, $where) as $row) {
$loaded[(int) $row['id_pm']] = new self($row);
$loaded[(int) $row['id_pm']][(int) $row['id_member']] = new self($row);
}

ksort($loaded);
Expand Down