mirror of
https://github.com/balzack/databag.git
synced 2025-02-12 03:29:16 +00:00
adding revision notification thread
This commit is contained in:
parent
664e179fba
commit
57b6936226
@ -68,12 +68,3 @@ func SetCloseMessage(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
||||
func SetContentRevision(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
||||
func SetProfileRevision(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
14
net/server/internal/api_setContentRevision.go
Normal file
14
net/server/internal/api_setContentRevision.go
Normal file
@ -0,0 +1,14 @@
|
||||
package databag
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func SetContentRevision(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
||||
func NotifyContentRevision(token string, revision int64) error {
|
||||
return nil
|
||||
}
|
@ -42,6 +42,7 @@ func SetProfile(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
SetProfileNotification(account)
|
||||
SetStatus(account)
|
||||
WriteResponse(w, nil)
|
||||
}
|
||||
|
15
net/server/internal/api_setProfileRevision.go
Normal file
15
net/server/internal/api_setProfileRevision.go
Normal file
@ -0,0 +1,15 @@
|
||||
package databag
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func SetProfileRevision(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
||||
func NotifyProfileRevision(token string, revision int64) error {
|
||||
return nil
|
||||
}
|
||||
|
@ -19,6 +19,8 @@ const APP_CARDCONFIRMED = "confirmed"
|
||||
const APP_CARDREQUESTED = "requested"
|
||||
const APP_CARDCONNECTING = "connecting"
|
||||
const APP_CARDCONNECTED = "connected"
|
||||
const APP_MODULEPROFILE = "profile"
|
||||
const APP_MODULECONTENT = "content"
|
||||
|
||||
func AppCardStatus(status string) bool {
|
||||
if status == APP_CARDPENDING {
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
)
|
||||
|
||||
var notify = make(chan *store.Notification)
|
||||
var notifyExit = make(chan bool, 1)
|
||||
var notifyExit = make(chan bool)
|
||||
|
||||
func ExitNotifications() {
|
||||
notifyExit <- true
|
||||
@ -27,14 +27,39 @@ func SendNotifications() {
|
||||
for {
|
||||
select {
|
||||
case notification := <-notify:
|
||||
PrintMsg("SENDING")
|
||||
PrintMsg(notification)
|
||||
node := "https://" + getStrConfigValue(CONFIG_DOMAIN, "") + "/"
|
||||
if notification.Node == node {
|
||||
SendLocalNotification(notification)
|
||||
} else {
|
||||
SendRemoteNotification(notification)
|
||||
}
|
||||
if err := store.DB.Delete(¬ification).Error; err != nil {
|
||||
ErrMsg(err)
|
||||
}
|
||||
case <-notifyExit:
|
||||
PrintMsg("EXITING")
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func SendLocalNotification(notification *store.Notification) {
|
||||
if notification.Module == APP_MODULEPROFILE {
|
||||
if err := NotifyProfileRevision(notification.Token, notification.Revision); err != nil {
|
||||
ErrMsg(err)
|
||||
}
|
||||
} else if notification.Module == APP_MODULECONTENT {
|
||||
if err := NotifyContentRevision(notification.Token, notification.Revision); err != nil {
|
||||
ErrMsg(err)
|
||||
}
|
||||
} else {
|
||||
LogMsg("unknown notification type")
|
||||
}
|
||||
}
|
||||
|
||||
func SendRemoteNotification(notification *store.Notification) {
|
||||
PrintMsg(notification)
|
||||
}
|
||||
|
||||
// notify all cards of profile change
|
||||
func SetProfileNotification(account *store.Account) {
|
||||
|
||||
@ -49,7 +74,8 @@ func SetProfileNotification(account *store.Account) {
|
||||
err := store.DB.Transaction(func(tx *gorm.DB) error {
|
||||
for _, card := range cards {
|
||||
notification := &store.Notification{
|
||||
Url: card.Node + "/contact/profile/revision",
|
||||
Node: card.Node,
|
||||
Module: APP_MODULEPROFILE,
|
||||
Token: card.OutToken,
|
||||
Revision: account.ProfileRevision,
|
||||
}
|
||||
@ -81,7 +107,8 @@ func SetContentNotification(account *store.Account) {
|
||||
err := store.DB.Transaction(func(tx *gorm.DB) error {
|
||||
for _, card := range cards {
|
||||
notification := &store.Notification{
|
||||
Url: card.Node + "/contact/content/revision",
|
||||
Node: card.Node,
|
||||
Module: APP_MODULECONTENT,
|
||||
Token: card.OutToken,
|
||||
Revision: account.ViewRevision + account.ContentRevision + card.ViewRevision,
|
||||
}
|
||||
@ -112,7 +139,8 @@ func SetContactContentNotification(account *store.Account, cardId string) {
|
||||
err := store.DB.Transaction(func(tx *gorm.DB) error {
|
||||
for _, card := range cards {
|
||||
notification := &store.Notification{
|
||||
Url: card.Node + "/contact/content/revision",
|
||||
Node: card.Node,
|
||||
Module: APP_MODULECONTENT,
|
||||
Token: card.OutToken,
|
||||
Revision: account.ViewRevision + account.ContentRevision + card.ViewRevision,
|
||||
}
|
||||
|
@ -29,7 +29,8 @@ func AutoMigrate(db *gorm.DB) {
|
||||
|
||||
type Notification struct {
|
||||
ID uint `gorm:"primaryKey;not null;unique;autoIncrement"`
|
||||
Url string `gorm:"not null"`
|
||||
Node string `gorm:"not null"`
|
||||
Module string `gorm:"not null"`
|
||||
Token string `gorm:"not null"`
|
||||
Revision int64 `gorm:"not null"`
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user