mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-11-17 08:07:30 -06:00
[feature] Show + federate emojis in accounts (#837)
* Start adding account emoji * get emojis serialized + deserialized nicely * update tests * set / retrieve emojis on accounts * show account emojis in web view * fetch emojis from db based on ids * fix typo in test * lint * fix pg migration * update tests * update emoji checking logic * update comment * clarify comments + add some spacing * tidy up loops a lil (thanks kim)
This commit is contained in:
parent
15a67b7bef
commit
c4a08292ee
34 changed files with 934 additions and 127 deletions
|
|
@ -27,7 +27,9 @@ import (
|
|||
|
||||
"github.com/stretchr/testify/suite"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/ap"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/db/bundb"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||
"github.com/uptrace/bun"
|
||||
)
|
||||
|
||||
type AccountTestSuite struct {
|
||||
|
|
@ -71,17 +73,70 @@ func (suite *AccountTestSuite) TestGetAccountByUsernameDomain() {
|
|||
}
|
||||
|
||||
func (suite *AccountTestSuite) TestUpdateAccount() {
|
||||
ctx := context.Background()
|
||||
|
||||
testAccount := suite.testAccounts["local_account_1"]
|
||||
|
||||
testAccount.DisplayName = "new display name!"
|
||||
testAccount.EmojiIDs = []string{"01GD36ZKWTKY3T1JJ24JR7KY1Q", "01GD36ZV904SHBHNAYV6DX5QEF"}
|
||||
|
||||
_, err := suite.db.UpdateAccount(context.Background(), testAccount)
|
||||
_, err := suite.db.UpdateAccount(ctx, testAccount)
|
||||
suite.NoError(err)
|
||||
|
||||
updated, err := suite.db.GetAccountByID(context.Background(), testAccount.ID)
|
||||
updated, err := suite.db.GetAccountByID(ctx, testAccount.ID)
|
||||
suite.NoError(err)
|
||||
suite.Equal("new display name!", updated.DisplayName)
|
||||
suite.Equal([]string{"01GD36ZKWTKY3T1JJ24JR7KY1Q", "01GD36ZV904SHBHNAYV6DX5QEF"}, updated.EmojiIDs)
|
||||
suite.WithinDuration(time.Now(), updated.UpdatedAt, 5*time.Second)
|
||||
|
||||
// get account without cache + make sure it's really in the db as desired
|
||||
dbService, ok := suite.db.(*bundb.DBService)
|
||||
if !ok {
|
||||
panic("db was not *bundb.DBService")
|
||||
}
|
||||
|
||||
noCache := >smodel.Account{}
|
||||
err = dbService.GetConn().
|
||||
NewSelect().
|
||||
Model(noCache).
|
||||
Where("account.id = ?", bun.Ident(testAccount.ID)).
|
||||
Relation("AvatarMediaAttachment").
|
||||
Relation("HeaderMediaAttachment").
|
||||
Relation("Emojis").
|
||||
Scan(ctx)
|
||||
|
||||
suite.NoError(err)
|
||||
suite.Equal("new display name!", noCache.DisplayName)
|
||||
suite.Equal([]string{"01GD36ZKWTKY3T1JJ24JR7KY1Q", "01GD36ZV904SHBHNAYV6DX5QEF"}, noCache.EmojiIDs)
|
||||
suite.WithinDuration(time.Now(), noCache.UpdatedAt, 5*time.Second)
|
||||
suite.NotNil(noCache.AvatarMediaAttachment)
|
||||
suite.NotNil(noCache.HeaderMediaAttachment)
|
||||
|
||||
// update again to remove emoji associations
|
||||
testAccount.EmojiIDs = []string{}
|
||||
|
||||
_, err = suite.db.UpdateAccount(ctx, testAccount)
|
||||
suite.NoError(err)
|
||||
|
||||
updated, err = suite.db.GetAccountByID(ctx, testAccount.ID)
|
||||
suite.NoError(err)
|
||||
suite.Equal("new display name!", updated.DisplayName)
|
||||
suite.Empty(updated.EmojiIDs)
|
||||
suite.WithinDuration(time.Now(), updated.UpdatedAt, 5*time.Second)
|
||||
|
||||
err = dbService.GetConn().
|
||||
NewSelect().
|
||||
Model(noCache).
|
||||
Where("account.id = ?", bun.Ident(testAccount.ID)).
|
||||
Relation("AvatarMediaAttachment").
|
||||
Relation("HeaderMediaAttachment").
|
||||
Relation("Emojis").
|
||||
Scan(ctx)
|
||||
|
||||
suite.NoError(err)
|
||||
suite.Equal("new display name!", noCache.DisplayName)
|
||||
suite.Empty(noCache.EmojiIDs)
|
||||
suite.WithinDuration(time.Now(), noCache.UpdatedAt, 5*time.Second)
|
||||
}
|
||||
|
||||
func (suite *AccountTestSuite) TestInsertAccountWithDefaults() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue