Automatically add a tag for every group messages
If you post to a group !foo, it's automatically listed as being tagged "foo". This is to keep users from having to do !foo #foo in all their messages.
This commit is contained in:
parent
9978eadbf2
commit
ca90d790aa
@ -94,23 +94,28 @@ class Notice extends Memcached_DataObject
|
||||
/* Add them to the database */
|
||||
foreach(array_unique($match[1]) as $hashtag) {
|
||||
/* elide characters we don't want in the tag */
|
||||
$hashtag = common_canonical_tag($hashtag);
|
||||
|
||||
$tag = DB_DataObject::factory('Notice_tag');
|
||||
$tag->notice_id = $this->id;
|
||||
$tag->tag = $hashtag;
|
||||
$tag->created = $this->created;
|
||||
$id = $tag->insert();
|
||||
if (!$id) {
|
||||
$last_error = PEAR::getStaticProperty('DB_DataObject','lastError');
|
||||
common_log(LOG_ERR, 'DB error inserting hashtag: ' . $last_error->message);
|
||||
common_server_error(sprintf(_('DB error inserting hashtag: %s'), $last_error->message));
|
||||
return;
|
||||
}
|
||||
$this->saveTag($hashtag);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function saveTag($hashtag)
|
||||
{
|
||||
$hashtag = common_canonical_tag($hashtag);
|
||||
|
||||
$tag = new Notice_tag();
|
||||
$tag->notice_id = $this->id;
|
||||
$tag->tag = $hashtag;
|
||||
$tag->created = $this->created;
|
||||
$id = $tag->insert();
|
||||
|
||||
if (!$id) {
|
||||
throw new ServerException(sprintf(_('DB error inserting hashtag: %s'),
|
||||
$last_error->message));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static function saveNew($profile_id, $content, $source=null, $is_local=1, $reply_to=null, $uri=null) {
|
||||
|
||||
$profile = Profile::staticGet($profile_id);
|
||||
@ -621,6 +626,15 @@ class Notice extends Memcached_DataObject
|
||||
continue;
|
||||
}
|
||||
|
||||
// we automatically add a tag for every group name, too
|
||||
|
||||
$tag = Notice_tag::pkeyGet(array('tag' => common_canonical_tag($nickname),
|
||||
'notice_id' => $this->id));
|
||||
|
||||
if (is_null($tag)) {
|
||||
$this->saveTag($nickname);
|
||||
}
|
||||
|
||||
if ($profile->isMember($group)) {
|
||||
|
||||
$gi = new Group_inbox();
|
||||
|
@ -19,7 +19,7 @@
|
||||
|
||||
require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
|
||||
|
||||
class Notice_tag extends Memcached_DataObject
|
||||
class Notice_tag extends Memcached_DataObject
|
||||
{
|
||||
###START_AUTOCODE
|
||||
/* the code below is auto generated do not remove the above tag */
|
||||
@ -35,9 +35,9 @@ class Notice_tag extends Memcached_DataObject
|
||||
|
||||
/* the code above is auto generated do not remove the tag below */
|
||||
###END_AUTOCODE
|
||||
|
||||
|
||||
static function getStream($tag, $offset=0, $limit=20) {
|
||||
$qry =
|
||||
$qry =
|
||||
'SELECT notice.* ' .
|
||||
'FROM notice JOIN notice_tag ON notice.id = notice_tag.notice_id ' .
|
||||
'WHERE notice_tag.tag = "%s" ';
|
||||
@ -46,7 +46,7 @@ class Notice_tag extends Memcached_DataObject
|
||||
'notice_tag:notice_stream:' . common_keyize($tag),
|
||||
$offset, $limit);
|
||||
}
|
||||
|
||||
|
||||
function blowCache()
|
||||
{
|
||||
$cache = common_memcache();
|
||||
@ -54,4 +54,9 @@ class Notice_tag extends Memcached_DataObject
|
||||
$cache->delete(common_cache_key('notice_tag:notice_stream:' . $this->tag));
|
||||
}
|
||||
}
|
||||
|
||||
function &pkeyGet($kv)
|
||||
{
|
||||
return Memcached_DataObject::pkeyGet('Notice_tag', $kv);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user