-
Notifications
You must be signed in to change notification settings - Fork 0
/
User.py
42 lines (34 loc) · 1.53 KB
/
User.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# The User class contains the name of the user, as well as a messageList,
# with values of type Message. As the user makes/deletes offers, the messageList will be updated with his/her current messages.
from Message import Message
class User:
def __init__(self, name):
# Name to call the User
self.name = name
# List of active messages that the User has send/edited.
self.messageList = []
# Should User want to access a certain message in messageList (through Manage Posts), this will track the requested index
self.requestedIndex = 0
# Adds a new message to the end of the messageList
def addMessage(self, type):
self.messageList.append(Message(type))
# Lists all active messages that the User has
def listMessages(self):
self.clearUnsentMessages()
text = ""
for i in range(len(self.messageList)):
message = self.messageList[i]
status = message.getstatus()
text += (str(i + 1) + ": " + message.title + " " + status + '\n')
return text
# Deletes all unused messages in the messageList (To reduce space used, and easier listMessages functionality)
def clearUnsentMessages(self):
i = 0
while (i < len(self.messageList)):
if(self.messageList[i].id == 0):
del self.messageList[i]
continue
i += 1
# MUTATOR
def setRequestedIndex(self, index):
self.requestedIndex = index