Send error messages in a system room. (next: error messages the other way around)
This commit is contained in:
parent
a4dd3b310d
commit
5ab2608ee8
3 changed files with 33 additions and 11 deletions
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue