forked from MirrorHub/mautrix-whatsapp
Improve invite message text
This commit is contained in:
parent
630095e28a
commit
79f51af06e
2 changed files with 10 additions and 23 deletions
26
commands.go
26
commands.go
|
@ -288,30 +288,20 @@ func (handler *CommandHandler) CommandJoin(ce *CommandEvent) {
|
|||
func (handler *CommandHandler) CommandAccept(ce *CommandEvent) {
|
||||
if ce.Portal == nil || len(ce.ReplyTo) == 0 {
|
||||
ce.Reply("You must reply to a group invite message when using this command.")
|
||||
return
|
||||
}
|
||||
evt, err := ce.Portal.MainIntent().GetEvent(ce.RoomID, ce.ReplyTo)
|
||||
if err != nil {
|
||||
} else if evt, err := ce.Portal.MainIntent().GetEvent(ce.RoomID, ce.ReplyTo); err != nil {
|
||||
handler.log.Errorln("Failed to get event %s to handle !wa accept command: %v", ce.ReplyTo, err)
|
||||
ce.Reply("Failed to get reply event")
|
||||
return
|
||||
}
|
||||
meta, ok := evt.Content.Raw[inviteMetaField].(map[string]interface{})
|
||||
if !ok {
|
||||
} else if meta, ok := evt.Content.Raw[inviteMetaField].(map[string]interface{}); !ok {
|
||||
ce.Reply("That doesn't look like a group invite message.")
|
||||
return
|
||||
}
|
||||
jid, inviter, code, expiration, ok := parseInviteMeta(meta)
|
||||
if !ok {
|
||||
} else if jid, inviter, code, expiration, ok := parseInviteMeta(meta); !ok {
|
||||
ce.Reply("That doesn't look like a group invite message.")
|
||||
return
|
||||
}
|
||||
err = ce.User.Client.AcceptGroupInvite(jid, inviter, code, expiration)
|
||||
if err != nil {
|
||||
} else if inviter.User == ce.User.JID.User {
|
||||
ce.Reply("You can't accept your own invites")
|
||||
} else if err = ce.User.Client.AcceptGroupInvite(jid, inviter, code, expiration); err != nil {
|
||||
ce.Reply("Failed to accept group invite: %v", err)
|
||||
return
|
||||
} else {
|
||||
ce.Reply("Successfully accepted the invite, the portal should be created momentarily")
|
||||
}
|
||||
ce.Reply("Successfully accepted the invite, the portal should be created momentarily")
|
||||
}
|
||||
|
||||
const cmdCreateHelp = `create - Create a group chat.`
|
||||
|
|
|
@ -1563,15 +1563,12 @@ func (portal *Portal) convertLocationMessage(intent *appservice.IntentAPI, msg *
|
|||
return &ConvertedMessage{Intent: intent, Type: event.EventMessage, Content: content}
|
||||
}
|
||||
|
||||
const inviteMsg = `<a href="https://matrix.to/#/%s">%s</a> has invited you to join %s:
|
||||
<blockquote>%s</blockquote>
|
||||
The invite expires at %s. Reply to this message with <code>!wa accept</code> to accept the invite.`
|
||||
const inviteMsg = `%s<hr/>This invitation to join "%s" expires at %s. Reply to this message with <code>!wa accept</code> to accept the invite.`
|
||||
const inviteMetaField = "fi.mau.whatsapp.invite"
|
||||
|
||||
func (portal *Portal) convertGroupInviteMessage(intent *appservice.IntentAPI, info *types.MessageInfo, msg *waProto.GroupInviteMessage) *ConvertedMessage {
|
||||
puppet := portal.bridge.GetPuppetByJID(info.Sender)
|
||||
expiry := time.Unix(msg.GetInviteExpiration(), 0)
|
||||
htmlMessage := fmt.Sprintf(inviteMsg, intent.UserID, html.EscapeString(puppet.Displayname), msg.GetGroupName(), html.EscapeString(msg.GetCaption()), expiry)
|
||||
htmlMessage := fmt.Sprintf(inviteMsg, html.EscapeString(msg.GetCaption()), msg.GetGroupName(), expiry)
|
||||
content := &event.MessageEventContent{
|
||||
MsgType: event.MsgText,
|
||||
Body: format.HTMLToText(htmlMessage),
|
||||
|
|
Loading…
Reference in a new issue