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:
		@@ -94,22 +94,27 @@ class Notice extends Memcached_DataObject
 | 
				
			|||||||
        /* Add them to the database */
 | 
					        /* Add them to the database */
 | 
				
			||||||
        foreach(array_unique($match[1]) as $hashtag) {
 | 
					        foreach(array_unique($match[1]) as $hashtag) {
 | 
				
			||||||
            /* elide characters we don't want in the tag */
 | 
					            /* elide characters we don't want in the tag */
 | 
				
			||||||
 | 
					            $this->saveTag($hashtag);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        return true;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    function saveTag($hashtag)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
        $hashtag = common_canonical_tag($hashtag);
 | 
					        $hashtag = common_canonical_tag($hashtag);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            $tag = DB_DataObject::factory('Notice_tag');
 | 
					        $tag = new Notice_tag();
 | 
				
			||||||
        $tag->notice_id = $this->id;
 | 
					        $tag->notice_id = $this->id;
 | 
				
			||||||
        $tag->tag = $hashtag;
 | 
					        $tag->tag = $hashtag;
 | 
				
			||||||
        $tag->created = $this->created;
 | 
					        $tag->created = $this->created;
 | 
				
			||||||
        $id = $tag->insert();
 | 
					        $id = $tag->insert();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (!$id) {
 | 
					        if (!$id) {
 | 
				
			||||||
                $last_error = PEAR::getStaticProperty('DB_DataObject','lastError');
 | 
					            throw new ServerException(sprintf(_('DB error inserting hashtag: %s'),
 | 
				
			||||||
                common_log(LOG_ERR, 'DB error inserting hashtag: ' . $last_error->message);
 | 
					                                              $last_error->message));
 | 
				
			||||||
                common_server_error(sprintf(_('DB error inserting hashtag: %s'), $last_error->message));
 | 
					 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
        return true;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    static function saveNew($profile_id, $content, $source=null, $is_local=1, $reply_to=null, $uri=null) {
 | 
					    static function saveNew($profile_id, $content, $source=null, $is_local=1, $reply_to=null, $uri=null) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -621,6 +626,15 @@ class Notice extends Memcached_DataObject
 | 
				
			|||||||
                continue;
 | 
					                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)) {
 | 
					            if ($profile->isMember($group)) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                $gi = new Group_inbox();
 | 
					                $gi = new Group_inbox();
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -54,4 +54,9 @@ class Notice_tag extends Memcached_DataObject
 | 
				
			|||||||
            $cache->delete(common_cache_key('notice_tag:notice_stream:' . $this->tag));
 | 
					            $cache->delete(common_cache_key('notice_tag:notice_stream:' . $this->tag));
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    function &pkeyGet($kv)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return Memcached_DataObject::pkeyGet('Notice_tag', $kv);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user