-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add get discord message logs api #755
base: develop
Are you sure you want to change the base?
Changes from 5 commits
c4fc704
1576bc1
b6fdccd
ee45f85
ec17de8
dc910f2
0a066f5
3c29625
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -776,3 +776,51 @@ func (h *handler) SweepOgifEvent(c *gin.Context) { | |
|
||
c.JSON(http.StatusOK, view.CreateResponse[any](nil, nil, nil, nil, "events swept successfully")) | ||
} | ||
|
||
// ListChannelMessageLogs godoc | ||
// @Summary Get list of messages in channel and its thread | ||
// @Description Get list of messages in channel and its thread | ||
// @id ListChannelMessageLogs | ||
// @Tags Discord | ||
// @Accept json | ||
// @Produce json | ||
// @Param discord_channel_id path string true "Channel Discord ID" | ||
// @Param startDate query string true "Start Date" | ||
// @Param endDate query string true "End Date" | ||
// @Success 200 {object} ListResearchTopicResponse | ||
// @Failure 400 {object} ErrorResponse | ||
// @Failure 404 {object} ErrorResponse | ||
// @Failure 500 {object} ErrorResponse | ||
// @Router /discords/{discord_channel_id}/message-logs [get] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be updated |
||
func (h *handler) ListChannelMessageLogs(c *gin.Context) { | ||
var input = request.GetChannelMessagesInput{ | ||
DiscordChannelID: c.Param("discord_channel_id"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @nnhuyhoang will this allow client call any discord_channel_id, if yes, gonna reject this for now please follow up with me about this approach, need to validate/whitelist some channels only |
||
} | ||
|
||
if err := c.ShouldBindQuery(&input); err != nil { | ||
c.JSON(http.StatusBadRequest, view.CreateResponse[any](nil, nil, err, input, "bind query failed")) | ||
return | ||
} | ||
|
||
if err := input.Validate(); err != nil { | ||
c.JSON(http.StatusBadRequest, view.CreateResponse[any](nil, nil, err, input, "")) | ||
return | ||
} | ||
|
||
startDate := input.GetStartDate() | ||
endDate := input.GetEndDate() | ||
|
||
// maximum 3 month messages | ||
threeMonths := time.Hour * 24 * 90 | ||
if endDate.Sub(*startDate) > threeMonths { | ||
newEndDate := startDate.Add(threeMonths) | ||
endDate = &newEndDate | ||
} | ||
|
||
messages, err := h.controller.Discord.ListDiscordChannelMessageLogs(c, input.DiscordChannelID, startDate, endDate) | ||
if err != nil { | ||
c.JSON(http.StatusInternalServerError, view.CreateResponse[any](nil, nil, err, nil, "")) | ||
return | ||
} | ||
c.JSON(http.StatusOK, view.CreateResponse(view.ToListDiscordTextMessageLog(messages), nil, nil, nil, "")) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package view | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/dwarvesf/fortress-api/pkg/model" | ||
) | ||
|
||
type DiscordTextMessageLog struct { | ||
ID string `json:"id"` | ||
Content string `json:"content"` | ||
AuthorName string `json:"author_name"` | ||
AuthorID string `json:"author_id"` | ||
ChannelID string `json:"channel_id"` | ||
GuildID string `json:"guild_id"` | ||
Timestamp time.Time `json:"timestamp"` | ||
} | ||
|
||
func ToDiscordTextMessageLog(message model.DiscordTextMessageLog) DiscordTextMessageLog { | ||
return DiscordTextMessageLog{ | ||
ID: message.ID, | ||
Content: message.Content, | ||
AuthorName: message.AuthorName, | ||
AuthorID: message.AuthorID, | ||
ChannelID: message.ChannelID, | ||
GuildID: message.GuildID, | ||
Timestamp: message.Timestamp, | ||
} | ||
} | ||
|
||
func ToListDiscordTextMessageLog(messages []model.DiscordTextMessageLog) []DiscordTextMessageLog { | ||
var results = make([]DiscordTextMessageLog, 0, len(messages)) | ||
|
||
for _, message := range messages { | ||
results = append(results, ToDiscordTextMessageLog(message)) | ||
} | ||
|
||
return results | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@namnhce @nnhuyhoang
this seems like a potential OOM, since on prod we only have 100MB-ish memory, make sure we dont OOM here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will test on dev with the same amount of messages, if cannot handle them , find another way