[Twitter Bridge] Don't send @-less replies to Twitter
[Twitter Bridge] Don't send @-less replies to Twitter
| Issue ID: | 3386 |
| Issue Category: | bug |
| Component: | plugin |
| Priority: | critical |
| Status: | active |
| Assigned: | Unassigned |
| Version: | 1.1 |
| Keywords: | bridge, twitter |
I think the code for the "don't send @replies to twitter" option isn't catching the new style @-less replies. Several of my replies to OStatus users this morning have made their way to my Twitter account, I believe because they don't mention the user specifically at the beginning of the post.

Updates
#1
Probably more related to the currently disabled Twitter-Bridge: http://status.net/wiki/Service_status
#2
I'm on my own site, with the Twitter bridge enabled, and I'm definitely seeing this behavior.
#3
related to http://status.net/open-source/issues/3350 and http://status.net/open-source/issues/3358
#4
@ssweeny Sorry, that wasn't obvious. Over the weekend both me (status.davidhaberthuer) and bavatar (http://diekershoff.homeunix.net/statusnet/bavatar) had troubles with twitter mirroring. maybe it's also related to this.
#5
Replies lacking the @-syntax are going to twitter for me as well.
#6
I'm also experiencing this issue.
#7
+1
#8
Same here with my own instance.
Have no idea of which part of the code is concerned.
#9
Have done some tests tonight.
The whole problem seems to be located in plugins/TwitterBridge/twitter.php file, ans specially into the block between line 123 & 127.
If you force line 126 to return false, notices won't be sent to Twitter, what ever could be the result of tests in function is_twitter_bound.
So I guess there's something wrong with tests, and specially the "if" statement line 123.
Comparing it with 0.9.9 code, we have some difference (with bitwise operators) I can not exactly explain.
I will continue my investigations tomorrow.
One more time, sorry for spamming your timelines, guys :)
#10
OK, think I've found a first problem:
line 124 from file "plugins/TwitterBridge/twitter.php" we have:
($flink->noticesync & FOREIGN_NOTICE_SEND_REPLY == FOREIGN_NOTICE_SEND_REPLY)
This may turn into problem since "==" operator has precedence on "&" operator.
That means that PHP will first evaluate "FOREIGN_NOTICE_SEND_REPLY == FOREIGN_NOTICE_SEND_REPLY" which is obviously TRUE and then evaluate "$flink->noticesync & TRUE", which I guess always returns TRUE.
So, solution could be to add parenthesis like:
( ($flink->noticesync & FOREIGN_NOTICE_SEND_REPLY) == FOREIGN_NOTICE_SEND_REPLY)
But, performaing some other tests, I found that is_twitter_notice($notice->reply_to) was sometime wrongly evaluated as TRUE.
On concerned notice was indeed a reply, involving myself, @evan (who I'm subscribed to) and @march (who I wasn't subscribed to). So I think we may have another problem in "is_twitter_notice" function. But stating this function is almost very simple, problem could be in "Notice_to_status::staticGet('notice_id', $id);".
Don't know exactly yet, I'll investigate that later in the day.
#11
Little update on this topic.
The merge request I made yesterday works on my instance. Thanks to it, we can recover v0.9.x behaviour.
BUT, using web interface, if you want to reply to an ostatus notice, then the reply IS sent to Twitter.
I believe that is_twitter_notice is somewhat buggy and always returns true for replies, even if the original notice did not came from twitter.
EDIT: I just checked on my instance, and I'm wrong. Here is an example:
- I received this notice: http://keuser.fr/notice/59580 (with id 331684 on my instance)
- I reply to it with an "old-school" client, ie reply begin with @-nickname. Therfore, notice was not sent to Twitter because of !preg_match test in twitter.php line 123)
- I sent another reply from web interface. This one, even if not a "twitter reply" WAS sent to Twitter, still because of !preg_match. Since notice does not begin with @-nickname, !preg_match is evaluated to TRUE and therefore checks stops here and notice is sent.
As a conclusion, we should remove preg_match condition to get "is_twitter_notice" evaluated.
#12
Why didn't TwitterBridge plugin worked as expected
**************************************************
I recently ask for merge request 179 to partly fix this bug. Here are some detailled explanation about what was actually wrong.
Before merge-request 179
========================
https://gitorious.org/statusnet/mainline/merge_requests/179
3 checks to know if a notice should be sent or not:
1. !preg_match('/^@[a-zA-Z0-9_]{1,15}\b/u', $notice->content)
2. ($flink->noticesync & FOREIGN_NOTICE_SEND_REPLY == FOREIGN_NOTICE_SEND_REPLY)
3. is_twitter_notice($notice->reply_to)
As stated in code comments, the idea was to sent to Twitter:
- Notice NOT beginning with at-mention
- All notice if the user WANTS to send replies
- Twitter replies
First problem: assumption that notice beginning with at-mention are NOT twitter replies is quite... dangerous. By the way it worked because of last check.
BUT, with Statusnet version 1.x coming, things changed: with new web UI, replies now do not begin with at-mention anymore. As a consequence, !preg_match was ALWAYS evaluated as TRUE and... local replies are sent :(
Second problem was, old-style desktop or mobile client still uses at-mentions beginning notices for replies. Since !preg_match was evaluated as FALSE, second check was performed.
We touch the heart of the bug: PHP operator's precedence (http://www.php.net/manual/en/language.operators.precedence.php). In other words, "==" operator is to be evaluated BEFORE "&".
Therefore, second check can be changed as: ($flink->noticesync & TRUE); This, basically, is ALWAYS evaluated as TRUE and... local replies are sent :(
After merge request 179
=======================
The only change I made was adding parenthesis to restore correct precedence for second check.
This way, I JUST RESTORE v0.9.x BEHAVIOUR. Not more.
But we still have a problem:
Since (($flink->noticesync & FOREIGN_NOTICE_SEND_REPLY) == FOREIGN_NOTICE_SEND_REPLY) is now evaluated the right way, no more problem with old-style clients, but still one with WebUI (see above).
And now ?
=========
Now, I want to get rid, as much as possible, of this !preg_match check. Here are the use cases I've identified:
[pseudo-code]
Do we allow twitter export ?
yes:
Do we allow local replies to be sent ?
yes: send it.
no: Is the notice a Twitter reply or repeat ?
yes: send it.
no: Is the notice a 'new' one (ie not a reply)
yes: send it.
no: does the notice NOT begin with at-mention ?
yes: send it.
no: DON't send it.
no: DON't send it.
[/pseudo-code]
Here's the corresponding code I'm currently testing on my instance:
function is_twitter_bound($notice, $flink) {
if ($notice->object_type == ActivityObject::ACTIVITY) {
return false;
}
$allowedVerbs = array(ActivityVerb::POST, ActivityVerb::SHARE);
if (!in_array($notice->verb, $allowedVerbs)) {
return false;
}
if (!empty($flink) && (($flink->noticesync & FOREIGN_NOTICE_SEND) == FOREIGN_NOTICE_SEND)) {
if ( ( ($flink->noticesync & FOREIGN_NOTICE_SEND_REPLY) == FOREIGN_NOTICE_SEND_REPLY ) ||
( is_twitter_notice($notice->reply_to) || is_twitter_notice($notice->repeat_of) ) ||
( empty($notice->reply_to) && !preg_match('/^@[a-zA-Z0-9_]{1,15}\b/u', $notice->content) )
) {
return true;
}
}
return false;
}
This way, I'm now able to catch replies sent from web UI. Those ARE replies, but not beginning with at-mention. Here, they won't be sent to Twitter.
"But, you wanted to get rid of preg_match and you still use it ?"
- Yes, that's right, and here's why: I sometimes need to be able to sent a notice to specific people on statusnet. For that, I begin my notice with at-mention. But I usually don't want this notice to be send to Twitter. That's why I keep preg_match in the code. And, yes, I could have use same tips to be able to sent "direct mention" to Twitter and to StatusNet but... Since I use StatusNet, I just prefer to give it an higher priority :)
#13
My opinion is that rather than not sending @-less replies to Twitter, StatusNet should - assuming it isn't there - automatically add the @username if true==is_twitter_notice($notice->reply_to)
However, I'm not sure how to fetch the Twitter username in the easiest/best manner from $notice->reply_to.
#14
Hmmm... right, but that's IMHO another topic.
The function I fixed there just check whether or not it should sent notice to twitter. It's called by another function "broadcast_twitter" in plugin/TwitterBridge/twitter.php
Since this function also deals with repeat (ie build retweet), adding @-nickname should occurs there.
The problem is that:
- we'll have to deal with both new web UI, which does not add @-nickname, and "old style" clients, which do.
- adding @-nickname could make notice length more than 140 caracters. Then Twitter will through an error with which we'll have to deal as well (and besides that, this will be confusing for users)
Another solution could be to add @-nickname in web UI, but this has also drawbacks: this will make UI javascript code a bit more complex.
#15
OK, have been using my patch more half a month now without any problem.
Did a merge request to get it merged into master:
https://gitorious.org/statusnet/mainline/merge_requests/2227
Please review and comment :)
#16
Just to second Jean, I've had his patch running on my instance as well, for nearly as long, without issue. Works great. :)
#17
I have been testing Jean-Baptiste's patch for a few days on my own instance, and confirm everything works as expected.
Cheers,
Julien
#18
#19
I believe this bug is still alive, as the situation of @-less replies to a twitter-bound $notice->reply_to can occur:
I have described the issue on a merge request that I hope people could try out:
https://gitorious.org/statusnet/mainline/merge_requests/222
The description is pasted below:
As can be seen on the following links a Twitter reply was sent to Twitter despite the user's (@jolla) settings to do so:
http://identi.ca/conversation/94684618
https://twitter.com/JollaMobile/status/264710462145433601
The reason should be that @mbjunior had a twitter-bound post. So is_twitter_notice($notice->reply_to) was true and thus made the reply twitter-bound.
I modified the relevant part of twitter.php to do what I think is right. Unfortunately I don't have any direct way of testing this myself.
Does it make sense?
#20
A similar bug:
[Twitter Bridge] local '@' replies beginning with @ disrespect the user preference to not cross-post
http://status.net/open-source/issues/3703
#21
This bug is still alive. I am not the only one affected by it.
This is a real urgent one. Why? Many people bridging to twitter and if you cant chat at status.net without anoying your (probably much larger) twitter audience, you will not chatting at all. So there are much lesser interaction between status.net-accounts as at twitter due to this bug.
You can also subscribe to the
RSS feed for updates to this issue.