- if strings.TrimSpace(text) == "" {
- return WhatsAppChat{}, WhatsAppMessage{}, false
- }
-
- contextInfo := extended.GetContextInfo()
- message := WhatsAppMessage{
- ID: info.ID,
- Time: info.Timestamp,
- Mine: info.IsFromMe,
- }
-
- if !message.Mine {
- message.Sender = whatsappContactName(ctx, device, info.Sender, info.PushName)
- }
-
- for _, mentioned := range contextInfo.GetMentionedJID() {
- jid, err := types.ParseJID(mentioned)
- switch {
- case err != nil:
- case slices.Contains(own, jid.User):
- message.Mention = true
- text = strings.ReplaceAll(text, "@"+jid.User, "@you")
- default:
- text = strings.ReplaceAll(text, "@"+jid.User, "@"+whatsappContactName(ctx, device, jid, ""))
- }
- }
-
- participant, err := types.ParseJID(contextInfo.GetParticipant())
- message.Reply = err == nil && slices.Contains(own, participant.User)
-
- for _, id := range own {
- text = strings.ReplaceAll(text, id, "OWN")
- }
-
- message.Text = text
- chatJID := info.Chat.ToNonAD()
- chat := WhatsAppChat{
- ID: chatJID.String(),
- Group: chatJID.Server == types.GroupServer,
- }
-
- if !chat.Group {
- push := info.PushName
- if message.Mine {
- push = ""
- }
-
- chat.Name = whatsappContactName(ctx, device, chatJID, push)
- }
-
- return chat, message, true
-}
-
-// caughtUpBy ends the catch-up of the connection with the number catchups, when
-// no later connection started a new one.
-func (w *WhatsApp) caughtUpBy(catchups int) {
- w.mutex.Lock()
- defer w.mutex.Unlock()
-
- if w.catchups == catchups {
- w.endCatchup()
- }
-}
-
-// endCatchup ends a running catch-up and wakes Run, which logs all batches. The
-// caller holds the mutex.
-func (w *WhatsApp) endCatchup() {
- if !w.catchingUp {
- return
- }
-
- w.catchingUp = false
- w.caughtUp = true
- if w.catchupTimer != nil {
- w.catchupTimer.Stop()