func (m *MemEngine) LatestCTime(u gregor.UID, d gregor.DeviceID) *time.Time { m.Lock() defer m.Unlock() log := m.getUser(u).log for i := len(log) - 1; i >= 0; i-- { if log[i].i != nil && log[i].i.item != nil && (d == nil || log[i].i.item.Metadata() != nil && (log[i].i.item.Metadata().DeviceID() == nil || bytes.Equal(d.Bytes(), log[i].i.item.Metadata().DeviceID().Bytes()))) { return &log[i].ctime } } return nil }
func isMessageForDevice(m gregor.InBandMessage, d gregor.DeviceID) bool { sum := m.ToStateUpdateMessage() if sum == nil { return true } if d == nil { return true } did := sum.Metadata().DeviceID() if did == nil { return true } if bytes.Equal(did.Bytes(), d.Bytes()) { return true } return false }
func (u *user) state(now time.Time, f gregor.ObjFactory, d gregor.DeviceID, t gregor.TimeOrOffset) (gregor.State, error) { var items []gregor.Item table := make(map[string]gregor.Item) for _, i := range u.items { md := i.item.Metadata() did := md.DeviceID() if d != nil && did != nil && !bytes.Equal(did.Bytes(), d.Bytes()) { continue } if t != nil && toTime(now, t).Before(i.ctime) { continue } if i.isDismissedAt(toTime(now, t)) { continue } exported, err := i.export(f) if err != nil { return nil, err } items = append(items, exported) table[exported.Metadata().MsgID().String()] = exported } return f.MakeStateWithLookupTable(items, table) }