add chat members to the backup
lazily fetch the chat members and add them to the chat during backup item downloads.
This commit is contained in:
parent
14817de592
commit
e298881a6c
@ -99,6 +99,13 @@ func (bh usersChatsBackupHandler) getItem(
|
|||||||
|
|
||||||
chat.SetMessages(msgs)
|
chat.SetMessages(msgs)
|
||||||
|
|
||||||
|
members, err := bh.ac.GetChatMembers(ctx, chatID, api.CallConfig{})
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, clues.Stack(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
chat.SetMembers(members)
|
||||||
|
|
||||||
return chat, api.TeamsChatInfo(chat), nil
|
return chat, api.TeamsChatInfo(chat), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -12,6 +12,79 @@ import (
|
|||||||
"github.com/alcionai/corso/src/pkg/services/m365/api/pagers"
|
"github.com/alcionai/corso/src/pkg/services/m365/api/pagers"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// chat members pager
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// delta queries are not supported
|
||||||
|
var _ pagers.NonDeltaHandler[models.ConversationMemberable] = &chatMembersPageCtrl{}
|
||||||
|
|
||||||
|
type chatMembersPageCtrl struct {
|
||||||
|
chatID string
|
||||||
|
gs graph.Servicer
|
||||||
|
builder *chats.ItemMembersRequestBuilder
|
||||||
|
options *chats.ItemMembersRequestBuilderGetRequestConfiguration
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *chatMembersPageCtrl) SetNextLink(nextLink string) {
|
||||||
|
p.builder = chats.NewItemMembersRequestBuilder(nextLink, p.gs.Adapter())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *chatMembersPageCtrl) GetPage(
|
||||||
|
ctx context.Context,
|
||||||
|
) (pagers.NextLinkValuer[models.ConversationMemberable], error) {
|
||||||
|
resp, err := p.builder.Get(ctx, p.options)
|
||||||
|
return resp, graph.Stack(ctx, err).OrNil()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *chatMembersPageCtrl) ValidModTimes() bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c Chats) NewChatMembersPager(
|
||||||
|
chatID string,
|
||||||
|
cc CallConfig,
|
||||||
|
) *chatMembersPageCtrl {
|
||||||
|
builder := c.Stable.
|
||||||
|
Client().
|
||||||
|
Chats().
|
||||||
|
ByChatId(chatID).
|
||||||
|
Members()
|
||||||
|
|
||||||
|
options := &chats.ItemMembersRequestBuilderGetRequestConfiguration{
|
||||||
|
QueryParameters: &chats.ItemMembersRequestBuilderGetQueryParameters{},
|
||||||
|
Headers: newPreferHeaders(preferPageSize(maxNonDeltaPageSize)),
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(cc.Select) > 0 {
|
||||||
|
options.QueryParameters.Select = cc.Select
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(cc.Expand) > 0 {
|
||||||
|
options.QueryParameters.Expand = cc.Expand
|
||||||
|
}
|
||||||
|
|
||||||
|
return &chatMembersPageCtrl{
|
||||||
|
chatID: chatID,
|
||||||
|
builder: builder,
|
||||||
|
gs: c.Stable,
|
||||||
|
options: options,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetChatMembers fetches a delta of all members in the chat.
|
||||||
|
func (c Chats) GetChatMembers(
|
||||||
|
ctx context.Context,
|
||||||
|
chatID string,
|
||||||
|
cc CallConfig,
|
||||||
|
) ([]models.ConversationMemberable, error) {
|
||||||
|
ctx = clues.Add(ctx, "chat_id", chatID)
|
||||||
|
pager := c.NewChatMembersPager(chatID, cc)
|
||||||
|
items, err := pagers.BatchEnumerateItems[models.ConversationMemberable](ctx, pager)
|
||||||
|
|
||||||
|
return items, graph.Stack(ctx, err).OrNil()
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// chat message pager
|
// chat message pager
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|||||||
@ -61,6 +61,11 @@ func (suite *ChatsPagerIntgSuite) TestEnumerateChats() {
|
|||||||
ac,
|
ac,
|
||||||
chatID,
|
chatID,
|
||||||
chat.GetLastMessagePreview())
|
chat.GetLastMessagePreview())
|
||||||
|
|
||||||
|
testEnumerateChatMembers(
|
||||||
|
suite.T(),
|
||||||
|
ac,
|
||||||
|
chatID)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -123,3 +128,22 @@ func testEnumerateChatMessages(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testEnumerateChatMembers(
|
||||||
|
t *testing.T,
|
||||||
|
ac Chats,
|
||||||
|
chatID string,
|
||||||
|
) {
|
||||||
|
ctx, flush := tester.NewContext(t)
|
||||||
|
defer flush()
|
||||||
|
|
||||||
|
cc := CallConfig{}
|
||||||
|
|
||||||
|
members, err := ac.GetChatMembers(ctx, chatID, cc)
|
||||||
|
require.NoError(t, err, clues.ToCore(err))
|
||||||
|
|
||||||
|
// no good way to test members right now. Even though
|
||||||
|
// the graph api response contains the `userID` and `email`
|
||||||
|
// properties, we can't access them in the sdk model
|
||||||
|
assert.NotEmpty(t, members)
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user