MCPcopy Create free account
hub / github.com/chanify/chanify / sendDirect

Method sendDirect

core/sender.go:108–131  ·  view source on GitHub ↗
(ctx sendContext, token *model.Token, msg *model.Message)

Source from the content-addressed store, hash-verified

106}
107
108func (c *Core) sendDirect(ctx sendContext, token *model.Token, msg *model.Message) {
109 uid := token.GetUserID()
110 key, err := c.logic.GetUserKey(uid)
111 if err != nil {
112 ctx.JSON(http.StatusBadRequest, gin.H{"res": http.StatusBadRequest, "msg": "invalid user"})
113 return
114 }
115 devs, err := c.logic.GetDevices(uid)
116 if err != nil || len(devs) <= 0 {
117 ctx.JSON(http.StatusNotFound, gin.H{"res": http.StatusNotFound, "msg": "no devices found"})
118 return
119 }
120 out := msg.EncryptData(key, uint64(time.Now().UTC().UnixNano()))
121 if len(out) > 4000 {
122 ctx.JSON(http.StatusRequestEntityTooLarge, gin.H{"res": http.StatusRequestEntityTooLarge, "msg": "message body too large"})
123 return
124 }
125 uuid, n := c.logic.SendAPNS(uid, out, devs, int(msg.Priority), "passive", msg.IsTimeline())
126 if n <= 0 {
127 ctx.JSON(http.StatusNotFound, gin.H{"res": http.StatusNotFound, "msg": "no devices send success"})
128 return
129 }
130 ctx.JSON(http.StatusOK, gin.H{"request-uid": uuid})
131}
132
133func (c *Core) sendForward(ctx sendContext, token *model.Token, msg *model.Message) {
134 msg.DisableToken()

Callers 4

sendMsgMethod · 0.95
TestSendDirectFunction · 0.80
TestSendDirectWatchFunction · 0.80
TestSendDirectMacOSFunction · 0.80

Calls 7

GetUserIDMethod · 0.80
GetUserKeyMethod · 0.80
EncryptDataMethod · 0.80
SendAPNSMethod · 0.80
IsTimelineMethod · 0.80
JSONMethod · 0.65
GetDevicesMethod · 0.65

Tested by 3

TestSendDirectFunction · 0.64
TestSendDirectWatchFunction · 0.64
TestSendDirectMacOSFunction · 0.64