[render skip] set last message id on api properly

This commit is contained in:
Andre Medeiros 2022-11-05 21:25:06 -04:00
parent 5eabaebf45
commit fc449fd7cf
2 changed files with 5 additions and 2 deletions

View file

@ -177,7 +177,7 @@ func (a *api) upsertAccountsHandler(w http.ResponseWriter, r *http.Request) {
// Set account ID from Reddit // Set account ID from Reddit
acc.AccountID = me.ID acc.AccountID = me.ID
mi, err := rac.MessageInbox(ctx) mi, err := rac.MessageInbox(ctx, reddit.WithQuery("limit", "1"))
if err != nil { if err != nil {
a.errorResponse(w, r, 500, err) a.errorResponse(w, r, 500, err)
return return
@ -185,6 +185,7 @@ func (a *api) upsertAccountsHandler(w http.ResponseWriter, r *http.Request) {
if mi.Count > 0 { if mi.Count > 0 {
acc.LastMessageID = mi.Children[0].FullName() acc.LastMessageID = mi.Children[0].FullName()
acc.CheckCount = 1
} }
if err := a.accountRepo.CreateOrUpdate(ctx, &acc); err != nil { if err := a.accountRepo.CreateOrUpdate(ctx, &acc); err != nil {
@ -252,7 +253,7 @@ func (a *api) upsertAccountHandler(w http.ResponseWriter, r *http.Request) {
// Set account ID from Reddit // Set account ID from Reddit
acct.AccountID = me.ID acct.AccountID = me.ID
mi, err := rac.MessageInbox(ctx) mi, err := rac.MessageInbox(ctx, reddit.WithQuery("limit", "1"))
if err != nil { if err != nil {
a.errorResponse(w, r, 500, err) a.errorResponse(w, r, 500, err)
return return
@ -260,6 +261,7 @@ func (a *api) upsertAccountHandler(w http.ResponseWriter, r *http.Request) {
if mi.Count > 0 { if mi.Count > 0 {
acct.LastMessageID = mi.Children[0].FullName() acct.LastMessageID = mi.Children[0].FullName()
acct.CheckCount = 1
} }
// Associate // Associate

View file

@ -103,6 +103,7 @@ func (p *postgresAccountRepository) CreateOrUpdate(ctx context.Context, acc *dom
UPDATE SET access_token = $3, UPDATE SET access_token = $3,
refresh_token = $4, refresh_token = $4,
token_expires_at = $5, token_expires_at = $5,
last_message_id = $6,
is_deleted = FALSE is_deleted = FALSE
RETURNING id` RETURNING id`