mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-04-25 22:58:12 +00:00
[AB-xxx] refactoring to use a separate updated column for the auto closing
wrapping modmail thread actions into a separate transaction
This commit is contained in:
@@ -92,8 +92,8 @@ public class ModmailAutoCloseListener implements ModmailThreadActionListener {
|
||||
}
|
||||
|
||||
private static Instant getTimeStampToConsider(ModMailThread thread) {
|
||||
if(thread.getUpdated() != null) {
|
||||
return thread.getUpdated();
|
||||
if(thread.getLastUpdated() != null) {
|
||||
return thread.getLastUpdated();
|
||||
}
|
||||
return thread.getCreated();
|
||||
}
|
||||
|
||||
@@ -53,6 +53,7 @@ import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
@@ -287,26 +288,33 @@ public class ModMailThreadServiceBean implements ModMailThreadService {
|
||||
.serverId(thread.getServer().getId())
|
||||
.serverUser(ServerUser.fromAUserInAServer(thread.getUser()))
|
||||
.messageCount(thread.getMessages() != null ? thread.getMessages().size() : 0)
|
||||
.updated(thread.getUpdated())
|
||||
.updated(thread.getLastUpdated())
|
||||
.created(thread.getCreated())
|
||||
.subscriberCount(thread.getSubscribers() != null ? thread.getSubscribers().size() : 0)
|
||||
.build();
|
||||
for (ModmailThreadActionListener modmailThreadActionListener : threadActionListeners) {
|
||||
try {
|
||||
log.info("Executing action {} for thread {}.", modmailThreadActionListener.getClass().getSimpleName(), model.getThreadId());
|
||||
ModmailThreadActionListener.ModmailThreadActionListenerResult result = modmailThreadActionListener.execute(model);
|
||||
ModmailThreadActionListener.ModmailThreadActionListenerResult result =
|
||||
self.executeThreadAction(modmailThreadActionListener, model);
|
||||
if(ModmailThreadActionListener.ModmailThreadActionListenerResult.FINAL == result) {
|
||||
log.info("Listener {} terminated for thread {}.", modmailThreadActionListener.getClass().getSimpleName(), model.getThreadId());
|
||||
break;
|
||||
}
|
||||
} catch (Exception exception) {
|
||||
log.error("Action failed to execute.", exception);
|
||||
log.error("Action failed to execute for thread {}.", thread.getId(), exception);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Transactional(propagation = Propagation.REQUIRES_NEW)
|
||||
public ModmailThreadActionListener.ModmailThreadActionListenerResult executeThreadAction(
|
||||
ModmailThreadActionListener modmailThreadActionListener, ModmailThreadActionListenerModel model) {
|
||||
return modmailThreadActionListener.execute(model);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is responsible for creating the instance in the database, sending the header in the newly created text channel and forwarding the initial message
|
||||
* by the user (if any), after this is complete, this method executes the method to perform the mod mail notification.
|
||||
|
||||
@@ -116,6 +116,7 @@ public class ModMailThreadManagementServiceBean implements ModMailThreadManageme
|
||||
.user(userInAServer)
|
||||
.server(userInAServer.getServerReference())
|
||||
.state(ModMailThreadState.INITIAL)
|
||||
.lastUpdated(Instant.now())
|
||||
.updated(Instant.now())
|
||||
.appeal(appeal)
|
||||
.build();
|
||||
@@ -133,6 +134,7 @@ public class ModMailThreadManagementServiceBean implements ModMailThreadManageme
|
||||
} else {
|
||||
modMailThread.setState(newState);
|
||||
}
|
||||
modMailThread.setLastUpdated(Instant.now());
|
||||
modMailThread.setUpdated(Instant.now());
|
||||
modMailThreadRepository.save(modMailThread);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
||||
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.26.xsd" >
|
||||
<include file="tables/tables.xml" relativeToChangelogFile="true"/>
|
||||
</databaseChangeLog>
|
||||
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
||||
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.26.xsd" >
|
||||
<changeSet author="Sheldan" id="mod_mail_thread-add_last_updated_column">
|
||||
<addColumn tableName="mod_mail_thread">
|
||||
<column name="last_updated" type="TIMESTAMP WITHOUT TIME ZONE" defaultValueComputed="CURRENT_TIMESTAMP">
|
||||
<constraints nullable="true" />
|
||||
</column>
|
||||
</addColumn>
|
||||
</changeSet>
|
||||
</databaseChangeLog>
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
||||
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.26.xsd" >
|
||||
<include file="modmail_thread.xml" relativeToChangelogFile="true"/>
|
||||
</databaseChangeLog>
|
||||
@@ -6,4 +6,5 @@
|
||||
<include file="1.5.37/collection.xml" relativeToChangelogFile="true"/>
|
||||
<include file="1.5.51/collection.xml" relativeToChangelogFile="true"/>
|
||||
<include file="1.6.22/collection.xml" relativeToChangelogFile="true"/>
|
||||
<include file="1.6.23/collection.xml" relativeToChangelogFile="true"/>
|
||||
</databaseChangeLog>
|
||||
@@ -56,6 +56,9 @@ public class ModMailThread implements Serializable {
|
||||
@Column(name = "updated", insertable = false, updatable = false)
|
||||
private Instant updated;
|
||||
|
||||
@Column(name = "last_updated")
|
||||
private Instant lastUpdated;
|
||||
|
||||
@Column(name = "closed")
|
||||
private Instant closed;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user