forked from GNUsocial/gnu-social
Do mention lookup for Webfinger accounts in OStatusPlugin
This commit is contained in:
parent
bf23c35495
commit
bd74f05a66
@ -136,25 +136,6 @@ class OStatusPlugin extends Plugin
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the feed settings page to the Connect Settings menu
|
||||
*
|
||||
* @param Action &$action The calling page
|
||||
*
|
||||
* @return boolean hook return
|
||||
*/
|
||||
function onEndConnectSettingsNav(&$action)
|
||||
{
|
||||
$action_name = $action->trimmed('action');
|
||||
|
||||
$action->menuItem(common_local_url('feedsubsettings'),
|
||||
_m('Feeds'),
|
||||
_m('Feed subscription options'),
|
||||
$action_name === 'feedsubsettings');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Automatically load the actions and libraries used by the plugin
|
||||
*
|
||||
@ -215,33 +196,16 @@ class OStatusPlugin extends Plugin
|
||||
* @fixme push webfinger lookup & sending to a background queue
|
||||
* @fixme also detect short-form name for remote subscribees where not ambiguous
|
||||
*/
|
||||
|
||||
function onEndNoticeSave($notice)
|
||||
{
|
||||
$count = preg_match_all('/(\w+\.)*\w+@(\w+\.)*\w+(\w+\-\w+)*\.\w+/', $notice->content, $matches);
|
||||
if ($count) {
|
||||
foreach ($matches[0] as $webfinger) {
|
||||
$mentioned = $notice->getReplies();
|
||||
|
||||
// FIXME: look up locally first
|
||||
foreach ($mentioned as $profile) {
|
||||
|
||||
// Check to see if we've got an actual webfinger
|
||||
$w = new Webfinger;
|
||||
$oprofile = Ostatus_profile::staticGet('profile_id', $profile->id);
|
||||
|
||||
$endpoint_uri = '';
|
||||
|
||||
$result = $w->lookup($webfinger);
|
||||
if (empty($result)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($result->links as $link) {
|
||||
if ($link['rel'] == 'salmon') {
|
||||
$endpoint_uri = $link['href'];
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($endpoint_uri)) {
|
||||
continue;
|
||||
}
|
||||
if (!empty($oprofile) && !empty($oprofile->salmonuri)) {
|
||||
|
||||
// FIXME: this needs to go out in a queue handler
|
||||
|
||||
@ -249,11 +213,42 @@ class OStatusPlugin extends Plugin
|
||||
$xml .= $notice->asAtomEntry();
|
||||
|
||||
$salmon = new Salmon();
|
||||
$salmon->post($endpoint_uri, $xml);
|
||||
$salmon->post($oprofile->salmonuri, $xml);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
function onEndFindMentions($sender, $text, &$mentions)
|
||||
{
|
||||
preg_match_all('/(?:^|\s+)@((?:\w+\.)*\w+@(?:\w+\.)*\w+(?:\w+\-\w+)*\.\w+)/',
|
||||
$text,
|
||||
$wmatches,
|
||||
PREG_OFFSET_CAPTURE);
|
||||
|
||||
foreach ($wmatches[1] as $wmatch) {
|
||||
|
||||
$webfinger = $wmatch[0];
|
||||
|
||||
$oprofile = Ostatus_profile::ensureWebfinger($webfinger);
|
||||
|
||||
if (!empty($oprofile)) {
|
||||
|
||||
$profile = $oprofile->localProfile();
|
||||
|
||||
$mentions[] = array('mentioned' => array($profile),
|
||||
'text' => $wmatch[0],
|
||||
'position' => $wmatch[1],
|
||||
'url' => $profile->profileurl);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify remote server and garbage collect unused feeds on unsubscribe.
|
||||
* @fixme send these operations to background queues
|
||||
|
Loading…
Reference in New Issue
Block a user