diff --git a/account.go b/account.go index c975c6e..59809e7 100644 --- a/account.go +++ b/account.go @@ -291,7 +291,7 @@ func (a *Account) userInfoUpdatedInternal(user UserID, info *UserInfo) error { if info.Avatar != nil { cache_key := fmt.Sprintf("%s/user_avatar/%s", a.Protocol, user) cache_val := info.Avatar.Filename() - if cache_val == "" || dbCacheTestAndSet(cache_key, cache_val) { + if cache_val == "" || dbKvTestAndSet(cache_key, cache_val) { err2 := mx.ProfileAvatar(mx_user_id, info.Avatar) if err2 != nil { err = err2 @@ -345,7 +345,7 @@ func (a *Account) roomInfoUpdatedInternal(roomId RoomID, author UserID, info *Ro if info.Picture != nil { cache_key := fmt.Sprintf("%s/room_picture/%s", a.Protocol, roomId) cache_val := info.Picture.Filename() - if cache_val == "" || dbCacheTestAndSet(cache_key, cache_val) { + if cache_val == "" || dbKvTestAndSet(cache_key, cache_val) { err2 := mx.RoomAvatarAs(mx_room_id, info.Picture, as_mxid) if err2 != nil { err = err2 @@ -417,7 +417,7 @@ func (a *Account) eventInternal(event *Event) error { if event.Id != "" { cache_key := fmt.Sprintf("%s/event_seen/%s/%s", a.Protocol, mx_room_id, event.Id) - if !dbCacheTestAndSet(cache_key, "yes") { + if !dbKvTestAndSet(cache_key, "yes") { // false: cache key was not modified, meaning we // already saw the event return nil @@ -475,11 +475,11 @@ func (a *Account) eventInternal(event *Event) error { func (a *Account) CacheGet(key string) string { cache_key := fmt.Sprintf("%s/account/%s/%s/%s", a.Protocol, a.MatrixUser, a.AccountName, key) - return dbCacheGet(cache_key) + return dbKvGet(cache_key) } func (a *Account) CachePut(key string, value string) { cache_key := fmt.Sprintf("%s/account/%s/%s/%s", a.Protocol, a.MatrixUser, a.AccountName, key) - dbCachePut(cache_key, value) + dbKvPut(cache_key, value) } diff --git a/connector/irc/config.go b/connector/irc/config.go index 33469ed..0b36473 100644 --- a/connector/irc/config.go +++ b/connector/irc/config.go @@ -4,8 +4,10 @@ import ( . "git.deuxfleurs.fr/Deuxfleurs/easybridge/connector" ) +const IRC_PROTOCOL = "IRC" + func init() { - Register("irc", Protocol{ + Register(IRC_PROTOCOL, Protocol{ NewConnector: func() Connector { return &IRC{} }, Schema: ConfigSchema{ &ConfigEntry{ diff --git a/connector/irc/irc.go b/connector/irc/irc.go index 977b71d..dafe9db 100644 --- a/connector/irc/irc.go +++ b/connector/irc/irc.go @@ -32,7 +32,7 @@ func (irc *IRC) SetHandler(h Handler) { } func (irc *IRC) Protocol() string { - return "irc" + return IRC_PROTOCOL } func (irc *IRC) Configure(c Configuration) error { diff --git a/connector/mattermost/config.go b/connector/mattermost/config.go index dd3bbbb..3be8f67 100644 --- a/connector/mattermost/config.go +++ b/connector/mattermost/config.go @@ -4,8 +4,10 @@ import ( . "git.deuxfleurs.fr/Deuxfleurs/easybridge/connector" ) +const MATTERMOST_PROTOCOL = "Mattermost" + func init() { - Register("mattermost", Protocol{ + Register(MATTERMOST_PROTOCOL, Protocol{ NewConnector: func() Connector { return &Mattermost{} }, Schema: ConfigSchema{ &ConfigEntry{ diff --git a/connector/mattermost/mattermost.go b/connector/mattermost/mattermost.go index 530938c..12ac604 100644 --- a/connector/mattermost/mattermost.go +++ b/connector/mattermost/mattermost.go @@ -49,7 +49,7 @@ func (mm *Mattermost) SetHandler(h Handler) { } func (mm *Mattermost) Protocol() string { - return "mattermost" + return MATTERMOST_PROTOCOL } func (mm *Mattermost) Configure(c Configuration) error { diff --git a/connector/xmpp/config.go b/connector/xmpp/config.go index a6abfac..a3a97ec 100644 --- a/connector/xmpp/config.go +++ b/connector/xmpp/config.go @@ -4,8 +4,10 @@ import ( . "git.deuxfleurs.fr/Deuxfleurs/easybridge/connector" ) +const XMPP_PROTOCOL = "XMPP" + func init() { - Register("xmpp", Protocol{ + Register(XMPP_PROTOCOL, Protocol{ NewConnector: func() Connector { return &XMPP{} }, Schema: ConfigSchema{ &ConfigEntry{ diff --git a/connector/xmpp/xmpp.go b/connector/xmpp/xmpp.go index fb34361..dcf1db6 100644 --- a/connector/xmpp/xmpp.go +++ b/connector/xmpp/xmpp.go @@ -43,7 +43,7 @@ func (xm *XMPP) SetHandler(h Handler) { } func (xm *XMPP) Protocol() string { - return "xmpp" + return XMPP_PROTOCOL } func (xm *XMPP) Configure(c Configuration) error { diff --git a/db.go b/db.go index 9090626..a004496 100644 --- a/db.go +++ b/db.go @@ -27,7 +27,7 @@ func InitDb() error { db.AutoMigrate(&DbAccountConfig{}) - db.AutoMigrate(&DbCache{}) + db.AutoMigrate(&DbKv{}) db.AutoMigrate(&DbUserMap{}) db.Model(&DbUserMap{}).AddIndex("idx_protocol_user", "protocol", "user_id") @@ -55,7 +55,7 @@ type DbAccountConfig struct { } // Long-term cache entries -type DbCache struct { +type DbKv struct { gorm.Model Key string `gorm:"unique_index"` @@ -130,27 +130,27 @@ func dbUnlockSlot(key string) { // ---- -func dbCacheGet(key string) string { - var entry DbCache - if db.Where(&DbCache{Key: key}).First(&entry).RecordNotFound() { +func dbKvGet(key string) string { + var entry DbKv + if db.Where(&DbKv{Key: key}).First(&entry).RecordNotFound() { return "" } else { return entry.Value } } -func dbCachePut(key string, value string) { - var entry DbCache - db.Where(&DbCache{Key: key}).Assign(&DbCache{Value: value}).FirstOrCreate(&entry) +func dbKvPut(key string, value string) { + var entry DbKv + db.Where(&DbKv{Key: key}).Assign(&DbKv{Value: value}).FirstOrCreate(&entry) } -func dbCacheTestAndSet(key string, value string) bool { +func dbKvTestAndSet(key string, value string) bool { dbLockSlot(key) defer dbUnlockSlot(key) // True if value was changed, false if was already set - if dbCacheGet(key) != value { - dbCachePut(key, value) + if dbKvGet(key) != value { + dbKvPut(key, value) return true } return false diff --git a/server.go b/server.go index 6ec6549..f5a5db0 100644 --- a/server.go +++ b/server.go @@ -133,7 +133,7 @@ func handleTxnEvent(e *mxlib.Event) error { } else if room := dbIsPublicRoom(e.RoomId); room != nil { cache_key := fmt.Sprintf("%s/event_seen/%s/%s", room.Protocol, e.RoomId, ev.Id) - dbCachePut(cache_key, "yes") + dbKvPut(cache_key, "yes") // If this is a regular room acct := FindJoinedAccount(e.Sender, room.Protocol, room.RoomID) if acct != nil { diff --git a/templates/home.html b/templates/home.html index da3e478..1975297 100644 --- a/templates/home.html +++ b/templates/home.html @@ -34,8 +34,8 @@
Add account
-IRC -XMPP -Mattermost +IRC +XMPP +Mattermost {{end}}