Remove impossible check and improve things for testing
This commit is contained in:
parent
ad540e268d
commit
fafc7f55be
@ -50,6 +50,10 @@ func (config *Config) NewSession(mxid string) *Session {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Session) GetUserID() string {
|
||||
return s.UserID
|
||||
}
|
||||
|
||||
func (s *Session) Clear() {
|
||||
s.Rooms = make(map[string]*rooms.Room)
|
||||
s.PushRules = nil
|
||||
|
@ -45,12 +45,6 @@ type Member struct {
|
||||
|
||||
// eventToRoomMember converts a m.room.member state event into a Member object.
|
||||
func eventToRoomMember(userID string, event *gomatrix.Event) *Member {
|
||||
if event == nil {
|
||||
return &Member{
|
||||
UserID: userID,
|
||||
Membership: MembershipLeave,
|
||||
}
|
||||
}
|
||||
membership, _ := event.Content["membership"].(string)
|
||||
avatarURL, _ := event.Content["avatar_url"].(string)
|
||||
|
||||
|
@ -25,21 +25,25 @@ import (
|
||||
"time"
|
||||
|
||||
"maunium.net/go/gomatrix"
|
||||
"maunium.net/go/gomuks/config"
|
||||
"maunium.net/go/gomuks/matrix/rooms"
|
||||
)
|
||||
|
||||
type SyncerSession interface {
|
||||
GetRoom(id string) *rooms.Room
|
||||
GetUserID() string
|
||||
}
|
||||
|
||||
// GomuksSyncer is the default syncing implementation. You can either write your own syncer, or selectively
|
||||
// replace parts of this default syncer (e.g. the ProcessResponse method). The default syncer uses the observer
|
||||
// pattern to notify callers about incoming events. See GomuksSyncer.OnEventType for more information.
|
||||
type GomuksSyncer struct {
|
||||
Session *config.Session
|
||||
Session SyncerSession
|
||||
listeners map[string][]gomatrix.OnEventListener // event type to listeners array
|
||||
FirstSyncDone bool
|
||||
}
|
||||
|
||||
// NewGomuksSyncer returns an instantiated GomuksSyncer
|
||||
func NewGomuksSyncer(session *config.Session) *GomuksSyncer {
|
||||
func NewGomuksSyncer(session SyncerSession) *GomuksSyncer {
|
||||
return &GomuksSyncer{
|
||||
Session: session,
|
||||
listeners: make(map[string][]gomatrix.OnEventListener),
|
||||
@ -56,7 +60,7 @@ func (s *GomuksSyncer) ProcessResponse(res *gomatrix.RespSync, since string) (er
|
||||
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
err = fmt.Errorf("ProcessResponse for %s since %s panicked: %s\n%s", s.Session.UserID, since, r, debug.Stack())
|
||||
err = fmt.Errorf("ProcessResponse for %s since %s panicked: %s\n%s", s.Session.GetUserID(), since, r, debug.Stack())
|
||||
}
|
||||
}()
|
||||
|
||||
|
@ -15,3 +15,20 @@
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package matrix_test
|
||||
|
||||
import (
|
||||
"maunium.net/go/gomuks/matrix/rooms"
|
||||
)
|
||||
|
||||
type mockSyncerSession struct {
|
||||
rooms map[string]*rooms.Room
|
||||
userID string
|
||||
}
|
||||
|
||||
func (mss *mockSyncerSession) GetRoom(id string) *rooms.Room {
|
||||
return mss.rooms[id]
|
||||
}
|
||||
|
||||
func (mss *mockSyncerSession) GetUserID() string {
|
||||
return mss.userID
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user