mirror of
https://dev.narayana.im/narayana/telegabber.git
synced 2026-08-05 04:07:07 +00:00
Start refactoring SendMessage functions to varargs
This commit is contained in:
parent
0d5d8e45b0
commit
0ab4073cc0
1 changed files with 106 additions and 13 deletions
|
|
@ -130,7 +130,11 @@ func ResourcePrep(resource string) (string, error) {
|
||||||
|
|
||||||
// SendMessage creates and sends a message stanza
|
// SendMessage creates and sends a message stanza
|
||||||
func SendMessage(to, from, body, id string, component *xmpp.Component, reply *Reply, timestamp int64, replaceId string, isCarbon, isGroupchat, requestReceipt bool, originalFrom, stanzaId, mamQueryId, mucJID string, mucUserItem *MUCUserItem) {
|
func SendMessage(to, from, body, id string, component *xmpp.Component, reply *Reply, timestamp int64, replaceId string, isCarbon, isGroupchat, requestReceipt bool, originalFrom, stanzaId, mamQueryId, mucJID string, mucUserItem *MUCUserItem) {
|
||||||
sendMessageWrapper(to, from, body, "", "", id, component, reply, nil, timestamp, "", replaceId, isCarbon, isGroupchat, false, requestReceipt, originalFrom, 0, "", stanzaId, 0, mamQueryId, mucJID, mucUserItem)
|
sendMessageWrapper(to, from, component,
|
||||||
|
SMBody(body), SMId(id), SMReply(reply), SMTimestamp(timestamp), SMReplaceId(replaceId),
|
||||||
|
SMIsCarbon(isCarbon), SMIsGroupchat(isGroupchat), SMRequestReceipt(requestReceipt),
|
||||||
|
SMOriginalFrom(originalFrom), SMStanzaId(stanzaId), SMMamQueryId(mamQueryId), SMMucJID(mucJID), SMMucUserItem(mucUserItem),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendServiceMessage creates and sends a simple message stanza from transport
|
// SendServiceMessage creates and sends a simple message stanza from transport
|
||||||
|
|
@ -139,7 +143,7 @@ func SendServiceMessage(to, body string, component *xmpp.Component) {
|
||||||
if uuid, err := uuid.NewRandom(); err == nil {
|
if uuid, err := uuid.NewRandom(); err == nil {
|
||||||
id = uuid.String()
|
id = uuid.String()
|
||||||
}
|
}
|
||||||
sendMessageWrapper(to, "", body, "", "", id, component, nil, nil, 0, "", "", false, false, false, false, "", 0, "", "", 0, "", "", nil)
|
sendMessageWrapper(to, "", component, SMBody(body), SMId(id))
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendTextMessage creates and sends a simple message stanza
|
// SendTextMessage creates and sends a simple message stanza
|
||||||
|
|
@ -148,7 +152,7 @@ func SendTextMessage(to, from, body string, component *xmpp.Component, isGroupch
|
||||||
if uuid, err := uuid.NewRandom(); err == nil {
|
if uuid, err := uuid.NewRandom(); err == nil {
|
||||||
id = uuid.String()
|
id = uuid.String()
|
||||||
}
|
}
|
||||||
sendMessageWrapper(to, from, body, "", "", id, component, nil, nil, 0, "", "", false, isGroupchat, false, false, "", 0, "", "", 0, "", "", nil)
|
sendMessageWrapper(to, from, component, SMBody(body), SMId(id), SMIsGroupchat(isGroupchat))
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendMUCAnnouncement creates and sends a message by a temporary occupant
|
// SendMUCAnnouncement creates and sends a message by a temporary occupant
|
||||||
|
|
@ -173,7 +177,7 @@ func SendMUCAnnouncement(to, from, body, nickname, id string, component *xmpp.Co
|
||||||
id = uuid.String()
|
id = uuid.String()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sendMessageWrapper(to, fullFrom, body, "", "", id, component, nil, nil, 0, "", "", false, true, false, false, "", 0, "", "", 0, "", "", nil)
|
sendMessageWrapper(to, fullFrom, component, SMBody(body), SMId(id), SMIsGroupchat(true))
|
||||||
|
|
||||||
SendPresence(
|
SendPresence(
|
||||||
component,
|
component,
|
||||||
|
|
@ -188,43 +192,132 @@ func SendMUCAnnouncement(to, from, body, nickname, id string, component *xmpp.Co
|
||||||
|
|
||||||
// SendErrorMessage creates and sends an error message stanza
|
// SendErrorMessage creates and sends an error message stanza
|
||||||
func SendErrorMessage(to, from, text string, code int, isGroupchat bool, component *xmpp.Component) {
|
func SendErrorMessage(to, from, text string, code int, isGroupchat bool, component *xmpp.Component) {
|
||||||
sendMessageWrapper(to, from, "", "", text, "", component, nil, nil, 0, "", "", false, isGroupchat, false, false, "", code, "", "", 0, "", "", nil)
|
sendMessageWrapper(to, from, component, SMErrorText(text), SMIsGroupchat(isGroupchat), SMErrorCode(code))
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendErrorMessageWithBody creates and sends an error message stanza with body payload
|
// SendErrorMessageWithBody creates and sends an error message stanza with body payload
|
||||||
func SendErrorMessageWithBody(to, from, body, errorText, id string, code int, isGroupchat bool, component *xmpp.Component) {
|
func SendErrorMessageWithBody(to, from, body, errorText, id string, code int, isGroupchat bool, component *xmpp.Component) {
|
||||||
sendMessageWrapper(to, from, body, "", errorText, id, component, nil, nil, 0, "", "", false, isGroupchat, false, false, "", code, "", "", 0, "", "", nil)
|
sendMessageWrapper(to, from, component, SMBody(body), SMErrorText(errorText), SMId(id), SMIsGroupchat(isGroupchat), SMErrorCode(code))
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendMessageWithOOB creates and sends a message stanza with OOB URL
|
// SendMessageWithOOB creates and sends a message stanza with OOB URL
|
||||||
func SendMessageWithOOB(to, from, body, id string, component *xmpp.Component, reply *Reply, timestamp int64, oob, replaceId string, isCarbon, isGroupchat, requestReceipt bool, originalFrom, stanzaId, mamQueryId, mucJID string, mucUserItem *MUCUserItem) {
|
func SendMessageWithOOB(to, from, body, id string, component *xmpp.Component, reply *Reply, timestamp int64, oob, replaceId string, isCarbon, isGroupchat, requestReceipt bool, originalFrom, stanzaId, mamQueryId, mucJID string, mucUserItem *MUCUserItem) {
|
||||||
sendMessageWrapper(to, from, body, "", "", id, component, reply, nil, timestamp, oob, replaceId, isCarbon, isGroupchat, false, requestReceipt, originalFrom, 0, "", stanzaId, 0, mamQueryId, mucJID, mucUserItem)
|
sendMessageWrapper(to, from, component,
|
||||||
|
SMBody(body), SMId(id), SMReply(reply), SMTimestamp(timestamp), SMOOB(oob), SMReplaceId(replaceId),
|
||||||
|
SMIsCarbon(isCarbon), SMIsGroupchat(isGroupchat), SMRequestReceipt(requestReceipt),
|
||||||
|
SMOriginalFrom(originalFrom), SMStanzaId(stanzaId), SMMamQueryId(mamQueryId), SMMucJID(mucJID), SMMucUserItem(mucUserItem),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendSubjectMessage creates and sends a MUC subject
|
// SendSubjectMessage creates and sends a MUC subject
|
||||||
func SendSubjectMessage(to, from, subject, id string, component *xmpp.Component, timestamp int64) {
|
func SendSubjectMessage(to, from, subject, id string, component *xmpp.Component, timestamp int64) {
|
||||||
sendMessageWrapper(to, from, "", subject, "", id, component, nil, nil, timestamp, "", "", false, true, true, false, "", 0, "", "", 0, "", "", nil)
|
sendMessageWrapper(to, from, component, SMSubject(subject), SMId(id), SMTimestamp(timestamp), SMIsGroupchat(true), SMForceSubject(true))
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendMessageMarker creates and sends a message stanza with a XEP-0333 marker
|
// SendMessageMarker creates and sends a message stanza with a XEP-0333 marker
|
||||||
func SendMessageMarker(to string, from string, component *xmpp.Component, markerType MarkerType, markerId string) {
|
func SendMessageMarker(to string, from string, component *xmpp.Component, markerType MarkerType, markerId string) {
|
||||||
sendMessageWrapper(to, from, "", "", "", "", component, nil, &marker{
|
sendMessageWrapper(to, from, component, SMMarker(&marker{
|
||||||
Type: markerType,
|
Type: markerType,
|
||||||
Id: markerId,
|
Id: markerId,
|
||||||
}, 0, "", "", false, false, false, false, "", 0, "", "", 0, "", "", nil)
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendMUCInvite creates and send a MUC invitation message
|
// SendMUCInvite creates and send a MUC invitation message
|
||||||
func SendMUCInvite(to string, from string, component *xmpp.Component, inviteFrom string) {
|
func SendMUCInvite(to string, from string, component *xmpp.Component, inviteFrom string) {
|
||||||
sendMessageWrapper(to, from, "", "", "", "", component, nil, nil, 0, "", "", false, false, false, false, "", 0, inviteFrom, "", 0, "", "", nil)
|
sendMessageWrapper(to, from, component, SMInviteFrom(inviteFrom))
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendMUCStatusCode creates a groupchat message with a muc#user status code
|
// SendMUCStatusCode creates a groupchat message with a muc#user status code
|
||||||
func SendMUCStatusCode(to string, from string, component *xmpp.Component, statusCode int64) {
|
func SendMUCStatusCode(to string, from string, component *xmpp.Component, statusCode int64) {
|
||||||
sendMessageWrapper(to, from, "", "", "", "", component, nil, nil, 0, "", "", false, true, false, false, "", 0, "", "", statusCode, "", "", nil)
|
sendMessageWrapper(to, from, component, SMIsGroupchat(true), SMStatusCode(statusCode))
|
||||||
}
|
}
|
||||||
|
|
||||||
func sendMessageWrapper(to, from, body, subject, errorText, id string, component *xmpp.Component, reply *Reply, marker *marker, timestamp int64, oob, replaceId string, isCarbon, isGroupchat, forceSubject, requestReceipt bool, originalFrom string, errorCode int, inviteFrom, stanzaId string, statusCode int64, mamQueryId, mucJID string, mucUserItem *MUCUserItem) {
|
// SMBody is the message body
|
||||||
|
var SMBody = args.NewString()
|
||||||
|
|
||||||
|
// SMSubject is a MUC subject
|
||||||
|
var SMSubject = args.NewString()
|
||||||
|
|
||||||
|
// SMErrorText is the human-readable error text
|
||||||
|
var SMErrorText = args.NewString()
|
||||||
|
|
||||||
|
// SMId is the stanza id
|
||||||
|
var SMId = args.NewString()
|
||||||
|
|
||||||
|
// SMReply is a XEP-0461 reply reference (*Reply)
|
||||||
|
var SMReply = args.New()
|
||||||
|
|
||||||
|
// SMMarker is a XEP-0333 marker (*marker)
|
||||||
|
var SMMarker = args.New()
|
||||||
|
|
||||||
|
// SMTimestamp is a XEP-0203 delay timestamp
|
||||||
|
var SMTimestamp = args.NewInt64()
|
||||||
|
|
||||||
|
// SMOOB is a XEP-0066 out of band URL
|
||||||
|
var SMOOB = args.NewString()
|
||||||
|
|
||||||
|
// SMReplaceId is a XEP-0308 replaced message id
|
||||||
|
var SMReplaceId = args.NewString()
|
||||||
|
|
||||||
|
// SMIsCarbon marks the message as a XEP-0280 carbon copy
|
||||||
|
var SMIsCarbon = args.NewBool()
|
||||||
|
|
||||||
|
// SMIsGroupchat marks the message as a groupchat message
|
||||||
|
var SMIsGroupchat = args.NewBool()
|
||||||
|
|
||||||
|
// SMForceSubject forces an empty MUC subject element to be included
|
||||||
|
var SMForceSubject = args.NewBool()
|
||||||
|
|
||||||
|
// SMRequestReceipt requests a XEP-0184 receipt
|
||||||
|
var SMRequestReceipt = args.NewBool()
|
||||||
|
|
||||||
|
// SMOriginalFrom is a XEP-0033 original sender address
|
||||||
|
var SMOriginalFrom = args.NewString()
|
||||||
|
|
||||||
|
// SMErrorCode is a legacy numeric error code
|
||||||
|
var SMErrorCode = args.NewInt()
|
||||||
|
|
||||||
|
// SMInviteFrom is a XEP-0045 MUC direct invitation sender
|
||||||
|
var SMInviteFrom = args.NewString()
|
||||||
|
|
||||||
|
// SMStanzaId is a XEP-0359 stanza id
|
||||||
|
var SMStanzaId = args.NewString()
|
||||||
|
|
||||||
|
// SMStatusCode is a XEP-0045 muc#user status code
|
||||||
|
var SMStatusCode = args.NewInt64()
|
||||||
|
|
||||||
|
// SMMamQueryId is a XEP-0313 MAM query id (namespace-prefixed, space-separated)
|
||||||
|
var SMMamQueryId = args.NewString()
|
||||||
|
|
||||||
|
// SMMucJID is the real MUC room JID to send to
|
||||||
|
var SMMucJID = args.NewString()
|
||||||
|
|
||||||
|
// SMMucUserItem is a XEP-0045 muc#user item (*MUCUserItem)
|
||||||
|
var SMMucUserItem = args.New()
|
||||||
|
|
||||||
|
func sendMessageWrapper(to, from string, component *xmpp.Component, args ...args.V) {
|
||||||
|
body := SMBody.Get(args)
|
||||||
|
subject := SMSubject.Get(args)
|
||||||
|
errorText := SMErrorText.Get(args)
|
||||||
|
id := SMId.Get(args)
|
||||||
|
reply, _ := SMReply.Get(args).(*Reply)
|
||||||
|
marker, _ := SMMarker.Get(args).(*marker)
|
||||||
|
timestamp := SMTimestamp.Get(args)
|
||||||
|
oob := SMOOB.Get(args)
|
||||||
|
replaceId := SMReplaceId.Get(args)
|
||||||
|
isCarbon := SMIsCarbon.Get(args)
|
||||||
|
isGroupchat := SMIsGroupchat.Get(args)
|
||||||
|
forceSubject := SMForceSubject.Get(args)
|
||||||
|
requestReceipt := SMRequestReceipt.Get(args)
|
||||||
|
originalFrom := SMOriginalFrom.Get(args)
|
||||||
|
errorCode := SMErrorCode.Get(args)
|
||||||
|
inviteFrom := SMInviteFrom.Get(args)
|
||||||
|
stanzaId := SMStanzaId.Get(args)
|
||||||
|
statusCode := SMStatusCode.Get(args)
|
||||||
|
mamQueryId := SMMamQueryId.Get(args)
|
||||||
|
mucJID := SMMucJID.Get(args)
|
||||||
|
mucUserItem, _ := SMMucUserItem.Get(args).(*MUCUserItem)
|
||||||
|
|
||||||
toJid, err := stanza.NewJid(to)
|
toJid, err := stanza.NewJid(to)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithFields(log.Fields{
|
log.WithFields(log.Fields{
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue