123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- package ticket
- import (
- "github.com/ClickHouse/clickhouse-go/v2/lib/driver"
- "github.com/kelindar/bitmap"
- "google.golang.org/protobuf/types/known/timestamppb"
- "time"
- )
- func (x *Ticket) Scan(row driver.Rows) error {
- var (
- from map[string]string
- createdAt time.Time
- updatedAt time.Time
- err error
- )
- if err = row.Scan(
- &x.TicketId,
- &x.ThreadId,
- &x.To,
- &from,
- &x.Flags,
- &x.Meta,
- &x.Tags,
- &createdAt,
- &updatedAt,
- &x.MessageIds,
- &x.Subjects,
- ); err != nil {
- return err
- }
- x.From = &EmailAddress{
- Address: from["address"],
- Name: from["name"],
- }
- x.CreatedAt = timestamppb.New(createdAt)
- x.UpdatedAt = timestamppb.New(updatedAt)
- return nil
- }
- func (x *Ticket) SetFlags(flags ...TicketFlag) {
- mask := bitmap.FromBytes(x.Flags)
- for i := range flags {
- if TicketFlag_unknown_ticket_flag == flags[i] {
- continue
- }
- mask.Set(uint32(flags[i]))
- }
- x.Flags = mask.ToBytes()
- }
- func (x *Ticket) RemoveFlags(flags ...TicketFlag) {
- mask := bitmap.FromBytes(x.Flags)
- for i := range flags {
- if TicketFlag_unknown_ticket_flag == flags[i] {
- continue
- }
- mask.Remove(uint32(flags[i]))
- }
- x.Flags = mask.ToBytes()
- }
- func (x *Ticket) HasFlag(flag TicketFlag) bool {
- return bitmap.
- FromBytes(x.Flags).
- Contains(uint32(flag))
- }
|