From e5300cdfb93be77a1f9604c5b93298498f6bfa23 Mon Sep 17 00:00:00 2001 From: Hugo Thunnissen Date: Wed, 29 Jan 2020 22:07:32 +0100 Subject: [PATCH] Make verified groups optional DC verified groups stopped working for a while, so it seemed like a good idea to make the use of this feature optional. A new (boolean) config value called verified_groups has been added. --- whappdc-core/bridge_context.go | 3 +++ whappdc-core/config.go | 7 +++--- whappdc-core/deltachat.go | 41 ++++++++++++++++++++-------------- whappdc/whapp_context.go | 2 +- 4 files changed, 32 insertions(+), 21 deletions(-) diff --git a/whappdc-core/bridge_context.go b/whappdc-core/bridge_context.go index de2e9d6..7434f4d 100644 --- a/whappdc-core/bridge_context.go +++ b/whappdc-core/bridge_context.go @@ -1,6 +1,8 @@ package core import ( + "log" + "github.com/Rhymen/go-whatsapp" "github.com/hugot/go-deltachat/deltabot" "github.com/hugot/go-deltachat/deltachat" @@ -46,6 +48,7 @@ func (b *BridgeContext) Init( } for i := 0; i < 10; i++ { + log.Println("Attempting whapp login") err = CreateAndLoginWhappConnection(b.Config.App.DataFolder, b) if err == nil { diff --git a/whappdc-core/config.go b/whappdc-core/config.go index 661c7eb..f678e0d 100644 --- a/whappdc-core/config.go +++ b/whappdc-core/config.go @@ -7,9 +7,10 @@ import ( ) type AppConfig struct { - DataFolder string `yaml:"data_folder"` - UserAddress string `yaml:"user"` - ShowFromMe bool `yaml:"show_from_me"` + DataFolder string `yaml:"data_folder"` + UserAddress string `yaml:"user"` + ShowFromMe bool `yaml:"show_from_me"` + VerifiedGroups bool `yaml:"verified_groups"` } type Config struct { diff --git a/whappdc-core/deltachat.go b/whappdc-core/deltachat.go index 1387ff6..c5e8d1f 100644 --- a/whappdc-core/deltachat.go +++ b/whappdc-core/deltachat.go @@ -56,32 +56,39 @@ func BootstrapDcClientFromConfig(config Config, ctx *BridgeContext) (*deltachat. userName := "user" dcUserID := DCCtx.CreateContact(&userName, &config.App.UserAddress) - // Send a message in a 1:1 chat first, this will let the user's client know that the - // crypto setup has changed if it has - DCCtx.SendTextMessage( - DCCtx.CreateChatByContactID(dcUserID), - "Hi, Whapp-Deltachat is initializing", - ) - - userChatIDRaw := ctx.DB.Get([]byte("user-chat-id")) var ( userChatID uint32 err error ) - if userChatIDRaw == nil { - userChatID, err = AddUserAsVerifiedContact(dcUserID, dcClient) - if err != nil { - return nil, err + if config.App.VerifiedGroups { + // Send a message in a 1:1 chat first, this will let the user's client know that the + // crypto setup has changed if it has + DCCtx.SendTextMessage( + DCCtx.CreateChatByContactID(dcUserID), + "Hi, Whapp-Deltachat is initializing", + ) + + userChatIDRaw := ctx.DB.Get([]byte("user-chat-id")) + + // The verified group chat that is used as 1:1 between whappDC and the user is + // created here if verified groups are enabled. + if userChatIDRaw == nil { + userChatID, err = AddUserAsVerifiedContact(dcUserID, dcClient) + if err != nil { + return nil, err + } + } else { + userChatID = binary.LittleEndian.Uint32(userChatIDRaw) } + + userChatIDbs := make([]byte, 4) + binary.LittleEndian.PutUint32(userChatIDbs, userChatID) + err = ctx.DB.Put([]byte("user-chat-id"), userChatIDbs) } else { - userChatID = binary.LittleEndian.Uint32(userChatIDRaw) + userChatID = DCCtx.CreateChatByContactID(dcUserID) } - userChatIDbs := make([]byte, 4) - binary.LittleEndian.PutUint32(userChatIDbs, userChatID) - err = ctx.DB.Put([]byte("user-chat-id"), userChatIDbs) - ctx.DCUserID = dcUserID ctx.DCUserChatID = userChatID ctx.DCContext = DCCtx diff --git a/whappdc/whapp_context.go b/whappdc/whapp_context.go index c8378e7..a9926fb 100644 --- a/whappdc/whapp_context.go +++ b/whappdc/whapp_context.go @@ -48,7 +48,7 @@ func (w *WhappContext) GetOrCreateDCIDForJID(JID string) (uint32, error) { chatName = sender.Name } - DCID := w.BridgeCtx.DCContext.CreateGroupChat(true, chatName) + DCID := w.BridgeCtx.DCContext.CreateGroupChat(w.BridgeCtx.Config.App.VerifiedGroups, chatName) err := w.BridgeCtx.DB.StoreDCIDForJID(JID, DCID)