channel pager implementation
This commit is contained in:
parent
84440ade4d
commit
397526c4c8
@ -31,10 +31,3 @@ type BackupHandler interface {
|
|||||||
teamID, channelID, messageID string,
|
teamID, channelID, messageID string,
|
||||||
) (serialization.Parsable, error)
|
) (serialization.Parsable, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type BackupMessagesHandler interface {
|
|
||||||
GetMessage(ctx context.Context, teamID, channelID, itemID string) (models.ChatMessageable, error)
|
|
||||||
NewMessagePager(teamID, channelID string) api.ChannelMessageDeltaEnumerator
|
|
||||||
GetChannel(ctx context.Context, teamID, channelID string) (models.Channelable, error)
|
|
||||||
GetReply(ctx context.Context, teamID, channelID, messageID string) (serialization.Parsable, error)
|
|
||||||
}
|
|
||||||
|
|||||||
@ -1,7 +1,13 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/alcionai/clues"
|
||||||
|
"github.com/alcionai/corso/src/internal/common/ptr"
|
||||||
|
"github.com/alcionai/corso/src/internal/m365/graph"
|
||||||
"github.com/microsoftgraph/msgraph-sdk-go/models"
|
"github.com/microsoftgraph/msgraph-sdk-go/models"
|
||||||
|
"github.com/microsoftgraph/msgraph-sdk-go/teams"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
@ -14,30 +20,206 @@ type ChannelMessageDeltaEnumerator interface {
|
|||||||
SetNextLinker
|
SetNextLinker
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: implement
|
var _ ChannelMessageDeltaEnumerator = &MessagePageCtrl{}
|
||||||
// var _ ChannelMessageDeltaEnumerator = &messagePageCtrl{}
|
|
||||||
|
|
||||||
// type messagePageCtrl struct {
|
type MessagePageCtrl struct {
|
||||||
// gs graph.Servicer
|
gs graph.Servicer
|
||||||
// builder *teams.ItemChannelsItemMessagesRequestBuilder
|
builder *teams.ItemChannelsItemMessagesDeltaRequestBuilder
|
||||||
// options *teams.ItemChannelsItemMessagesRequestBuilderGetRequestConfiguration
|
options *teams.ItemChannelsItemMessagesDeltaRequestBuilderGetRequestConfiguration
|
||||||
// }
|
}
|
||||||
|
|
||||||
|
func (c Channels) NewMessagePager(
|
||||||
|
teamID,
|
||||||
|
channelID string,
|
||||||
|
fields []string,
|
||||||
|
) *MessagePageCtrl {
|
||||||
|
requestConfig := &teams.ItemChannelsItemMessagesDeltaRequestBuilderGetRequestConfiguration{
|
||||||
|
QueryParameters: &teams.ItemChannelsItemMessagesDeltaRequestBuilderGetQueryParameters{
|
||||||
|
Select: fields,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
res := &MessagePageCtrl{
|
||||||
|
gs: c.Stable,
|
||||||
|
options: requestConfig,
|
||||||
|
builder: c.Stable.
|
||||||
|
Client().
|
||||||
|
Teams().
|
||||||
|
ByTeamId(teamID).
|
||||||
|
Channels().
|
||||||
|
ByChannelId(channelID).
|
||||||
|
Messages().
|
||||||
|
Delta(),
|
||||||
|
}
|
||||||
|
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *MessagePageCtrl) SetNext(nextLink string) {
|
||||||
|
p.builder = teams.NewItemChannelsItemMessagesDeltaRequestBuilder(nextLink, p.gs.Adapter())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *MessagePageCtrl) GetPage(ctx context.Context) (DeltaPageLinker, error) {
|
||||||
|
var (
|
||||||
|
resp DeltaPageLinker
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
|
||||||
|
resp, err = p.builder.Get(ctx, p.options)
|
||||||
|
if err != nil {
|
||||||
|
return nil, graph.Stack(ctx, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *MessagePageCtrl) ValuesIn(l PageLinker) ([]models.ChatMessageable, error) {
|
||||||
|
return getValues[models.ChatMessageable](l)
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// channel pager
|
// channel pager
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
type ChannelDeltaEnumerator interface {
|
type ChannelDeltaEnumerator interface {
|
||||||
DeltaGetPager
|
PageLinker
|
||||||
ValuesInPageLinker[models.Channelable]
|
ValuesInPageLinker[models.Channelable]
|
||||||
SetNextLinker
|
SetNextLinker
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: implement
|
// TODO: implement
|
||||||
// var _ ChannelDeltaEnumerator = &channelsPageCtrl{}
|
var _ ChannelDeltaEnumerator = &channelPageCtrl{}
|
||||||
|
|
||||||
// type channelsPageCtrl struct {
|
type channelPageCtrl struct {
|
||||||
// gs graph.Servicer
|
gs graph.Servicer
|
||||||
// builder *teams.ItemChannelsChannelItemRequestBuilder
|
builder *teams.ItemChannelsRequestBuilder
|
||||||
// options *teams.ItemChannelsChannelItemRequestBuilderGetRequestConfiguration
|
options *teams.ItemChannelsRequestBuilderGetRequestConfiguration
|
||||||
// }
|
}
|
||||||
|
|
||||||
|
func (c Channels) NewChannelPager(
|
||||||
|
teamID,
|
||||||
|
channelID string,
|
||||||
|
fields []string,
|
||||||
|
) *channelPageCtrl {
|
||||||
|
requestConfig := &teams.ItemChannelsRequestBuilderGetRequestConfiguration{
|
||||||
|
QueryParameters: &teams.ItemChannelsRequestBuilderGetQueryParameters{
|
||||||
|
Select: fields,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
res := &channelPageCtrl{
|
||||||
|
gs: c.Stable,
|
||||||
|
options: requestConfig,
|
||||||
|
builder: c.Stable.
|
||||||
|
Client().
|
||||||
|
Teams().
|
||||||
|
ByTeamId(teamID).
|
||||||
|
Channels(),
|
||||||
|
}
|
||||||
|
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *channelPageCtrl) SetNext(nextLink string) {
|
||||||
|
p.builder = teams.NewItemChannelsRequestBuilder(nextLink, p.gs.Adapter())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *channelPageCtrl) GetPage(ctx context.Context) (PageLinker, error) {
|
||||||
|
var (
|
||||||
|
resp PageLinker
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
|
||||||
|
resp, err = p.builder.Get(ctx, p.options)
|
||||||
|
if err != nil {
|
||||||
|
return nil, graph.Stack(ctx, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *channelPageCtrl) ValuesIn(l PageLinker) ([]models.Channelable, error) {
|
||||||
|
return getValues[models.Channelable](l)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *channelPageCtrl) GetOdataNextLink() *string {
|
||||||
|
// TODO: no delta present here. Is it possible to have interface which does not have
|
||||||
|
// GetOdataNextLink method
|
||||||
|
emptyString := ""
|
||||||
|
return &emptyString
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// non delta item pager
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
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())
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user