Minor changes
This commit is contained in:
parent
cc63a197c6
commit
01f456781c
@ -48,11 +48,12 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (es EventSource) String() string {
|
func (es EventSource) String() string {
|
||||||
if es == EventSourcePresence {
|
switch {
|
||||||
|
case es == EventSourcePresence:
|
||||||
return "presence"
|
return "presence"
|
||||||
} else if es == EventSourceAccountData {
|
case es == EventSourceAccountData:
|
||||||
return "account data"
|
return "user account data"
|
||||||
} else if es & EventSourceJoin != 0 {
|
case es&EventSourceJoin != 0:
|
||||||
es -= EventSourceJoin
|
es -= EventSourceJoin
|
||||||
switch es {
|
switch es {
|
||||||
case EventSourceState:
|
case EventSourceState:
|
||||||
@ -64,13 +65,13 @@ func (es EventSource) String() string {
|
|||||||
case EventSourceAccountData:
|
case EventSourceAccountData:
|
||||||
return "room account data (joined)"
|
return "room account data (joined)"
|
||||||
}
|
}
|
||||||
} else if es & EventSourceInvite != 0 {
|
case es&EventSourceInvite != 0:
|
||||||
es -= EventSourceInvite
|
es -= EventSourceInvite
|
||||||
switch es {
|
switch es {
|
||||||
case EventSourceState:
|
case EventSourceState:
|
||||||
return "invited state"
|
return "invited state"
|
||||||
}
|
}
|
||||||
} else if es & EventSourceLeave != 0 {
|
case es&EventSourceLeave != 0:
|
||||||
es -= EventSourceLeave
|
es -= EventSourceLeave
|
||||||
switch es {
|
switch es {
|
||||||
case EventSourceState:
|
case EventSourceState:
|
||||||
@ -106,15 +107,15 @@ func NewGomuksSyncer(session SyncerSession) *GomuksSyncer {
|
|||||||
// ProcessResponse processes a Matrix sync response.
|
// ProcessResponse processes a Matrix sync response.
|
||||||
func (s *GomuksSyncer) ProcessResponse(res *mautrix.RespSync, since string) (err error) {
|
func (s *GomuksSyncer) ProcessResponse(res *mautrix.RespSync, since string) (err error) {
|
||||||
debug.Print("Received sync response")
|
debug.Print("Received sync response")
|
||||||
s.processSyncEvents(nil, res.Presence.Events, EventSourcePresence, false)
|
s.processSyncEvents(nil, res.Presence.Events, EventSourcePresence)
|
||||||
s.processSyncEvents(nil, res.AccountData.Events, EventSourceAccountData, false)
|
s.processSyncEvents(nil, res.AccountData.Events, EventSourceAccountData)
|
||||||
|
|
||||||
for roomID, roomData := range res.Rooms.Join {
|
for roomID, roomData := range res.Rooms.Join {
|
||||||
room := s.Session.GetRoom(roomID)
|
room := s.Session.GetRoom(roomID)
|
||||||
s.processSyncEvents(room, roomData.State.Events, EventSourceJoin|EventSourceState, false)
|
s.processSyncEvents(room, roomData.State.Events, EventSourceJoin|EventSourceState)
|
||||||
s.processSyncEvents(room, roomData.Timeline.Events, EventSourceJoin|EventSourceTimeline, false)
|
s.processSyncEvents(room, roomData.Timeline.Events, EventSourceJoin|EventSourceTimeline)
|
||||||
s.processSyncEvents(room, roomData.Ephemeral.Events, EventSourceJoin|EventSourceEphemeral, false)
|
s.processSyncEvents(room, roomData.Ephemeral.Events, EventSourceJoin|EventSourceEphemeral)
|
||||||
s.processSyncEvents(room, roomData.AccountData.Events, EventSourceJoin|EventSourceAccountData, false)
|
s.processSyncEvents(room, roomData.AccountData.Events, EventSourceJoin|EventSourceAccountData)
|
||||||
|
|
||||||
if len(room.PrevBatch) == 0 {
|
if len(room.PrevBatch) == 0 {
|
||||||
room.PrevBatch = roomData.Timeline.PrevBatch
|
room.PrevBatch = roomData.Timeline.PrevBatch
|
||||||
@ -123,14 +124,14 @@ func (s *GomuksSyncer) ProcessResponse(res *mautrix.RespSync, since string) (err
|
|||||||
|
|
||||||
for roomID, roomData := range res.Rooms.Invite {
|
for roomID, roomData := range res.Rooms.Invite {
|
||||||
room := s.Session.GetRoom(roomID)
|
room := s.Session.GetRoom(roomID)
|
||||||
s.processSyncEvents(room, roomData.State.Events, EventSourceInvite|EventSourceState, false)
|
s.processSyncEvents(room, roomData.State.Events, EventSourceInvite|EventSourceState)
|
||||||
}
|
}
|
||||||
|
|
||||||
for roomID, roomData := range res.Rooms.Leave {
|
for roomID, roomData := range res.Rooms.Leave {
|
||||||
room := s.Session.GetRoom(roomID)
|
room := s.Session.GetRoom(roomID)
|
||||||
room.HasLeft = true
|
room.HasLeft = true
|
||||||
s.processSyncEvents(room, roomData.State.Events, EventSourceLeave|EventSourceState, true)
|
s.processSyncEvents(room, roomData.State.Events, EventSourceLeave|EventSourceState)
|
||||||
s.processSyncEvents(room, roomData.Timeline.Events, EventSourceLeave|EventSourceTimeline, false)
|
s.processSyncEvents(room, roomData.Timeline.Events, EventSourceLeave|EventSourceTimeline)
|
||||||
|
|
||||||
if len(room.PrevBatch) == 0 {
|
if len(room.PrevBatch) == 0 {
|
||||||
room.PrevBatch = roomData.Timeline.PrevBatch
|
room.PrevBatch = roomData.Timeline.PrevBatch
|
||||||
@ -145,11 +146,9 @@ func (s *GomuksSyncer) ProcessResponse(res *mautrix.RespSync, since string) (err
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *GomuksSyncer) processSyncEvents(room *rooms.Room, events []*mautrix.Event, source EventSource, checkStateKey bool) {
|
func (s *GomuksSyncer) processSyncEvents(room *rooms.Room, events []*mautrix.Event, source EventSource) {
|
||||||
for _, event := range events {
|
for _, event := range events {
|
||||||
if !checkStateKey || event.StateKey != nil {
|
s.processSyncEvent(room, event, source)
|
||||||
s.processSyncEvent(room, event, source)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user