Advertisement:

Author Topic: [4884] Delete first message.  (Read 9340 times)

Offline lucas-ruroken

  • SMF Hero
  • ******
  • Posts: 4,885
  • Gender: Male
  • Adk Developer
    • lucas.ruroken on Facebook
    • SMF Personal
[4884] Delete first message.
« on: July 21, 2011, 11:48:21 PM »
Again, I don't know if this is a bug or not ;)

When I try to delete the first message of every topic.
Code: [Select]
You are not allowed to delete the first post in a topic.

If you want to delete this topic, click on the Remove Topic link, or ask a moderator/administrator to do it for you.

I think The delete button should not be in that position.

Possible solution:
Display.template.php
Code: [Select]
// How about... even... remove it entirely?!
if ($message['can_remove'])

replace with:
Code: [Select]
// How about... even... remove it entirely?!
if ($message['can_remove'] && $context['topic_first_message'] != $message['id'])


Regards. - Adk Team
« Last Edit: November 18, 2011, 10:24:09 AM by Joker™ »

Offline Joker™

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 5,560
  • Gender: Male
Re: Delete first message.
« Reply #1 on: July 22, 2011, 06:43:45 AM »
With that you need to update "id_first_msg" column in _topics table.
My Mods
How to enable Post Moderation


"For the wise man looks into space and he knows there is no limited dimensions." - Laozi

All support seeking PM gets microwaved.

Offline Illori

  • Doc Coordinator
  • SMF Master
  • *
  • Posts: 26,958
Re: Delete first message.
« Reply #2 on: November 18, 2011, 09:42:15 AM »
should we consider this a bug?

Offline Joker™

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 5,560
  • Gender: Male
Re: Delete first message.
« Reply #3 on: November 18, 2011, 10:23:22 AM »
My Mods
How to enable Post Moderation


"For the wise man looks into space and he knows there is no limited dimensions." - Laozi

All support seeking PM gets microwaved.

Offline lucas-ruroken

  • SMF Hero
  • ******
  • Posts: 4,885
  • Gender: Male
  • Adk Developer
    • lucas.ruroken on Facebook
    • SMF Personal
Re: [4884] Delete first message.
« Reply #4 on: November 18, 2011, 02:14:00 PM »
Perfect ;)!

Offline Joker™

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 5,560
  • Gender: Male
Re: [4884] Delete first message.
« Reply #5 on: November 18, 2011, 05:46:24 PM »
Perfect ;)!
Thank you and thanks for providing the fix with the bug report :).
My Mods
How to enable Post Moderation


"For the wise man looks into space and he knows there is no limited dimensions." - Laozi

All support seeking PM gets microwaved.

Offline Antechinus

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 22,182
  • Master of BBC Abuse
Re: [4884] Delete first message.
« Reply #6 on: November 18, 2011, 05:55:08 PM »
should we consider this a bug?

Not sure that I would. Seems to me that if you're going to delete the OP of a tread, there's not much point keeping the thread. I assume that was the original reasoning behind this.

No harm in having it tracked though, in case we do decide to change it.

Offline Joker™

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 5,560
  • Gender: Male
Re: [4884] Delete first message.
« Reply #7 on: November 19, 2011, 11:26:41 PM »

Not sure that I would. Seems to me that if you're going to delete the OP of a tread, there's not much point keeping the thread. I assume that was the original reasoning behind this.

No harm in having it tracked though, in case we do decide to change it.
But Ant don't you think there should be some warning when someone clicks the remove button in first post itself saying "This is going to remove whole topic or you can use split button" and the buttons behavior should be tweaked somewhat.

Only case that button can work on present setup is when there are no replies to a topic. Lets say you have 90% topic with replies and merely 10% without replies (just a general assumption), in that case the remove button in 1st posts seems a bit useless. Just my opinion :).
My Mods
How to enable Post Moderation


"For the wise man looks into space and he knows there is no limited dimensions." - Laozi

All support seeking PM gets microwaved.

Offline Antechinus

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 22,182
  • Master of BBC Abuse
Re: [4884] Delete first message.
« Reply #8 on: November 20, 2011, 03:43:54 PM »
But Ant don't you think there should be some warning when someone clicks the remove button in first post itself saying "This is going to remove whole topic or you can use split button"..

But it doesn't remove the whole topic at all. You have to use the separate "remove topic" button in the moderators' options at the bottom.

I'm just wondering if this tweak is worth the extra code. It's another conditional that has to be run every time the page is loaded.
« Last Edit: November 20, 2011, 03:48:05 PM by Antechinus »

Offline Joker™

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 5,560
  • Gender: Male
Re: [4884] Delete first message.
« Reply #9 on: November 21, 2011, 06:19:12 AM »
I'm just wondering if this tweak is worth the extra code. It's another conditional that has to be run every time the page is loaded.
Yeah, but then again when someone click the remove button on first post SMF makes check in RemoveTopic.php

Code: [Select]
// ...if there is only one post.
if (!empty($row['num_replies']))
fatal_lang_error('delFirstPost', false);
My Mods
How to enable Post Moderation


"For the wise man looks into space and he knows there is no limited dimensions." - Laozi

All support seeking PM gets microwaved.

Online emanuele

  • Developer
  • SMF Super Hero
  • *
  • Posts: 12,141
  • Gender: Male
  • Because Orange is Orange
Re: [4884] Delete first message.
« Reply #10 on: November 21, 2011, 06:42:31 AM »
Not sure that I would. Seems to me that if you're going to delete the OP of a tread, there's not much point keeping the thread. I assume that was the original reasoning behind this.

No harm in having it tracked though, in case we do decide to change it.
Ant the point is exactly that we have inconsistency in the use of this button.
Here are the cases:
1) topic with 1 post: click "remove" the topic is deleted
2) topic with more than 1 post: click "remove" you get the error "You are not allowed to delete the first post in a topic. If you want to delete this topic, click on the Remove Topic link, or ask a moderator/administrator to do it for you."
 
