Skip to content

Commit

Permalink
do not create duplicate notifications for refetched posts
Browse files Browse the repository at this point in the history
  • Loading branch information
velzie committed Jan 3, 2025
1 parent 8dae17e commit 2ea2fd7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
5 changes: 4 additions & 1 deletion include/database.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,17 @@ namespace Database {

#define INSERT_OR_UPDATE(object, pkey, key, value)\
auto _query = STATEMENT(FMT("SELECT * FROM {} where {} = ? LIMIT 1", object.__table, #pkey));\
bool isNew = false;\
_query.bind(1, object.pkey);\
int _r;\
if (_query.executeStep()) {\
object.key = (string)_query.getColumn(#key);\
_r = object.update();\
}else {\
isNew = false;\
} else {\
object.key = value;\
_r = object.insert();\
isNew = true;\
}\

#define F(name)\
Expand Down
12 changes: 7 additions & 5 deletions src/entities/Note.cc
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,13 @@ Note Note::ingest(const json note) {

INSERT_OR_UPDATE(n, uri, id, utils::genid());

vector<string> alreadyNotifiedIds;
for (auto u : localUsersMentioned) {
if (std::find(alreadyNotifiedIds.begin(), alreadyNotifiedIds.end(), u.id) == alreadyNotifiedIds.end()) {
NotificationService::createMention(n, uOwner, u);
alreadyNotifiedIds.push_back(u.id);
if (isNew) {
vector<string> alreadyNotifiedIds;
for (auto u : localUsersMentioned) {
if (std::find(alreadyNotifiedIds.begin(), alreadyNotifiedIds.end(), u.id) == alreadyNotifiedIds.end()) {
NotificationService::createMention(n, uOwner, u);
alreadyNotifiedIds.push_back(u.id);
}
}
}

Expand Down

0 comments on commit 2ea2fd7

Please sign in to comment.