Skip to content

Commit

Permalink
hook into member-added event properly
Browse files Browse the repository at this point in the history
  • Loading branch information
missytake committed Jul 26, 2024
1 parent 5022d31 commit 13612f4
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions invitebot.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ func onBotInit(cli *botcli.BotCli, bot *deltachat.Bot, cmd *cobra.Command, args
if err != nil {
cli.Logger.Error(err)
}
err = bot.Rpc.SetConfig(accId, "delete_device_after", option.Some("1800"))
if err != nil {
cli.Logger.Error(err)
}
}
}
}
Expand All @@ -56,6 +52,10 @@ func onNewMsg(bot *deltachat.Bot, accId deltachat.AccountId, msgId deltachat.Msg
return
}

if msg.SystemMessageType == deltachat.SysmsgMemberAddedToGroup {
resendPads(bot.Rpc, accId, msg.ChatId)
}

if !msg.IsBot && !msg.IsInfo && msg.FromId > deltachat.ContactLastSpecial {
chat, err := bot.Rpc.GetBasicChatInfo(accId, msg.ChatId)
if err != nil {
Expand All @@ -68,9 +68,6 @@ func onNewMsg(bot *deltachat.Bot, accId deltachat.AccountId, msgId deltachat.Msg
logger.Error(err)
}
}
if msg.SystemMessageType == deltachat.SysmsgMemberAddedToGroup {
resendPads(bot.Rpc, accId, msg.ChatId)
}

args := strings.Split(msg.Text, " ")
switch args[0] {
Expand Down Expand Up @@ -114,13 +111,17 @@ func sendPad(rpc *deltachat.Rpc, accId deltachat.AccountId, chatId deltachat.Cha

func resendPads(rpc *deltachat.Rpc, accId deltachat.AccountId, chatId deltachat.ChatId) {
var toResend []deltachat.MsgId
selfAddr, err := rpc.GetConfig(accId, "configured_addr")
if err != nil {
selfAddr, err := rpc.GetConfig(accId, "addr")
if err == nil {
msgIds, _ := rpc.GetMessageIds(accId, chatId, true, false)
cli.Logger.Info(msgIds)
for _, id := range msgIds {
msg, _ := rpc.GetMessage(accId, id)
senderaddress := msg.Sender.Address
cli.Logger.Info(id)
cli.Logger.Info(senderaddress)
if senderaddress == selfAddr.Unwrap() && msg.WebxdcInfo != nil {
cli.Logger.Info(toResend)
toResend = append(toResend, id)
}
}
Expand Down

0 comments on commit 13612f4

Please sign in to comment.