summaryrefslogtreecommitdiff
path: root/testrig
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2022-09-26 11:56:01 +0200
committerLibravatar GitHub <noreply@github.com>2022-09-26 11:56:01 +0200
commitc4a08292ee44bc731ff90bad18a3f37e5ee8ef22 (patch)
tree1726f8450ec37f744204a857c3be2bfab17f206c /testrig
parent[bugfix] more nil checks baybeeeeeeeeeeeeeeeeeeee (#854) (diff)
downloadgotosocial-c4a08292ee44bc731ff90bad18a3f37e5ee8ef22.tar.xz
[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)
Diffstat (limited to 'testrig')
-rw-r--r--testrig/db.go1
-rw-r--r--testrig/media/kip-original.gifbin0 -> 1428 bytes
-rw-r--r--testrig/media/kip-static.pngbin0 -> 802 bytes
-rw-r--r--testrig/media/yell-original.pngbin0 -> 10889 bytes
-rw-r--r--testrig/media/yell-static.pngbin0 -> 10808 bytes
-rw-r--r--testrig/testmodels.go82
-rw-r--r--testrig/transportcontroller.go15
7 files changed, 98 insertions, 0 deletions
diff --git a/testrig/db.go b/testrig/db.go
index ae3132835..72446e2bc 100644
--- a/testrig/db.go
+++ b/testrig/db.go
@@ -32,6 +32,7 @@ import (
var testModels = []interface{}{
&gtsmodel.Account{},
+ &gtsmodel.AccountToEmoji{},
&gtsmodel.Application{},
&gtsmodel.Block{},
&gtsmodel.DomainBlock{},
diff --git a/testrig/media/kip-original.gif b/testrig/media/kip-original.gif
new file mode 100644
index 000000000..6e83746f6
--- /dev/null
+++ b/testrig/media/kip-original.gif
Binary files differ
diff --git a/testrig/media/kip-static.png b/testrig/media/kip-static.png
new file mode 100644
index 000000000..1ba296687
--- /dev/null
+++ b/testrig/media/kip-static.png
Binary files differ
diff --git a/testrig/media/yell-original.png b/testrig/media/yell-original.png
new file mode 100644
index 000000000..b369a96b1
--- /dev/null
+++ b/testrig/media/yell-original.png
Binary files differ
diff --git a/testrig/media/yell-static.png b/testrig/media/yell-static.png
new file mode 100644
index 000000000..9b5d2837e
--- /dev/null
+++ b/testrig/media/yell-static.png
Binary files differ
diff --git a/testrig/testmodels.go b/testrig/testmodels.go
index 98b23721e..f53022fd8 100644
--- a/testrig/testmodels.go
+++ b/testrig/testmodels.go
@@ -952,6 +952,28 @@ func NewTestEmojis() map[string]*gtsmodel.Emoji {
VisibleInPicker: TrueBool(),
CategoryID: "",
},
+ "yell": {
+ ID: "01GD5KP5CQEE1R3X43Y1EHS2CW",
+ Shortcode: "yell",
+ Domain: "fossbros-anonymous.io",
+ CreatedAt: TimeMustParse("2020-03-18T13:12:00+01:00"),
+ UpdatedAt: TimeMustParse("2020-03-18T13:12:00+01:00"),
+ ImageRemoteURL: "http://fossbros-anonymous.io/emoji/yell.gif",
+ ImageStaticRemoteURL: "",
+ ImageURL: "http://localhost:8080/fileserver/01GD5KR15NHTY8FZ01CD4D08XP/emoji/original/01GD5KP5CQEE1R3X43Y1EHS2CW.png",
+ ImagePath: "/tmp/gotosocial/01GD5KR15NHTY8FZ01CD4D08XP/emoji/original/01GD5KP5CQEE1R3X43Y1EHS2CW.png",
+ ImageStaticURL: "http://localhost:8080/fileserver/01GD5KR15NHTY8FZ01CD4D08XP/emoji/static/01GD5KP5CQEE1R3X43Y1EHS2CW.png",
+ ImageStaticPath: "/tmp/gotosocial/01GD5KR15NHTY8FZ01CD4D08XP/emoji/static/01GD5KP5CQEE1R3X43Y1EHS2CW.png",
+ ImageContentType: "image/png",
+ ImageStaticContentType: "image/png",
+ ImageFileSize: 10889,
+ ImageStaticFileSize: 10808,
+ ImageUpdatedAt: TimeMustParse("2020-03-18T13:12:00+01:00"),
+ Disabled: FalseBool(),
+ URI: "http://fossbros-anonymous.io/emoji/01GD5KP5CQEE1R3X43Y1EHS2CW",
+ VisibleInPicker: FalseBool(),
+ CategoryID: "",
+ },
}
}
@@ -1045,6 +1067,10 @@ func newTestStoredEmoji() map[string]filenames {
Original: "rainbow-original.png",
Static: "rainbow-static.png",
},
+ "yell": {
+ Original: "yell-original.png",
+ Static: "yell-static.png",
+ },
}
}
@@ -1941,6 +1967,22 @@ func NewTestFediServices() map[string]vocab.ActivityStreamsService {
}
}
+func NewTestFediEmojis() map[string]vocab.TootEmoji {
+ return map[string]vocab.TootEmoji{
+ "http://fossbros-anonymous.io/emoji/01GD5HCC2YECT012TK8PAGX4D1": newAPEmoji(
+ URLMustParse("http://fossbros-anonymous.io/emoji/01GD5HCC2YECT012TK8PAGX4D1"),
+ "kip_van_den_bos",
+ TimeMustParse("2022-09-13T12:13:12+02:00"),
+ newAPImage(
+ URLMustParse("http://fossbros-anonymous.io/emoji/kip.gif"),
+ "image/gif",
+ "",
+ "",
+ ),
+ ),
+ }
+}
+
// RemoteAttachmentFile mimics a remote (federated) attachment
type RemoteAttachmentFile struct {
Data []byte
@@ -1968,6 +2010,16 @@ func NewTestFediAttachments(relativePath string) map[string]RemoteAttachmentFile
panic(err)
}
+ kipBytes, err := os.ReadFile(fmt.Sprintf("%s/kip-original.gif", relativePath))
+ if err != nil {
+ panic(err)
+ }
+
+ yellBytes, err := os.ReadFile(fmt.Sprintf("%s/yell-original.png", relativePath))
+ if err != nil {
+ panic(err)
+ }
+
return map[string]RemoteAttachmentFile{
"https://s3-us-west-2.amazonaws.com/plushcity/media_attachments/files/106/867/380/219/163/828/original/88e8758c5f011439.jpg": {
Data: beeBytes,
@@ -1985,6 +2037,14 @@ func NewTestFediAttachments(relativePath string) map[string]RemoteAttachmentFile
Data: peglinBytes,
ContentType: "image/gif",
},
+ "http://fossbros-anonymous.io/emoji/kip.gif": {
+ Data: kipBytes,
+ ContentType: "image/gif",
+ },
+ "http://fossbros-anonymous.io/emoji/yell.gif": {
+ Data: yellBytes,
+ ContentType: "image/png",
+ },
}
}
@@ -2857,6 +2917,28 @@ func newAPImage(url *url.URL, mediaType string, imageDescription string, blurhas
return image
}
+func newAPEmoji(id *url.URL, name string, updated time.Time, image vocab.ActivityStreamsImage) vocab.TootEmoji {
+ emoji := streams.NewTootEmoji()
+
+ idProp := streams.NewJSONLDIdProperty()
+ idProp.SetIRI(id)
+ emoji.SetJSONLDId(idProp)
+
+ nameProp := streams.NewActivityStreamsNameProperty()
+ nameProp.AppendXMLSchemaString(`:` + strings.Trim(name, ":") + `:`)
+ emoji.SetActivityStreamsName(nameProp)
+
+ updatedProp := streams.NewActivityStreamsUpdatedProperty()
+ updatedProp.Set(updated)
+ emoji.SetActivityStreamsUpdated(updatedProp)
+
+ iconProp := streams.NewActivityStreamsIconProperty()
+ iconProp.AppendActivityStreamsImage(image)
+ emoji.SetActivityStreamsIcon(iconProp)
+
+ return emoji
+}
+
// NewAPNote returns a new activity streams note for the given parameters
func NewAPNote(
noteID *url.URL,
diff --git a/testrig/transportcontroller.go b/testrig/transportcontroller.go
index 68f03398d..70f2f0c61 100644
--- a/testrig/transportcontroller.go
+++ b/testrig/transportcontroller.go
@@ -64,6 +64,7 @@ type MockHTTPClient struct {
testRemoteGroups map[string]vocab.ActivityStreamsGroup
testRemoteServices map[string]vocab.ActivityStreamsService
testRemoteAttachments map[string]RemoteAttachmentFile
+ testRemoteEmojis map[string]vocab.TootEmoji
SentMessages sync.Map
}
@@ -90,6 +91,7 @@ func NewMockHTTPClient(do func(req *http.Request) (*http.Response, error), relat
mockHTTPClient.testRemoteGroups = NewTestFediGroups()
mockHTTPClient.testRemoteServices = NewTestFediServices()
mockHTTPClient.testRemoteAttachments = NewTestFediAttachments(relativeMediaPath)
+ mockHTTPClient.testRemoteEmojis = NewTestFediEmojis()
mockHTTPClient.do = func(req *http.Request) (*http.Response, error) {
responseCode := http.StatusNotFound
@@ -173,6 +175,19 @@ func NewMockHTTPClient(do func(req *http.Request) (*http.Response, error), relat
responseBytes = serviceJSON
responseContentType = applicationActivityJSON
responseContentLength = len(serviceJSON)
+ } else if emoji, ok := mockHTTPClient.testRemoteEmojis[req.URL.String()]; ok {
+ emojiI, err := streams.Serialize(emoji)
+ if err != nil {
+ panic(err)
+ }
+ emojiJSON, err := json.Marshal(emojiI)
+ if err != nil {
+ panic(err)
+ }
+ responseCode = http.StatusOK
+ responseBytes = emojiJSON
+ responseContentType = applicationActivityJSON
+ responseContentLength = len(emojiJSON)
} else if attachment, ok := mockHTTPClient.testRemoteAttachments[req.URL.String()]; ok {
responseCode = http.StatusOK
responseBytes = attachment.Data