Personally I would avoid deleting the entire topic clicking on a "remove" button in a message (unless it's the only message in the topic of course :P), so as usual I have a question: why can't we delete the first post of a topic?
Technically is for sure more demanding than delete any other post (you have to set a new id_first_msg...and I think that's all), but it's possible.
So why instead of add another check on each page we don't simply allow to delete the first message and make the use of this button consistent across all the messages?

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.

Offline Joker™

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 5,560
  • Gender: Male
Re: [4884] Delete first message.
« Reply #11 on: November 21, 2011, 08:59:40 AM »
Technically is for sure more demanding than delete any other post (you have to set a new id_first_msg...and I think that's all), but it's possible.
So why instead of add another check on each page we don't simply allow to delete the first message and make the use of this button consistent across all the messages?
Sounds a great option. Instead of that error we can do something creative. But TBH we have to make a nice check on such code as it can end up in breaking more then expected :P.
My Mods
How to enable Post Moderation


"For the wise man looks into space and he knows there is no limited dimensions." - Laozi

All support seeking PM gets microwaved.

Online emanuele

  • Developer
  • SMF Super Hero
  • *
  • Posts: 12,141
  • Gender: Male
  • Because Orange is Orange
Re: [4884] Delete first message.
« Reply #12 on: November 21, 2011, 09:13:49 AM »
And now that I'm looking at the code there is a real bug too: the reports associated to the message are closed before the check if the topic should be removed or not.
So if the first message of a topic (with more than one message) is reported and someone tries to delete it, the reports are set to close, but the message is not deleted.

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.

Online emanuele

  • Developer
  • SMF Super Hero
  • *
  • Posts: 12,141
  • Gender: Male
  • Because Orange is Orange
Re: [4884] Delete first message.
« Reply #13 on: November 21, 2011, 12:14:39 PM »
Is there anyone brave enough? :P

Code: (find) [Select]
// ...if there is only one post.
if (!empty($row['num_replies']))
fatal_lang_error('delFirstPost', false);

// It's only one post in this topic, lemme save ya some trouble!
require_once($sourcedir . '/Subs-Topic.php');
removeTopics($row['id_topic']);
return true;

Code: (replace with) [Select]
// ...if there is more than one post.
if (!empty($row['num_replies']))
{
$request = $smcFunc['db_query']('', '
SELECT id_msg, id_member
FROM {db_prefix}messages
WHERE id_topic = {int:topic_id}
ORDER BY id_msg ASC
LIMIT 1 ,1',
array(
'topic_id' => $row['id_topic'],
)
);
list($new_first_msg_id, $new_first_msg_member) = $smcFunc['db_fetch_row']($request);
$smcFunc['db_free_result']($request))

$smcFunc['db_query']('', '
UPDATE {db_prefix}topics
SET id_first_msg = {int:id_msg},
id_member_started = {int:id_member}
WHERE id_topic = {int:topic_id}',
array(
'id_msg' => $new_first_msg_id,
'id_member' => $new_first_msg_member,
'topic_id' => $row['id_topic'],
)
);
}
else
{
// It's only one post in this topic, lemme save ya some trouble!
require_once($sourcedir . '/Subs-Topic.php');
removeTopics($row['id_topic']);
return true;
}

Not so nice to see actually, but it should solve both the issues.
« Last Edit: November 22, 2011, 06:26:00 AM by emanuele »

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.

Offline Antechinus

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 22,182
  • Master of BBC Abuse
Re: [4884] Delete first message.
« Reply #14 on: November 21, 2011, 03:56:03 PM »
Try it and see what explodes. Dev builds are for destruction testing. ;D

ETA: And you'd want to get rid of the conditional in RemoveTopic.php too.

Online emanuele

  • Developer
  • SMF Super Hero
  • *
  • Posts: 12,141
  • Gender: Male
  • Because Orange is Orange
Re: [4884] Delete first message.
« Reply #15 on: November 21, 2011, 04:11:23 PM »
ETA: And you'd want to get rid of the conditional in RemoveTopic.php too.
Do you mean the "else" part?
I don't know, at that point it would make sense...I think...

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.

Offline Antechinus

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 22,182
  • Master of BBC Abuse
Re: [4884] Delete first message.
« Reply #16 on: November 21, 2011, 04:19:47 PM »
NVM. Brain fart. Need more coffee.

Offline HunterP

  • Sr. Member
  • ****
  • Posts: 937
  • Gender: Male
  • SMF 2.0.4
    • Hulpverleningsforum Nederland
Re: [4884] Delete first message.
« Reply #17 on: November 21, 2011, 04:28:17 PM »

I've had several cases in which I'd wanted to delete the first message, but didn't consider this as a bug. Ofcourse this can be worked around by splitting from the second message, but this causes the id_topic to be updated and in some cases this causes other problems (links, twitter, etc). So if it would become possible to delete the first message, with the id_first_msg (etc) updated, two thumbs up :)

Offline Joker™

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 5,560
  • Gender: Male
Re: [4884] Delete first message.
« Reply #18 on: November 22, 2011, 05:31:00 AM »
Is there anyone brave enough? :P

Worked fine on my end.

Just a thought why can't we pick up the 2nd row of the result directly? I think I used some code somewhere to pick up the 2nd row result directly. Does it make any sense?


ETA: And you'd want to get rid of the conditional in RemoveTopic.php too.
Ant I think with the present proposed code we require that else loop also, as in earlier case the execution of files stops after facing the "fatal_lang_error" function but in this case if we don't have else loop over there it will try to execute the "removeTopics($row['id_topic']);" code as well.


* Joker™  not happy with emanuele's code as it hasn't broken anything in test forum :laugh:
My Mods
How to enable Post Moderation


"For the wise man looks into space and he knows there is no limited dimensions." - Laozi

All support seeking PM gets microwaved.

Online emanuele

  • Developer
  • SMF Super Hero
  • *
  • Posts: 12,141
  • Gender: Male
  • Because Orange is Orange
Re: [4884] Delete first message.
« Reply #19 on: November 22, 2011, 05:43:19 AM »
Just a thought why can't we pick up the 2nd row of the result directly? I think I used some code somewhere to pick up the 2nd row result directly. Does it make any sense?
Yes, you are right.
Fixed.


* Joker™  not happy with emanuele's code as it hasn't broken anything in test forum :laugh:
* emanuele too... :(

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.