Skip to content

Commit

Permalink
add new item types to support stars
Browse files Browse the repository at this point in the history
  • Loading branch information
rcarver committed Jul 17, 2015
1 parent e01e312 commit fdd62a3
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
18 changes: 18 additions & 0 deletions item.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ const (
TYPE_MESSAGE = "message"
TYPE_FILE = "file"
TYPE_FILE_COMMENT = "file_comment"
TYPE_CHANNEL = "channel"
TYPE_IM = "im"
TYPE_GROUP = "group"
)

// Item is any type of slack message - message, file, or file comment.
Expand All @@ -30,6 +33,21 @@ func NewFileCommentItem(f *File, c *Comment) Item {
return Item{Type: TYPE_FILE_COMMENT, File: f, Comment: c}
}

// NewChannelItem turns a channel id into a typed channel struct.
func NewChannelItem(ch string) Item {
return Item{Type: TYPE_CHANNEL, Channel: ch}
}

// NewIMItem turns a channel id into a typed im struct.
func NewIMItem(ch string) Item {
return Item{Type: TYPE_IM, Channel: ch}
}

// NewGroupItem turns a channel id into a typed group struct.
func NewGroupItem(ch string) Item {
return Item{Type: TYPE_GROUP, Channel: ch}
}

// ItemRef is a reference to a message of any type. One of FileID,
// CommentId, or the combination of ChannelId and Timestamp must be
// specified.
Expand Down
33 changes: 33 additions & 0 deletions item_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,39 @@ func TestNewFileCommentItem(t *testing.T) {
}
}

func TestNewChannelItem(t *testing.T) {
c := "C1"
ci := NewChannelItem(c)
if ci.Type != TYPE_CHANNEL {
t.Errorf("got Type %s, want %s", ci.Type, TYPE_CHANNEL)
}
if ci.Channel != "C1" {
t.Errorf("got Channel %v, want %v", ci.Channel, "C1")
}
}

func TestNewIMItem(t *testing.T) {
c := "D1"
ci := NewIMItem(c)
if ci.Type != TYPE_IM {
t.Errorf("got Type %s, want %s", ci.Type, TYPE_IM)
}
if ci.Channel != "D1" {
t.Errorf("got Channel %v, want %v", ci.Channel, "D1")
}
}

func TestNewGroupItem(t *testing.T) {
c := "G1"
ci := NewGroupItem(c)
if ci.Type != TYPE_GROUP {
t.Errorf("got Type %s, want %s", ci.Type, TYPE_GROUP)
}
if ci.Channel != "G1" {
t.Errorf("got Channel %v, want %v", ci.Channel, "G1")
}
}

func TestNewRefToMessage(t *testing.T) {
ref := NewRefToMessage("chan", "ts")
if got, want := ref.ChannelId, "chan"; got != want {
Expand Down

0 comments on commit fdd62a3

Please sign in to comment.