From facc375e8cf41f87f6b90fe5117754e2b639ce83 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Wed, 26 Feb 2020 16:32:58 +0100 Subject: Whoops & refactor --- account.go | 26 ++++++++++++-------------- connector/xmpp/xmpp.go | 2 +- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/account.go b/account.go index a76b782..cd6d033 100644 --- a/account.go +++ b/account.go @@ -87,13 +87,7 @@ func (a *Account) connect(config map[string]string, join_rooms []string) { } for _, room := range join_rooms { - var entry DbJoinedRoom - db.Where(&DbJoinedRoom{ - MxUserID: a.MatrixUser, - Protocol: a.Protocol, - AccountName: a.AccountName, - RoomID: RoomID(room), - }).FirstOrCreate(&entry) + a.addAutojoin(RoomID(room)) } var autojoin []DbJoinedRoom @@ -110,6 +104,16 @@ func (a *Account) connect(config map[string]string, join_rooms []string) { } } +func (a *Account) addAutojoin(roomId RoomID) { + var entry DbJoinedRoom + db.Where(&DbJoinedRoom{ + MxUserID: a.MatrixUser, + Protocol: a.Protocol, + AccountName: a.AccountName, + RoomID: roomId, + }).FirstOrCreate(&entry) +} + // ---- Begin event handlers ---- func (a *Account) Joined(roomId RoomID) { @@ -118,13 +122,7 @@ func (a *Account) Joined(roomId RoomID) { a.ezbrMessagef("Dropping Account.Joined %s: %s", roomId, err.Error()) } - var entry DbJoinedRoom - db.Where(&DbJoinedRoom{ - MxUserID: a.MatrixUser, - Protocol: a.Protocol, - AccountName: a.AccountName, - RoomID: roomId, - }).FirstOrCreate(&entry) + a.addAutojoin(roomId) } func (a *Account) joinedInternal(roomId RoomID) error { diff --git a/connector/xmpp/xmpp.go b/connector/xmpp/xmpp.go index 727c4d8..1215a66 100644 --- a/connector/xmpp/xmpp.go +++ b/connector/xmpp/xmpp.go @@ -82,7 +82,7 @@ func (xm *XMPP) Configure(c Configuration) error { } xm.jid_localpart = jid_parts[0] - xm.nickname = c.GetString("nickname", xm.jid_locakpart) + xm.nickname, _ = c.GetString("nickname", xm.jid_localpart) xm.password, err = c.GetString("password") if err != nil { -- cgit v1.2.3