Store previous post ID in details

This commit is contained in:
Abhishek Pandey 2024-01-12 18:06:03 -08:00
parent 4dcb820201
commit e1f569d4e6
4 changed files with 30 additions and 5 deletions

View File

@ -124,13 +124,17 @@ func (bh conversationsBackupHandler) getItem(
containerIDs path.Elements, // expects: [conversationID, threadID]
postID string,
) (models.Postable, *details.GroupsInfo, error) {
cc := api.CallConfig{
Expand: []string{"inReplyTo"},
}
return bh.ac.GetConversationPost(
ctx,
groupID,
containerIDs[0],
containerIDs[1],
postID,
api.CallConfig{})
cc)
}
//lint:ignore U1000 false linter issue due to generics

View File

@ -65,6 +65,7 @@ type ConversationPostInfo struct {
Creator string `json:"creator,omitempty"`
Preview string `json:"preview,omitempty"`
Recipients []string `json:"recipients,omitempty"`
InReplyTo string `json:"inReplyTo,omitempty"`
Size int64 `json:"size,omitempty"`
Topic string `json:"topic,omitempty"`
}

View File

@ -69,8 +69,25 @@ func (c Conversations) GetConversationPost(
preview = "malformed or unparseable content body: " + preview
}
var inReplyToID string
prevPost := post.GetInReplyTo()
if prevPost != nil {
inReplyToID = ptr.Val(prevPost.GetId())
}
// Set prev post to nil to avoid storing it again in the backup. Storage is unnecessary
// since this is a read only property and graph doesn't support POSTing it. This is
// also safe to do since we do a full enumeration every time, so post and all its
// ancestors are guaranteed to exist.
//
// All we need to persist here is the prev post ID here so that we can build the
// reply tree during restore operation and restore posts top to bottom using
// POST /groups/{id}/conversations/{id}/threads/{id}/posts/{id}/reply
post.SetInReplyTo(nil)
if !ptr.Val(post.GetHasAttachments()) && !HasAttachments(post.GetBody()) {
return post, conversationPostInfo(post, contentLen, preview), nil
return post, conversationPostInfo(post, contentLen, preview, inReplyToID), nil
}
attachments, totalSize, err := c.getAttachments(
@ -95,7 +112,9 @@ func (c Conversations) GetConversationPost(
post.SetAttachments(attachments)
return post, conversationPostInfo(post, contentLen, preview), graph.Stack(ctx, err).OrNil()
return post,
conversationPostInfo(post, contentLen, preview, inReplyToID),
graph.Stack(ctx, err).OrNil()
}
// ---------------------------------------------------------------------------
@ -105,7 +124,7 @@ func (c Conversations) GetConversationPost(
func conversationPostInfo(
post models.Postable,
size int64,
preview string,
preview, prevPostID string,
) *details.GroupsInfo {
if post == nil {
return nil
@ -120,6 +139,7 @@ func conversationPostInfo(
CreatedAt: ptr.Val(post.GetCreatedDateTime()),
Creator: sender,
Preview: preview,
InReplyTo: prevPostID,
Size: size,
}

View File

@ -109,7 +109,7 @@ func (suite *ConversationsAPIUnitSuite) TestConversationPostInfo() {
t := suite.T()
post, expected := test.postAndInfo()
result := conversationPostInfo(post, 0, "")
result := conversationPostInfo(post, 0, "", "")
assert.Equal(t, expected, result)
})