Skip to content

Commit

Permalink
Take into account mentions imported from other systems that handle th…
Browse files Browse the repository at this point in the history
…ings differently

Signed-off-by: emanuele <emanuele45@gmail.com>
  • Loading branch information
emanuele45 committed Jun 9, 2015
1 parent f3b6c71 commit 2b1785d
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 6 deletions.
17 changes: 13 additions & 4 deletions sources/controllers/Mentions.controller.php
Expand Up @@ -427,6 +427,7 @@ public function prepareMentionMessage(&$mentions, $type)
global $txt, $scripturl, $context, $modSettings, $user_info;

$boards = array();
$unset_keys = array();
$removed = false;

foreach ($mentions as $key => $row)
Expand All @@ -437,7 +438,12 @@ public function prepareMentionMessage(&$mentions, $type)

// These things are associated to messages and require permission checks
if (in_array($row['mention_type'], array('men', 'like', 'rlike')))
$boards[$key] = $row['id_board'];
{
if (empty($row['id_board']))
$unset_keys[] = $key;
else
$boards[$key] = $row['id_board'];
}

$mentions[$key]['message'] = str_replace(
array(
Expand Down Expand Up @@ -465,15 +471,18 @@ public function prepareMentionMessage(&$mentions, $type)
// You can't see the board where this mention is, so we drop it from the results
if (!in_array($board, $accessibleBoards))
{
$removed = true;
unset($mentions[$key]);
$unset_keys[] = $key;
}
}
}

// If some of these mentions are no longer visable, we need to do some maintenance
if ($removed)
if (!empty($unset_keys))
{
$removed = true;
foreach ($unset_keys as $key)
unset($mentions[$key]);

if (!empty($modSettings['user_access_mentions']))
$modSettings['user_access_mentions'] = @unserialize($modSettings['user_access_mentions']);
else
Expand Down
30 changes: 30 additions & 0 deletions sources/subs/Mentions.subs.php
Expand Up @@ -256,6 +256,36 @@ function changeMentionStatus($id_mention, $status = 1)
return $success;
}

/**
* Completely remove from the database a set of mentions.
*
* Doesn't check permissions, access, anything. It just deletes everything.
*
* @package Mentions
* @param int[] $id_mentions the mention ids
*/
function removeMentions($id_mentions)
{
global $user_info;

$db = database();

$db->query('', '
DELETE FROM {db_prefix}log_mentions
WHERE id_mention IN ({array_int:id_mentions})',
array(
'id_mentions' => $id_mentions,
)
);
$success = $db->affected_rows() != 0;

// Update the top level mentions count
if ($success)
updateMentionMenuCount($status, $user_info['id']);

return $success;
}

/**
* Toggles a mention on/off
*
Expand Down
14 changes: 12 additions & 2 deletions sources/subs/ScheduledTask.class.php
Expand Up @@ -1425,7 +1425,7 @@ public function user_access_mentions()
{
// Find all the mentions that this user can or cannot see
$request = $db->query('', '
SELECT mnt.id_mention
SELECT mnt.id_mention, m.id_board
FROM {db_prefix}log_mentions as mnt
LEFT JOIN {db_prefix}messages AS m ON (m.id_msg = mnt.id_msg)
LEFT JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
Expand All @@ -1442,10 +1442,20 @@ public function user_access_mentions()
)
);
$mentions = array();
$remove = array();
while ($row = $db->fetch_assoc($request))
$mentions[] = $row['id_mention'];
{
if (empty($row['id_board']))
$remove[] = $row['id_mention'];
else
$mentions[] = $row['id_mention'];
}
$db->free_result($request);

if (!empty($remove))
{
removeMentions($remove);
}
// If we found something toggle them and increment the start for the next round
if (!empty($mentions))
toggleMentionsAccessibility($mentions, $can == 'can');
Expand Down

0 comments on commit 2b1785d

Please sign in to comment.