gtsocial-umbx

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

mention.go (4241B)


      1 // GoToSocial
      2 // Copyright (C) GoToSocial Authors admin@gotosocial.org
      3 // SPDX-License-Identifier: AGPL-3.0-or-later
      4 //
      5 // This program is free software: you can redistribute it and/or modify
      6 // it under the terms of the GNU Affero General Public License as published by
      7 // the Free Software Foundation, either version 3 of the License, or
      8 // (at your option) any later version.
      9 //
     10 // This program is distributed in the hope that it will be useful,
     11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
     12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13 // GNU Affero General Public License for more details.
     14 //
     15 // You should have received a copy of the GNU Affero General Public License
     16 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
     17 
     18 package gtsmodel
     19 
     20 import (
     21 	"context"
     22 	"time"
     23 )
     24 
     25 // Mention refers to the 'tagging' or 'mention' of a user within a status.
     26 type Mention struct {
     27 	ID               string    `validate:"required,ulid" bun:"type:CHAR(26),pk,nullzero,notnull,unique"`        // id of this item in the database
     28 	CreatedAt        time.Time `validate:"-" bun:"type:timestamptz,nullzero,notnull,default:current_timestamp"` // when was item created
     29 	UpdatedAt        time.Time `validate:"-" bun:"type:timestamptz,nullzero,notnull,default:current_timestamp"` // when was item last updated
     30 	StatusID         string    `validate:"required,ulid" bun:"type:CHAR(26),nullzero,notnull"`                  // ID of the status this mention originates from
     31 	Status           *Status   `validate:"-" bun:"rel:belongs-to"`                                              // status referred to by statusID
     32 	OriginAccountID  string    `validate:"required,ulid" bun:"type:CHAR(26),nullzero,notnull"`                  // ID of the mention creator account
     33 	OriginAccountURI string    `validate:"url" bun:",nullzero,notnull"`                                         // ActivityPub URI of the originator/creator of the mention
     34 	OriginAccount    *Account  `validate:"-" bun:"rel:belongs-to"`                                              // account referred to by originAccountID
     35 	TargetAccountID  string    `validate:"required,ulid" bun:"type:CHAR(26),nullzero,notnull"`                  // Mention target/receiver account ID
     36 	TargetAccount    *Account  `validate:"-" bun:"rel:belongs-to"`                                              // account referred to by targetAccountID
     37 	Silent           *bool     `validate:"-" bun:",nullzero,notnull,default:false"`                             // Prevent this mention from generating a notification?
     38 
     39 	/*
     40 		NON-DATABASE CONVENIENCE FIELDS
     41 		These fields are just for convenience while passing the mention
     42 		around internally, to make fewer database calls and whatnot. They're
     43 		not meant to be put in the database!
     44 	*/
     45 
     46 	// NameString is for putting in the namestring of the mentioned user
     47 	// before the mention is dereferenced. Should be in a form along the lines of:
     48 	// @whatever_username@example.org
     49 	//
     50 	// This will not be put in the database, it's just for convenience.
     51 	NameString string `validate:"-" bun:"-"`
     52 	// TargetAccountURI is the AP ID (uri) of the user mentioned.
     53 	//
     54 	// This will not be put in the database, it's just for convenience.
     55 	TargetAccountURI string `validate:"-" bun:"-"`
     56 	// TargetAccountURL is the web url of the user mentioned.
     57 	//
     58 	// This will not be put in the database, it's just for convenience.
     59 	TargetAccountURL string `validate:"-" bun:"-"`
     60 	// A pointer to the gtsmodel account of the mentioned account.
     61 }
     62 
     63 // ParseMentionFunc describes a function that takes a lowercase account name
     64 // in the form "@test@whatever.example.org" for a remote account, or "@test"
     65 // for a local account, and returns a fully populated mention for that account,
     66 // with the given origin status ID and origin account ID.
     67 //
     68 // If the account is remote and not yet found in the database, then ParseMentionFunc
     69 // will try to webfinger the remote account and put it in the database before returning.
     70 //
     71 // Mentions generated by this function are not put in the database, that's still up to
     72 // the caller to do.
     73 type ParseMentionFunc func(ctx context.Context, targetAccount string, originAccountID string, statusID string) (*Mention, error)