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) {
|
func (handler *CommandHandler) CommandAccept(ce *CommandEvent) {
|
||||||
if ce.Portal == nil || len(ce.ReplyTo) == 0 {
|
if ce.Portal == nil || len(ce.ReplyTo) == 0 {
|
||||||
ce.Reply("You must reply to a group invite message when using this command.")
|
ce.Reply("You must reply to a group invite message when using this command.")
|
||||||
return
|
} else if evt, err := ce.Portal.MainIntent().GetEvent(ce.RoomID, ce.ReplyTo); err != nil {
|
||||||
}
|
|
||||||
evt, err := ce.Portal.MainIntent().GetEvent(ce.RoomID, ce.ReplyTo)
|
|
||||||
if err != nil {
|
|
||||||
handler.log.Errorln("Failed to get event %s to handle !wa accept command: %v", ce.ReplyTo, err)
|
handler.log.Errorln("Failed to get event %s to handle !wa accept command: %v", ce.ReplyTo, err)
|
||||||
ce.Reply("Failed to get reply event")
|
ce.Reply("Failed to get reply event")
|
||||||
return
|
} else if meta, ok := evt.Content.Raw[inviteMetaField].(map[string]interface{}); !ok {
|
||||||
}
|
|
||||||
meta, ok := evt.Content.Raw[inviteMetaField].(map[string]interface{})
|
|
||||||
if !ok {
|
|
||||||
ce.Reply("That doesn't look like a group invite message.")
|
ce.Reply("That doesn't look like a group invite message.")
|
||||||
return
|
} else if jid, inviter, code, expiration, ok := parseInviteMeta(meta); !ok {
|
||||||
}
|
|
||||||
jid, inviter, code, expiration, ok := parseInviteMeta(meta)
|
|
||||||
if !ok {
|
|
||||||
ce.Reply("That doesn't look like a group invite message.")
|
ce.Reply("That doesn't look like a group invite message.")
|
||||||
return
|
} else if inviter.User == ce.User.JID.User {
|
||||||
}
|
ce.Reply("You can't accept your own invites")
|
||||||
err = ce.User.Client.AcceptGroupInvite(jid, inviter, code, expiration)
|
} else if err = ce.User.Client.AcceptGroupInvite(jid, inviter, code, expiration); err != nil {
|
||||||
if err != nil {
|
|
||||||
ce.Reply("Failed to accept group invite: %v", err)
|
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.`
|
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}
|
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:
|
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.`
|
||||||
<blockquote>%s</blockquote>
|
|
||||||
The invite expires at %s. Reply to this message with <code>!wa accept</code> to accept the invite.`
|
|
||||||
const inviteMetaField = "fi.mau.whatsapp.invite"
|
const inviteMetaField = "fi.mau.whatsapp.invite"
|
||||||
|
|
||||||
func (portal *Portal) convertGroupInviteMessage(intent *appservice.IntentAPI, info *types.MessageInfo, msg *waProto.GroupInviteMessage) *ConvertedMessage {
|
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)
|
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{
|
content := &event.MessageEventContent{
|
||||||
MsgType: event.MsgText,
|
MsgType: event.MsgText,
|
||||||
Body: format.HTMLToText(htmlMessage),
|
Body: format.HTMLToText(htmlMessage),
|
||||||
|
|
Loading…
Reference in a new issue