Skip to content

Commit

Permalink
fixes #329 - set message expiration when sending to whatsapp group wi…
Browse files Browse the repository at this point in the history
…th disappearing messages
  • Loading branch information
d99kris committed Jan 18, 2025
1 parent 325ece1 commit fcb15ad
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/common/src/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@

#pragma once

#define NCHAT_VERSION "5.5.6"
#define NCHAT_VERSION "5.5.7"
47 changes: 39 additions & 8 deletions lib/wmchat/go/gowm.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,15 @@ const (
)

var (
mx sync.Mutex
clients map[int]*whatsmeow.Client = make(map[int]*whatsmeow.Client)
paths map[int]string = make(map[int]string)
contacts map[int]map[string]string = make(map[int]map[string]string)
states map[int]State = make(map[int]State)
timeReads map[int]map[string]time.Time = make(map[int]map[string]time.Time)
handlers map[int]*WmEventHandler = make(map[int]*WmEventHandler)
sendTypes map[int]int = make(map[int]int)
mx sync.Mutex
clients map[int]*whatsmeow.Client = make(map[int]*whatsmeow.Client)
paths map[int]string = make(map[int]string)
contacts map[int]map[string]string = make(map[int]map[string]string)
states map[int]State = make(map[int]State)
timeReads map[int]map[string]time.Time = make(map[int]map[string]time.Time)
expirations map[int]map[string]uint32 = make(map[int]map[string]uint32)
handlers map[int]*WmEventHandler = make(map[int]*WmEventHandler)
sendTypes map[int]int = make(map[int]int)
)

// keep in sync with enum FileStatus in protocol.h
Expand Down Expand Up @@ -104,6 +105,7 @@ func AddConn(conn *whatsmeow.Client, path string, sendType int) int {
contacts[connId] = make(map[string]string)
states[connId] = None
timeReads[connId] = make(map[string]time.Time)
expirations[connId] = make(map[string]uint32)
handlers[connId] = &WmEventHandler{connId}
sendTypes[connId] = sendType
mx.Unlock()
Expand All @@ -117,6 +119,7 @@ func RemoveConn(connId int) {
delete(contacts, connId)
delete(states, connId)
delete(timeReads, connId)
delete(expirations, connId)
delete(handlers, connId)
delete(sendTypes, connId)
mx.Unlock()
Expand Down Expand Up @@ -199,6 +202,24 @@ func SetTimeRead(connId int, chatId string, timeRead time.Time) {
mx.Unlock()
}

func GetExpiration(connId int, chatId string) uint32 {
var expiration uint32
var ok bool
mx.Lock()
expiration, ok = expirations[connId][chatId]
mx.Unlock()
if !ok {
expiration = 0
}
return expiration
}

func SetExpiration(connId int, chatId string, expiration uint32) {
mx.Lock()
expirations[connId][chatId] = expiration
mx.Unlock()
}

// download info
var downloadInfoVersion = 1 // bump version upon any struct change
type DownloadInfo struct {
Expand Down Expand Up @@ -1015,6 +1036,10 @@ func (handler *WmEventHandler) GetContacts() {
LOG_TRACE(fmt.Sprintf("Call CWmNewContactsNotify %s %s", groupId, groupName))
CWmNewContactsNotify(connId, groupId, groupName, groupPhone, BoolToInt(false))
AddContactName(connId, groupId, groupName)

if group.GroupEphemeral.IsEphemeral {
SetExpiration(connId, groupId, group.GroupEphemeral.DisappearingTimer)
}
}
}

Expand Down Expand Up @@ -1975,6 +2000,12 @@ func WmSendMessage(connId int, chatId string, text string, quotedId string, quot
}
}

expiration := GetExpiration(connId, chatId)
if expiration != 0 {
LOG_TRACE("send expiration " + strconv.FormatUint(uint64(expiration), 10))
contextInfo.Expiration = &expiration
}

// check message type
if len(filePath) == 0 {

Expand Down
2 changes: 1 addition & 1 deletion src/nchat.1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man.
.TH NCHAT "1" "January 2025" "nchat 5.5.6" "User Commands"
.TH NCHAT "1" "January 2025" "nchat 5.5.7" "User Commands"
.SH NAME
nchat \- ncurses chat
.SH SYNOPSIS
Expand Down

0 comments on commit fcb15ad

Please sign in to comment.