MCPcopy Create free account
hub / github.com/daodst/chat / replyGetData

Method replyGetData

server/topic.go:900–928  ·  view source on GitHub ↗

replyGetData is a response to a get.data request - load a list of stored messages, send them to session as {data} response goes to a single session rather than all sessions in a topic

(sess *Session, id string, req *MsgBrowseOpts)

Source from the content-addressed store, hash-verified

898// replyGetData is a response to a get.data request - load a list of stored messages, send them to session as {data}
899// response goes to a single session rather than all sessions in a topic
900func (t *Topic) replyGetData(sess *Session, id string, req *MsgBrowseOpts) error {
901 now := time.Now().UTC().Round(time.Millisecond)
902
903 opts := msgOpts2storeOpts(req, sess.tag, t.perUser[sess.uid].lastSeenTag[sess.tag])
904
905 messages, err := store.Messages.GetAll(sess.appid, t.name, opts)
906 if err != nil {
907 log.Println("topic: error loading topics ", err)
908 reply := ErrUnknown(id, t.original, now)
909 simpleByteSender(sess.send, reply)
910 return err
911 }
912 log.Println("Loaded messages ", len(messages))
913
914 // Push the list of updated topics to the client as data messages
915 if messages != nil {
916 for _, mm := range messages {
917 from := types.ParseUid(mm.From)
918 msg := &ServerComMessage{Data: &MsgServerData{
919 Topic: t.original,
920 From: from.UserId(),
921 Timestamp: mm.CreatedAt,
922 Content: mm.Content}}
923 simpleByteSender(sess.send, msg)
924 }
925 }
926
927 return nil
928}
929
930func (t *Topic) makeInvite(notify, target, from types.Uid, act types.InviteAction, modeWant,
931 modeGiven types.AccessMode, info interface{}) *ServerComMessage {

Callers 2

runMethod · 0.95
handleSubscriptionMethod · 0.95

Calls 4

msgOpts2storeOptsFunction · 0.85
ErrUnknownFunction · 0.85
simpleByteSenderFunction · 0.85
GetAllMethod · 0.80

Tested by

no test coverage detected