// Copyright (C) 2020 Finogeeks Co., Ltd // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License, version 3, // as published by the Free Software Foundation. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Affero General Public License for more details. // // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . package processors import ( "context" "github.com/finogeeks/ligase/common" "github.com/finogeeks/ligase/common/config" "github.com/finogeeks/ligase/dbupdates/dbregistry" "github.com/finogeeks/ligase/dbupdates/dbupdatetypes" "github.com/finogeeks/ligase/model/dbtypes" "github.com/finogeeks/ligase/skunkworks/log" "github.com/finogeeks/ligase/storage/model" ) func init() { dbregistry.Register("roomserver_room_domains", NewDBRoomserverRoomDomainsProcessor, nil) } type DBRoomserverRoomDomainsProcessor struct { name string cfg *config.Dendrite db model.RoomServerDatabase } func NewDBRoomserverRoomDomainsProcessor( name string, cfg *config.Dendrite, ) dbupdatetypes.DBEventSeqProcessor { p := new(DBRoomserverRoomDomainsProcessor) p.name = name p.cfg = cfg return p } func (p *DBRoomserverRoomDomainsProcessor) Start() { db, err := common.GetDBInstance("roomserver", p.cfg) if err != nil { log.Panicf("failed to connect to room server db") } p.db = db.(model.RoomServerDatabase) } func (p *DBRoomserverRoomDomainsProcessor) Process(ctx context.Context, inputs []dbupdatetypes.DBEventDataInput) error { if len(inputs) == 0 { return nil } switch inputs[0].Event.Key { case dbtypes.RoomDomainInsertKey: p.processInsert(ctx, inputs) default: log.Errorf("invalid %s event key %d", p.name, inputs[0].Event.Key) } return nil } func (p *DBRoomserverRoomDomainsProcessor) processInsert(ctx context.Context, inputs []dbupdatetypes.DBEventDataInput) error { for _, v := range inputs { msg := v.Event.RoomDBEvents.RoomDomainInsert err := p.db.RoomDomainsInsertRaw(ctx, msg.RoomNid, msg.Domain, msg.Offset) if err != nil { log.Error(p.name, "insert err", err, msg.RoomNid, msg.Domain, msg.Offset) } } return nil }