You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
1.1 KiB
Go
60 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"log"
|
|
|
|
"github.com/Rhymen/go-whatsapp"
|
|
"github.com/hugot/go-deltachat/deltachat"
|
|
)
|
|
|
|
type BridgeContext struct {
|
|
Config *Config
|
|
WhappConn *whatsapp.Conn
|
|
DCContext *deltachat.Context
|
|
DB *Database
|
|
MessageTracker *MessageTracker
|
|
DCUserID uint32
|
|
DCUserChatID uint32
|
|
}
|
|
|
|
// Find or create a deltachat verified group chat for a whatsapp JID and return it's ID.
|
|
func (b *BridgeContext) GetOrCreateDCIDForJID(JID string) (uint32, error) {
|
|
if DCID, _ := b.DB.GetDCIDForWhappJID(JID); DCID != nil {
|
|
return *DCID, nil
|
|
}
|
|
|
|
chatName := JID
|
|
chat, ok := b.WhappConn.Store.Chats[JID]
|
|
|
|
if ok {
|
|
chatName = chat.Name
|
|
}
|
|
|
|
DCID := b.DCContext.CreateGroupChat(true, chatName)
|
|
|
|
err := b.DB.StoreDCIDForJID(JID, DCID)
|
|
|
|
if err != nil {
|
|
return DCID, err
|
|
}
|
|
|
|
b.DCContext.AddContactToChat(DCID, b.DCUserID)
|
|
|
|
return DCID, err
|
|
}
|
|
|
|
func (b *BridgeContext) SendLog(logString string) {
|
|
b.DCContext.SendTextMessage(b.DCUserChatID, logString)
|
|
}
|
|
|
|
func (b *BridgeContext) MessageWasSent(ID string) bool {
|
|
sent, err := b.MessageTracker.WasSent(ID)
|
|
|
|
if err != nil {
|
|
log.Println(err)
|
|
b.SendLog(err.Error())
|
|
}
|
|
|
|
return sent
|
|
}
|