Skip to content

Commit

Permalink
Merge branch 'main' into fix_ui
Browse files Browse the repository at this point in the history
  • Loading branch information
zeripath authored Jul 17, 2021
2 parents 5877c49 + e83abfc commit 1a4338c
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 11 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ test: test-frontend test-backend

.PHONY: test-backend
test-backend:
@echo "Running go test with -tags '$(TEST_TAGS)'..."
@echo "Running go test with $(GOTESTFLAGS) -tags '$(TEST_TAGS)'..."
@$(GO) test $(GOTESTFLAGS) -mod=vendor -tags='$(TEST_TAGS)' $(GO_PACKAGES)

.PHONY: test-frontend
Expand Down Expand Up @@ -389,7 +389,7 @@ coverage:

.PHONY: unit-test-coverage
unit-test-coverage:
@echo "Running unit-test-coverage -tags '$(TEST_TAGS)'..."
@echo "Running unit-test-coverage $(GOTESTFLAGS) -tags '$(TEST_TAGS)'..."
@$(GO) test $(GOTESTFLAGS) -mod=vendor -tags='$(TEST_TAGS)' -cover -coverprofile coverage.out $(GO_PACKAGES) && echo "\n==>\033[32m Ok\033[m\n" || exit 1

.PHONY: vendor
Expand Down
35 changes: 31 additions & 4 deletions modules/queue/queue_disk_channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package queue

import (
"io/ioutil"
"sync"
"testing"

"code.gitea.io/gitea/modules/util"
Expand All @@ -22,6 +23,7 @@ func TestPersistableChannelQueue(t *testing.T) {
}
}

lock := sync.Mutex{}
queueShutdown := []func(){}
queueTerminate := []func(){}

Expand All @@ -41,8 +43,12 @@ func TestPersistableChannelQueue(t *testing.T) {
assert.NoError(t, err)

go queue.Run(func(shutdown func()) {
lock.Lock()
defer lock.Unlock()
queueShutdown = append(queueShutdown, shutdown)
}, func(terminate func()) {
lock.Lock()
defer lock.Unlock()
queueTerminate = append(queueTerminate, terminate)
})

Expand All @@ -69,7 +75,11 @@ func TestPersistableChannelQueue(t *testing.T) {
assert.Error(t, err)

// Now shutdown the queue
for _, callback := range queueShutdown {
lock.Lock()
callbacks := make([]func(), len(queueShutdown))
copy(callbacks, queueShutdown)
lock.Unlock()
for _, callback := range callbacks {
callback()
}

Expand All @@ -87,7 +97,11 @@ func TestPersistableChannelQueue(t *testing.T) {
}

// terminate the queue
for _, callback := range queueTerminate {
lock.Lock()
callbacks = make([]func(), len(queueTerminate))
copy(callbacks, queueTerminate)
lock.Unlock()
for _, callback := range callbacks {
callback()
}

Expand All @@ -110,8 +124,12 @@ func TestPersistableChannelQueue(t *testing.T) {
assert.NoError(t, err)

go queue.Run(func(shutdown func()) {
lock.Lock()
defer lock.Unlock()
queueShutdown = append(queueShutdown, shutdown)
}, func(terminate func()) {
lock.Lock()
defer lock.Unlock()
queueTerminate = append(queueTerminate, terminate)
})

Expand All @@ -122,10 +140,19 @@ func TestPersistableChannelQueue(t *testing.T) {
result4 := <-handleChan
assert.Equal(t, test2.TestString, result4.TestString)
assert.Equal(t, test2.TestInt, result4.TestInt)
for _, callback := range queueShutdown {

lock.Lock()
callbacks = make([]func(), len(queueShutdown))
copy(callbacks, queueShutdown)
lock.Unlock()
for _, callback := range callbacks {
callback()
}
for _, callback := range queueTerminate {
lock.Lock()
callbacks = make([]func(), len(queueTerminate))
copy(callbacks, queueTerminate)
lock.Unlock()
for _, callback := range callbacks {
callback()
}

Expand Down
2 changes: 2 additions & 0 deletions routers/web/user/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func Notifications(c *context.Context) {
return
}
if c.QueryBool("div-only") {
c.Data["SequenceNumber"] = c.Query("sequence-number")
c.HTML(http.StatusOK, tplNotificationDiv)
return
}
Expand Down Expand Up @@ -175,6 +176,7 @@ func NotificationStatusPost(c *context.Context) {
return
}
c.Data["Link"] = setting.AppURL + "notifications"
c.Data["SequenceNumber"] = c.Req.PostFormValue("sequence-number")

c.HTML(http.StatusOK, tplNotificationDiv)
}
Expand Down
2 changes: 1 addition & 1 deletion templates/user/notification/notification_div.tmpl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="page-content user notification" id="notification_div" data-params="{{.Page.GetParams}}">
<div class="page-content user notification" id="notification_div" data-params="{{.Page.GetParams}}" data-sequence-number="{{.SequenceNumber}}">
<div class="ui container">
<h1 class="ui dividing header">{{.i18n.Tr "notification.notifications"}}</h1>
<div class="ui top attached tabular menu">
Expand Down
16 changes: 12 additions & 4 deletions web_src/js/features/notification.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const {AppSubUrl, csrf, NotificationSettings} = window.config;

let notificationSequenceNumber = 0;

export function initNotificationsTable() {
$('#notification_table .button').on('click', async function () {
const data = await updateNotification(
Expand All @@ -10,8 +12,10 @@ export function initNotificationsTable() {
$(this).data('notification-id'),
);

$('#notification_div').replaceWith(data);
initNotificationsTable();
if ($(data).data('sequence-number') === notificationSequenceNumber) {
$('#notification_div').replaceWith(data);
initNotificationsTable();
}
await updateNotificationCount();

return false;
Expand Down Expand Up @@ -139,10 +143,13 @@ async function updateNotificationTable() {
url: `${AppSubUrl}/notifications?${notificationDiv.data('params')}`,
data: {
'div-only': true,
'sequence-number': ++notificationSequenceNumber,
}
});
notificationDiv.replaceWith(data);
initNotificationsTable();
if ($(data).data('sequence-number') === notificationSequenceNumber) {
notificationDiv.replaceWith(data);
initNotificationsTable();
}
}
}

Expand Down Expand Up @@ -182,6 +189,7 @@ async function updateNotification(url, status, page, q, notificationID) {
page,
q,
noredirect: true,
'sequence-number': ++notificationSequenceNumber,
},
});
}

0 comments on commit 1a4338c

Please sign in to comment.