mirror of
https://github.com/amigan/aim-oscar-server.git
synced 2024-11-21 12:09:48 -05:00
only store messages if they're meant to be stored
This commit is contained in:
parent
7af076ff6a
commit
9a28132dae
3 changed files with 26 additions and 9 deletions
|
@ -68,9 +68,11 @@ func MessageDelivery(sm *SessionManager) (chan *models.Message, routineFn) {
|
|||
log.Printf("sent message %d to user %s at %s", message.Cookie, message.To, s.RemoteAddr())
|
||||
}
|
||||
|
||||
if message.StoreOffline {
|
||||
if err := message.MarkDelivered(context.Background(), db); err != nil {
|
||||
log.Panicf("could not mark message %d as delivered: %s", message.Cookie, err.Error())
|
||||
}
|
||||
}
|
||||
} else {
|
||||
log.Printf("could not find session for user %s", message.To)
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ type Message struct {
|
|||
From string
|
||||
To string
|
||||
Contents string
|
||||
StoreOffline bool
|
||||
CreatedAt time.Time `bun:",nullzero,notnull,default:current_timestamp"`
|
||||
DeliveredAt time.Time `bun:",nullzero"`
|
||||
}
|
||||
|
@ -26,6 +27,7 @@ func InsertMessage(ctx context.Context, db *bun.DB, cookie uint64, from string,
|
|||
From: from,
|
||||
To: to,
|
||||
Contents: contents,
|
||||
StoreOffline: true,
|
||||
}
|
||||
if _, err := db.NewInsert().Model(msg).Exec(ctx, msg); err != nil {
|
||||
return nil, errors.Wrap(err, "could not update user")
|
||||
|
|
|
@ -176,10 +176,23 @@ func (icbm *ICBM) HandleSNAC(ctx context.Context, db *bun.DB, snac *oscar.SNAC)
|
|||
return ctx, errors.New("read insufficient data from message fragment")
|
||||
}
|
||||
|
||||
message, err := models.InsertMessage(ctx, db, msgID, user.Username, to, string(messageContents))
|
||||
var message *models.Message
|
||||
|
||||
// TLV 0x6 is the client telling the server to store the message if the recipient is offline
|
||||
saveofflineTLV := oscar.FindTLV(tlvs, 6)
|
||||
if saveofflineTLV != nil {
|
||||
message, err = models.InsertMessage(ctx, db, msgID, user.Username, to, string(messageContents))
|
||||
if err != nil {
|
||||
return ctx, errors.Wrap(err, "could not insert message")
|
||||
}
|
||||
} else {
|
||||
message = &models.Message{
|
||||
Cookie: msgID,
|
||||
From: user.Username,
|
||||
To: to,
|
||||
Contents: string(messageContents),
|
||||
}
|
||||
}
|
||||
|
||||
// Fire the message off into the communication channel to get delivered
|
||||
icbm.CommCh <- message
|
||||
|
|
Loading…
Reference in a new issue