mirror of
https://github.com/status-im/status-go.git
synced 2025-02-16 16:56:53 +00:00
Added emoji_reaction persistence
This commit is contained in:
parent
241439e56b
commit
fdc180039f
@ -8,6 +8,8 @@ type EmojiReaction struct {
|
||||
// ID calculated as keccak256(compressedAuthorPubKey, data) where data is unencrypted payload.
|
||||
ID string
|
||||
|
||||
Clock uint64
|
||||
|
||||
// MessageID the ID of the target message that the user wishes to react to
|
||||
MessageID string
|
||||
|
||||
|
@ -705,3 +705,54 @@ func (db sqlitePersistence) BlockContact(contact *Contact) ([]*Chat, error) {
|
||||
|
||||
return chats, err
|
||||
}
|
||||
|
||||
func (db sqlitePersistence) SaveEmojiReaction(emojiReaction *EmojiReaction) (err error) {
|
||||
tx, err := db.db.BeginTx(context.Background(), &sql.TxOptions{})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer func() {
|
||||
if err == nil {
|
||||
err = tx.Commit()
|
||||
return
|
||||
}
|
||||
// don't shadow original error
|
||||
_ = tx.Rollback()
|
||||
}()
|
||||
|
||||
allFields := db.tableEmojiReactionsAllFields()
|
||||
valuesVector := strings.Repeat("?, ", db.tableEmojiReactionsAllFieldsCount()-1) + "?"
|
||||
query := "INSERT INTO emoji_reactions(" + allFields + ") VALUES (" + valuesVector + ")" // nolint: gosec
|
||||
stmt, err := tx.Prepare(query)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
allValues := []interface{}{
|
||||
emojiReaction.ID,
|
||||
emojiReaction.Clock,
|
||||
emojiReaction.From,
|
||||
emojiReaction.EmojiID,
|
||||
emojiReaction.MessageID,
|
||||
emojiReaction.ChatID,
|
||||
emojiReaction.Retracted,
|
||||
}
|
||||
|
||||
_, err = stmt.Exec(allValues...)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (db sqlitePersistence) tableEmojiReactionsAllFields() string {
|
||||
return `id,
|
||||
clock_value,
|
||||
source,
|
||||
emoji_id,
|
||||
message_id,
|
||||
chat_id,
|
||||
retracted`
|
||||
}
|
||||
|
||||
func (db sqlitePersistence) tableEmojiReactionsAllFieldsCount() int {
|
||||
return strings.Count(db.tableEmojiReactionsAllFields(), ",") + 1
|
||||
}
|
||||
|
@ -3269,6 +3269,7 @@ func (m *Messenger) SendEmojiReaction(ctx context.Context, chatID, messageID str
|
||||
|
||||
emojiR := &EmojiReaction{
|
||||
ID: types.EncodeHex(id),
|
||||
Clock: clock,
|
||||
MessageID: messageID,
|
||||
ChatID: chatID,
|
||||
EmojiID: protobuf.EmojiReaction_Type(emojiID),
|
||||
@ -3279,12 +3280,18 @@ func (m *Messenger) SendEmojiReaction(ctx context.Context, chatID, messageID str
|
||||
response.EmojiReactions = []*EmojiReaction{emojiR}
|
||||
response.Chats = []*Chat{chat}
|
||||
|
||||
// TODO emoji reaction persistence
|
||||
err = m.persistence.SaveEmojiReaction(emojiR)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &response, nil
|
||||
}
|
||||
|
||||
func (m *Messenger) SendEmojiReactionRetraction(ctx context.Context, EmojiReactionID string) (*MessengerResponse, error) {
|
||||
// TODO
|
||||
|
||||
// TODO check that the sender is the key owner
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user