Skip to content

Commit

Permalink
history sync
Browse files Browse the repository at this point in the history
  • Loading branch information
nocodeleaks committed May 23, 2024
1 parent 60005c5 commit bccdca4
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@
"mattn",
"messageid",
"msgevt",
"msginfo",
"myvar",
"officedocument",
"openxmlformats",
Expand Down
2 changes: 1 addition & 1 deletion src/models/qp_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ package models
import log "github.com/sirupsen/logrus"

// quepasa build version, if ends with .0 means stable versions.
const QpVersion = "3.24.523.1253 ! High Unstable ! Do not update, casca de bala ! "
const QpVersion = "3.24.523.1625 ! High Unstable ! Do not update, casca de bala ! "

const QpLogLevel = log.InfoLevel
2 changes: 1 addition & 1 deletion src/models/qp_whatsapp_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func (handler *QPWhatsappHandlers) GetMessage(id string) (msg whatsapp.WhatsappM
// sends the message throw external publishers
func (source *QPWhatsappHandlers) Trigger(payload *whatsapp.WhatsappMessage) {
if source != nil {
if source.server != nil && !MessagesSignalRHub.IsInterfaceNil() {
if source.server != nil {
go SignalRDispatch(source.server.Token, payload)
}

Expand Down
19 changes: 19 additions & 0 deletions src/whatsapp/whatsapp_options_extended.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package whatsapp

import "time"

// Whatsapp service options, setted on start, so if want to changed then, you have to restart the entire service
type WhatsappOptionsExtended struct {

Expand Down Expand Up @@ -102,3 +104,20 @@ func (source WhatsappOptionsExtended) HandleBroadcasts(local WhatsappBoolean) bo
return source.Broadcasts.ToBoolean(WhatsappBroadcasts)
}
}

func (source WhatsappOptionsExtended) HandleHistory(mts uint64) bool {
if source.HistorySync != nil {
days := *source.HistorySync
if days == 0 {
return true
}

current := time.Now()
limit := current.AddDate(0, 0, -int(days))
if int64(mts) > limit.Unix() {
return true
}
}

return false
}
15 changes: 14 additions & 1 deletion src/whatsmeow/whatsmeow_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,12 @@ func (source *WhatsmeowHandlers) OnHistorySyncEvent(evt events.HistorySync) {
logentry.Infof("history sync: %s", evt.Data.SyncType)
// HistorySyncSaveJSON(evt)

// whatsmeow service options
options := source.GetServiceOptions()
if options.HistorySync == nil {
return
}

conversations := evt.Data.GetConversations()
for _, conversation := range conversations {
for _, historyMsg := range conversation.GetMessages() {
Expand All @@ -309,7 +315,14 @@ func (source *WhatsmeowHandlers) OnHistorySyncEvent(evt events.HistorySync) {
return
}

msgevt, err := source.Client.ParseWebMessage(wid, historyMsg.GetMessage())
// converting to event
msgInfo := historyMsg.GetMessage()
msgTime := msgInfo.GetMessageTimestamp()
if !options.HandleHistory(msgTime) {
continue
}

msgevt, err := source.Client.ParseWebMessage(wid, msgInfo)
if err != nil {
logentry.Errorf("failed to parse web message at history sync: %v", err)
return
Expand Down

0 comments on commit bccdca4

Please sign in to comment.