tickbox to display "new topics" by BOT user_id

Support area for phpBB's mChat extension
Post Reply
talonos
Posts: 5
Joined: 08 Mar 2017, 21:43

tickbox to display "new topics" by BOT user_id

#1

Post by talonos » 06 Dec 2018, 22:17

ok so i've added an rss news automation bot to one of my phpbb projects,

now rss updates can be really spammy in mchat when they are updated. i'm not really wanting to block the bot from posting the new topic in mchat but i'm more looking into an option for users (like the sound tickbox) that will enable them to see new posted item by the bot which would be specified by the user_id.

i've had a look at mchat coding and for the love of god i can seem to work out how to do it.

User avatar
kasimi
mChat developer
Posts: 795
Joined: 06 Oct 2016, 09:56
Location: Germany
Contact:

Re: tickbox to display "new topics" by BOT user_id

#2

Post by kasimi » 06 Dec 2018, 22:25

You will need to subscribe to the dmzx.mchat.get_messages_modify_sql event and add a condition to the sql_array's WHERE value. This will disable fetching your RSS posts based on the user setting. For example, in your event handler:

Code: Select all

if (!$this->user->data['user_mchat_rss_topics'])
{
    $sql_array = $event['sql_array'];
    $sql_array['WHERE'] .= ' AND m.user_id <> ' . (int) $rss_bot_user_id;
    $event['sql_array'] = $sql_array;
}

talonos
Posts: 5
Joined: 08 Mar 2017, 21:43

Re: tickbox to display "new topics" by BOT user_id

#3

Post by talonos » 07 Dec 2018, 16:08

i got the above code working perfectly, my only issue now is setting the ucp section up. i've injected all of the required code but the one bit that doesn't seem to work at all is

Code: Select all

			'dmzx.mchat.ucp_settings_modify' => 'update_rss',

Code: Select all

	/**
	 * @param data $event
	 */	
	public function update_rss($event)
	{
		$event['ucp_settings'] = array_merge($event['ucp_settings'], [
			'user_mchat_rss_topics' => ['default' => 0],
		]);
}
the html code has been tested by me manually changing that setting in database. its really got my head baffled now.

User avatar
kasimi
mChat developer
Posts: 795
Joined: 06 Oct 2016, 09:56
Location: Germany
Contact:

Re: tickbox to display "new topics" by BOT user_id

#4

Post by kasimi » 07 Dec 2018, 16:41

Currently there is no way to add a user-specific setting without also adding a permission. If you don't need a permission, don't let mChat handle your option, and instead implement everything yourself.

If you do want a Can customize permission, make sure these points are all working correctly:
  • Add a global permission called u_mchat_rss_topics. This is the Can customize permission.
  • Add an entry in the config table called mchat_rss_topics. This value is used if a user does not have the permission.
  • Add a column to the users table called user_mchat_rss_topics. That's the user-specific value that is used if the user has the permission.
  • Use name="user_mchat_rss_topics" for the yes/no options in your UCP template.
  • In your dmzx.mchat.ucp_settings_modify event handler, change 'user_mchat_rss_topics' => ['default' => 0], to 'mchat_rss_topics' => ['default' => 0],


As you mentioned the sound option in the navbar dropdown menu, keep in mind that the values of these navbar options are all stored client side, without needing a UCP option. So I think there is an easier way for you to solve this: skip all of the above points and use JavaScript and a cookie to toggle fetching RSS topics. Make your navbar item set the cookie if RSS topics should be skipped, and remove the cookie when RSS topics should be displayed.

Then, instead of

Code: Select all

if (!$this->user->data['user_mchat_rss_topics'])
you would do something like

Code: Select all

if ($this->request->variable($this->config['cookie_name'] . '_mchat_skip_rss', false, false, \phpbb\request\request_interface::COOKIE))
And that's all you need. No new config entry, no new user column and no permission.

talonos
Posts: 5
Joined: 08 Mar 2017, 21:43

Re: tickbox to display "new topics" by BOT user_id

#5

Post by talonos » 07 Dec 2018, 19:46

UCP section now up and running,

during testing i had an error come up on index.

Code: Select all

You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ' AND m.user_id <> 2 ORDER BY m.message_id DESC LIMIT 18446744073709551615' at line 1 [1064]

SQL

