item pager for channels
This commit is contained in:
parent
7de04b98ab
commit
27990e6174
@ -3,7 +3,10 @@ package api
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
"github.com/alcionai/clues"
|
||||||
|
"github.com/alcionai/corso/src/internal/common/ptr"
|
||||||
"github.com/alcionai/corso/src/internal/m365/graph"
|
"github.com/alcionai/corso/src/internal/m365/graph"
|
||||||
|
"github.com/microsoftgraph/msgraph-sdk-go/models"
|
||||||
"github.com/microsoftgraph/msgraph-sdk-go/teams"
|
"github.com/microsoftgraph/msgraph-sdk-go/teams"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -68,3 +71,74 @@ func (p *messagePageCtrl) GetPage(ctx context.Context) (PageLinker, error) {
|
|||||||
|
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type MessageItemIDType struct {
|
||||||
|
ItemID string
|
||||||
|
}
|
||||||
|
|
||||||
|
type channelItemPageCtrl struct {
|
||||||
|
gs graph.Servicer
|
||||||
|
builder *teams.ItemChannelsItemMessagesRequestBuilder
|
||||||
|
options *teams.ItemChannelsItemMessagesRequestBuilderGetRequestConfiguration
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c Channels) GetItemIDsInContainer(
|
||||||
|
ctx context.Context,
|
||||||
|
teamID, channelID string,
|
||||||
|
) (map[string]MessageItemIDType, error) {
|
||||||
|
ctx = clues.Add(ctx, "channel_id", channelID)
|
||||||
|
pager := c.NewChannelItemPager(teamID, channelID)
|
||||||
|
|
||||||
|
items, err := enumerateItems(ctx, pager)
|
||||||
|
if err != nil {
|
||||||
|
return nil, graph.Wrap(ctx, err, "enumerating contacts")
|
||||||
|
}
|
||||||
|
|
||||||
|
m := map[string]MessageItemIDType{}
|
||||||
|
|
||||||
|
for _, item := range items {
|
||||||
|
m[ptr.Val(item.GetId())] = MessageItemIDType{
|
||||||
|
ItemID: ptr.Val(item.GetId()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return m, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c Channels) NewChannelItemPager(
|
||||||
|
teamID, containerID string,
|
||||||
|
selectProps ...string,
|
||||||
|
) itemPager[models.ChatMessageable] {
|
||||||
|
options := &teams.ItemChannelsItemMessagesRequestBuilderGetRequestConfiguration{
|
||||||
|
QueryParameters: &teams.ItemChannelsItemMessagesRequestBuilderGetQueryParameters{},
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(selectProps) > 0 {
|
||||||
|
options.QueryParameters.Select = selectProps
|
||||||
|
}
|
||||||
|
|
||||||
|
builder := c.Stable.
|
||||||
|
Client().
|
||||||
|
Teams().
|
||||||
|
ByTeamId(teamID).
|
||||||
|
Channels().
|
||||||
|
ByChannelId(containerID).
|
||||||
|
Messages()
|
||||||
|
|
||||||
|
return &channelItemPageCtrl{c.Stable, builder, options}
|
||||||
|
}
|
||||||
|
|
||||||
|
//lint:ignore U1000 False Positive
|
||||||
|
func (p *channelItemPageCtrl) getPage(ctx context.Context) (PageLinkValuer[models.ChatMessageable], error) {
|
||||||
|
page, err := p.builder.Get(ctx, p.options)
|
||||||
|
if err != nil {
|
||||||
|
return nil, graph.Stack(ctx, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return EmptyDeltaLinker[models.ChatMessageable]{PageLinkValuer: page}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
//lint:ignore U1000 False Positive
|
||||||
|
func (p *channelItemPageCtrl) setNext(nextLink string) {
|
||||||
|
p.builder = teams.NewItemChannelsItemMessagesRequestBuilder(nextLink, p.gs.Adapter())
|
||||||
|
}
|
||||||
|
|||||||
@ -139,24 +139,29 @@ func deleteChannel(ctx context.Context, credentials account.M365Config, teamID,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// func (suite *ChannelPagerIntgSuite) TestMessages_CreateGetAndDelete() {
|
// func (suite *ChannelPagerIntgSuite) TestMessages_CreateGetAndDelete() {
|
||||||
// t := suite.T()
|
// t := suite.T()
|
||||||
// ctx, flush := tester.NewContext(t)
|
// ctx, flush := tester.NewContext(t)
|
||||||
// defer flush()
|
// defer flush()
|
||||||
|
|
||||||
// var (
|
// var (
|
||||||
// teamID = tconfig.M365TeamsID(t)
|
// teamID = tconfig.M365TeamsID(t)
|
||||||
// channelID = tconfig.M365ChannelID(t)
|
// channelID = tconfig.M365ChannelID(t)
|
||||||
// credentials = suite.its.ac.Credentials
|
// credentials = suite.its.ac.Credentials
|
||||||
// chanClient = suite.its.ac.Channels()
|
// chanClient = suite.its.ac.Channels()
|
||||||
// )
|
// )
|
||||||
|
|
||||||
// POST channel
|
// // GET channel - should be not found
|
||||||
// patchBody := models.NewChatMessage()
|
// message, _, err := chanClient.GetMessage(ctx, teamID, channelID, "", "")
|
||||||
// body := models.NewItemBody()
|
// assert.Error(t, err, clues.ToCore(err))
|
||||||
// content := "Hello World"
|
|
||||||
// body.SetContent(&content)
|
// // POST channel
|
||||||
// patchBody.SetBody(body)
|
// // patchBody := models.NewChatMessage()
|
||||||
|
// // body := models.NewItemBody()
|
||||||
|
// // content := "Hello World"
|
||||||
|
// // body.SetContent(&content)
|
||||||
|
// // patchBody.SetBody(body)
|
||||||
|
|
||||||
|
// // _, := suite.its.ac.Channels().PostMessage(ctx, teamID, channelID, patchBody)
|
||||||
|
// // assert.NoError(t, err, clues.ToCore(err))
|
||||||
|
|
||||||
// _, := suite.its.ac.Channels().PostMessage(ctx, teamID, channelID, patchBody)
|
|
||||||
// assert.NoError(t, err, clues.ToCore(err))
|
|
||||||
// }
|
// }
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user