add emoji + tags
This commit is contained in:
@ -26,6 +26,7 @@ import (
|
|||||||
"github.com/superseriousbusiness/gotosocial/internal/config"
|
"github.com/superseriousbusiness/gotosocial/internal/config"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/db"
|
"github.com/superseriousbusiness/gotosocial/internal/db"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/db/model"
|
"github.com/superseriousbusiness/gotosocial/internal/db/model"
|
||||||
|
"github.com/superseriousbusiness/gotosocial/internal/distributor"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/media"
|
"github.com/superseriousbusiness/gotosocial/internal/media"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/oauth"
|
"github.com/superseriousbusiness/gotosocial/internal/oauth"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/router"
|
"github.com/superseriousbusiness/gotosocial/internal/router"
|
||||||
@ -54,15 +55,17 @@ type statusModule struct {
|
|||||||
db db.DB
|
db db.DB
|
||||||
oauthServer oauth.Server
|
oauthServer oauth.Server
|
||||||
mediaHandler media.MediaHandler
|
mediaHandler media.MediaHandler
|
||||||
|
distributor distributor.Distributor
|
||||||
log *logrus.Logger
|
log *logrus.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
// New returns a new account module
|
// New returns a new account module
|
||||||
func New(config *config.Config, db db.DB, oauthServer oauth.Server, mediaHandler media.MediaHandler, log *logrus.Logger) apimodule.ClientAPIModule {
|
func New(config *config.Config, db db.DB, oauthServer oauth.Server, mediaHandler media.MediaHandler, distributor distributor.Distributor, log *logrus.Logger) apimodule.ClientAPIModule {
|
||||||
return &statusModule{
|
return &statusModule{
|
||||||
config: config,
|
config: config,
|
||||||
db: db,
|
db: db,
|
||||||
mediaHandler: mediaHandler,
|
mediaHandler: mediaHandler,
|
||||||
|
distributor: distributor,
|
||||||
log: log,
|
log: log,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,13 +23,13 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/config"
|
"github.com/superseriousbusiness/gotosocial/internal/config"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/db"
|
"github.com/superseriousbusiness/gotosocial/internal/db"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/db/model"
|
"github.com/superseriousbusiness/gotosocial/internal/db/model"
|
||||||
|
"github.com/superseriousbusiness/gotosocial/internal/distributor"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/oauth"
|
"github.com/superseriousbusiness/gotosocial/internal/oauth"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/util"
|
"github.com/superseriousbusiness/gotosocial/internal/util"
|
||||||
"github.com/superseriousbusiness/gotosocial/pkg/mastotypes"
|
"github.com/superseriousbusiness/gotosocial/pkg/mastotypes"
|
||||||
@ -101,7 +101,6 @@ func (m *statusModule) statusCreatePOSTHandler(c *gin.Context) {
|
|||||||
thisStatusID := uuid.NewString()
|
thisStatusID := uuid.NewString()
|
||||||
thisStatusURI := fmt.Sprintf("%s/%s", uris.StatusesURI, thisStatusID)
|
thisStatusURI := fmt.Sprintf("%s/%s", uris.StatusesURI, thisStatusID)
|
||||||
thisStatusURL := fmt.Sprintf("%s/%s", uris.StatusesURL, thisStatusID)
|
thisStatusURL := fmt.Sprintf("%s/%s", uris.StatusesURL, thisStatusID)
|
||||||
|
|
||||||
newStatus := &model.Status{
|
newStatus := &model.Status{
|
||||||
ID: thisStatusID,
|
ID: thisStatusID,
|
||||||
URI: thisStatusURI,
|
URI: thisStatusURI,
|
||||||
@ -116,7 +115,6 @@ func (m *statusModule) statusCreatePOSTHandler(c *gin.Context) {
|
|||||||
ActivityStreamsType: model.ActivityStreamsNote,
|
ActivityStreamsType: model.ActivityStreamsNote,
|
||||||
}
|
}
|
||||||
|
|
||||||
// take care of side effects -- mentions, updating metadata, etc, etc
|
|
||||||
menchies, err := m.db.AccountStringsToMentions(util.DeriveMentions(form.Status), authed.Account.ID, thisStatusID)
|
menchies, err := m.db.AccountStringsToMentions(util.DeriveMentions(form.Status), authed.Account.ID, thisStatusID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l.Debugf("error generating mentions from status: %s", err)
|
l.Debugf("error generating mentions from status: %s", err)
|
||||||
@ -124,6 +122,17 @@ func (m *statusModule) statusCreatePOSTHandler(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
newStatus.Mentions = menchies
|
||||||
|
|
||||||
|
// take care of side effects -- federation, mentions, updating metadata, etc, etc
|
||||||
|
|
||||||
|
|
||||||
|
m.distributor.FromClientAPI() <- distributor.FromClientAPI{
|
||||||
|
APObjectType: model.ActivityStreamsNote,
|
||||||
|
APActivityType: model.ActivityStreamsCreate,
|
||||||
|
Activity: newStatus,
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateCreateStatus(form *advancedStatusCreateForm, config *config.StatusesConfig, accountID string, db db.DB) error {
|
func validateCreateStatus(form *advancedStatusCreateForm, config *config.StatusesConfig, accountID string, db db.DB) error {
|
||||||
|
|||||||
37
internal/db/model/emoji.go
Normal file
37
internal/db/model/emoji.go
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
GoToSocial
|
||||||
|
Copyright (C) 2021 GoToSocial Authors admin@gotosocial.org
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Affero General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Affero General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package model
|
||||||
|
|
||||||
|
import "time"
|
||||||
|
|
||||||
|
type Emoji struct {
|
||||||
|
ID string `pg:"type:uuid,default:gen_random_uuid(),pk,notnull"`
|
||||||
|
Shortcode string `pg:"notnull"`
|
||||||
|
CreatedAt time.Time `pg:"type:timestamp,notnull,default:now()"`
|
||||||
|
UpdatedAt time.Time `pg:"type:timestamp,notnull,default:now()"`
|
||||||
|
ImageFileName string
|
||||||
|
ImageContentType string
|
||||||
|
ImageFileSize string
|
||||||
|
ImageUpdatedAt time.Time `pg:"type:timestamp,notnull,default:now()"`
|
||||||
|
Disabled bool
|
||||||
|
URI string
|
||||||
|
ImageRemoteURL string
|
||||||
|
VisibleInPicker bool
|
||||||
|
CategoryID string
|
||||||
|
}
|
||||||
@ -51,6 +51,12 @@ type Status struct {
|
|||||||
// What is the activitystreams type of this status? See: https://www.w3.org/TR/activitystreams-vocabulary/#object-types
|
// What is the activitystreams type of this status? See: https://www.w3.org/TR/activitystreams-vocabulary/#object-types
|
||||||
// Will probably almost always be Note but who knows!.
|
// Will probably almost always be Note but who knows!.
|
||||||
ActivityStreamsType ActivityStreamsObject
|
ActivityStreamsType ActivityStreamsObject
|
||||||
|
// Mentions created in this status -- will not be put in the database along with the status
|
||||||
|
Mentions []*Mention `pg:"-"`
|
||||||
|
// Hashtags used in this status -- will not be put in the database along with the status
|
||||||
|
Tags []*Tag `pg:"-"`
|
||||||
|
// Emojis used in this status -- will not be put in the database along with the status
|
||||||
|
Emojis []*Emoji `pg:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Visibility represents the visibility granularity of a status.
|
// Visibility represents the visibility granularity of a status.
|
||||||
|
|||||||
36
internal/db/model/tag.go
Normal file
36
internal/db/model/tag.go
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
GoToSocial
|
||||||
|
Copyright (C) 2021 GoToSocial Authors admin@gotosocial.org
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Affero General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Affero General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package model
|
||||||
|
|
||||||
|
import "time"
|
||||||
|
|
||||||
|
type Tag struct {
|
||||||
|
ID string `pg:"type:uuid,default:gen_random_uuid(),pk,notnull"`
|
||||||
|
Name string `pg:"unique,notnull"`
|
||||||
|
CreatedAt time.Time `pg:"type:timestamp,notnull,default:now()"`
|
||||||
|
UpdatedAt time.Time `pg:"type:timestamp,notnull,default:now()"`
|
||||||
|
Useable bool
|
||||||
|
Trendable bool
|
||||||
|
Listable bool
|
||||||
|
ReviewedAt time.Time
|
||||||
|
RequestedReviewAt time.Time
|
||||||
|
LastStatusAt time.Time
|
||||||
|
MaxScore float32
|
||||||
|
MaxScoreAt time.Time
|
||||||
|
}
|
||||||
@ -21,6 +21,7 @@ package distributor
|
|||||||
import (
|
import (
|
||||||
"github.com/go-fed/activity/pub"
|
"github.com/go-fed/activity/pub"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
"github.com/superseriousbusiness/gotosocial/internal/db/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Distributor should be passed to api modules (see internal/apimodule/...). It is used for
|
// Distributor should be passed to api modules (see internal/apimodule/...). It is used for
|
||||||
@ -30,10 +31,10 @@ import (
|
|||||||
// fire messages into the distributor and not wait for a reply before proceeding with other work. This allows
|
// fire messages into the distributor and not wait for a reply before proceeding with other work. This allows
|
||||||
// for clean distribution of messages without slowing down the client API and harming the user experience.
|
// for clean distribution of messages without slowing down the client API and harming the user experience.
|
||||||
type Distributor interface {
|
type Distributor interface {
|
||||||
// ClientAPIIn returns a channel for accepting messages that come from the gts client API.
|
// FromClientAPI returns a channel for accepting messages that come from the gts client API.
|
||||||
ClientAPIIn() chan interface{}
|
FromClientAPI() chan FromClientAPI
|
||||||
// ClientAPIOut returns a channel for putting in messages that need to go to the gts client API.
|
// ClientAPIOut returns a channel for putting in messages that need to go to the gts client API.
|
||||||
ClientAPIOut() chan interface{}
|
ToClientAPI() chan ToClientAPI
|
||||||
// Start starts the Distributor, reading from its channels and passing messages back and forth.
|
// Start starts the Distributor, reading from its channels and passing messages back and forth.
|
||||||
Start() error
|
Start() error
|
||||||
// Stop stops the distributor cleanly, finishing handling any remaining messages before closing down.
|
// Stop stops the distributor cleanly, finishing handling any remaining messages before closing down.
|
||||||
@ -43,8 +44,8 @@ type Distributor interface {
|
|||||||
// distributor just implements the Distributor interface
|
// distributor just implements the Distributor interface
|
||||||
type distributor struct {
|
type distributor struct {
|
||||||
federator pub.FederatingActor
|
federator pub.FederatingActor
|
||||||
clientAPIIn chan interface{}
|
fromClientAPI chan FromClientAPI
|
||||||
clientAPIOut chan interface{}
|
toClientAPI chan ToClientAPI
|
||||||
stop chan interface{}
|
stop chan interface{}
|
||||||
log *logrus.Logger
|
log *logrus.Logger
|
||||||
}
|
}
|
||||||
@ -53,21 +54,21 @@ type distributor struct {
|
|||||||
func New(federator pub.FederatingActor, log *logrus.Logger) Distributor {
|
func New(federator pub.FederatingActor, log *logrus.Logger) Distributor {
|
||||||
return &distributor{
|
return &distributor{
|
||||||
federator: federator,
|
federator: federator,
|
||||||
clientAPIIn: make(chan interface{}, 100),
|
fromClientAPI: make(chan FromClientAPI, 100),
|
||||||
clientAPIOut: make(chan interface{}, 100),
|
toClientAPI: make(chan ToClientAPI, 100),
|
||||||
stop: make(chan interface{}),
|
stop: make(chan interface{}),
|
||||||
log: log,
|
log: log,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ClientAPIIn returns a channel for accepting messages that come from the gts client API.
|
// ClientAPIIn returns a channel for accepting messages that come from the gts client API.
|
||||||
func (d *distributor) ClientAPIIn() chan interface{} {
|
func (d *distributor) FromClientAPI() chan FromClientAPI {
|
||||||
return d.clientAPIIn
|
return d.fromClientAPI
|
||||||
}
|
}
|
||||||
|
|
||||||
// ClientAPIOut returns a channel for putting in messages that need to go to the gts client API.
|
// ClientAPIOut returns a channel for putting in messages that need to go to the gts client API.
|
||||||
func (d *distributor) ClientAPIOut() chan interface{} {
|
func (d *distributor) ToClientAPI() chan ToClientAPI {
|
||||||
return d.clientAPIOut
|
return d.toClientAPI
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start starts the Distributor, reading from its channels and passing messages back and forth.
|
// Start starts the Distributor, reading from its channels and passing messages back and forth.
|
||||||
@ -76,10 +77,10 @@ func (d *distributor) Start() error {
|
|||||||
DistLoop:
|
DistLoop:
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case clientMsgIn := <-d.clientAPIIn:
|
case clientMsg := <-d.fromClientAPI:
|
||||||
d.log.Infof("received clientMsgIn: %+v", clientMsgIn)
|
d.log.Infof("received message FROM client API: %+v", clientMsg)
|
||||||
case clientMsgOut := <-d.clientAPIOut:
|
case clientMsg := <-d.toClientAPI:
|
||||||
d.log.Infof("received clientMsgOut: %+v", clientMsgOut)
|
d.log.Infof("received message TO client API: %+v", clientMsg)
|
||||||
case <-d.stop:
|
case <-d.stop:
|
||||||
break DistLoop
|
break DistLoop
|
||||||
}
|
}
|
||||||
@ -94,3 +95,15 @@ func (d *distributor) Stop() error {
|
|||||||
close(d.stop)
|
close(d.stop)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type FromClientAPI struct {
|
||||||
|
APObjectType model.ActivityStreamsObject
|
||||||
|
APActivityType model.ActivityStreamsActivity
|
||||||
|
Activity interface{}
|
||||||
|
}
|
||||||
|
|
||||||
|
type ToClientAPI struct {
|
||||||
|
APObjectType model.ActivityStreamsObject
|
||||||
|
APActivityType model.ActivityStreamsActivity
|
||||||
|
Activity interface{}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user