```php
// Add a topic subscription entry if required
$isSubscribed = ForumThread_Subscription::already_subscribed($thread->ID);
if(isset($data['TopicSubscription'])) {
	if(!$isSubscribed) {
		// Create a new topic subscription for this member
		$obj = new ForumThread_Subscription();
		$obj->ThreadID = $thread->ID;
		$obj->MemberID = Member::currentUserID();
		$obj->write();
	}
} elseif($isSubscribed) {
	// See if the member wanted to remove themselves
	DB::query("DELETE FROM \"ForumThread_Subscription\" WHERE \"ThreadID\" = '$post->ThreadID' AND \"MemberID\" = '$member->ID'");
}
```