feat: add im home and message action flows
This commit is contained in:
+24
-7
@@ -1013,8 +1013,12 @@ func (t *Topic) sendSubNotifications(asUid types.Uid, sid, userAgent string) {
|
||||
// in response to a client request (msg, asUid) and broadcasts it to the attached sessions.
|
||||
func (t *Topic) saveAndBroadcastMessage(msg *ClientComMessage, asUid types.Uid, noEcho bool, attachments []string, head map[string]any, content any) error {
|
||||
pud, userFound := t.perUser[asUid]
|
||||
// Anyone is allowed to post to 'sys' topic.
|
||||
if t.cat != types.TopicCatSys {
|
||||
if t.cat == types.TopicCatSys {
|
||||
if msg.sess != nil && msg.sess.authLvl != auth.LevelRoot {
|
||||
msg.sess.queueOut(ErrPermissionDenied(msg.Id, t.original(asUid), msg.Timestamp))
|
||||
return types.ErrPermissionDenied
|
||||
}
|
||||
} else {
|
||||
// If it's not 'sys' check write permission.
|
||||
if !(pud.modeWant & pud.modeGiven).IsWriter() {
|
||||
msg.sess.queueOut(ErrPermissionDenied(msg.Id, t.original(asUid), msg.Timestamp))
|
||||
@@ -1032,9 +1036,14 @@ func (t *Topic) saveAndBroadcastMessage(msg *ClientComMessage, asUid types.Uid,
|
||||
// Make sure the received Head does not include a fake "sender" header.
|
||||
delete(head, "sender")
|
||||
}
|
||||
if msg.sess != nil && msg.sess.authLvl != auth.LevelRoot {
|
||||
if msgType, _ := head["type"].(string); msgType == "system" {
|
||||
msg.sess.queueOut(ErrPermissionDenied(msg.Id, t.original(asUid), msg.Timestamp))
|
||||
return types.ErrPermissionDenied
|
||||
}
|
||||
}
|
||||
|
||||
markedReadBySender := false
|
||||
if err, unreadUpdated := store.Messages.Save(t.tenantID,
|
||||
saveResult, err := store.Messages.Save(t.tenantID,
|
||||
&types.Message{
|
||||
ObjHeader: types.ObjHeader{CreatedAt: msg.Timestamp},
|
||||
TenantID: t.tenantID,
|
||||
@@ -1043,14 +1052,22 @@ func (t *Topic) saveAndBroadcastMessage(msg *ClientComMessage, asUid types.Uid,
|
||||
From: asUid.String(),
|
||||
Head: head,
|
||||
Content: content,
|
||||
}, attachments, (pud.modeGiven & pud.modeWant).IsReader()); err != nil {
|
||||
}, attachments, (pud.modeGiven & pud.modeWant).IsReader())
|
||||
if err != nil {
|
||||
logs.Warn.Printf("topic[%s]: failed to save message: %v", t.name, err)
|
||||
msg.sess.queueOut(ErrUnknown(msg.Id, t.original(asUid), msg.Timestamp))
|
||||
|
||||
return err
|
||||
} else {
|
||||
markedReadBySender = unreadUpdated
|
||||
}
|
||||
if saveResult != nil && saveResult.Duplicate {
|
||||
if msg.Id != "" && msg.sess != nil {
|
||||
reply := NoErrAccepted(msg.Id, t.original(asUid), msg.Timestamp)
|
||||
reply.Ctrl.Params = map[string]any{"seq": saveResult.SeqId}
|
||||
msg.sess.queueOut(reply)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
markedReadBySender := saveResult != nil && saveResult.MarkedReadBySender
|
||||
|
||||
t.lastID++
|
||||
t.touched = msg.Timestamp
|
||||
|
||||
Reference in New Issue
Block a user