diff options
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 + } + } + } } } |