Skip to content

Commit

Permalink
chore: remove single conversation
Browse files Browse the repository at this point in the history
  • Loading branch information
soulteary committed Jun 7, 2023
1 parent 6449d5c commit cb221b0
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
15 changes: 15 additions & 0 deletions components/local-conversation-storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,21 @@ func ClearConversationListByUserID(userID string) {
updateRefsByUserID(uid, make(LinkReferences))
}

// Clear the message id of the user
func ClearConversationIdByUserID(userID string, conversationID string) {
uid := UserID(userID)
refs := getRefsByUserID(uid)
filteredRefs := make(LinkReferences)
for _, refID := range refs {
if refID == conversationID {
updateConversationDataByMessageID(refID, Message{})
} else {
filteredRefs[refID] = refs[refID]
}
}
updateRefsByUserID(uid, filteredRefs)
}

// Get the conversation info by conversation id
func GetConversationInfoByID(userID string, conversationID string) (conversationInfo Message) {
refs := getRefsByUserID(UserID(userID))
Expand Down
22 changes: 22 additions & 0 deletions internal/api/conversation/conversation.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,28 @@ func GetConversationById(c *gin.Context) {
}

func UpdateConversation(c *gin.Context) {
type RequestBody struct {
IsVisible bool `json:"is_visible"`
}
var requestBody RequestBody
if err := c.ShouldBindJSON(&requestBody); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}

if !requestBody.IsVisible {
// TODO bind user
userID := c.Request.Header.Get("x-user-id")
if userID != "" {
fmt.Println("[user]", userID)
} else {
userID = define.DEFAULT_USER_NAME
}

id := c.Param("id")
mock.ClearConversationByID(userID, id)
}

c.JSON(http.StatusOK, datatypes.UpdateConversationResponse{Success: true})
}

Expand Down
6 changes: 6 additions & 0 deletions internal/mock/conversations.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,9 @@ func ClearConversationList(userID string) datatypes.ConversationsList {
}
return GetConversationList(userID)
}

func ClearConversationByID(userID string, conversationID string) {
if define.ENABLE_HISTORY_LIST {
lcs.ClearConversationIdByUserID(userID, conversationID)
}
}

0 comments on commit cb221b0

Please sign in to comment.