diff options
author | Alex Auvolat <alex@adnab.me> | 2020-02-17 15:30:01 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2020-02-17 15:30:01 +0100 |
commit | c740f76826c0291005111c8554c256e8f491e7b9 (patch) | |
tree | 32ca1e98591d3c8afeaba124eb2c872800a058c9 /appservice/server.go | |
parent | 51f3c45e05558153880f1b6898be86e84e76a5a1 (diff) | |
download | easybridge-c740f76826c0291005111c8554c256e8f491e7b9.tar.gz easybridge-c740f76826c0291005111c8554c256e8f491e7b9.zip |
Handle users leaving from rooms
Diffstat (limited to 'appservice/server.go')
-rw-r--r-- | appservice/server.go | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/appservice/server.go b/appservice/server.go index 79a8f1a..00f23f1 100644 --- a/appservice/server.go +++ b/appservice/server.go @@ -107,11 +107,7 @@ func handleTxnEvent(e *mxlib.Event) { } // Look up if this is a private message room - var pm_room DbPmRoomMap - is_pm_room := !db.First(&pm_room, DbPmRoomMap{ - MxRoomID: e.RoomId, - }).RecordNotFound() - if is_pm_room { + if pm_room := dbIsPmRoom(e.RoomId); pm_room != nil { acct := FindAccount(pm_room.MxUserID, pm_room.AccountName) if acct != nil && e.Sender == pm_room.MxUserID { ev.Author = acct.Conn.User() @@ -121,11 +117,7 @@ func handleTxnEvent(e *mxlib.Event) { } // Look up if this is a regular room - var room DbRoomMap - is_room := !db.First(&room, DbRoomMap{ - MxRoomID: e.RoomId, - }).RecordNotFound() - if is_room { + if room := dbIsPublicRoom(e.RoomId); room != nil { acct := FindJoinedAccount(e.Sender, room.Protocol, room.RoomID) if acct != nil { ev.Author = acct.Conn.User() @@ -133,5 +125,24 @@ func handleTxnEvent(e *mxlib.Event) { acct.Conn.Send(ev) } } + } else if e.Type == "m.room.member" { + ms := e.Content["membership"].(string) + if ms == "leave" { + // If leaving a PM room, we must delete it + if pm_room := dbIsPmRoom(e.RoomId); pm_room != nil { + them_mx := userMxId(pm_room.Protocol, pm_room.UserID) + mxRoomLeaveAs(e.RoomId, them_mx) + db.Delete(pm_room) + } + + // If leaving a public room, leave from server as well + if room := dbIsPublicRoom(e.RoomId); room != nil { + acct := FindJoinedAccount(e.Sender, room.Protocol, room.RoomID) + if acct != nil { + acct.Conn.Leave(room.RoomID) + // TODO: manage autojoin list, remove this room + } + } + } } } |