aboutsummaryrefslogtreecommitdiff
path: root/appservice
diff options
context:
space:
mode:
Diffstat (limited to 'appservice')
-rw-r--r--appservice/account.go39
-rw-r--r--appservice/server.go21
2 files changed, 50 insertions, 10 deletions
diff --git a/appservice/account.go b/appservice/account.go
index 311f266..a2b95d7 100644
--- a/appservice/account.go
+++ b/appservice/account.go
@@ -249,6 +249,43 @@ func (a *Account) eventInternal(event *Event) error {
typ = "m.emote"
}
- return mx.SendMessageAs(mx_room_id, typ, event.Text, mx_user_id)
+ err = mx.SendMessageAs(mx_room_id, typ, event.Text, mx_user_id)
+ if err != nil {
+ return err
+ }
+
+ if event.Attachements != nil {
+ for _, file := range event.Attachements {
+ mxfile, err := mx.UploadMedia(file)
+ if err != nil {
+ return err
+ }
+ content := map[string]interface{} {
+ "body": mxfile.Filename(),
+ "filename": mxfile.Filename(),
+ "url": fmt.Sprintf("mxc://%s/%s", mxfile.MxcServer, mxfile.MxcMediaId),
+ }
+ if sz := mxfile.ImageSize(); sz != nil {
+ content["msgtype"] = "m.image"
+ content["info"] = map[string]interface{} {
+ "mimetype": mxfile.Mimetype(),
+ "size": mxfile.Size(),
+ "width": sz.Width,
+ "height": sz.Height,
+ }
+ } else {
+ content["msgtype"] = "m.file"
+ content["info"] = map[string]interface{} {
+ "mimetype": mxfile.Mimetype(),
+ "size": mxfile.Size(),
+ }
+ }
+ err = mx.SendAs(mx_room_id, "m.room.message", content, mx_user_id)
+ if err != nil {
+ return err
+ }
+ }
+ }
+ return nil
}
}
diff --git a/appservice/server.go b/appservice/server.go
index 48e26a6..5a5cebe 100644
--- a/appservice/server.go
+++ b/appservice/server.go
@@ -41,15 +41,18 @@ func Start(r *mxlib.Registration, c *Config) (chan error, error) {
if mxe, ok := err.(*mxlib.MxError); !ok || mxe.ErrCode != "M_USER_IN_USE" {
return nil, err
}
- err = mx.ProfileDisplayname(ezbrMxId(), fmt.Sprintf("Easybridge (%s)", EASYBRIDGE_SYSTEM_PROTOCOL))
- if err != nil {
- return nil, err
- }
- err = mx.ProfileAvatar(ezbrMxId(), &connector.FileMediaObject{
- Path: "easybridge.jpg",
- })
- if err != nil {
- return nil, err
+ if err == nil {
+ // If Easybridge account was created, update avatar and display name
+ err = mx.ProfileAvatar(ezbrMxId(), &connector.FileMediaObject{
+ Path: "easybridge.jpg",
+ })
+ if err != nil {
+ return nil, err
+ }
+ err = mx.ProfileDisplayname(ezbrMxId(), fmt.Sprintf("Easybridge (%s)", EASYBRIDGE_SYSTEM_PROTOCOL))
+ if err != nil {
+ return nil, err
+ }
}
router := mux.NewRouter()