SELECT m.*, u.username, u.user_colour, u.user_avatar, u.user_avatar_type, u.user_avatar_width, u.user_avatar_height, u.user_allow_pm, p.post_visibility FROM (phpbb_mchat m) LEFT JOIN phpbb_users u ON (m.user_id = u.user_id) LEFT JOIN phpbb_posts p ON (m.post_id = p.post_id AND m.forum_id <> 0) WHERE (m.message_id > 3) AND m.user_id <> 2 ORDER BY m.message_id DESC LIMIT 18446744073709551615
this has popped up quite allot on local test AND a quick live test. it spits error on mchat refresh and sometimes even on page load. i'll look into that tomorrow thou as i'm not putting extension live yet anyways and missus has decided she want to go to the pub now lol.

User avatar
kasimi
mChat developer
Posts: 795
Joined: 06 Oct 2016, 09:56
Location: Germany
Contact:

Re: tickbox to display "new topics" by BOT user_id

#6

Post by kasimi » 07 Dec 2018, 19:59

The query looks good to me. I tested it locally and it runs fine.

talonos
Posts: 5
Joined: 08 Mar 2017, 21:43

Re: tickbox to display "new topics" by BOT user_id

#7

Post by talonos » 07 Dec 2018, 23:10

kasimi wrote:
07 Dec 2018, 19:59
The query looks good to me. I tested it locally and it runs fine.
yes query is good and everything else but it seems that the error looks like its only popping up on certain groups (mainly m_ and a_ groups). tried on a few accounts. even though the perms for the extensions (mchat AND feedbot) are identical the issue still pops up for admins and such.

even disabled all of the if statements for the perms too and still the same issue.

talonos
Posts: 5
Joined: 08 Mar 2017, 21:43

Re: tickbox to display "new topics" by BOT user_id

#8

Post by talonos » 08 Dec 2018, 00:22

ok so i now know reason why its throwing an error.

it seems that when mchat calls the function that runs the sql its different for user groups.....

this is the "working call" for registered user

Code: Select all

SELECT m.*, u.username, u.user_colour, u.user_avatar, u.user_avatar_type, u.user_avatar_width, u.user_avatar_height, u.user_allow_pm, p.post_visibility FROM (phpbb_mchat m) LEFT JOIN phpbb_users u ON (m.user_id = u.user_id) LEFT JOIN phpbb_posts p ON (m.post_id = p.post_id AND m.forum_id <> 0) WHERE (m.post_id <> 2 OR m.user_id = 226 OR m.forum_id <> 0) AND m.user_id <> 2 ORDER BY m.message_id DESC LIMIT 10
and this is the code it calls for admin user

Code: Select all

SELECT m.*, u.username, u.user_colour, u.user_avatar, u.user_avatar_type, u.user_avatar_width, u.user_avatar_height, u.user_allow_pm, p.post_visibility FROM (phpbb_mchat m) LEFT JOIN phpbb_users u ON (m.user_id = u.user_id) LEFT JOIN phpbb_posts p ON (m.post_id = p.post_id AND m.forum_id <> 0) WHERE AND m.user_id <> 2 ORDER BY m.message_id DESC LIMIT 10
at quick glance they look similiar until you get to where i've been putting the injection in.

Code: Select all

(m.post_id <> 2 OR m.user_id = 226 OR m.forum_id <> 0)
the above code is on the registered user call but missing from the admin call.

i've absolutly no idea where that extra code is comming from but its a breaking issue. ima have to build an if statement for a build around (if statement doesn't work as the mchat_refresh for admin then requires the "AND ")

admin call works if i don't put "AND " in the inject (it breaks mchat refresh for admin :-1: as that bit needs the "AND ")but then it breaks the other calls.

OMG this is so annoying.

Added in 21 minutes 27 seconds:
BOOM! i got it

mchat functions.php line: 516

Code: Select all

if (!$this->auth->acl_get('u_viewonline'))
removed the if statement block and it all works correctly now without having to use multiple (and failing) if statements in feedbot extension.

we don't use viewonline OR login_post_to_chat or whatever its called on live forums so not an issue for our usage.

User avatar
kasimi
mChat developer
Posts: 795
Joined: 06 Oct 2016, 09:56
Location: Germany
Contact:

Re: tickbox to display "new topics" by BOT user_id

#9

Post by kasimi » 08 Dec 2018, 12:48

You're using mChat 2.0.x. Use this in your event handler:

Code: Select all

$sql_array['WHERE'] = implode(' AND ', array_filter([$sql_array['WHERE'], 'm.user_id <> ' . (int) $rss_bot_user_id]));

Post Reply

Who is online

Users browsing this forum: Xcalibr8 and 1 guest