func (o ObjFactory) makeItem(c gregor.Category, d *time.Time, b gregor.Body) *Item { return &Item{ Dtime_: timeToTimeOrOffset(d), Category_: Category(c.String()), Body_: Body(b.Bytes()), } }
func (s State) ItemsWithCategoryPrefix(gc gregor.Category) ([]gregor.Item, error) { var ret []gregor.Item c := Category(gc.String()) for _, i := range s.Items_ { if i.HasCategoryPrefix(c) { ret = append(ret, i) } } return ret, nil }
func (s *SQLEngine) items(u gregor.UID, d gregor.DeviceID, t gregor.TimeOrOffset, m gregor.MsgID, cp gregor.Category) ([]gregor.Item, error) { qry := `SELECT i.msgid, m.devid, i.category, i.dtime, i.body, m.ctime FROM gregor_items AS i INNER JOIN gregor_messages AS m ON (i.uid=m.uid AND i.msgid=m.msgid) WHERE i.uid=? AND (i.dtime IS NULL OR i.dtime > ` qb := s.newQueryBuilder() qb.Build(qry, hexEnc(u)) if t != nil { qb.TimeOrOffset(t) } else { qb.Now() } qb.Build(")") if d != nil { // A "NULL" devid in this case means that the Item/message is intended for all // devices. So include that as well. qb.Build("AND (m.devid=? OR m.devid IS NULL)", hexEnc(d)) } if t != nil { qb.Build("AND m.ctime <=") qb.TimeOrOffset(t) } if m != nil { qb.Build("AND i.msgid=?", hexEnc(m)) } if cp != nil { qb.Build(" AND i.category LIKE ?", cp.String()+"%") } qb.Build("ORDER BY m.ctime ASC") stmt, err := s.driver.Prepare(qb.Query()) if err != nil { return nil, err } defer stmt.Close() rows, err := stmt.Query(qb.Args()...) if err != nil { return nil, err } var items []gregor.Item for rows.Next() { item, err := s.rowToItem(u, rows) if err != nil { return nil, err } items = append(items, item) } return items, nil }
func (o ObjFactory) MakeDismissalByRange(uid gregor.UID, msgid gregor.MsgID, devid gregor.DeviceID, ctime time.Time, c gregor.Category, d time.Time) (gregor.InBandMessage, error) { md, err := o.makeMetadata(uid, msgid, devid, ctime, gregor.InBandMsgTypeUpdate) if err != nil { return nil, err } return InBandMessage{ StateUpdate_: &StateUpdateMessage{ Md_: md, Dismissal_: &Dismissal{ Ranges_: []MsgRange{{ EndTime_: timeToTimeOrOffset(&d), Category_: Category(c.String()), }}, }, }, }, nil }