feat: complete IM P0 and P1 reliability work
This commit is contained in:
+22
-3
@@ -1047,7 +1047,10 @@ func (t *Topic) saveAndBroadcastMessage(msg *ClientComMessage, asUid types.Uid,
|
||||
delete(head, "sender")
|
||||
}
|
||||
if msg.sess != nil && msg.sess.authLvl != auth.LevelRoot {
|
||||
if msgType, _ := head["type"].(string); msgType == "system" {
|
||||
legacyType, _ := head["type"].(string)
|
||||
productType, _ := head["x-im-type"].(string)
|
||||
if legacyType == "system" || legacyType == "system_event" ||
|
||||
productType == "system" || productType == "system_event" {
|
||||
msg.sess.queueOut(ErrPermissionDenied(msg.Id, t.original(asUid), msg.Timestamp))
|
||||
return types.ErrPermissionDenied
|
||||
}
|
||||
@@ -1060,6 +1063,20 @@ func (t *Topic) saveAndBroadcastMessage(msg *ClientComMessage, asUid types.Uid,
|
||||
}
|
||||
head = normalized
|
||||
}
|
||||
if t.cat == types.TopicCatGrp && msg.sess != nil && msg.sess.authLvl != auth.LevelRoot &&
|
||||
store.GroupBusiness != nil && store.Store != nil && store.Store.IsOpen() {
|
||||
access := pud.modeWant & pud.modeGiven
|
||||
canPost, err := store.GroupBusiness.CanPost(t.tenantID, t.name, asUid, access.IsAdmin(), msg.Timestamp)
|
||||
if err != nil {
|
||||
logs.Warn.Printf("topic[%s]: failed to check group mute policy: %v", t.name, err)
|
||||
msg.sess.queueOut(ErrUnknown(msg.Id, t.original(asUid), msg.Timestamp))
|
||||
return err
|
||||
}
|
||||
if !canPost {
|
||||
msg.sess.queueOut(ErrPermissionDenied(msg.Id, t.original(asUid), msg.Timestamp))
|
||||
return types.ErrPermissionDenied
|
||||
}
|
||||
}
|
||||
if t.cat == types.TopicCatP2P && msg.sess != nil && msg.sess.authLvl != auth.LevelRoot &&
|
||||
store.Relations != nil && store.Store != nil && store.Store.IsOpen() {
|
||||
peer := t.p2pOtherUser(asUid)
|
||||
@@ -2301,7 +2318,7 @@ func (t *Topic) replyGetDesc(sess *Session, asUid types.Uid, _ bool, opts *MsgGe
|
||||
// because to stay in memory at least one of the users must be connected to topic.
|
||||
// FIXME(gene): it breaks when user A stays active in one session and connects-disconnects
|
||||
// from another session. The second session will not see correct LastSeen time and UserAgent.
|
||||
if pud.lastSeen != nil {
|
||||
if pud.lastSeen != nil && imCanViewLastSeen(t.tenantID, asUid, t.p2pOtherUser(asUid)) {
|
||||
desc.LastSeen = &MsgLastSeenInfo{
|
||||
When: pud.lastSeen,
|
||||
UserAgent: pud.lastUA,
|
||||
@@ -2733,8 +2750,10 @@ func (t *Topic) replyGetSub(sess *Session, asUid types.Uid, authLevel auth.Level
|
||||
// Reporting user's subscriptions to other topics. P2P topic name is the
|
||||
// UID of the other user.
|
||||
with := sub.GetWith()
|
||||
canViewLastSeen := true
|
||||
if with != "" {
|
||||
mts.Topic = with
|
||||
canViewLastSeen = imCanViewLastSeen(t.tenantID, asUid, types.ParseUserId(with))
|
||||
mts.Online = t.perSubs[with].online && !deleted && presencer
|
||||
} else if strings.HasPrefix(sub.Topic, "slf") {
|
||||
mts.Topic = "slf"
|
||||
@@ -2759,7 +2778,7 @@ func (t *Topic) replyGetSub(sess *Session, asUid types.Uid, authLevel auth.Level
|
||||
}
|
||||
|
||||
lastSeen := sub.GetLastSeen()
|
||||
if lastSeen != nil && !mts.Online {
|
||||
if lastSeen != nil && !mts.Online && canViewLastSeen {
|
||||
mts.LastSeen = &MsgLastSeenInfo{
|
||||
When: lastSeen,
|
||||
UserAgent: sub.GetUserAgent(),
|
||||
|
||||
Reference in New Issue
Block a user