Store previous post ID in details
This commit is contained in:
parent
4dcb820201
commit
e1f569d4e6
@ -124,13 +124,17 @@ func (bh conversationsBackupHandler) getItem(
|
|||||||
containerIDs path.Elements, // expects: [conversationID, threadID]
|
containerIDs path.Elements, // expects: [conversationID, threadID]
|
||||||
postID string,
|
postID string,
|
||||||
) (models.Postable, *details.GroupsInfo, error) {
|
) (models.Postable, *details.GroupsInfo, error) {
|
||||||
|
cc := api.CallConfig{
|
||||||
|
Expand: []string{"inReplyTo"},
|
||||||
|
}
|
||||||
|
|
||||||
return bh.ac.GetConversationPost(
|
return bh.ac.GetConversationPost(
|
||||||
ctx,
|
ctx,
|
||||||
groupID,
|
groupID,
|
||||||
containerIDs[0],
|
containerIDs[0],
|
||||||
containerIDs[1],
|
containerIDs[1],
|
||||||
postID,
|
postID,
|
||||||
api.CallConfig{})
|
cc)
|
||||||
}
|
}
|
||||||
|
|
||||||
//lint:ignore U1000 false linter issue due to generics
|
//lint:ignore U1000 false linter issue due to generics
|
||||||
|
|||||||
@ -65,6 +65,7 @@ type ConversationPostInfo struct {
|
|||||||
Creator string `json:"creator,omitempty"`
|
Creator string `json:"creator,omitempty"`
|
||||||
Preview string `json:"preview,omitempty"`
|
Preview string `json:"preview,omitempty"`
|
||||||
Recipients []string `json:"recipients,omitempty"`
|
Recipients []string `json:"recipients,omitempty"`
|
||||||
|
InReplyTo string `json:"inReplyTo,omitempty"`
|
||||||
Size int64 `json:"size,omitempty"`
|
Size int64 `json:"size,omitempty"`
|
||||||
Topic string `json:"topic,omitempty"`
|
Topic string `json:"topic,omitempty"`
|
||||||
}
|
}
|
||||||
|
|||||||
@ -69,8 +69,25 @@ func (c Conversations) GetConversationPost(
|
|||||||
preview = "malformed or unparseable content body: " + preview
|
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()) {
|
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(
|
attachments, totalSize, err := c.getAttachments(
|
||||||
@ -95,7 +112,9 @@ func (c Conversations) GetConversationPost(
|
|||||||
|
|
||||||
post.SetAttachments(attachments)
|
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(
|
func conversationPostInfo(
|
||||||
post models.Postable,
|
post models.Postable,
|
||||||
size int64,
|
size int64,
|
||||||
preview string,
|
preview, prevPostID string,
|
||||||
) *details.GroupsInfo {
|
) *details.GroupsInfo {
|
||||||
if post == nil {
|
if post == nil {
|
||||||
return nil
|
return nil
|
||||||
@ -120,6 +139,7 @@ func conversationPostInfo(
|
|||||||
CreatedAt: ptr.Val(post.GetCreatedDateTime()),
|
CreatedAt: ptr.Val(post.GetCreatedDateTime()),
|
||||||
Creator: sender,
|
Creator: sender,
|
||||||
Preview: preview,
|
Preview: preview,
|
||||||
|
InReplyTo: prevPostID,
|
||||||
Size: size,
|
Size: size,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -109,7 +109,7 @@ func (suite *ConversationsAPIUnitSuite) TestConversationPostInfo() {
|
|||||||
t := suite.T()
|
t := suite.T()
|
||||||
|
|
||||||
post, expected := test.postAndInfo()
|
post, expected := test.postAndInfo()
|
||||||
result := conversationPostInfo(post, 0, "")
|
result := conversationPostInfo(post, 0, "", "")
|
||||||
|
|
||||||
assert.Equal(t, expected, result)
|
assert.Equal(t, expected, result)
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user