aboutsummaryrefslogtreecommitdiff
path: root/appservice
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2020-02-17 19:52:50 +0100
committerAlex Auvolat <alex@adnab.me>2020-02-17 19:52:50 +0100
commit5ab2608ee8bd36b7c7b0d670d24b5851250e3887 (patch)
tree991da5f05ab7f1370d3d959fe1d0ada9c1ac18b3 /appservice
parenta4dd3b310d68f5c6147bdeaf8ecd3556c2cf7859 (diff)
downloadeasybridge-5ab2608ee8bd36b7c7b0d670d24b5851250e3887.tar.gz
easybridge-5ab2608ee8bd36b7c7b0d670d24b5851250e3887.zip
Send error messages in a system room. (next: error messages the other way around)
Diffstat (limited to 'appservice')
-rw-r--r--appservice/account.go19
-rw-r--r--appservice/db.go10
-rw-r--r--appservice/matrix.go15
3 files changed, 33 insertions, 11 deletions
diff --git a/appservice/account.go b/appservice/account.go
index d8bf8cf..013a420 100644
--- a/appservice/account.go
+++ b/appservice/account.go
@@ -55,12 +55,18 @@ func RemoveAccount(mxUser string, name string) {
}
}
+func (a *Account) ezbrMessagef(format string, args ...interface{}) {
+ msg := fmt.Sprintf(format, args...)
+ msg = fmt.Sprintf("%s: %s", a.Protocol, msg)
+ ezbrSystemSend(a.MatrixUser, msg)
+}
+
// ---- Begin event handlers ----
func (a *Account) Joined(roomId RoomID) {
err := a.joinedInternal(roomId)
if err != nil {
- log.Warnf("Dropping Account.Joined %s: %s", roomId, err)
+ a.ezbrMessagef("Dropping Account.Joined %s: %s", roomId, err)
}
}
@@ -86,7 +92,7 @@ func (a *Account) joinedInternal(roomId RoomID) error {
func (a *Account) Left(roomId RoomID) {
err := a.leftInternal(roomId)
if err != nil {
- log.Warnf("Dropping Account.Left %s: %s", roomId, err)
+ a.ezbrMessagef("Dropping Account.Left %s: %s", roomId, err)
}
}
@@ -108,7 +114,7 @@ func (a *Account) leftInternal(roomId RoomID) error {
func (a *Account) UserInfoUpdated(user UserID, info *UserInfo) {
err := a.userInfoUpdatedInternal(user, info)
if err != nil {
- log.Warnf("Dropping Account.UserInfoUpdated %s: %s", user, err)
+ a.ezbrMessagef("Dropping Account.UserInfoUpdated %s: %s", user, err)
}
}
@@ -137,7 +143,7 @@ func (a *Account) userInfoUpdatedInternal(user UserID, info *UserInfo) error {
func (a *Account) RoomInfoUpdated(roomId RoomID, author UserID, info *RoomInfo) {
err := a.roomInfoUpdatedInternal(roomId, author, info)
if err != nil {
- log.Warnf("Dropping Account.RoomInfoUpdated %s: %s", roomId, err)
+ a.ezbrMessagef("Dropping Account.RoomInfoUpdated %s: %s", roomId, err)
}
}
@@ -163,7 +169,8 @@ func (a *Account) roomInfoUpdatedInternal(roomId RoomID, author UserID, info *Ro
}
if info.Name != "" {
- err2 := mxRoomNameAs(mx_room_id, info.Name, as_mxid)
+ name := fmt.Sprintf("%s (%s)", info.Name, a.Protocol)
+ err2 := mxRoomNameAs(mx_room_id, name, as_mxid)
if err2 != nil {
err = err2
}
@@ -182,7 +189,7 @@ func (a *Account) roomInfoUpdatedInternal(roomId RoomID, author UserID, info *Ro
func (a *Account) Event(event *Event) {
err := a.eventInternal(event)
if err != nil {
- log.Warnf("Dropping Account.Event %s %s %s: %s", event.Author, event.Recipient, event.Room, err)
+ a.ezbrMessagef("Dropping Account.Event %s %s %s: %s", event.Author, event.Recipient, event.Room, err)
}
}
diff --git a/appservice/db.go b/appservice/db.go
index 512e7b5..1c68e6f 100644
--- a/appservice/db.go
+++ b/appservice/db.go
@@ -131,11 +131,11 @@ func dbGetMxPmRoom(protocol string, them connector.UserID, themMxId string, usMx
return "", err
}
- err = mxRoomJoinAs(mx_room_id, themMxId)
- if err != nil {
- log.Printf("Could not join %s as %s", mx_room_id, themMxId)
- return "", err
- }
+ //err = mxRoomJoinAs(mx_room_id, themMxId)
+ //if err != nil {
+ // log.Printf("Could not join %s as %s", mx_room_id, themMxId)
+ // return "", err
+ //}
room = DbPmRoomMap{
MxUserID: usMxId,
diff --git a/appservice/matrix.go b/appservice/matrix.go
index 550e5a5..a212d85 100644
--- a/appservice/matrix.go
+++ b/appservice/matrix.go
@@ -11,12 +11,27 @@ import (
log "github.com/sirupsen/logrus"
. "git.deuxfleurs.fr/Deuxfleurs/easybridge/mxlib"
+ "git.deuxfleurs.fr/Deuxfleurs/easybridge/connector"
)
func ezbrMxId() string {
return fmt.Sprintf("@%s:%s", registration.SenderLocalpart, config.MatrixDomain)
}
+func ezbrSystemRoom(user_mx_id string) (string, error) {
+ return dbGetMxPmRoom("system", connector.UserID("Easybridge"), ezbrMxId(), user_mx_id, "easybridge")
+}
+
+func ezbrSystemSend(user_mx_id string, msg string) {
+ mx_room_id, err := ezbrSystemRoom(user_mx_id)
+ if err == nil {
+ err = mxSendMessageAs(mx_room_id, "m.text", msg, ezbrMxId())
+ }
+ if err != nil {
+ log.Warnf("(%s) %s", user_mx_id, msg)
+ }
+}
+
// ----
var httpClient *http.Client